GteTSManifoldMesh.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.0 (2016/06/19)
7 
8 #pragma once
9 
12 #include <map>
13 #include <memory>
14 
15 namespace gte
16 {
17 
19 {
20 public:
21  // Triangle data types.
22  class Triangle;
23  typedef std::shared_ptr<Triangle> (*TCreator)(int, int, int);
24  typedef std::map<TriangleKey<false>, std::shared_ptr<Triangle>> TMap;
25 
26  // Tetrahedron data types.
27  class Tetrahedron;
28  typedef std::shared_ptr<Tetrahedron> (*SCreator)(int, int, int, int);
29  typedef std::map<TetrahedronKey<true>, std::shared_ptr<Tetrahedron>> SMap;
30 
31  // Triangle object.
33  {
34  public:
35  virtual ~Triangle();
36  Triangle(int v0, int v1, int v2);
37 
38  // Vertices of the face.
39  int V[3];
40 
41  // Tetrahedra sharing the face.
42  std::weak_ptr<Tetrahedron> T[2];
43  };
44 
45  // Tetrahedron object.
47  {
48  public:
49  virtual ~Tetrahedron();
50  Tetrahedron(int v0, int v1, int v2, int v3);
51 
52  // Vertices, listed in an order so that each face vertices in
53  // counterclockwise order when viewed from outside the tetrahedron.
54  int V[4];
55 
56  // Adjacent faces. T[i] points to the triangle face opposite V[i].
57  // T[0] points to face (V[1],V[2],V[3])
58  // T[1] points to face (V[0],V[3],V[2])
59  // T[2] points to face (V[0],V[1],V[3])
60  // T[3] points to face (V[0],V[2],V[1])
61  std::weak_ptr<Triangle> T[4];
62 
63  // Adjacent tetrahedra. S[i] points to the adjacent tetrahedron
64  // sharing face T[i].
65  std::weak_ptr<Tetrahedron> S[4];
66  };
67 
68 
69  // Construction and destruction.
70  virtual ~TSManifoldMesh();
71  TSManifoldMesh(TCreator tCreator = nullptr, SCreator sCreator = nullptr);
72 
73  // Support for a deep copy of the mesh. The mTMap and mSMap objects have
74  // dynamically allocated memory for triangles and tetrahedra. A shallow
75  // copy of the pointers to this memory is problematic. Allowing sharing,
76  // say, via std::shared_ptr, is an option but not really the intent of
77  // copying the mesh graph.
78  TSManifoldMesh(TSManifoldMesh const& mesh);
79  TSManifoldMesh& operator=(TSManifoldMesh const& mesh);
80 
81  // Member access.
82  TMap const& GetTriangles() const;
83  SMap const& GetTetrahedra() const;
84 
85  // If the insertion of a tetrahedron fails because the mesh would become
86  // nonmanifold, the default behavior is to trigger a LogError message.
87  // You can disable this behavior in situations where you want the Logger
88  // system on but you want to continue gracefully without an assertion.
89  void AssertOnNonmanifoldInsertion(bool doAssert);
90 
91  // If <v0,v1,v2,v3> is not in the mesh, a Tetrahedron object is created
92  // and returned; otherwise, <v0,v1,v2,v3> is in the mesh and nullptr is
93  // returned. If the insertion leads to a nonmanifold mesh, the call
94  // fails with a nullptr returned.
95  std::shared_ptr<Tetrahedron> Insert(int v0, int v1, int v2, int v3);
96 
97  // If <v0,v1,v2,v3> is in the mesh, it is removed and 'true' is returned;
98  // otherwise, <v0,v1,v2,v3> is not in the mesh and 'false' is returned.
99  bool Remove(int v0, int v1, int v2, int v3);
100 
101  // Destroy the triangles and tetrahedra to obtain an empty mesh.
102  virtual void Clear();
103 
104  // A manifold mesh is closed if each face is shared twice.
105  bool IsClosed() const;
106 
107 protected:
108  // The triangle data and default triangle creation.
109  static std::shared_ptr<Triangle> CreateTriangle(int v0, int v1, int v2);
110  TCreator mTCreator;
111  TMap mTMap;
112 
113  // The tetrahedron data and default tetrahedron creation.
114  static std::shared_ptr<Tetrahedron> CreateTetrahedron(int v0, int v1, int v2, int v3);
115  SCreator mSCreator;
116  SMap mSMap;
117  bool mAssertOnNonmanifoldInsertion; // default: true
118 };
119 
120 }
std::map< TriangleKey< false >, std::shared_ptr< Triangle > > TMap
GLfloat GLfloat v1
Definition: glcorearb.h:812
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:814
GLfloat v0
Definition: glcorearb.h:811
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:813
std::map< TetrahedronKey< true >, std::shared_ptr< Tetrahedron > > SMap
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01