GteVETManifoldMesh.cpp
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 #include <GTEnginePCH.h>
9 #include <LowLevel/GteLogger.h>
11 using namespace gte;
12 
14 {
15 }
16 
18  :
19  ETManifoldMesh(eCreator, tCreator),
20  mVCreator(vCreator ? vCreator : CreateVertex)
21 {
22 }
23 
25 {
26  *this = mesh;
27 }
28 
30 {
31  Clear();
32  mVCreator = mesh.mVCreator;
34  return *this;
35 }
36 
38 {
39  return mVMap;
40 }
41 
42 std::shared_ptr<VETManifoldMesh::Triangle> VETManifoldMesh::Insert(int v0, int v1, int v2)
43 {
44  std::shared_ptr<Triangle> tri = ETManifoldMesh::Insert(v0, v1, v2);
45  if (!tri)
46  {
47  return nullptr;
48  }
49 
50  for (int i = 0; i < 3; ++i)
51  {
52  int vIndex = tri->V[i];
53  auto vItem = mVMap.find(vIndex);
54  std::shared_ptr<Vertex> vertex;
55  if (vItem == mVMap.end())
56  {
57  vertex = mVCreator(vIndex);
58  mVMap[vIndex] = vertex;
59  }
60  else
61  {
62  vertex = vItem->second;
63  }
64 
65  vertex->TAdjacent.insert(tri);
66 
67  for (int j = 0; j < 3; ++j)
68  {
69  auto edge = tri->E[j].lock();
70  if (edge)
71  {
72  if (edge->V[0] == vIndex)
73  {
74  vertex->VAdjacent.insert(edge->V[1]);
75  vertex->EAdjacent.insert(edge);
76  }
77  else if (edge->V[1] == vIndex)
78  {
79  vertex->VAdjacent.insert(edge->V[0]);
80  vertex->EAdjacent.insert(edge);
81  }
82  }
83  else
84  {
85  LogError("Malformed mesh: Triangle edges must not be null.");
86  return nullptr;
87  }
88  }
89  }
90 
91  return tri;
92 }
93 
94 bool VETManifoldMesh::Remove(int v0, int v1, int v2)
95 {
96  auto tItem = mTMap.find(TriangleKey<true>(v0, v1, v2));
97  if (tItem == mTMap.end())
98  {
99  return false;
100  }
101 
102  std::shared_ptr<Triangle> tri = tItem->second;
103  for (int i = 0; i < 3; ++i)
104  {
105  int vIndex = tri->V[i];
106  auto vItem = mVMap.find(vIndex);
107  if (vItem != mVMap.end())
108  {
109  std::shared_ptr<Vertex> vertex = vItem->second;
110  for (int j = 0; j < 3; ++j)
111  {
112  auto edge = tri->E[j].lock();
113  if (edge)
114  {
115  if (edge->T[0].lock() && !edge->T[1].lock())
116  {
117  if (edge->V[0] == vIndex)
118  {
119  vertex->VAdjacent.erase(edge->V[1]);
120  vertex->EAdjacent.erase(edge);
121  }
122  else if (edge->V[1] == vIndex)
123  {
124  vertex->VAdjacent.erase(edge->V[0]);
125  vertex->EAdjacent.erase(edge);
126  }
127  }
128  }
129  else
130  {
131  LogError("Malformed mesh: Triangle edges must not be null.");
132  return false;
133  }
134  }
135 
136  vertex->TAdjacent.erase(tri);
137 
138  if (vertex->TAdjacent.size() == 0)
139  {
140  LogAssert(vertex->VAdjacent.size() == 0 && vertex->EAdjacent.size() == 0,
141  "Malformed mesh: Inconsistent vertex adjacency information.");
142 
143  mVMap.erase(vItem);
144  }
145  }
146  else
147  {
148  LogError("Malformed mesh: Vertex must exist in the mesh.");
149  return false;
150  }
151  }
152 
153  return ETManifoldMesh::Remove(v0, v1, v2);
154 }
155 
157 {
158  mVMap.clear();
160 }
161 
162 std::shared_ptr<VETManifoldMesh::Vertex> VETManifoldMesh::CreateVertex(int vIndex)
163 {
164  return std::make_shared<Vertex>(vIndex);
165 }
166 
168 {
169 }
170 
172  :
173  V(vIndex)
174 {
175 }
std::shared_ptr< Triangle >(* TCreator)(int, int, int)
virtual void Clear() override
#define LogAssert(condition, message)
Definition: GteLogger.h:86
ETManifoldMesh & operator=(ETManifoldMesh const &mesh)
GLfloat GLfloat v1
Definition: glcorearb.h:812
VETManifoldMesh & operator=(VETManifoldMesh const &mesh)
static std::shared_ptr< Vertex > CreateVertex(int vIndex)
#define LogError(message)
Definition: GteLogger.h:92
std::shared_ptr< Edge >(* ECreator)(int, int)
virtual std::shared_ptr< Triangle > Insert(int v0, int v1, int v2)
GLfloat v0
Definition: glcorearb.h:811
virtual bool Remove(int v0, int v1, int v2) override
virtual bool Remove(int v0, int v1, int v2)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:813
VETManifoldMesh(VCreator vCreator=nullptr, ECreator eCreator=nullptr, TCreator tCreator=nullptr)
std::map< int, std::shared_ptr< Vertex > > VMap
std::shared_ptr< Vertex >(* VCreator)(int)
virtual std::shared_ptr< Triangle > Insert(int v0, int v1, int v2) override
VMap const & GetVertices() const


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