CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
GeTrMeshSimplification.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 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 "Ge/GePoint3dArray.h"
30#include "Ge/GeExtents3d.h"
31#include "Ge/GePoint2dArray.h"
32#include "Ge/GeMatrix3dArray.h"
33#include "Ge/GeIntArray.h"
34#include <set>
35#include <vector>
36
37namespace GeMesh
38{
39typedef std::pair<int, int> intPair;
41
42struct int3
43{
44 int3() { val[0] = val[1] = val[2] = 0; }
45 void set(int a) { val[0] = val[1] = val[2] = a; }
46 int operator [](unsigned int i) const
47 {
48 return val[i];
49 }
50 int& operator [](unsigned int i)
51 {
52 return val[i];
53 }
54 int val[3];
55};
56
58{
59 OdGeTr() : tagFace(-1) { nb.set(-1); tagEdge.set(-1); }
60 void replaceNb(int nbOld, int nbNew);
61
66};
67
69{
70public:
76 virtual ~OdGeMesh() {}
77
78 virtual double distanceTo(const OdGePoint3d& pt, OdGePoint3d& ptClosest, bool bPrecise) const = 0;
79 virtual int checkMeshMismatch(const OdGeMesh& mesh, OdGePoint3dArray& aPtMismatch, double tol) const = 0;
80
81public:
85};
86
88{
89public:
90 virtual double distanceTo(const OdGePoint3d& pt, OdGePoint3d& ptClosest, bool bPrecise) const ODRX_OVERRIDE;
91 virtual int checkMeshMismatch(const OdGeMesh& mesh, OdGePoint3dArray& aPtMismatch, double tol) const ODRX_OVERRIDE;
92
93 OdGeVector3d trNormal(int t, double* area = NULL) const;
95 bool walkNextTr(int& iTr, int& w, bool dir) const;
96 bool walkAroundVertex(int& iTr, int& w, int3& aux) const;
97 int getCoEdge(int t, int e) const;
100 void append(const OdGeTrMesh& mesh);
101 void clear();
104
105 void dump(FILE* f) const;
106public:
108
109 // vector to assign vertices to triangles
111};
112
114{
115 VertexPair() : m_cost(1e300) {}
116 VertexPair(int a, int b) : m_cost(1e300) { m_edge.first = a; m_edge.second = b; }
117 // is this point present in pair?
118 bool isPresent(int a) { return m_edge.first == a || m_edge.second == a; }
119 // is equal?
120 bool equal(VertexPair& pair) { return isPresent(pair.m_edge.first) && isPresent(pair.m_edge.second); }
121 void replace(int a, int b);
122 int nb(int a);
123
124 // cost (error) of contraction this pair
125 double m_cost;
126 // indices of 2 vertices
128 // position of new point (after contraction) which minimizes error
130};
131
133{
134 double m_cost;
135 int m_ind;
136 VertexPairKey(double cost, int ind) {m_cost = cost; m_ind = ind;}
137};
138
140{
141protected:
144 void computeErrorOnPair(int iPair);
145 virtual bool computeQ(int iVt) = 0;
147
148protected:
149 // vertices
151 // tolerance ^2
152 double m_eps2;
153 // max edge length
155 // quadrics to approximate error at each vertex
157 // contraction candidates
159 // vector to assign vertices to pairs
161 // map to keep pairs sorted by cost
162 std::set<VertexPairKey> m_pairMap;
163};
164
166{
167public:
169 void reset(OdGeTrMesh& trng);
170 void algo(double simpPercent);
171
172private:
173 virtual bool computeQ(int iVt) ODRX_OVERRIDE;
174 bool isEdgeValid(int t, int v);
175 bool checkEdge(int t, int v);
176 bool checkOverlap(int v1, int v2);
177 int selectPairs();
178 int contractPair();
179 void removeGarbage();
180#ifdef _DEBUG
181 bool checkVxToTr(int iVt);
182#endif
183
184private:
185 // mesh to simplificate
186 OdGeTrMesh* m_pTrng;
187 // determines the vertex's fan type (0 - closed, 1 - open, 2 - corner)
188 OdGeIntArray m_fanType;
189};
190
202GE_TOOLKIT_EXPORT bool triangulateProfile(const OdGePoint2dArray& vertexSource, const std::vector<OdInt32>& inFaceData, OdArray<OdInt32>& vecTriangles, double tol = 0);
203
204GE_TOOLKIT_EXPORT bool compareMeshes(const OdGeTrMesh& meshTemplate, const OdGeTrMesh& mesh, double tolCoef, bool bDebugOutput);
205}
206
207#endif // OD_GETRSIMPLIFICATION_H
208
OdArray< OdGePoint3d, OdMemoryAllocator< OdGePoint3d > > OdGePoint3dArray
tol
#define GE_TOOLKIT_EXPORT
Definition GeExport.h:35
OdArray< OdGePoint2d, OdMemoryAllocator< OdGePoint2d > > OdGePoint2dArray
Definition GeGbl.h:45
OdArray< int, OdMemoryAllocator< int > > OdGeIntArray
Definition GeIntArray.h:35
OdArray< OdGeMatrix3d, OdMemoryAllocator< OdGeMatrix3d > > OdGeMatrix3dArray
#define ODRX_OVERRIDE
std::set< VertexPairKey > m_pairMap
OdArray< VertexPair, OdMemoryAllocator< VertexPair > > m_pair
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
virtual int checkMeshMismatch(const OdGeMesh &mesh, OdGePoint3dArray &aPtMismatch, double tol) const =0
virtual double distanceTo(const OdGePoint3d &pt, OdGePoint3d &ptClosest, bool bPrecise) const =0
virtual double distanceTo(const OdGePoint3d &pt, OdGePoint3d &ptClosest, bool bPrecise) const ODRX_OVERRIDE
int getCoEdge(int t, int e) const
OdArray< OdIntPairArray > m_vxToTr
OdGeVector3d vxNormal(int v) const
void append(const OdGeTrMesh &mesh)
void dump(FILE *f) const
bool walkAroundVertex(int &iTr, int &w, int3 &aux) const
void removeUnusedVertices()
virtual int checkMeshMismatch(const OdGeMesh &mesh, OdGePoint3dArray &aPtMismatch, double tol) const ODRX_OVERRIDE
OdGeVector3d trNormal(int t, double *area=NULL) const
void removeDegenerateTriangles(double tol)
bool walkNextTr(int &iTr, int &w, bool dir) const
GLfloat GLfloat v1
Definition gles2_ext.h:295
GLfloat f
Definition gles2_ext.h:564
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
GE_TOOLKIT_EXPORT bool compareMeshes(const OdGeTrMesh &meshTemplate, const OdGeTrMesh &mesh, double tolCoef, bool bDebugOutput)
std::pair< int, int > intPair
OdArray< intPair, OdMemoryAllocator< intPair > > OdIntPairArray
GE_TOOLKIT_EXPORT bool triangulateProfile(const OdGePoint2dArray &vertexSource, const std::vector< OdInt32 > &inFaceData, OdArray< OdInt32 > &vecTriangles, double tol=0)
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