CFx SDK Documentation  2020SP3
GeTrMeshSimplification.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef OD_GETRSIMPLIFICATION_H
25 #define OD_GETRSIMPLIFICATION_H
26 
27 
28 #include "OdPlatformSettings.h"
29 #include "GePoint3dArray.h"
30 #include "GeExtents3d.h"
31 #include "Ge/GePoint2dArray.h"
32 #include <set>
33 #include <vector>
34 
35 namespace GeMesh
36 {
37 typedef std::pair<int, int> intPair;
38 
39 struct int3
40 {
41  int3() { val[0] = val[1] = val[2] = 0; }
42  void set(int a) { val[0] = val[1] = val[2] = a; }
43  int operator [](unsigned int i) const
44  {
45  return val[i];
46  }
47  int& operator [](unsigned int i)
48  {
49  return val[i];
50  }
51  int val[3];
52 };
53 
55 {
56  OdGeTr() : tagFace(-1) { nb.set(-1); tagEdge.set(-1); }
57  void replaceNb(int nbOld, int nbNew);
58 
61  int tagFace;
63 };
64 
66 {
67 public:
69  virtual ~OdGeMesh() {}
70 
71  virtual double distanceTo(const OdGePoint3d& pt, OdGePoint3d& ptClosest, bool bPrecise) const = 0;
72  virtual int checkMeshMismatch(const OdGeMesh& mesh, OdGePoint3dArray& aPtMismatch, double tol) const = 0;
73 
74 public:
77 };
78 
80 {
81 public:
82  virtual double distanceTo(const OdGePoint3d& pt, OdGePoint3d& ptClosest, bool bPrecise) const;
83  virtual int checkMeshMismatch(const OdGeMesh& mesh, OdGePoint3dArray& aPtMismatch, double tol) const;
84 
85  OdGeVector3d trNormal(int t, double* area = NULL) const;
86  OdGeVector3d vxNormal(int v) const;
87  bool walkNextTr(int& iTr, int& w, bool dir) const;
88  bool walkAroundVertex(int& iTr, int& w, int3& aux) const;
89  int getCoEdge(int t, int e) const;
90  int fillNbLinks();
92  void clear();
93  void fillVxToTr();
94 public:
96 
97  // vector to assign vertices to triangles
99 };
100 
102 {
103  VertexPair() : m_cost(1e300) {}
104  VertexPair(int a, int b) { m_edge.first = a; m_edge.second = b; }
105  // is this point present in pair?
106  bool isPresent(int a) { return m_edge.first == a || m_edge.second == a; }
107  // is equal?
108  bool equal(VertexPair& pair) { return isPresent(pair.m_edge.first) && isPresent(pair.m_edge.second); }
109  void replace(int a, int b);
110  int nb(int a);
111 
112  // cost (error) of contraction this pair
113  double m_cost;
114  // indices of 2 vertices
116  // position of new point (after contraction) which minimizes error
118 };
119 
121 {
122  double m_cost;
123  int m_ind;
124  VertexPairKey(double cost, int ind) {m_cost = cost; m_ind = ind;}
125 };
126 
128 {
129 protected:
132  void computeErrorOnPair(int iPair);
133  virtual bool computeQ(int iVt) = 0;
134 
135 protected:
136  // vertices
138  // tolerance ^2
139  double m_eps2;
140  // max edge length
141  double m_maxEdLen2;
142  // quadrics to approximate error at each vertex
144  // contraction candidates
146  // vector to assign vertices to pairs
148  // map to keep pairs sorted by cost
149  std::set<VertexPairKey> m_pairMap;
150 };
151 
153 {
154 public:
156  void reset(OdGeTrMesh& trng);
157  void algo(double simpPercent);
158 
159 private:
160  virtual bool computeQ(int iVt);
161  bool isEdgeValid(int t, int v);
162  bool checkEdge(int t, int v);
163  bool checkOverlap(int v1, int v2);
164  int selectPairs();
165  int contractPair();
166  void removeGarbage();
167 #ifdef _DEBUG
168  bool checkVxToTr(int iVt);
169 #endif
170 
171 private:
172  // mesh to simplificate
173  OdGeTrMesh* m_pTrng;
174  // determines the vertex's fan type (0 - closed, 1 - open, 2 - corner)
175  OdArray<int> m_fanType;
176  // vector to assign vertices to triangles
177  //OdArray<OdArray<intPair > > m_vxToTr;
178 };
179 
180 GE_TOOLKIT_EXPORT bool triangulateProfile(const OdGePoint2dArray& vertexSource, const std::vector<OdInt32>& inFaceData, OdArray<OdInt32>& vecTriangles);
181 }
182 
183 #endif // OD_GETRSIMPLIFICATION_H
184 
GeMesh::GeSimplificationBase::m_pairMap
std::set< VertexPairKey > m_pairMap
Definition: GeTrMeshSimplification.h:149
GeMesh::OdGeMesh::m_aVxTag
OdArray< int > m_aVxTag
Definition: GeTrMeshSimplification.h:76
GeMesh::OdGeTrMesh::clear
void clear()
v1
GLfloat GLfloat v1
Definition: gles2_ext.h:295
OdGeVector3d
Definition: GeVector3d.h:54
NULL
#define NULL
Definition: GsProperties.h:177
GeMesh::OdGeTr::nb
int3 nb
Definition: GeTrMeshSimplification.h:60
GeMesh::OdGeTrMesh::m_aTr
OdArray< OdGeTr > m_aTr
Definition: GeTrMeshSimplification.h:95
GeMesh::OdGeTrMesh::walkNextTr
bool walkNextTr(int &iTr, int &w, bool dir) const
GeMesh::OdGeTrMesh::m_vxToTr
OdArray< OdArray< intPair > > m_vxToTr
Definition: GeTrMeshSimplification.h:98
GeMesh::VertexPair
Definition: GeTrMeshSimplification.h:102
tol
tol
Definition: DimVarDefs.h:2287
GeMesh::OdGeTrMesh::fillVxToTr
void fillVxToTr()
GeMesh::GeSimplificationBase::m_vxToPair
OdArray< OdArray< int > > m_vxToPair
Definition: GeTrMeshSimplification.h:147
GeMesh::VertexPair::replace
void replace(int a, int b)
GeExtents3d.h
GeMesh::VertexPair::nb
int nb(int a)
GeMesh::OdGeTr::tagFace
int tagFace
Definition: GeTrMeshSimplification.h:61
v2
GLfloat GLfloat GLfloat v2
Definition: gles2_ext.h:296
GeMesh::VertexPair::VertexPair
VertexPair(int a, int b)
Definition: GeTrMeshSimplification.h:104
GePoint3dArray.h
OdArray< OdGePoint3d, OdMemoryAllocator< OdGePoint3d > >
GeMesh::GeSimplificationBase::computeErrorOnPair
void computeErrorOnPair(int iPair)
GeMesh::VertexPair::m_newVx
OdGePoint3d m_newVx
Definition: GeTrMeshSimplification.h:117
GeMesh::VertexPairKey::m_ind
int m_ind
Definition: GeTrMeshSimplification.h:123
GeMesh::GeSimplificationBase::computeQ
virtual bool computeQ(int iVt)=0
GeMesh::GeTrngSimplification::algo
void algo(double simpPercent)
GeMesh::OdGeTr::replaceNb
void replaceNb(int nbOld, int nbNew)
GeMesh::VertexPairKey::VertexPairKey
VertexPairKey(double cost, int ind)
Definition: GeTrMeshSimplification.h:124
GeMesh::VertexPair::VertexPair
VertexPair()
Definition: GeTrMeshSimplification.h:103
w
GLfloat GLfloat GLfloat GLfloat w
Definition: gles2_ext.h:320
GeMesh::OdGeMesh::checkMeshMismatch
virtual int checkMeshMismatch(const OdGeMesh &mesh, OdGePoint3dArray &aPtMismatch, double tol) const =0
GeMesh::VertexPair::m_cost
double m_cost
Definition: GeTrMeshSimplification.h:113
GeMesh::OdGeMesh
Definition: GeTrMeshSimplification.h:66
GeMesh::GeTrngSimplification::GeTrngSimplification
GeTrngSimplification()
GeMesh::OdGeTr::tr
int3 tr
Definition: GeTrMeshSimplification.h:59
OdGePoint3d
Definition: GePoint3d.h:55
GeMesh::OdGeMesh::~OdGeMesh
virtual ~OdGeMesh()
Definition: GeTrMeshSimplification.h:69
GeMesh::GeSimplificationBase::m_pair
OdArray< VertexPair > m_pair
Definition: GeTrMeshSimplification.h:145
GeMesh::VertexPairKey::m_cost
double m_cost
Definition: GeTrMeshSimplification.h:122
GeMesh::GeSimplificationBase::reset
void reset(OdGePoint3dArray &vx)
GeMesh::GeSimplificationBase::GeSimplificationBase
GeSimplificationBase()
GeMesh::GeSimplificationBase
Definition: GeTrMeshSimplification.h:128
GeMesh::OdGeTrMesh::fillNbLinks
int fillNbLinks()
GeMesh::VertexPair::isPresent
bool isPresent(int a)
Definition: GeTrMeshSimplification.h:106
GeMesh::OdGeTr::OdGeTr
OdGeTr()
Definition: GeTrMeshSimplification.h:56
GeMesh::OdGeTrMesh
Definition: GeTrMeshSimplification.h:80
GeMesh::OdGeTr::tagEdge
int3 tagEdge
Definition: GeTrMeshSimplification.h:62
GeMesh::int3::operator[]
int operator[](unsigned int i) const
Definition: GeTrMeshSimplification.h:43
GeMesh::OdGeMesh::getExtents
OdGeExtents3d getExtents() const
GeMesh::OdGeTrMesh::vxNormal
OdGeVector3d vxNormal(int v) const
v
const GLfloat * v
Definition: gles2_ext.h:315
OdPlatformSettings.h
GeMesh::VertexPairKey
Definition: GeTrMeshSimplification.h:121
GeMesh::GeSimplificationBase::m_eps2
double m_eps2
Definition: GeTrMeshSimplification.h:139
GeMesh::GeTrngSimplification::reset
void reset(OdGeTrMesh &trng)
GeMesh::OdGeTrMesh::trNormal
OdGeVector3d trNormal(int t, double *area=NULL) const
GeMesh::GeTrngSimplification
Definition: GeTrMeshSimplification.h:153
GeMesh::OdGeTrMesh::checkMeshMismatch
virtual int checkMeshMismatch(const OdGeMesh &mesh, OdGePoint3dArray &aPtMismatch, double tol) const
GePoint2dArray.h
GeMesh::triangulateProfile
GE_TOOLKIT_EXPORT bool triangulateProfile(const OdGePoint2dArray &vertexSource, const std::vector< OdInt32 > &inFaceData, OdArray< OdInt32 > &vecTriangles)
GeMesh::intPair
std::pair< int, int > intPair
Definition: GeTrMeshSimplification.h:37
GeMesh::OdGeMesh::m_aVx
OdGePoint3dArray m_aVx
Definition: GeTrMeshSimplification.h:75
GeMesh::OdGeMesh::distanceTo
virtual double distanceTo(const OdGePoint3d &pt, OdGePoint3d &ptClosest, bool bPrecise) const =0
GeMesh::GeSimplificationBase::m_Q
OdArray< OdGeMatrix3d > m_Q
Definition: GeTrMeshSimplification.h:143
GeMesh
Definition: GeTrMeshSimplification.h:36
GE_TOOLKIT_EXPORT
#define GE_TOOLKIT_EXPORT
Definition: GeExport.h:49
OdGeExtents3d
Definition: GeExtents3d.h:45
GeMesh::GeSimplificationBase::m_pVx
OdGePoint3dArray * m_pVx
Definition: GeTrMeshSimplification.h:137
GeMesh::VertexPair::equal
bool equal(VertexPair &pair)
Definition: GeTrMeshSimplification.h:108
GeMesh::VertexPair::m_edge
intPair m_edge
Definition: GeTrMeshSimplification.h:115
GeMesh::int3::val
int val[3]
Definition: GeTrMeshSimplification.h:51
GeMesh::int3
Definition: GeTrMeshSimplification.h:40
GeMesh::OdGeTrMesh::getCoEdge
int getCoEdge(int t, int e) const
GeMesh::OdGeTr
Definition: GeTrMeshSimplification.h:55
GeMesh::OdGeTrMesh::removeDegenerateTriangles
void removeDegenerateTriangles(double tol)
GeMesh::OdGeTrMesh::walkAroundVertex
bool walkAroundVertex(int &iTr, int &w, int3 &aux) const
GeMesh::int3::set
void set(int a)
Definition: GeTrMeshSimplification.h:42
GeMesh::int3::int3
int3()
Definition: GeTrMeshSimplification.h:41
GeMesh::GeSimplificationBase::m_maxEdLen2
double m_maxEdLen2
Definition: GeTrMeshSimplification.h:141
GeMesh::OdGeTrMesh::distanceTo
virtual double distanceTo(const OdGePoint3d &pt, OdGePoint3d &ptClosest, bool bPrecise) const