CDT  1.4.5
C++ library for constrained Delaunay triangulation
Loading...
Searching...
No Matches
CDT.hpp
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#ifndef CDT_WbKVsqQQaFWUcDDZzmmC
10#define CDT_WbKVsqQQaFWUcDDZzmmC
11
12#include "CDT.h"
13
14#include <algorithm>
15#include <deque>
16#include <limits>
17#include <stdexcept>
18
19CDT_ENSURE_PRECISE_MATH_FOR_CONSTRUCTIONS
20
21namespace CDT
22{
23
25 const TriangleVec& triangles,
26 const VertInd verticesSize)
27{
28 VerticesTriangles vertTris(verticesSize);
29 for(TriInd iT(0); iT < triangles.size(); ++iT)
30 {
31 const VerticesArr3& vv = triangles[iT].vertices;
32 for(VerticesArr3::const_iterator v = vv.begin(); v != vv.end(); ++v)
33 {
34 vertTris[*v].push_back(iT);
35 }
36 }
37 return vertTris;
38}
39
40template <typename T>
41DuplicatesInfo RemoveDuplicates(std::vector<V2d<T> >& vertices)
42{
44 vertices.begin(), vertices.end(), getX_V2d<T>, getY_V2d<T>);
45 RemoveDuplicates(vertices, di.duplicates);
46 return di;
47}
48
49CDT_INLINE_IF_HEADER_ONLY void
50RemapEdges(std::vector<Edge>& edges, const std::vector<std::size_t>& mapping)
51{
53 edges.begin(),
54 edges.end(),
55 mapping,
58 edge_make);
59}
60
61template <typename T>
63 std::vector<V2d<T> >& vertices,
64 std::vector<Edge>& edges)
65{
67 vertices,
70 edges.begin(),
71 edges.end(),
74 edge_make);
75}
76
77CDT_INLINE_IF_HEADER_ONLY EdgeUSet
79{
80 EdgeUSet edges;
81 typedef TriangleVec::const_iterator CIt;
82 for(CIt t = triangles.begin(); t != triangles.end(); ++t)
83 {
84 edges.insert(Edge(VertInd(t->vertices[0]), VertInd(t->vertices[1])));
85 edges.insert(Edge(VertInd(t->vertices[1]), VertInd(t->vertices[2])));
86 edges.insert(Edge(VertInd(t->vertices[2]), VertInd(t->vertices[0])));
87 }
88 return edges;
89}
90
91CDT_INLINE_IF_HEADER_ONLY unordered_map<Edge, EdgeVec>
92EdgeToPiecesMapping(const unordered_map<Edge, EdgeVec>& pieceToOriginals)
93{
94 unordered_map<Edge, EdgeVec> originalToPieces;
95 typedef unordered_map<Edge, EdgeVec>::const_iterator Cit;
96 for(Cit ptoIt = pieceToOriginals.begin(); ptoIt != pieceToOriginals.end();
97 ++ptoIt)
98 {
99 const Edge piece = ptoIt->first;
100 const EdgeVec& originals = ptoIt->second;
101 for(EdgeVec::const_iterator origIt = originals.begin();
102 origIt != originals.end();
103 ++origIt)
104 {
105 originalToPieces[*origIt].push_back(piece);
106 }
107 }
108 return originalToPieces;
109}
110
111} // namespace CDT
112
113CDT_RESTORE_MATH_SETTINGS_FOR_CONSTRUCTIONS
114
115#endif // header-guard
Public API.
std::vector< TriIndVec > VerticesTriangles
Triangles by vertex index.
Definition CDT.h:44
CDT_EXPORT VerticesTriangles calculateTrianglesByVertex(const TriangleVec &triangles, VertInd verticesSize)
Calculate triangles adjacent to vertices (triangles by vertex index)
Definition CDT.hpp:24
void RemoveDuplicates(std::vector< TVertex, TAllocator > &vertices, const std::vector< std::size_t > &duplicates)
Remove duplicates in-place from vector of custom points.
Definition CDT.h:322
void RemapEdges(TEdgeIter first, TEdgeIter last, const std::vector< std::size_t > &mapping, TGetEdgeVertexStart getStart, TGetEdgeVertexEnd getEnd, TMakeEdgeFromStartAndEnd makeEdge)
Remap vertex indices in edges (in-place) using given vertex-index mapping.
Definition CDT.h:340
DuplicatesInfo RemoveDuplicatesAndRemapEdges(std::vector< TVertex, TVertexAllocator > &vertices, TGetVertexCoordX getX, TGetVertexCoordY getY, TEdgeIter edgesFirst, TEdgeIter edgesLast, TGetEdgeVertexStart getStart, TGetEdgeVertexEnd getEnd, TMakeEdgeFromStartAndEnd makeEdge)
Find point duplicates, remove them from vector (in-place) and remap edges (in-place)
Definition CDT.h:366
CDT_EXPORT EdgeUSet extractEdgesFromTriangles(const TriangleVec &triangles)
Extract all edges of triangles.
Definition CDT.hpp:78
CDT_EXPORT unordered_map< Edge, EdgeVec > EdgeToPiecesMapping(const unordered_map< Edge, EdgeVec > &pieceToOriginals)
Definition CDT.hpp:92
DuplicatesInfo FindDuplicates(TVertexIter first, TVertexIter last, TGetVertexCoordX getX, TGetVertexCoordY getY)
Find duplicates in given custom point-type range.
Definition CDT.h:293
Namespace containing triangulation functionality.
std::vector< Edge > EdgeVec
Vector of edges.
Definition CDTUtils.h:386
unordered_set< Edge > EdgeUSet
Hash table of edges.
Definition CDTUtils.h:387
VertInd edge_get_v2(const Edge &e)
Get edge second vertex.
Definition CDTUtils.h:375
VertInd edge_get_v1(const Edge &e)
Get edge first vertex.
Definition CDTUtils.h:369
IndexSizeType VertInd
Vertex index.
Definition CDTUtils.h:247
array< VertInd, 3 > VerticesArr3
array of three vertex indices
Definition CDTUtils.h:266
Edge edge_make(VertInd iV1, VertInd iV2)
Get edge second vertex.
Definition CDTUtils.h:381
const T & getX_V2d(const V2d< T > &v)
X- coordinate getter for V2d.
Definition CDTUtils.h:204
IndexSizeType TriInd
Triangle index.
Definition CDTUtils.h:249
std::vector< Triangle > TriangleVec
Vector of triangles.
Definition CDTUtils.h:451
const T & getY_V2d(const V2d< T > &v)
Y-coordinate getter for V2d.
Definition CDTUtils.h:211
Information about removed duplicated vertices.
Definition CDT.h:68
std::vector< std::size_t > duplicates
duplicates' indices
Definition CDT.h:70
Edge connecting two vertices: vertex with smaller index is always first.
Definition CDTUtils.h:327
2D vector
Definition CDTUtils.h:185