CDT  1.4.1
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
10#include "CDT.h"
11
12#include <algorithm>
13#include <deque>
14#include <limits>
15#include <stdexcept>
16
17namespace CDT
18{
19
21 const TriangleVec& triangles,
22 const VertInd verticesSize)
23{
24 VerticesTriangles vertTris(verticesSize);
25 for(TriInd iT(0); iT < triangles.size(); ++iT)
26 {
27 const VerticesArr3& vv = triangles[iT].vertices;
28 for(VerticesArr3::const_iterator v = vv.begin(); v != vv.end(); ++v)
29 {
30 vertTris[*v].push_back(iT);
31 }
32 }
33 return vertTris;
34}
35
36template <typename T>
37DuplicatesInfo RemoveDuplicates(std::vector<V2d<T> >& vertices)
38{
40 vertices.begin(), vertices.end(), getX_V2d<T>, getY_V2d<T>);
41 RemoveDuplicates(vertices, di.duplicates);
42 return di;
43}
44
46RemapEdges(std::vector<Edge>& edges, const std::vector<std::size_t>& mapping)
47{
49 edges.begin(),
50 edges.end(),
51 mapping,
54 edge_make);
55}
56
57template <typename T>
59 std::vector<V2d<T> >& vertices,
60 std::vector<Edge>& edges)
61{
63 vertices,
66 edges.begin(),
67 edges.end(),
70 edge_make);
71}
72
75{
76 EdgeUSet edges;
77 typedef TriangleVec::const_iterator CIt;
78 for(CIt t = triangles.begin(); t != triangles.end(); ++t)
79 {
80 edges.insert(Edge(VertInd(t->vertices[0]), VertInd(t->vertices[1])));
81 edges.insert(Edge(VertInd(t->vertices[1]), VertInd(t->vertices[2])));
82 edges.insert(Edge(VertInd(t->vertices[2]), VertInd(t->vertices[0])));
83 }
84 return edges;
85}
86
87CDT_INLINE_IF_HEADER_ONLY unordered_map<Edge, EdgeVec>
88EdgeToPiecesMapping(const unordered_map<Edge, EdgeVec>& pieceToOriginals)
89{
90 unordered_map<Edge, EdgeVec> originalToPieces;
91 typedef unordered_map<Edge, EdgeVec>::const_iterator Cit;
92 for(Cit ptoIt = pieceToOriginals.begin(); ptoIt != pieceToOriginals.end();
93 ++ptoIt)
94 {
95 const Edge piece = ptoIt->first;
96 const EdgeVec& originals = ptoIt->second;
97 for(EdgeVec::const_iterator origIt = originals.begin();
98 origIt != originals.end();
99 ++origIt)
100 {
101 originalToPieces[*origIt].push_back(piece);
102 }
103 }
104 return originalToPieces;
105}
106
107} // namespace CDT
#define CDT_INLINE_IF_HEADER_ONLY
Macro for inlining non-template functions when in header-only mode to avoid multiple declaration erro...
Definition CDTUtils.h:38
Public API.
std::vector< TriIndVec > VerticesTriangles
Triangles by vertex index.
Definition CDT.h:44
CDT_EXPORT 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
CDT_EXPORT VerticesTriangles calculateTrianglesByVertex(const TriangleVec &triangles, VertInd verticesSize)
Calculate triangles adjacent to vertices (triangles by vertex index)
Definition CDT.hpp:20
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
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:74
CDT_EXPORT unordered_map< Edge, EdgeVec > EdgeToPiecesMapping(const unordered_map< Edge, EdgeVec > &pieceToOriginals)
Definition CDT.hpp:88
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:245
unordered_set< Edge > EdgeUSet
Hash table of edges.
Definition CDTUtils.h:246
VertInd edge_get_v2(const Edge &e)
Get edge second vertex.
Definition CDTUtils.h:234
VertInd edge_get_v1(const Edge &e)
Get edge first vertex.
Definition CDTUtils.h:228
IndexSizeType VertInd
Vertex index.
Definition CDTUtils.h:142
array< VertInd, 3 > VerticesArr3
array of three vertex indices
Definition CDTUtils.h:156
Edge edge_make(VertInd iV1, VertInd iV2)
Get edge second vertex.
Definition CDTUtils.h:240
const T & getX_V2d(const V2d< T > &v)
X- coordinate getter for V2d.
Definition CDTUtils.h:106
IndexSizeType TriInd
Triangle index.
Definition CDTUtils.h:144
std::vector< Triangle > TriangleVec
Vector of triangles.
Definition CDTUtils.h:308
const T & getY_V2d(const V2d< T > &v)
Y-coordinate getter for V2d.
Definition CDTUtils.h:113
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:209
2D vector
Definition CDTUtils.h:96