Skip to content

Commit 65be51a

Browse files
committed
#148 Fix bug: vertex with no adjacent triangle when resolving intersections
Add regression test
1 parent ebbe76b commit 65be51a

7 files changed

+123
-11
lines changed

CDT/extras/VerifyTopology.h

+11
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ inline bool verifyTopology(const CDT::Triangulation<T, TNearPointLocator>& cdt)
7474
return true;
7575
}
7676

77+
/// Check that each vertex has a neighbor triangle
78+
template <typename T, typename TNearPointLocator>
79+
inline bool eachVertexHasNeighborTriangle(
80+
const CDT::Triangulation<T, TNearPointLocator>& cdt)
81+
{
82+
for(const auto& vt : cdt.VertTrisInternal())
83+
if(vt == noNeighbor)
84+
return false;
85+
return true;
86+
}
87+
7788
} // namespace CDT
7889

7990
#endif

CDT/include/Triangulation.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ class CDT_EXPORT Triangulation
355355

356356
/// Access internal vertex adjacent triangles
357357
TriIndVec& VertTrisInternal();
358+
/// Access internal vertex adjacent triangles
359+
const TriIndVec& VertTrisInternal() const;
358360
/// @}
359361

360362
private:
@@ -586,7 +588,6 @@ class CDT_EXPORT Triangulation
586588
bool hasEdge(VertInd a, VertInd b) const;
587589
void setAdjacentTriangle(const VertInd v, const TriInd t);
588590
void pivotVertexTriangleCW(VertInd v);
589-
void removeAdjacentTriangle(VertInd v);
590591
/// Add vertex to nearest-point locator if locator is initialized
591592
void tryAddVertexToLocator(const VertInd v);
592593
/// Perform lazy initialization of nearest-point locator after the Kd-tree

CDT/include/Triangulation.hpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,19 @@ void Triangulation<T, TNearPointLocator>::removeTriangles(
208208
}
209209
}
210210
}
211+
211212
template <typename T, typename TNearPointLocator>
212213
TriIndVec& Triangulation<T, TNearPointLocator>::VertTrisInternal()
213214
{
214215
return m_vertTris;
215216
}
216217

218+
template <typename T, typename TNearPointLocator>
219+
const TriIndVec& Triangulation<T, TNearPointLocator>::VertTrisInternal() const
220+
{
221+
return m_vertTris;
222+
}
223+
217224
template <typename T, typename TNearPointLocator>
218225
void Triangulation<T, TNearPointLocator>::finalizeTriangulation(
219226
const TriIndUSet& removedTriangles)
@@ -605,7 +612,6 @@ void Triangulation<T, TNearPointLocator>::insertEdgeIteration(
605612
outerTrisL.push_back(edgeNeighbor(tOpo, polyL.back(), iVopo));
606613
}
607614
polyL.push_back(iVopo);
608-
removeAdjacentTriangle(iVopo);
609615
iV = iVL;
610616
iVL = iVopo;
611617
}
@@ -627,7 +633,6 @@ void Triangulation<T, TNearPointLocator>::insertEdgeIteration(
627633
outerTrisR.push_back(edgeNeighbor(tOpo, polyR.back(), iVopo));
628634
}
629635
polyR.push_back(iVopo);
630-
removeAdjacentTriangle(iVopo);
631636
iV = iVR;
632637
iVR = iVopo;
633638
}
@@ -2005,13 +2010,6 @@ void Triangulation<T, TNearPointLocator>::pivotVertexTriangleCW(const VertInd v)
20052010
triangles[m_vertTris[v]].vertices[2] == v);
20062011
}
20072012

