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
19namespace CDT
20{
21
23 const TriangleVec& triangles,
24 const VertInd verticesSize)
25{
26 VerticesTriangles vertTris(verticesSize);
27 for(TriInd iT(0); iT < triangles.size(); ++iT)
28 {
29 const VerticesArr3& vv = triangles[iT].vertices;
30 for(VerticesArr3::const_iterator v = vv.begin(); v != vv.end(); ++v)
31 {
32 vertTris[*v].push_back(iT);
33 }
34 }
35 return vertTris;
36}
37
38template <typename T>
39DuplicatesInfo RemoveDuplicates(std::vector<V2d<T> >& vertices)
40{
42 vertices.begin(), vertices.end(), getX_V2d<T>, getY_V2d<T>);
43 RemoveDuplicates(vertices, di.duplicates);
44 return di;
45}
46
47CDT_INLINE_IF_HEADER_ONLY void
48RemapEdges(std::vector<Edge>& edges, const std::vector<std::size_t>& mapping)
49{
51 edges.begin(),
52 edges.end(),
53 mapping,
56 edge_make);
57}
58
59template <typename T>
61 std::vector<V2d<T> >& vertices,
62 std::vector<Edge>& edges)
63{
65 vertices,
68 edges.begin(),
69 edges.end(),
72 edge_make);
73}
74
75CDT_INLINE_IF_HEADER_ONLY EdgeUSet
77{
78 EdgeUSet edges;
79 typedef TriangleVec::const_iterator CIt;
80 for(CIt t = triangles.begin(); t != triangles.end(); ++t)
81 {
82 edges.insert(Edge(VertInd(t->vertices[0]), VertInd(t->vertices[1])));
83 edges.insert(Edge(VertInd(t->vertices[1]), VertInd(t->vertices[2])));
84 edges.insert(Edge(VertInd(t->vertices[2]), VertInd(t->vertices[0])));
85 }
86 return edges;
87}
88
89CDT_INLINE_IF_HEADER_ONLY unordered_map<Edge, EdgeVec>
90EdgeToPiecesMapping(const unordered_map<Edge, EdgeVec>& pieceToOriginals)
91{
92 unordered_map<Edge, EdgeVec> originalToPieces;
93 typedef unordered_map<Edge, EdgeVec>::const_iterator Cit;
94 for(Cit ptoIt = pieceToOriginals.begin(); ptoIt != pieceToOriginals.end();
95 ++ptoIt)
96 {
97 const Edge piece = ptoIt->first;
98 const EdgeVec& originals = ptoIt->second;
99 for(EdgeVec::const_iterator origIt = originals.begin();
100 origIt != originals.end();
101 ++origIt)
102 {
103 originalToPieces[*origIt].push_back(piece);
104 }
105 }
106 return originalToPieces;
107}
108
109} // namespace CDT
110
111#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:22
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:76
CDT_EXPORT unordered_map< Edge, EdgeVec > EdgeToPiecesMapping(const unordered_map< Edge, EdgeVec > &pieceToOriginals)
Definition CDT.hpp:90
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:346
unordered_set< Edge > EdgeUSet
Hash table of edges.
Definition CDTUtils.h:347
VertInd edge_get_v2(const Edge &e)
Get edge second vertex.
Definition CDTUtils.h:335
VertInd edge_get_v1(const Edge &e)
Get edge first vertex.
Definition CDTUtils.h:329
IndexSizeType VertInd
Vertex index.
Definition CDTUtils.h:207
array< VertInd, 3 > VerticesArr3
array of three vertex indices
Definition CDTUtils.h:226
Edge edge_make(VertInd iV1, VertInd iV2)
Get edge second vertex.
Definition CDTUtils.h:341
const T & getX_V2d(const V2d< T > &v)
X- coordinate getter for V2d.
Definition CDTUtils.h:164
IndexSizeType TriInd
Triangle index.
Definition CDTUtils.h:209
std::vector< Triangle > TriangleVec
Vector of triangles.
Definition CDTUtils.h:411
const T & getY_V2d(const V2d< T > &v)
Y-coordinate getter for V2d.
Definition CDTUtils.h:171
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:287
2D vector
Definition CDTUtils.h:145