KrisLibrary  1.0.0
TriMeshOperators.h
Go to the documentation of this file.
1 #ifndef MESHING_TRI_MESH_OPERATORS_H
2 #define MESHING_TRI_MESH_OPERATORS_H
3 
4 #include "TriMeshTopology.h"
5 #include <KrisLibrary/utils/IntPair.h>
6 #include <KrisLibrary/errors.h>
7 #include <list>
8 
15 namespace Meshing {
16 
19 
21 inline Real Angle(const Vector3& e1,const Vector3& e2)
22 {
23  Real ne1=e1.norm();
24  Real ne2=e2.norm();
25  if(FuzzyZero(ne2) || FuzzyZero(ne1)) return Zero;
26  Real cosa = e1.dot(e2)/(ne1*ne2);
27  return Acos(Clamp(cosa,-One,One));
28 }
29 
31 inline int CCWNeighbor(const TriMeshWithTopology& mesh,int t,int v)
32 {
33  int vindex=mesh.tris[t].getIndex(v);
34  Assert(vindex>=0);
35  int eccw=(vindex+1)%3; //the ccw edge about v
36  return mesh.triNeighbors[t][eccw];
37 }
38 
40 inline int CWNeighbor(const TriMeshWithTopology& mesh,int t,int v)
41 {
42  int vindex=mesh.tris[t].getIndex(v);
43  Assert(vindex>=0);
44  int ecw=(vindex+2)%3; //the cw edge about v
45  return mesh.triNeighbors[t][ecw];
46 }
47 
49 inline IntPair Neighbors(const TriMeshWithTopology& mesh,int t,int v)
50 {
51  int vindex=mesh.tris[t].getIndex(v);
52  Assert(vindex>=0);
53  int eccw=(vindex+1)%3; //the ccw edge about v
54  int ecw=(vindex+2)%3; //the cw edge about v
55  return IntPair(mesh.triNeighbors[t][eccw],mesh.triNeighbors[t][ecw]);
56 }
57 
59 inline int CCWAdjacentVertex(const TriMeshWithTopology& mesh,int t,int v)
60 {
61  int vindex=mesh.tris[t].getIndex(v);
62  Assert(vindex>=0);
63  int eccw=(vindex+2)%3; //the ccw edge about v
64  return mesh.tris[t][eccw];
65 }
66 
68 inline int CWAdjacentVertex(const TriMeshWithTopology& mesh,int t,int v)
69 {
70  int vindex=mesh.tris[t].getIndex(v);
71  Assert(vindex>=0);
72  int ecw=(vindex+1)%3; //the cw edge about v
73  return mesh.tris[t][ecw];
74 }
75 
77 inline IntPair AdjacentVertices(const TriMeshWithTopology& mesh,int t,int v)
78 {
79  int vindex=mesh.tris[t].getIndex(v);
80  Assert(vindex>=0);
81  int eccw=(vindex+2)%3; //the ccw edge about v
82  int ecw=(vindex+1)%3; //the cw edge about v
83  return IntPair(mesh.tris[t][eccw],mesh.tris[t][ecw]);
84 }
85 
87 inline bool FloatingVertex(const TriMeshWithTopology& mesh,int v)
88 {
89  Assert(!mesh.incidentTris.empty());
90  return mesh.incidentTris[v].empty();
91 }
92 
94 inline bool BoundaryVertex(const TriMeshWithTopology& mesh,int v)
95 {
96  Assert(!mesh.incidentTris.empty());
97  Assert(!mesh.triNeighbors.empty());
98  for(size_t i=0;i<mesh.incidentTris[v].size();i++) {
99  int t=mesh.incidentTris[v][i];
100  IntPair n=Neighbors(mesh,t,v);
101  if(n.a < 0 || n.b < 0) return true;
102  }
103  return false;
104 }
105 
106 inline Real IncidentTriangleArea(const TriMeshWithTopology& mesh,int v)
107 {
108  Assert(!mesh.incidentTris.empty());
109  Real size=0;
110  Triangle3D tri;
111  for(size_t i=0;i<mesh.incidentTris[v].size();i++) {
112  mesh.GetTriangle(mesh.incidentTris[v][i],tri);
113  size += tri.area();
114  }
115  return size;
116 }
117 
120 bool IncidentTriangleOrdering(const TriMeshWithTopology& mesh,int v,vector<list<int> >& triStrips);
121 
124 Real VertexGaussianCurvature(const TriMeshWithTopology& mesh,int v);
125 
128 Real VertexAbsMeanCurvature(const TriMeshWithTopology& mesh,int v);
129 
132 void MergeVertices(TriMesh& mesh,Real tolerance,bool dropDegenerate=true);
133 
145 int ApproximateShrink(TriMeshWithTopology& mesh,Real amount,bool mergeFirst=true);
146 
149 } //namespace Meshing
150 
151 #endif
bool IncidentTriangleOrdering(const TriMeshWithTopology &mesh, int v, vector< list< int > > &triStrips)
Returns true if the vertex is a boundary vertex.
Definition: TriMeshOperators.cpp:13
IntPair AdjacentVertices(const TriMeshWithTopology &mesh, int t, int v)
Returns the vertices on t adjacent to v in (CCW,CW) order.
Definition: TriMeshOperators.h:77
The namespace for all classes/functions in the Meshing package.
Definition: AnyGeometry.h:11
A 3D vector class.
Definition: math3d/primitives.h:136
A triangle mesh that contains connectivity relations between vertices and triangles.
Definition: TriMeshTopology.h:31
int CCWAdjacentVertex(const TriMeshWithTopology &mesh, int t, int v)
Returns the vertex adjacent to v on the CCW side of t.
Definition: TriMeshOperators.h:59
A lightweight integer 2-tuple class.
Definition: IntPair.h:9
bool BoundaryVertex(const TriMeshWithTopology &mesh, int v)
Returns true if the vertex is a boundary vertex.
Definition: TriMeshOperators.h:94
bool FuzzyZero(double a, double eps=dEpsilon)
Returns true if a is zero within +/- eps.
Definition: math.h:224
IntPair Neighbors(const TriMeshWithTopology &mesh, int t, int v)
Returns the (CCW neighbor,CW neighbor) of t about v.
Definition: TriMeshOperators.h:49
int CWNeighbor(const TriMeshWithTopology &mesh, int t, int v)
Returns the triangle neighboring t CW about v.
Definition: TriMeshOperators.h:40
int ApproximateShrink(TriMeshWithTopology &mesh, Real amount, bool mergeFirst)
Definition: TriMeshOperators.cpp:260
Real VertexGaussianCurvature(const TriMeshWithTopology &mesh, int v)
Definition: TriMeshOperators.cpp:60
vector< TriNeighbors > triNeighbors
neighboring triangles of triangles
Definition: TriMeshTopology.h:59
void MergeVertices(TriMesh &mesh, Real tolerance, bool dropDegenerate)
Definition: TriMeshOperators.cpp:200
bool FloatingVertex(const TriMeshWithTopology &mesh, int v)
Returns true if the vertex is "floating".
Definition: TriMeshOperators.h:87
double Clamp(double x, double a, double b)
Returns a if x < a, b if x > b, otherwise x.
Definition: math.h:209
int CCWNeighbor(const TriMeshWithTopology &mesh, int t, int v)
Returns the triangle neighboring t CCW about v.
Definition: TriMeshOperators.h:31
int CWAdjacentVertex(const TriMeshWithTopology &mesh, int t, int v)
Returns the vertex adjacent to v on the CCW side of t.
Definition: TriMeshOperators.h:68
A 3D triangle class.
Definition: Triangle3D.h:26
Real Angle(const Vector3 &e1, const Vector3 &e2)
Returns the angle between two vectors.
Definition: TriMeshOperators.h:21
A basic triangle mesh.
Definition: TriMesh.h:41
Real VertexAbsMeanCurvature(const TriMeshWithTopology &mesh, int v)
Definition: TriMeshOperators.cpp:115
void GetTriangle(int tri, Triangle3D &t) const
Returns a Triangle3D structure for triangle tri.
Definition: TriMesh.cpp:35
vector< vector< int > > incidentTris
triangles incident on vertices
Definition: TriMeshTopology.h:58