CFx SDK Documentation  2023 SP0
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 
tol
Definition: DimVarDefs.h:2287
#define GE_TOOLKIT_EXPORT
Definition: GeExport.h:49
#define NULL
Definition: GsProperties.h:177
std::set< VertexPairKey > m_pairMap
OdArray< OdArray< int > > m_vxToPair
void computeErrorOnPair(int iPair)
virtual bool computeQ(int iVt)=0
void reset(OdGePoint3dArray &vx)
void reset(OdGeTrMesh &trng)
void algo(double simpPercent)
OdGeExtents3d getExtents() const
OdGePoint3dArray m_aVx
virtual int checkMeshMismatch(const OdGeMesh &mesh, OdGePoint3dArray &aPtMismatch, double tol) const =0
virtual double distanceTo(const OdGePoint3d &pt, OdGePoint3d &ptClosest, bool bPrecise) const =0
OdArray< OdGeTr > m_aTr
virtual double distanceTo(const OdGePoint3d &pt, OdGePoint3d &ptClosest, bool bPrecise) const
int getCoEdge(int t, int e) const
OdArray< OdArray< intPair > > m_vxToTr
OdGeVector3d vxNormal(int v) const
bool walkAroundVertex(int &iTr, int &w, int3 &aux) const
OdGeVector3d trNormal(int t, double *area=NULL) const
virtual int checkMeshMismatch(const OdGeMesh &mesh, OdGePoint3dArray &aPtMismatch, double tol) const
void removeDegenerateTriangles(double tol)
bool walkNextTr(int &iTr, int &w, bool dir) const
GLfloat GLfloat v1
Definition: gles2_ext.h:295
GLfloat GLfloat GLfloat v2
Definition: gles2_ext.h:296
GLfloat GLfloat GLfloat GLfloat w
Definition: gles2_ext.h:320
const GLfloat * v
Definition: gles2_ext.h:315
std::pair< int, int > intPair
GE_TOOLKIT_EXPORT bool triangulateProfile(const OdGePoint2dArray &vertexSource, const std::vector< OdInt32 > &inFaceData, OdArray< OdInt32 > &vecTriangles)
void replaceNb(int nbOld, int nbNew)
void replace(int a, int b)
bool equal(VertexPair &pair)
VertexPairKey(double cost, int ind)
int operator[](unsigned int i) const