CDT  1.4.5
C++ library for constrained Delaunay triangulation
Loading...
Searching...
No Matches
Triangulation.h
Go to the documentation of this file.
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
9
10#ifndef CDT_vW1vZ0lO8rS4gY4uI4fB
11#define CDT_vW1vZ0lO8rS4gY4uI4fB
12
13#include "CDTUtils.h"
14#include "LocatorKDTree.h"
15
16#include <algorithm>
17#include <cstdlib>
18#include <iterator>
19#include <stack>
20#include <stdexcept>
21#include <string>
22#include <utility>
23#include <vector>
24
26namespace CDT
27{
28
31
38struct CDT_EXPORT VertexInsertionOrder
39{
44 enum Enum
45 {
54 };
55};
56
58struct CDT_EXPORT SuperGeometryType
59{
64 enum Enum
65 {
68 };
69};
70
75{
90};
91
97typedef unsigned short LayerDepth;
98typedef LayerDepth BoundaryOverlapCount;
99
104{
105public:
107 SourceLocation(const std::string& file, const std::string& func, int line)
108 : m_file(file)
109 , m_func(func)
110 , m_line(line)
111 {}
112
113 const std::string& file() const
114 {
115 return m_file;
116 }
117
118 const std::string& func() const
119 {
120 return m_func;
121 }
122
123 int line() const
124 {
125 return m_line;
126 }
127
128private:
129 std::string m_file;
130 std::string m_func;
131 int m_line;
132};
133
135#define CDT_SOURCE_LOCATION \
136 SourceLocation(std::string(__FILE__), std::string(__func__), __LINE__)
137
142class CDT_EXPORT Error : public std::runtime_error
143{
144public:
146 Error(const std::string& description, const SourceLocation& srcLoc)
147 : std::runtime_error(
148 description + "\nin '" + srcLoc.func() + "' at " + srcLoc.file() +
149 ":" + CDT::to_string(srcLoc.line()))
150 , m_description(description)
151 , m_srcLoc(srcLoc)
152 {}
153
154 virtual ~Error() CDT_NOEXCEPT
155 {}
156
157 const std::string& description() const
158 {
159 return m_description;
160 }
161
163 {
164 return m_srcLoc;
165 }
166
167private:
168 std::string m_description;
169 SourceLocation m_srcLoc;
170};
171
176class CDT_EXPORT FinalizedError : public Error
177{
178public:
181 : Error(
182 "Triangulation was finalized with 'erase...' method. Further "
183 "modification is not possible.",
184 srcLoc)
185 {}
186};
187
191class CDT_EXPORT DuplicateVertexError : public Error
192{
193public:
196 const VertInd v1,
197 const VertInd v2,
198 const SourceLocation& srcLoc)
199 : Error(
200 "Duplicate vertex detected: #" + CDT::to_string(v1) +
201 " is a duplicate of #" + CDT::to_string(v2),
202 srcLoc)
203 , m_v1(v1)
204 , m_v2(v2)
205 {}
206
207 VertInd v1() const
208 {
209 return m_v1;
210 }
211
212 VertInd v2() const
213 {
214 return m_v2;
215 }
216
217private:
218 VertInd m_v1, m_v2;
219};
220
225class CDT_EXPORT IntersectingConstraintsError : public Error
226{
227public:
230 const Edge& e1,
231 const Edge& e2,
232 const SourceLocation& srcLoc)
233 : Error(
234 "Intersecting constraint edges detected: (" +
235 CDT::to_string(e1.v1()) + ", " + CDT::to_string(e1.v2()) +
236 ") intersects (" + CDT::to_string(e2.v1()) + ", " +
237 CDT::to_string(e2.v2()) + ")",
238 srcLoc)
239 , m_e1(e1)
240 , m_e2(e2)
241 {}
242
243 const Edge& e1() const
244 {
245 return m_e1;
246 }
247
248 const Edge& e2() const
249 {
250 return m_e2;
251 }
252
253private:
254 Edge m_e1, m_e2;
255};
256
262class CDT_EXPORT InvalidEdgeSplitVertex : public Error
263{
264public:
267 const Edge& e1,
268 const Edge& e2,
269 const SourceLocation& srcLoc)
270 : Error(
271 "Intersection of constraint edges (" + CDT::to_string(e1.v1()) +
272 ", " + CDT::to_string(e1.v2()) + ") and (" +
273 CDT::to_string(e2.v1()) + ", " + CDT::to_string(e2.v2()) +
274 ") can not be resolved: computed split vertex is invalid",
275 srcLoc)
276 , m_e1(e1)
277 , m_e2(e2)
278 {}
279
280 const Edge& e1() const
281 {
282 return m_e1;
283 }
284
285 const Edge& e2() const
286 {
287 return m_e2;
288 }
289
290private:
291 Edge m_e1, m_e2;
292};
293
294#ifdef CDT_ENABLE_CALLBACK_HANDLER
295
315
319struct CDT_EXPORT TriangleChangeType
320{
330};
331
332// parameter names are used for documentation purposes, even if they are un-used
333// in the interface's default implementation
334#pragma GCC diagnostic push
335#pragma GCC diagnostic ignored "-Wunused-parameter"
336
341class CDT_EXPORT ICallbackHandler
342{
343public:
346 {}
347
353 virtual void onAddSuperTriangle()
354 {}
355
366 const TriInd iRepurposedTri,
367 const TriInd iNewTri1,
368 const TriInd iNewTri2)
369 {}
370
383 const TriInd iRepurposedTri1,
384 const TriInd iRepurposedTri2,
385 const TriInd iNewTri1,
386 const TriInd iNewTri2)
387 {}
388
394 virtual void onFlipEdge(const TriInd iT, const TriInd iTopo)
395 {}
396
402 virtual void
403 onAddVertexStart(const VertInd iV, const AddVertexType::Enum vertexType)
404 {}
405
410 virtual void onAddEdgeStart(const Edge& edge)
411 {}
412
419 virtual void onReTriangulatePolygon(const std::vector<TriInd>& tris)
420 {}
421
426 virtual bool isAbortCalculation() const
427 {
428 return false;
429 };
430};
431
432// parameter names are used for documentation purposes, even if they are
433// un-used in the interface's default implementation
434#pragma GCC diagnostic pop
435
436#endif
437
443
452template <typename T, typename TNearPointLocator = LocatorKDTree<T> >
453class CDT_EXPORT Triangulation
454{
455public:
456 typedef std::vector<V2d<T> > V2dVec;
460
468 unordered_map<Edge, BoundaryOverlapCount> overlapCount;
469
475 unordered_map<Edge, EdgeVec> pieceToOriginals;
476
477 /*____ API _____*/
484 explicit Triangulation(VertexInsertionOrder::Enum vertexInsertionOrder);
495 VertexInsertionOrder::Enum vertexInsertionOrder,
496 IntersectingConstraintEdges::Enum intersectingEdgesStrategy,
497 T minDistToConstraintEdge);
510 VertexInsertionOrder::Enum vertexInsertionOrder,
511 const TNearPointLocator& nearPtLocator,
512 IntersectingConstraintEdges::Enum intersectingEdgesStrategy,
513 T minDistToConstraintEdge);
528 template <
529 typename TVertexIter,
530 typename TGetVertexCoordX,
531 typename TGetVertexCoordY>
532 void insertVertices(
533 TVertexIter first,
534 TVertexIter last,
535 TGetVertexCoordX getX,
536 TGetVertexCoordY getY);
543 void insertVertices(const std::vector<V2d<T> >& vertices);
578 template <
579 typename TEdgeIter,
580 typename TGetEdgeVertexStart,
581 typename TGetEdgeVertexEnd>
582 void insertEdges(
583 TEdgeIter first,
584 TEdgeIter last,
585 TGetEdgeVertexStart getStart,
586 TGetEdgeVertexEnd getEnd);
612 void insertEdges(const std::vector<Edge>& edges);
647 template <
648 typename TEdgeIter,
649 typename TGetEdgeVertexStart,
650 typename TGetEdgeVertexEnd>
651 void conformToEdges(
652 TEdgeIter first,
653 TEdgeIter last,
654 TGetEdgeVertexStart getStart,
655 TGetEdgeVertexEnd getEnd);
681 void conformToEdges(const std::vector<Edge>& edges);
689 void eraseOuterTriangles();
702
708 bool isFinalized() const;
709
723 std::vector<LayerDepth> calculateTriangleDepths() const;
724
725#ifdef CDT_ENABLE_CALLBACK_HANDLER
733 void setCallbackHandler(ICallbackHandler* callbackHandler);
734#endif
741
749 void flipEdge(TriInd iT, TriInd iTopo);
750
755 void flipEdge(
756 TriInd iT,
757 TriInd iTopo,
758 VertInd v1,
759 VertInd v2,
760 VertInd v3,
761 VertInd v4,
762 TriInd n1,
763 TriInd n2,
764 TriInd n3,
765 TriInd n4);
766
772 void removeTriangles(const TriIndUSet& removedTriangles);
773
777 const TriIndVec& VertTrisInternal() const;
779
780private:
781 /*____ Detail __*/
782 void addSuperTriangle(const Box2d<T>& box);
783 void addNewVertex(const V2d<T>& pos, TriInd iT);
784 void insertVertex(VertInd iVert);
785 void insertVertex(VertInd iVert, VertInd walkStart);
786 void ensureDelaunayByEdgeFlips(VertInd iV1, std::stack<TriInd>& triStack);
788 std::vector<Edge> insertVertex_FlipFixedEdges(VertInd iV1);
789
791 typedef tuple<IndexSizeType, IndexSizeType, TriInd, TriInd, Index>
792 TriangulatePseudoPolygonTask;
793
806 void insertEdge(
807 Edge edge,
808 Edge originalEdge,
809 EdgeVec& remaining,
810 std::vector<TriangulatePseudoPolygonTask>& tppIterations);
811
824 void insertEdgeIteration(
825 Edge edge,
826 Edge originalEdge,
827 EdgeVec& remaining,
828 std::vector<TriangulatePseudoPolygonTask>& tppIterations);
829
831 typedef tuple<Edge, EdgeVec, BoundaryOverlapCount> ConformToEdgeTask;
832
845 void conformToEdge(
846 Edge edge,
847 EdgeVec originals,
848 BoundaryOverlapCount overlaps,
849 std::vector<ConformToEdgeTask>& remaining);
850
862 void conformToEdgeIteration(
863 Edge edge,
864 const EdgeVec& originals,
865 BoundaryOverlapCount overlaps,
866 std::vector<ConformToEdgeTask>& remaining);
867
868 tuple<TriInd, VertInd, VertInd> intersectedTriangle(
869 VertInd iA,
870 const V2d<T>& a,
871 const V2d<T>& b,
872 T orientationTolerance = T(0)) const;
874 std::stack<TriInd> insertVertexInsideTriangle(VertInd v, TriInd iT);
876 std::stack<TriInd> insertVertexOnEdge(
877 VertInd v,
878 TriInd iT1,
879 TriInd iT2,
880 const bool doHandleFixedSplitEdge = false);
881 array<TriInd, 2> trianglesAt(const V2d<T>& pos) const;
882 array<TriInd, 2>
883 walkingSearchTrianglesAt(VertInd iV, VertInd startVertex) const;
884 TriInd walkTriangles(VertInd startVertex, const V2d<T>& pos) const;
887 void edgeFlipInfo(
888 TriInd iT,
889 VertInd iV1,
890 TriInd& iTopo,
891 VertInd& iV2,
892 VertInd& iV3,
893 VertInd& iV4,
894 TriInd& n1,
895 TriInd& n2,
896 TriInd& n3,
897 TriInd& n4);
898 bool isFlipNeeded(VertInd iV1, VertInd iV2, VertInd iV3, VertInd iV4) const;
899 void changeNeighbor(TriInd iT, TriInd oldNeighbor, TriInd newNeighbor);
900 void changeNeighbor(
901 TriInd iT,
902 VertInd iVedge1,
903 VertInd iVedge2,
904 TriInd newNeighbor);
905 void triangulatePseudoPolygon(
906 const std::vector<VertInd>& poly,
907 unordered_map<Edge, TriInd>& outerTris,
908 TriInd iT,
909 TriInd iN,
910 std::vector<TriInd>& trianglesToReuse,
911 std::vector<TriangulatePseudoPolygonTask>& iterations);
912 void triangulatePseudoPolygonIteration(
913 const std::vector<VertInd>& poly,
914 unordered_map<Edge, TriInd>& outerTris,
915 std::vector<TriInd>& trianglesToReuse,
916 std::vector<TriangulatePseudoPolygonTask>& iterations);
917 IndexSizeType findDelaunayPoint(
918 const std::vector<VertInd>& poly,
919 IndexSizeType iA,
920 IndexSizeType iB) const;
921 TriInd addTriangle(const Triangle& t);
922 TriInd addTriangle();
928 void finalizeTriangulation(const TriIndUSet& removedTriangles);
929 TriIndUSet growToBoundary(std::stack<TriInd> seeds) const;
930 void fixEdge(const Edge& edge);
931 void fixEdge(const Edge& edge, const Edge& originalEdge);
937 void splitFixedEdge(const Edge& edge, const VertInd iSplitVert);
946 VertInd addSplitEdgeVertex(
947 const V2d<T>& splitVert,
948 const TriInd iT,
949 const TriInd iTopo);
959 VertInd splitFixedEdgeAt(
960 const Edge& edge,
961 const V2d<T>& splitVert,
962 const TriInd iT,
963 const TriInd iTopo);
982 bool isEdgeSplitVertexValid(
983 const V2d<T>& splitVert,
984 TriInd iT,
985 TriInd iTopo,
986 VertInd iVL,
987 VertInd iVR) const;
995 Edge originalInputEdge(const Edge& e) const;
1003 const Triangle& triangleAt(TriInd iT) const;
1019 unordered_map<TriInd, LayerDepth> peelLayer(
1020 std::stack<TriInd> seeds,
1021 LayerDepth layerDepth,
1022 std::vector<LayerDepth>& triDepths) const;
1023
1024 void insertVertices_AsProvided(VertInd superGeomVertCount);
1025 void insertVertices_Randomized(VertInd superGeomVertCount);
1026 void insertVertices_KDTreeBFS(VertInd superGeomVertCount, Box2d<T> box);
1027 std::pair<TriInd, TriInd> edgeTriangles(VertInd a, VertInd b) const;
1028 bool hasEdge(VertInd a, VertInd b) const;
1029 void setAdjacentTriangle(const VertInd v, const TriInd t);
1030 void pivotVertexTriangleCW(VertInd v);
1032 void tryAddVertexToLocator(const VertInd v);
1035 void tryInitNearestPointLocator();
1036
1037 TNearPointLocator m_nearPtLocator;
1038 VertInd m_nTargetVerts;
1039 SuperGeometryType::Enum m_superGeomType;
1040 VertexInsertionOrder::Enum m_vertexInsertionOrder;
1041 IntersectingConstraintEdges::Enum m_intersectingEdgesStrategy;
1042 T m_minDistToConstraintEdge;
1043 TriIndVec m_vertTris;
1044#ifdef CDT_ENABLE_CALLBACK_HANDLER
1045 ICallbackHandler* m_callbackHandler;
1046#endif
1047};
1048
1051
1052namespace detail
1053{
1054
1057{
1058 typedef unsigned long long uint64;
1062 : m_state(state)
1063 {}
1064
1066 : m_state(0)
1067 {}
1068
1070 {
1071 uint64 z = (m_state += 0x9e3779b97f4a7c15);
1072 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
1073 z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
1074 return z ^ (z >> 31);
1075 }
1076};
1077
1079template <class RandomIt>
1080void random_shuffle(RandomIt first, RandomIt last)
1081{
1083 typename std::iterator_traits<RandomIt>::difference_type i, n;
1084 n = last - first;
1085 for(i = n - 1; i > 0; --i)
1086 {
1087 std::swap(first[i], first[prng() % (i + 1)]);
1088 }
1089}
1090
1092template <class ForwardIt, class T>
1093void iota(ForwardIt first, ForwardIt last, T value)
1094{
1095 while(first != last)
1096 {
1097 *first++ = value;
1098 ++value;
1099 }
1100}
1101
1102} // namespace detail
1103
1104//-----------------------
1105// Triangulation methods
1106//-----------------------
1107template <typename T, typename TNearPointLocator>
1108template <
1109 typename TVertexIter,
1110 typename TGetVertexCoordX,
1111 typename TGetVertexCoordY>
1113 const TVertexIter first,
1114 const TVertexIter last,
1115 TGetVertexCoordX getX,
1116 TGetVertexCoordY getY)
1117{
1118 if(isFinalized())
1119 handleException(FinalizedError(CDT_SOURCE_LOCATION));
1120
1121 const bool isFirstTime = vertices.empty();
1122
1123 //
1124 // performance optimization: pre-allocate triangles and vertices
1125 //
1126 const std::size_t nNewVertices = std::distance(first, last);
1127 std::size_t exactCapacityTriangles = triangles.size() + 2 * nNewVertices;
1128 std::size_t exactCapacityVertices = vertices.size() + nNewVertices;
1129 if(isFirstTime) // account for adding super-triangle on the first run
1130 {
1131 exactCapacityTriangles += 1;
1132 exactCapacityVertices += nSuperTriangleVertices;
1133 }
1134 std::size_t capacityTriangles = exactCapacityTriangles;
1135 std::size_t capacityVertices = exactCapacityVertices;
1136 // to avoid re-allocation and unused memory
1137 // over-allocate by a fixed factor
1138 // when constraint edge intersections are resolved and vertices are many
1139 // because vertex is added for each intersection
1140 // and total number of intersections is unknown
1141 const VertInd overAllocationVerticesThreshold(1000);
1142 const T overAllocationFactor(1.1);
1143 const bool isOverPreAllocated =
1144 m_intersectingEdgesStrategy ==
1146 VertInd(nNewVertices) >= overAllocationVerticesThreshold;
1147 if(isOverPreAllocated)
1148 {
1149 capacityTriangles *= overAllocationFactor;
1150 capacityVertices *= overAllocationFactor;
1151 }
1152 triangles.reserve(capacityTriangles);
1153 vertices.reserve(capacityVertices);
1154 m_vertTris.reserve(capacityVertices);
1155
1156 Box2d<T> box;
1157 if(isFirstTime)
1158 {
1159 box.envelopPoints(first, last, getX, getY);
1160 addSuperTriangle(box);
1161 }
1162 tryInitNearestPointLocator();
1163 const VertInd nExistingVerts = static_cast<VertInd>(vertices.size());
1164
1165 for(TVertexIter it = first; it != last; ++it)
1166 addNewVertex(V2d<T>(getX(*it), getY(*it)), noNeighbor);
1167
1168 switch(m_vertexInsertionOrder)
1169 {
1171 insertVertices_AsProvided(nExistingVerts);
1172 break;
1174 isFirstTime ? insertVertices_KDTreeBFS(nExistingVerts, box)
1175 : insertVertices_Randomized(nExistingVerts);
1176 break;
1177 }
1178
1179// make sure pre-allocation was correct
1180#ifdef CDT_ENABLE_CALLBACK_HANDLER
1181 assert(
1182 !m_callbackHandler || m_callbackHandler->isAbortCalculation() ||
1183 (vertices.size() == exactCapacityVertices));
1184 assert(
1185 !m_callbackHandler || m_callbackHandler->isAbortCalculation() ||
1186 (triangles.size() == exactCapacityTriangles));
1187#else
1188 assert(vertices.size() == exactCapacityVertices);
1189 assert(triangles.size() == exactCapacityTriangles);
1190#endif
1191}
1192
1193template <typename T, typename TNearPointLocator>
1194template <
1195 typename TEdgeIter,
1196 typename TGetEdgeVertexStart,
1197 typename TGetEdgeVertexEnd>
1199 TEdgeIter first,
1200 const TEdgeIter last,
1201 TGetEdgeVertexStart getStart,
1202 TGetEdgeVertexEnd getEnd)
1203{
1204 if(isFinalized())
1205 handleException(FinalizedError(CDT_SOURCE_LOCATION));
1206
1207 std::vector<TriangulatePseudoPolygonTask> tppIterations;
1208 EdgeVec remaining;
1209 for(; first != last; ++first)
1210 {
1211#ifdef CDT_ENABLE_CALLBACK_HANDLER
1212 if(m_callbackHandler && m_callbackHandler->isAbortCalculation())
1213 {
1214 return;
1215 }
1216#endif
1217 // +3 to account for super-triangle vertices
1218 const Edge edge(
1219 VertInd(getStart(*first) + m_nTargetVerts),
1220 VertInd(getEnd(*first) + m_nTargetVerts));
1221 insertEdge(edge, edge, remaining, tppIterations);
1222 }
1223}
1224
1225template <typename T, typename TNearPointLocator>
1226template <
1227 typename TEdgeIter,
1228 typename TGetEdgeVertexStart,
1229 typename TGetEdgeVertexEnd>
1231 TEdgeIter first,
1232 const TEdgeIter last,
1233 TGetEdgeVertexStart getStart,
1234 TGetEdgeVertexEnd getEnd)
1235{
1236 if(isFinalized())
1237 handleException(FinalizedError(CDT_SOURCE_LOCATION));
1238
1239 tryInitNearestPointLocator();
1240 // state shared between different runs for performance gains
1241 std::vector<ConformToEdgeTask> remaining;
1242 for(; first != last; ++first)
1243 {
1244#ifdef CDT_ENABLE_CALLBACK_HANDLER
1245 if(m_callbackHandler && m_callbackHandler->isAbortCalculation())
1246 {
1247 return;
1248 }
1249#endif
1250 // +3 to account for super-triangle vertices
1251 const Edge e(
1252 VertInd(getStart(*first) + m_nTargetVerts),
1253 VertInd(getEnd(*first) + m_nTargetVerts));
1254 conformToEdge(e, EdgeVec(1, e), 0, remaining);
1255 }
1256}
1257
1258} // namespace CDT
1259
1260#ifndef CDT_USE_AS_COMPILED_LIBRARY
1261#include "Triangulation.hpp"
1262#endif
1263
1264#endif // header-guard
Utilities and helpers.
Adapter between for KDTree and CDT.
void random_shuffle(RandomIt first, RandomIt last)
backport from c++11
void iota(ForwardIt first, ForwardIt last, T value)
backport from c++11
Triangulation class - implementation.
VertInd v2() const
second duplicate
VertInd v1() const
first duplicate
DuplicateVertexError(const VertInd v1, const VertInd v2, const SourceLocation &srcLoc)
Constructor.
virtual ~Error() CDT_NOEXCEPT
Destructor.
const SourceLocation & sourceLocation() const
Get source location from where the error was thrown.
Error(const std::string &description, const SourceLocation &srcLoc)
Constructor.
const std::string & description() const
Get error description.
Error thrown when triangulation modification is attempted after it was finalized.
FinalizedError(const SourceLocation &srcLoc)
Constructor.
Interface for the callback handler that user can derive from and inject into the triangulation to mon...
virtual void onAddSuperTriangle()
Called when super-triangle is added.
virtual void onInsertVertexOnEdge(const TriInd iRepurposedTri1, const TriInd iRepurposedTri2, const TriInd iNewTri1, const TriInd iNewTri2)
Called when inserted vertex is on an edge.
virtual bool isAbortCalculation() const
Tells whether the user wants to abort the triangulation at the earliest opportunity.
virtual ~ICallbackHandler()
Virtual destructor.
virtual void onReTriangulatePolygon(const std::vector< TriInd > &tris)
Called when inserting a constraint edge causes polygon containing triangles to be re-triangulated @tr...
virtual void onFlipEdge(const TriInd iT, const TriInd iTopo)
Called just before an edge between tro triangles is flipped.
virtual void onInsertVertexInsideTriangle(const TriInd iRepurposedTri, const TriInd iNewTri1, const TriInd iNewTri2)
Called when inserted vertex is inside a triangle.
virtual void onAddEdgeStart(const Edge &edge)
Called at the start of adding a constraint edge to the triangulation.
virtual void onAddVertexStart(const VertInd iV, const AddVertexType::Enum vertexType)
Called at the start of adding new vertex to the triangulation.
const Edge & e1() const
first intersecting constraint
const Edge & e2() const
second intersecting constraint
IntersectingConstraintsError(const Edge &e1, const Edge &e2, const SourceLocation &srcLoc)
Constructor.
const Edge & e2() const
second intersecting constraint
const Edge & e1() const
first intersecting constraint
InvalidEdgeSplitVertex(const Edge &e1, const Edge &e2, const SourceLocation &srcLoc)
Constructor.
Contains source location info: file, function, line.
SourceLocation(const std::string &file, const std::string &func, int line)
Constructor.
const std::string & func() const
source function
int line() const
source line
const std::string & file() const
source file
EdgeUSet fixedEdges
triangulation's constraints (fixed edges)
void eraseOuterTriangles()
Erase triangles outside of constrained boundary using growing.
void conformToEdges(TEdgeIter first, TEdgeIter last, TGetEdgeVertexStart getStart, TGetEdgeVertexEnd getEnd)
Insert constraint edges into triangulation for Conforming Delaunay Triangulation (for example see fig...
std::vector< V2d< T > > V2dVec
Vertices vector.
std::vector< LayerDepth > calculateTriangleDepths() const
Calculate depth of each triangle in constraint triangulation.
bool isFinalized() const
Check if the triangulation was finalized with erase... method and super-triangle was removed.
Triangulation(VertexInsertionOrder::Enum vertexInsertionOrder)
Constructor.
void eraseOuterTrianglesAndHoles()
Erase triangles outside of constrained boundary and auto-detected holes.
V2dVec vertices
triangulation's vertices
void insertEdges(TEdgeIter first, TEdgeIter last, TGetEdgeVertexStart getStart, TGetEdgeVertexEnd getEnd)
Insert constraint edges into triangulation for Constrained Delaunay Triangulation (for example see fi...
void insertVertices(TVertexIter first, TVertexIter last, TGetVertexCoordX getX, TGetVertexCoordY getY)
Insert custom point-types specified by iterator range and X/Y-getters.
Triangulation(VertexInsertionOrder::Enum vertexInsertionOrder, IntersectingConstraintEdges::Enum intersectingEdgesStrategy, T minDistToConstraintEdge)
Constructor.
void eraseSuperTriangle()
Erase triangles adjacent to super triangle.
unordered_map< Edge, EdgeVec > pieceToOriginals
Stores list of original edges represented by a given fixed edge.
Triangulation(VertexInsertionOrder::Enum vertexInsertionOrder, const TNearPointLocator &nearPtLocator, IntersectingConstraintEdges::Enum intersectingEdgesStrategy, T minDistToConstraintEdge)
Constructor.
unordered_map< Edge, BoundaryOverlapCount > overlapCount
Stores count of overlapping boundaries for a fixed edge.
TriangleVec triangles
triangulation's triangles
Triangulation()
Default constructor.
void setCallbackHandler(ICallbackHandler *callbackHandler)
Set user-provided callback handler.
void initializedWithCustomSuperGeometry()
Call this method after directly setting custom super-geometry via vertices and triangles members.
unsigned short LayerDepth
Type used for storing layer depths for triangles.
Definition CDT.h:40
void flipEdge(TriInd iT, TriInd iTopo)
Flip an edge between two triangle.
TriIndVec & VertTrisInternal()
Access internal vertex adjacent triangles.
void removeTriangles(const TriIndUSet &removedTriangles)
Remove triangles with specified indices.
Namespace containing triangulation functionality.
std::vector< Edge > EdgeVec
Vector of edges.
Definition CDTUtils.h:346
unordered_set< Edge > EdgeUSet
Hash table of edges.
Definition CDTUtils.h:347
std::vector< TriInd > TriIndVec
Vector of triangle indices.
Definition CDTUtils.h:225
IndexSizeType VertInd
Vertex index.
Definition CDTUtils.h:207
unordered_set< TriInd > TriIndUSet
Hash table of triangles.
Definition CDTUtils.h:348
IndexSizeType TriInd
Triangle index.
Definition CDTUtils.h:209
std::vector< Triangle > TriangleVec
Vector of triangles.
Definition CDTUtils.h:411
What type of vertex is added to the triangulation.
Enum
The Enum itself.
@ UserInput
Original vertex from user input.
@ FixedEdgeMidpoint
During conforming triangulation edge mid-point is added.
@ FixedEdgesIntersection
Resolving fixed/constraint edges' intersection.
2D bounding box
Definition CDTUtils.h:232
Box2d< T > & envelopPoints(TVertexIter first, TVertexIter last, TGetVertexCoordX getX, TGetVertexCoordY getY)
Envelop box around a collection of custom points.
Definition CDTUtils.h:263
Edge connecting two vertices: vertex with smaller index is always first.
Definition CDTUtils.h:287
Enum of strategies for treating intersecting constraint edges.
@ TryResolve
attempt to resolve constraint edge intersections
@ NotAllowed
constraint edge intersections are not allowed
@ DontCheck
No checks: slightly faster but less safe.
Enum of what type of geometry used to embed triangulation into.
Enum
The Enum itself.
@ SuperTriangle
conventional super-triangle
@ Custom
user-specified custom geometry (e.g., grid)
What type of triangle change happened.
@ AddedNew
new triangle added to the triangulation
@ ModifiedExisting
existing triangle was modified
Triangulation triangle (counter-clockwise winding)
Definition CDTUtils.h:360
2D vector
Definition CDTUtils.h:145
Enum of strategies specifying order in which a range of vertices is inserted.
@ AsProvided
insert vertices in same order they are provided
@ Auto
Automatic insertion order optimized for better performance.
SplitMix64 pseudo-random number generator.
SplitMix64RandGen()
default constructor
uint64 operator()()
functor's operator
unsigned long long uint64
uint64 type
SplitMix64RandGen(uint64 state)
constructor