Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

86 avoid stack overflow #102

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CDT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ endif()
message(STATUS "CDT_USE_BOOST is ${CDT_USE_BOOST}")
message(STATUS "CDT_USE_AS_COMPILED_LIBRARY is ${CDT_USE_AS_COMPILED_LIBRARY}")
message(STATUS "CDT_USE_64_BIT_INDEX_TYPE is ${CDT_USE_64_BIT_INDEX_TYPE}")
message(STATUS "CDT_ENABLE_TESTING is ${CDT_ENABLE_TESTING}")

# Use boost for c++98 versions of c++11 containers or for Boost::rtree
if(CDT_USE_BOOST)
Expand Down Expand Up @@ -237,7 +238,7 @@ if(CDT_ENABLE_TESTING)
set(Catch2_directory ${PROJECT_SOURCE_DIR}/tests/Catch2)
add_subdirectory(${Catch2_directory})
set(CMAKE_MODULE_PATH "${Catch2_directory}/extras" ${CMAKE_MODULE_PATH})
set(TEST_TARGET_NAME ${PROJECT_NAME}_tests)
set(TEST_TARGET_NAME ${PROJECT_NAME}-tests)
add_executable(${TEST_TARGET_NAME})
set_property(TARGET ${TEST_TARGET_NAME} PROPERTY CXX_STANDARD 17)
target_sources(${TEST_TARGET_NAME} PRIVATE tests/cdt.test.cpp)
Expand Down
97 changes: 86 additions & 11 deletions CDT/include/Triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,26 +358,93 @@ class CDT_EXPORT Triangulation
std::stack<TriInd>& triStack);
/// Flip fixed edges and return a list of flipped fixed edges
std::vector<Edge> insertVertex_FlipFixedEdges(VertInd iVert);

typedef std::vector<VertInd>::const_iterator VertIndCit;
/// State for an iteration of triangulate pseudo-polygon
typedef tuple<VertInd, VertInd, VertIndCit, VertIndCit, TriInd>
TriangulatePseudopolygonTask;

/**
* Insert an edge into constraint Delaunay triangulation
* @param edge edge to insert
* @param originalEdge original edge inserted edge is part of
* @param[in,out] remaining parts of the edge that still need to
* be inserted
* @param[in,out] tppIterations stack to be used for storing iterations of
* triangulating pseudo-polygon
* @note in-out state (@param remaining @param tppIterations) is shared
* between different runs for performance gains (reducing memory
* allocations)
*/
void insertEdge(
Edge edge,
Edge originalEdge,
EdgeVec& remaining,
std::vector<TriangulatePseudopolygonTask>& tppIterations);

/**
* Insert an edge or its part into constraint Delaunay triangulation
* @param edge edge to insert
* @param originalEdge original edge inserted edge is part of
* @param[in,out] remainingStack parts of the edge that still need to
* be inserted
* @param[in,out] tppIterations stack to be used for storing iterations of
* triangulating pseudo-polygon
* @note in-out state (@param remaining @param tppIterations) is shared
* between different runs for performance gains (reducing memory
* allocations)
*/
void insertEdge(Edge edge, Edge originalEdge);
void insertEdgeIteration(
Edge edge,
Edge originalEdge,
EdgeVec& remaining,
std::vector<TriangulatePseudopolygonTask>& tppIterations);

/// State for iteration of conforming to edge
typedef tuple<Edge, EdgeVec, BoundaryOverlapCount> ConformToEdgeTask;

