GteETManifoldMesh.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.1 (2017/01/02)
7 
8 #pragma once
9 
10 #include <Mathematics/GteEdgeKey.h>
12 #include <map>
13 #include <memory>
14 #include <vector>
15 
16 namespace gte
17 {
18 
20 {
21 public:
22  // Edge data types.
23  class Edge;
24  typedef std::shared_ptr<Edge> (*ECreator)(int, int);
25  typedef std::map<EdgeKey<false>, std::shared_ptr<Edge>> EMap;
26 
27  // Triangle data types.
28  class Triangle;
29  typedef std::shared_ptr<Triangle> (*TCreator)(int, int, int);
30  typedef std::map<TriangleKey<true>, std::shared_ptr<Triangle>> TMap;
31 
32  // Edge object.
34  {
35  public:
36  virtual ~Edge();
37  Edge(int v0, int v1);
38 
39  // Vertices of the edge.
40  int V[2];
41 
42  // Triangles sharing the edge.
43  std::weak_ptr<Triangle> T[2];
44  };
45 
46  // Triangle object.
48  {
49  public:
50  virtual ~Triangle();
51  Triangle(int v0, int v1, int v2);
52 
53  // Vertices, listed in counterclockwise order (V[0],V[1],V[2]).
54  int V[3];
55 
56  // Adjacent edges. E[i] points to edge (V[i],V[(i+1)%3]).
57  std::weak_ptr<Edge> E[3];
58 
59  // Adjacent triangles. T[i] points to the adjacent triangle
60  // sharing edge E[i].
61  std::weak_ptr<Triangle> T[3];
62  };
63 
64 
65  // Construction and destruction.
66  virtual ~ETManifoldMesh();
67  ETManifoldMesh(ECreator eCreator = nullptr, TCreator tCreator = nullptr);
68 
69  // Support for a deep copy of the mesh. The mEMap and mTMap objects have
70  // dynamically allocated memory for edges and triangles. A shallow copy
71  // of the pointers to this memory is problematic. Allowing sharing, say,
72  // via std::shared_ptr, is an option but not really the intent of copying
73  // the mesh graph.
74  ETManifoldMesh(ETManifoldMesh const& mesh);
75  ETManifoldMesh& operator=(ETManifoldMesh const& mesh);
76 
77  // Member access.
78  EMap const& GetEdges() const;
79  TMap const& GetTriangles() const;
80 
81  // If the insertion of a triangle fails because the mesh would become
82  // nonmanifold, the default behavior is to trigger a LogError message.
83  // You can disable this behavior in situations where you want the Logger
84  // system on but you want to continue gracefully without an assertion.
85  // The return value is the previous value of the internal state
86  // mAssertOnNonmanifoldInsertion.
87  bool AssertOnNonmanifoldInsertion(bool doAssert);
88 
89  // If <v0,v1,v2> is not in the mesh, a Triangle object is created and
90  // returned; otherwise, <v0,v1,v2> is in the mesh and nullptr is returned.
91  // If the insertion leads to a nonmanifold mesh, the call fails with a
92  // nullptr returned.
93  virtual std::shared_ptr<Triangle> Insert(int v0, int v1, int v2);
94 
95  // If <v0,v1,v2> is in the mesh, it is removed and 'true' is returned;
96  // otherwise, <v0,v1,v2> is not in the mesh and 'false' is returned.
97  virtual bool Remove(int v0, int v1, int v2);
98 
99  // Destroy the edges and triangles to obtain an empty mesh.
100  virtual void Clear();
101 
102  // A manifold mesh is closed if each edge is shared twice. A closed
103  // mesh is not necessarily oriented. For example, you could have a
104  // mesh with spherical topology. The upper hemisphere has outer-facing
105  // normals and the lower hemisphere has inner-facing normals. The
106  // discontinuity in orientation occurs on the circle shared by the
107  // hemispheres.
108  bool IsClosed() const;
109 
110  // Test whether all triangles in the mesh are oriented consistently and
111  // that no two triangles are coincident. The latter means that you
112  // cannot have both triangles <v0,v1,v2> and <v0,v2,v1> in the mesh to
113  // be considered oriented.
114  bool IsOriented() const;
115 
116  // Compute the connected components of the edge-triangle graph that the
117  // mesh represents. The first function returns pointers into 'this'
118  // object's containers, so you must consume the components before
119  // clearing or destroying 'this'. The second function returns triangle
120  // keys, which requires three times as much storage as the pointers but
121  // allows you to clear or destroy 'this' before consuming the components.
122  void GetComponents(std::vector<std::vector<std::shared_ptr<Triangle>>>& components) const;
123  void GetComponents(std::vector<std::vector<TriangleKey<true>>>& components) const;
124 
125 protected:
126  // The edge data and default edge creation.
127  static std::shared_ptr<Edge> CreateEdge(int v0, int v1);
128  ECreator mECreator;
129  EMap mEMap;
130 
131  // The triangle data and default triangle creation.
132  static std::shared_ptr<Triangle> CreateTriangle(int v0, int v1, int v2);
133  TCreator mTCreator;
134  TMap mTMap;
135  bool mAssertOnNonmanifoldInsertion; // default: true
136 
137  // Support for computing connected components. This is a straightforward
138  // depth-first search of the graph but uses a preallocated stack rather
139  // than a recursive function that could possibly overflow the call stack.
140  void DepthFirstSearch(std::shared_ptr<Triangle> const& tInitial,
141  std::map<std::shared_ptr<Triangle>, int>& visited,
142  std::vector<std::shared_ptr<Triangle>>& component) const;
143 };
144 
145 }
std::map< TriangleKey< true >, std::shared_ptr< Triangle > > TMap
GLfloat GLfloat v1
Definition: glcorearb.h:812
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
std::map< EdgeKey< false >, std::shared_ptr< Edge > > EMap
GLfloat v0
Definition: glcorearb.h:811
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:813
GLenum GLenum GLuint components
Definition: glext.h:8352
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59