https://mooseframework.inl.gov
Loading...
Searching...
No Matches
XYIncrementalDelaunay.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include <array>
13#include <cstddef>
14#include <limits>
15#include <set>
16#include <string>
17#include <utility>
18#include <vector>
19
46{
47public:
49 static constexpr std::size_t invalid_index = std::numeric_limits<std::size_t>::max();
50
52 struct Point2D
53 {
54 double x;
55 double y;
56 };
57
65 struct Triangle
66 {
67 std::array<std::size_t, 3> vertices;
68 std::array<std::size_t, 3> neighbors;
69 };
70
72 using Segment = std::pair<std::size_t, std::size_t>;
73
75 static Segment makeSegment(std::size_t v0, std::size_t v1);
76
86 void initialize(const std::vector<Point2D> & points, const std::vector<Segment> & segments);
87
96 std::size_t insertPoint(const Point2D & p);
97
108 void insertSegment(std::size_t v0, std::size_t v1);
109
111 std::size_t numPoints() const;
112
114 const Point2D & point(std::size_t id) const;
115
121 std::vector<Triangle> getTriangles() const;
122
124 bool isConstrainedSegment(std::size_t v0, std::size_t v1) const;
125
127 const std::set<Segment> & constrainedSegments() const { return _constraints; }
128
136 std::vector<std::string> checkInvariants() const;
137
145 std::vector<std::string> checkEmptyCircumcircle() const;
146
147private:
149 static constexpr std::size_t _num_bounding = 3;
150
152 static constexpr double _bounding_reach = 1000.0;
153
155 const double * xy(std::size_t v) const { return &_vertices[v].x; }
156
158 static bool isBounding(std::size_t v) { return v < _num_bounding; }
159
161 std::size_t toInternal(std::size_t id) const;
162
164 std::size_t toCaller(std::size_t v) const;
165
167 bool isConstrainedEdge(std::size_t v0, std::size_t v1) const;
168
170 unsigned int localVertexIndex(std::size_t t, std::size_t v) const;
171
173 unsigned int localEdgeIndex(std::size_t t, const Segment & edge) const;
174
176 bool containsPoint(std::size_t t, const Point2D & p) const;
177
184 std::size_t locate(const Point2D & p) const;
185
196 void growCavity(std::size_t seed, std::size_t v_new, std::set<std::size_t> & cavity) const;
197
205 std::vector<std::size_t> retriangulate(const std::vector<std::size_t> & removed,
206 const std::vector<std::array<std::size_t, 3>> & added);
207
220 void triangulatePseudopolygon(std::size_t v_start,
221 std::size_t v_end,
222 const std::vector<std::size_t> & chain,
223 std::size_t first,
224 std::size_t last,
225 std::vector<std::array<std::size_t, 3>> & triangles) const;
226
228 bool isStrictlyBetween(std::size_t v_first, std::size_t v_mid, std::size_t v_last) const;
229
231 std::string vertexName(std::size_t v) const;
232
234 std::vector<Point2D> _vertices;
235
237 std::vector<Triangle> _triangles;
238
240 std::vector<std::size_t> _vertex_triangle;
241
243 std::set<Segment> _constraints;
244
247};
Constrained Delaunay triangulation of a set of points in the plane, built one point at a time.
std::size_t _last_triangle
A triangle the last insertion produced, which is where the next point walk starts.
static constexpr std::size_t _num_bounding
The number of bounding triangle vertices padding the front of the vertex list.
const std::set< Segment > & constrainedSegments() const
void initialize(const std::vector< Point2D > &points, const std::vector< Segment > &segments)
Triangulates points and recovers every entry of segments as an edge of the result.
std::size_t numPoints() const
std::size_t insertPoint(const Point2D &p)
Inserts a point, restoring the constrained Delaunay property around it.
bool isConstrainedSegment(std::size_t v0, std::size_t v1) const
void triangulatePseudopolygon(std::size_t v_start, std::size_t v_end, const std::vector< std::size_t > &chain, std::size_t first, std::size_t last, std::vector< std::array< std::size_t, 3 > > &triangles) const
Triangulates a polygon whose vertices are all visible from one of its edges, which is the shape a rec...
static Segment makeSegment(std::size_t v0, std::size_t v1)
unsigned int localVertexIndex(std::size_t t, std::size_t v) const
std::pair< std::size_t, std::size_t > Segment
A constrained segment, held as a vertex id pair with the smaller id first.
static constexpr double _bounding_reach
How far the bounding triangle reaches beyond the points, as a multiple of their extent.
std::set< Segment > _constraints
The constrained segments, in caller vertex ids with the smaller id first.
std::vector< std::string > checkInvariants() const
Checks everything this class promises: that every triangle is counter-clockwise, that the neighbor en...
bool isStrictlyBetween(std::size_t v_first, std::size_t v_mid, std::size_t v_last) const
std::vector< Triangle > _triangles
The triangles, every one of them live and counter-clockwise.
std::vector< std::string > checkEmptyCircumcircle() const
Tests every vertex against the circumcircle of every triangle.
static bool isBounding(std::size_t v)
std::size_t locate(const Point2D &p) const
Finds the triangle a point falls in by walking from the triangle the last insertion produced,...
void growCavity(std::size_t seed, std::size_t v_new, std::set< std::size_t > &cavity) const
Collects the triangles of the triangulation built so far that have to make way for a new vertex,...
std::string vertexName(std::size_t v) const
std::vector< Point2D > _vertices
The bounding triangle vertices followed by the caller's points.
unsigned int localEdgeIndex(std::size_t t, const Segment &edge) const
std::size_t toInternal(std::size_t id) const
void insertSegment(std::size_t v0, std::size_t v1)
Makes the segment between two vertices an edge of the triangulation and records it as constrained,...
bool isConstrainedEdge(std::size_t v0, std::size_t v1) const
const Point2D & point(std::size_t id) const
const double * xy(std::size_t v) const
bool containsPoint(std::size_t t, const Point2D &p) const
std::vector< std::size_t > retriangulate(const std::vector< std::size_t > &removed, const std::vector< std::array< std::size_t, 3 > > &added)
Swaps one triangulation of a region for another, reusing the slots of the triangles it removes and re...
std::size_t toCaller(std::size_t v) const
static constexpr std::size_t invalid_index
Sentinel for a vertex, triangle or neighbor that does not exist.
std::vector< std::size_t > _vertex_triangle
One triangle touching each vertex of _vertices, which is where a walk around it starts.
std::vector< Triangle > getTriangles() const
A point of the triangulation, held as plain coordinates.
A triangle of the triangulation.
std::array< std::size_t, 3 > neighbors
std::array< std::size_t, 3 > vertices