Skip to content

Commit

Permalink
#148 Fix bug: vertex with no adjacent triangle when resolving interse…
Browse files Browse the repository at this point in the history
…ctions

Add regression test
  • Loading branch information
artem-ogre committed Oct 13, 2023
1 parent ebbe76b commit 65be51a
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 11 deletions.
11 changes: 11 additions & 0 deletions CDT/extras/VerifyTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ inline bool verifyTopology(const CDT::Triangulation<T, TNearPointLocator>& cdt)
return true;
}

/// Check that each vertex has a neighbor triangle
template <typename T, typename TNearPointLocator>
inline bool eachVertexHasNeighborTriangle(
const CDT::Triangulation<T, TNearPointLocator>& cdt)
{
for(const auto& vt : cdt.VertTrisInternal())
if(vt == noNeighbor)
return false;
return true;
}

} // namespace CDT

#endif
3 changes: 2 additions & 1 deletion CDT/include/Triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ class CDT_EXPORT Triangulation

/// Access internal vertex adjacent triangles
TriIndVec& VertTrisInternal();
/// Access internal vertex adjacent triangles
const TriIndVec& VertTrisInternal() const;
/// @}

private:
Expand Down Expand Up @@ -586,7 +588,6 @@ class CDT_EXPORT Triangulation
bool hasEdge(VertInd a, VertInd b) const;
void setAdjacentTriangle(const VertInd v, const TriInd t);
void pivotVertexTriangleCW(VertInd v);
void removeAdjacentTriangle(VertInd v);
/// Add vertex to nearest-point locator if locator is initialized
void tryAddVertexToLocator(const VertInd v);
/// Perform lazy initialization of nearest-point locator after the Kd-tree
Expand Down
16 changes: 7 additions & 9 deletions CDT/include/Triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,19 @@ void Triangulation<T, TNearPointLocator>::removeTriangles(
}
}
}

template <typename T, typename TNearPointLocator>
TriIndVec& Triangulation<T, TNearPointLocator>::VertTrisInternal()
{
return m_vertTris;
}

template <typename T, typename TNearPointLocator>
const TriIndVec& Triangulation<T, TNearPointLocator>::VertTrisInternal() const
{
return m_vertTris;
}

template <typename T, typename TNearPointLocator>
void Triangulation<T, TNearPointLocator>::finalizeTriangulation(
const TriIndUSet& removedTriangles)
Expand Down Expand Up @@ -605,7 +612,6 @@ void Triangulation<T, TNearPointLocator>::insertEdgeIteration(
outerTrisL.push_back(edgeNeighbor(tOpo, polyL.back(), iVopo));
}
polyL.push_back(iVopo);
removeAdjacentTriangle(iVopo);
iV = iVL;
iVL = iVopo;
}
Expand All @@ -627,7 +633,6 @@ void Triangulation<T, TNearPointLocator>::insertEdgeIteration(
outerTrisR.push_back(edgeNeighbor(tOpo, polyR.back(), iVopo));
}
polyR.push_back(iVopo);
removeAdjacentTriangle(iVopo);
iV = iVR;
iVR = iVopo;
}
Expand Down Expand Up @@ -2005,13 +2010,6 @@ void Triangulation<T, TNearPointLocator>::pivotVertexTriangleCW(const VertInd v)
triangles[m_vertTris[v]].vertices[2] == v);
}

template <typename T, typename TNearPointLocator>
void Triangulation<T, TNearPointLocator>::removeAdjacentTriangle(
const VertInd v)
{
m_vertTris[v] = noNeighbor;
}

template <typename T, typename TNearPointLocator>
void Triangulation<T, TNearPointLocator>::tryAddVertexToLocator(const VertInd v)
{
Expand Down
7 changes: 6 additions & 1 deletion CDT/tests/cdt.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ TEMPLATE_LIST_TEST_CASE(
cdt.insertVertices(vv);
cdt.insertEdges(ee);
REQUIRE(CDT::verifyTopology(cdt));
REQUIRE(CDT::eachVertexHasNeighborTriangle(cdt));

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

TEMPLATE_LIST_TEST_CASE("Ground truth tests: crossing edges", "", CoordTypes)
{
const auto inputFile = std::string("crossing-edges.txt");
const auto inputFile = GENERATE(
as<std::string>{},
"crossing-edges.txt",
"issue-148-crossing-edges.txt");

const auto order = VertexInsertionOrder::Auto;
const auto intersectingEdgesStrategy = IntersectingConstraintEdges::Resolve;
Expand All @@ -689,6 +693,7 @@ TEMPLATE_LIST_TEST_CASE("Ground truth tests: crossing edges", "", CoordTypes)
cdt.insertVertices(vv);
triangulationType == "" ? cdt.insertEdges(ee) : cdt.conformToEdges(ee);
REQUIRE(CDT::verifyTopology(cdt));
REQUIRE(CDT::eachVertexHasNeighborTriangle(cdt));
// make true to update expected files (development purposes only)
const auto outputFileBase = "expected/" +
inputFile.substr(0, inputFile.size() - 4) +
Expand Down
38 changes: 38 additions & 0 deletions CDT/tests/expected/issue-148-crossing-edges__auto_resolve_all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
15
0 1 4 4294967295 5 2
0 3 6 2 9 3
0 4 3 0 7 1
0 6 2 1 6 4294967295
1 2 5 4294967295 6 5
1 5 4 4 10 0
2 6 5 3 13 4
3 4 7 2 12 8
3 7 9 7 12 9
3 9 6 8 13 1
4 5 8 5 14 11
4 8 9 10 14 12
4 9 7 11 8 7
5 6 9 6 9 14
5 9 8 13 11 10

4
3 9
4 9
5 9
6 9

0

4
3 9
1
3 5
4 9
1
4 6
5 9
1
3 5
6 9
1
4 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
19
0 1 4 4294967295 5 2
0 3 6 2 9 3
0 4 3 0 7 1
0 6 2 1 6 4294967295
1 2 5 4294967295 6 5
1 5 4 4 10 0
2 6 5 3 13 4
3 4 7 2 12 8
3 7 10 7 16 9
3 10 6 8 15 1
4 5 8 5 14 11
4 8 11 10 17 12
4 11 7 11 16 7
5 6 9 6 15 14
5 9 8 13 17 10
6 10 9 9 18 13
7 11 10 12 18 8
8 9 11 14 18 11
9 10 11 15 16 17

6
3 10
4 11
5 9
6 10
9 10
10 11

0

6
3 10
1
3 5
4 11
1
4 6
5 9
1
3 5
6 10
1
4 6
9 10
1
3 5
10 11
1
4 6
9 changes: 9 additions & 0 deletions CDT/tests/inputs/issue-148-crossing-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
6 2
0 0.2
1 0
1 1
0 1
0.5 0.2
0.8 0.5
0 2
1 3

0 comments on commit 65be51a

Please sign in to comment.