/**
* Conform Delaunay triangulation to a fixed edge by recursively inserting
* mid point of the edge and then conforming to its halves
* @param edge fixed edge to conform to
* @param originalEdges original edges that new edge is piece of
* @param overlaps count of overlapping boundaries at the edge. Only used
* when re-introducing edge with overlaps > 0
* @param orientationTolerance tolerance for orient2d predicate,
* values [-tolerance,+tolerance] are considered as 0.
* @param[in,out] remaining remaining edge parts to be conformed to
* @param[in,out] reintroduce fixed edges that got removed during conforming
* process and need to be reintroduced
* @note in-out state (@param remaining @param reintroduce) is shared
* between different runs for performance gains (reducing memory
* allocations)
*/
void conformToEdge(
Edge edge,
EdgeVec originalEdges,
BoundaryOverlapCount overlaps);
const EdgeVec& originalEdges,
BoundaryOverlapCount overlaps,
EdgeVec& remaining,
std::vector<ConformToEdgeTask>& reintroduce);

/**
* Iteration of conform to fixed edge.
* @param edge fixed edge to conform to
* @param originalEdges original edges that new edge is piece of
* @param overlaps count of overlapping boundaries at the edge. Only used
* when re-introducing edge with overlaps > 0
* @param[in,out] remaining remaining edge parts that need to be conformed
* to
* @param[in,out] reintroduce fixed edges that got removed during conforming
* process and need to be reintroduced
* @note in-out state (@param remaining @param reintroduce) is shared
* between different runs for performance gains (reducing memory
* allocations)
*/
void conformToEdgeIteration(
Edge edge,
const EdgeVec& originalEdges,
BoundaryOverlapCount overlaps,
EdgeVec& remaining,
std::vector<ConformToEdgeTask>& reintroduce);

tuple<TriInd, VertInd, VertInd> intersectedTriangle(
VertInd iA,
const std::vector<TriInd>& candidates,
Expand Down Expand Up @@ -419,10 +486,12 @@ class CDT_EXPORT Triangulation
VertInd ia,
VertInd ib,
std::vector<VertInd>::const_iterator pointsFirst,
std::vector<VertInd>::const_iterator pointsLast);
VertInd findDelaunayPoint(
VertInd ia,
VertInd ib,
std::vector<VertInd>::const_iterator pointsLast,
TriInd parent,
std::vector<TriangulatePseudopolygonTask>& iterations);
std::vector<VertInd>::const_iterator findDelaunayPoint(
const V2d<T>& a,
const V2d<T>& b,
std::vector<VertInd>::const_iterator pointsFirst,
std::vector<VertInd>::const_iterator pointsLast) const;
TriInd pseudopolyOuterTriangle(VertInd ia, VertInd ib) const;
Expand Down Expand Up @@ -563,6 +632,9 @@ void Triangulation<T, TNearPointLocator>::insertEdges(
TGetEdgeVertexStart getStart,
TGetEdgeVertexEnd getEnd)
{
// state shared between different runs for performance gains
std::vector<TriangulatePseudopolygonTask> tppIterations;
EdgeVec remaining;
if(isFinalized())
{
throw std::runtime_error(
Expand All @@ -575,7 +647,7 @@ void Triangulation<T, TNearPointLocator>::insertEdges(
const Edge edge(
VertInd(getStart(*first) + m_nTargetVerts),
VertInd(getEnd(*first) + m_nTargetVerts));
insertEdge(edge, edge);
insertEdge(edge, edge, remaining, tppIterations);
}
eraseDummies();
}
Expand All @@ -597,13 +669,16 @@ void Triangulation<T, TNearPointLocator>::conformToEdges(
"Triangulation was finalized with 'erase...' method. Conforming to "
"new edges is not possible");
}
// state shared between different runs for performance gains
EdgeVec remaining;
std::vector<ConformToEdgeTask> reintroduce;
for(; first != last; ++first)
{
// +3 to account for super-triangle vertices
const Edge e(
VertInd(getStart(*first) + m_nTargetVerts),
VertInd(getEnd(*first) + m_nTargetVerts));
conformToEdge(e, EdgeVec(1, e), 0);
conformToEdge(e, EdgeVec(1, e), 0, remaining, reintroduce);
}
eraseDummies();
}
Expand Down
Loading