37 for (
auto const& element : mesh.
mTMap)
39 Insert(element.first.V[0], element.first.V[1], element.first.V[2]);
74 std::shared_ptr<Triangle> tri =
mTCreator(v0, v1, v2);
77 for (
int i0 = 2, i1 = 0; i1 < 3; i0 = i1++)
80 std::shared_ptr<Edge> edge;
81 auto eiter =
mEMap.find(ekey);
82 if (eiter ==
mEMap.end())
103 if (edge->T[1].lock())
114 auto adjacent = edge->T[0].lock();
120 for (
int j = 0; j < 3; ++j)
122 if (adjacent->E[j].lock() == edge)
124 adjacent->T[j] = tri;
131 tri->T[i0] = adjacent;
142 auto titer =
mTMap.find(tkey);
143 if (titer ==
mTMap.end())
150 std::shared_ptr<Triangle> tri = titer->second;
153 for (
int i = 0; i < 3; ++i)
156 auto edge = tri->E[i].lock();
164 if (edge->T[0].lock() == tri)
167 edge->T[0] = edge->T[1];
170 else if (edge->T[1].lock() == tri)
181 if (!edge->T[0].lock() && !edge->T[1].lock())
188 auto adjacent = tri->T[i].lock();
191 for (
int j = 0; j < 3; ++j)
193 if (adjacent->T[j].lock() == tri)
195 adjacent->T[j].reset();
214 for (
auto const& element :
mEMap)
216 auto edge = element.second;
217 if (!edge->T[0].lock() || !edge->T[1].lock())
227 for (
auto const& element :
mEMap)
229 auto edge = element.second;
230 if (edge->T[0].lock() && edge->T[1].lock())
235 bool edgePositive[2] = {
false,
false };
236 int vOpposite[2] = { -1, -1 };
237 for (
int j = 0; j < 2; ++j)
239 auto tri = edge->T[j].lock();
240 for (
int i = 0; i < 3; ++i)
242 if (tri->V[i] == element.first.V[0])
244 int vNext = tri->V[(i + 1) % 3];
245 if (vNext == element.first.V[1])
247 edgePositive[j] =
true;
248 vOpposite[j] = tri->V[(i + 2) % 3];
252 edgePositive[j] =
false;
253 vOpposite[j] = vNext;
262 if (edgePositive[0] == edgePositive[1] || vOpposite[0] == vOpposite[1])
272 std::vector<std::vector<std::shared_ptr<Triangle>>>&
components)
const 275 std::map<std::shared_ptr<Triangle>,
int> visited;
276 for (
auto const& element :
mTMap)
278 visited.insert(std::make_pair(element.second, 0));
281 for (
auto& element : mTMap)
283 auto tri = element.second;
284 if (visited[tri] == 0)
286 std::vector<std::shared_ptr<Triangle>> component;
297 std::map<std::shared_ptr<Triangle>,
int> visited;
298 for (
auto const& element :
mTMap)
300 visited.insert(std::make_pair(element.second, 0));
303 for (
auto& element : mTMap)
305 std::shared_ptr<Triangle> tri = element.second;
306 if (visited[tri] == 0)
308 std::vector<std::shared_ptr<Triangle>> component;
311 std::vector<TriangleKey<true>> keyComponent;
312 keyComponent.reserve(component.size());
313 for (
auto const&
t : component)
323 std::map<std::shared_ptr<Triangle>,
int>& visited,
324 std::vector<std::shared_ptr<Triangle>>& component)
const 328 std::vector<std::shared_ptr<Triangle>> tStack(
mTMap.size());
330 tStack[++
top] = tInitial;
333 std::shared_ptr<Triangle> tri = tStack[
top];
336 for (i = 0; i < 3; ++i)
338 std::shared_ptr<Triangle> adj = tri->T[i].lock();
339 if (adj && visited[adj] == 0)
348 component.push_back(tri);
356 return std::make_shared<Edge>(
v0,
v1);
361 return std::make_shared<Triangle>(
v0,
v1,
v2);
static std::shared_ptr< Triangle > CreateTriangle(int v0, int v1, int v2)
std::shared_ptr< Triangle >(* TCreator)(int, int, int)
bool mAssertOnNonmanifoldInsertion
ETManifoldMesh(ECreator eCreator=nullptr, TCreator tCreator=nullptr)
std::map< TriangleKey< true >, std::shared_ptr< Triangle > > TMap
EMap const & GetEdges() const
ETManifoldMesh & operator=(ETManifoldMesh const &mesh)
#define LogInformation(message)
virtual ~ETManifoldMesh()
bool AssertOnNonmanifoldInsertion(bool doAssert)
static std::shared_ptr< Edge > CreateEdge(int v0, int v1)
#define LogError(message)
std::map< EdgeKey< false >, std::shared_ptr< Edge > > EMap
std::shared_ptr< Edge >(* ECreator)(int, int)
virtual std::shared_ptr< Triangle > Insert(int v0, int v1, int v2)
void GetComponents(std::vector< std::vector< std::shared_ptr< Triangle >>> &components) const
Triangle(int v0, int v1, int v2)
void DepthFirstSearch(std::shared_ptr< Triangle > const &tInitial, std::map< std::shared_ptr< Triangle >, int > &visited, std::vector< std::shared_ptr< Triangle >> &component) const
TMap const & GetTriangles() const
virtual bool Remove(int v0, int v1, int v2)
GLfloat GLfloat GLfloat v2
GLenum GLenum GLuint components
GLdouble GLdouble GLdouble GLdouble top