2008-
template <typename T, typename TNearPointLocator>
2009-
void Triangulation<T, TNearPointLocator>::removeAdjacentTriangle(
2010-
const VertInd v)
2011-
{
2012-
m_vertTris[v] = noNeighbor;
2013-
}
2014-
20152013
template <typename T, typename TNearPointLocator>
20162014
void Triangulation<T, TNearPointLocator>::tryAddVertexToLocator(const VertInd v)
20172015
{

CDT/tests/cdt.test.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ TEMPLATE_LIST_TEST_CASE(
556556
cdt.insertVertices(vv);
557557
cdt.insertEdges(ee);
558558
REQUIRE(CDT::verifyTopology(cdt));
559+
REQUIRE(CDT::eachVertexHasNeighborTriangle(cdt));
559560

560561
// make true to update expected files (development purposes only)
561562
const auto outputFileBase = "expected/" +
@@ -671,7 +672,10 @@ TEMPLATE_LIST_TEST_CASE(
671672

672673
TEMPLATE_LIST_TEST_CASE("Ground truth tests: crossing edges", "", CoordTypes)
673674
{
674-
const auto inputFile = std::string("crossing-edges.txt");
675+
const auto inputFile = GENERATE(
676+
as<std::string>{},
677+
"crossing-edges.txt",
678+
"issue-148-crossing-edges.txt");
675679

676680
const auto order = VertexInsertionOrder::Auto;
677681
const auto intersectingEdgesStrategy = IntersectingConstraintEdges::Resolve;
@@ -689,6 +693,7 @@ TEMPLATE_LIST_TEST_CASE("Ground truth tests: crossing edges", "", CoordTypes)
689693
cdt.insertVertices(vv);
690694
triangulationType == "" ? cdt.insertEdges(ee) : cdt.conformToEdges(ee);
691695
REQUIRE(CDT::verifyTopology(cdt));
696+
REQUIRE(CDT::eachVertexHasNeighborTriangle(cdt));
692697
// make true to update expected files (development purposes only)
693698
const auto outputFileBase = "expected/" +
694699
inputFile.substr(0, inputFile.size() - 4) +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
15
2+
0 1 4 4294967295 5 2
3+
0 3 6 2 9 3
4+
0 4 3 0 7 1
5+
0 6 2 1 6 4294967295
6+
1 2 5 4294967295 6 5
7+
1 5 4 4 10 0
8+
2 6 5 3 13 4
9+
3 4 7 2 12 8
10+
3 7 9 7 12 9
11+
3 9 6 8 13 1
12+
4 5 8 5 14 11
13+
4 8 9 10 14 12
14+
4 9 7 11 8 7
15+
5 6 9 6 9 14
16+
5 9 8 13 11 10
17+
18+
4
19+
3 9
20+
4 9
21+
5 9
22+
6 9
23+
24+
0
25+
26+
4
27+
3 9
28+
1
29+
3 5
30+
4 9
31+
1
32+
4 6
33+
5 9
34+
1
35+
3 5
36+
6 9
37+
1
38+
4 6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
19
2+
0 1 4 4294967295 5 2
3+
0 3 6 2 9 3
4+
0 4 3 0 7 1
5+
0 6 2 1 6 4294967295
6+
1 2 5 4294967295 6 5
7+
1 5 4 4 10 0
8+
2 6 5 3 13 4
9+
3 4 7 2 12 8
10+
3 7 10 7 16 9
11+
3 10 6 8 15 1
12+
4 5 8 5 14 11
13+
4 8 11 10 17 12
14+
4 11 7 11 16 7
15+
5 6 9 6 15 14
16+
5 9 8 13 17 10
17+
6 10 9 9 18 13
18+
7 11 10 12 18 8
19+
8 9 11 14 18 11
20+
9 10 11 15 16 17
21+
22+
6
23+
3 10
24+
4 11
25+
5 9
26+
6 10
27+
9 10
28+
10 11
29+
30+
0
31+
32+
6
33+
3 10
34+
1
35+
3 5
36+
4 11
37+
1
38+
4 6
39+
5 9
40+
1
41+
3 5
42+
6 10
43+
1
44+
4 6
45+
9 10
46+
1
47+
3 5
48+
10 11
49+
1
50+
4 6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
6 2
2+
0 0.2
3+
1 0
4+
1 1
5+
0 1
6+
0.5 0.2
7+
0.8 0.5
8+
0 2
9+
1 3

0 commit comments

Comments
 (0)