NDEVR
API Documentation
DelaunayTriangulation.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: GeometrySurfacing
28File: DelaunayTriangulation
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Geometry.h>
34#if NDEVR_SURFACING
35#include <NDEVR/GeometrySurfacing.h>
36#include <NDEVR/Buffer.h>
37#include <NDEVR/Vector.h>
38#include <NDEVR/RadialObject.h>
39namespace NDEVR
40{
41 template<uint01 t_dims, class t_type> class RTree;
42
43 class SelectionInfo;
44 class InfoPipe;
49 class DelaunayPoint : public Vector<2, fltp08>
50 {
51 public:
53 DelaunayPoint();
58 DelaunayPoint(fltp08 a, fltp08 b);
64 DelaunayPoint(fltp08 a, fltp08 b, fltp08 x);
68 DelaunayPoint(const DelaunayPoint& p);
69
70 DelaunayPoint& operator=(const DelaunayPoint& p);
71 DelaunayPoint& operator=(const Vector<2, fltp08>& p);
72 bool operator==(const DelaunayPoint& p2) const;
73 bool operator!=(const DelaunayPoint& p2) const;
74 bool operator<(const DelaunayPoint& b) const;
75 public:
76 Vector<2, fltp08> t;
77 uint04 id;
78 uint04 original_id;
79 uint04 trid;
80 fltp08 ro;
81 };
85 class DelaunayTriangle : public Triangle<1, uint04>
86 {
87 public:
89 DelaunayTriangle();
94 DelaunayTriangle(uint04 a, uint04 b);
100 DelaunayTriangle(uint04 a, uint04 b, uint04 c);
109 DelaunayTriangle(uint04 a, uint04 b, uint04 c, uint04 ab, uint04 bc, uint04 ac);
113 DelaunayTriangle(const DelaunayTriangle& p);
118 constexpr uint04& neighborTriangle(TriangleLocation location)
119 {
120 switch (location)
121 {
122 case edge_ab: return edges[0];
123 case edge_bc: return edges[1];
124 case edge_ca: return edges[2];
125 default: lib_assert(false, "Not a valid line segment request"); return edges[0];
126 }
127 }
132 constexpr const uint04& neighborTriangle(TriangleLocation location) const
133 {
134 switch (location)
135 {
136 case edge_ab: return edges[0];
137 case edge_bc: return edges[1];
138 case edge_ca: return edges[2];
139 default: lib_assert(false, "Not a valid line segment request"); return edges[0];
140 }
141 }
146 constexpr const uint04& neighborTriangle(uint01 location) const
147 {
148 return edges[location];
149 }
154 constexpr void swapNeighborTriangle(uint04 old_tri_index, uint04 new_tri_index)
155 {
156 if (neighborTriangle(edge_ab) == old_tri_index)
157 neighborTriangle(edge_ab) = new_tri_index;
158 else if (neighborTriangle(edge_bc) == old_tri_index)
159 neighborTriangle(edge_bc) = new_tri_index;
160 else if (neighborTriangle(edge_ca) == old_tri_index)
161 neighborTriangle(edge_ca) = new_tri_index;
162 else
163 lib_assert(false, "Did not swap valid edge");
164 }
165 DelaunayTriangle& operator=(const DelaunayTriangle& p);
166 public:
167 Vector<3, uint04> edges;
168 RadialObject<2, fltp08> circle;
169 };
175 class NDEVR_SURFACING_API DelaunayTriangulation : public GeometrySurfacing
176 {
177 public:
179 DelaunayTriangulation();
180 virtual ~DelaunayTriangulation() override = default;
185 virtual bool runSurfacing(GeometrySurfacingParameters & parameters) override;
189 virtual Buffer<SurfacingDescription> defaultSurfacingArguments() override;
190
197 static Buffer<Triangle<1, uint04>> Delaunay(const Matrix<fltp08> matrix, const Buffer<Vertex<3, fltp08>>& points, LogPtr log = LogPtr());
204 static void Delaunay(const Matrix<fltp08> matrix, Geometry& points, const void* lock, LogPtr log = LogPtr());
212 static bool isDelaunay(const Vector<2, fltp08>& A, const Vector<2, fltp08>& B, const Vector<2, fltp08>& C, const Vector<2, fltp08>& D);
214 static void RegisterSurfacingEngine();
216 void clipBoundaryTris();
217 protected:
221 explicit DelaunayTriangulation(LogPtr log);
223 void makeDelaunay();
228 void setPoints(const Matrix<fltp08> matrix, const Buffer<Vertex<3, fltp08>>& points);
233 void setPoints(const Matrix<fltp08> matrix, const Geometry& points);
235 void setupMaxCircle();
237 void fillLookupTable();
239 void triangulate();
241 void initHull();
245 void formHull(uint04 k);
252 void formHullConvex(uint04& hidx, Vector<2, fltp08>& d, const Vector<2, fltp08>& x, DelaunayPoint& point);
259 void formHullConcave(uint04& hidx, Vector<2, fltp08>& d, const Vector<2, fltp08>& x, DelaunayPoint& point);
263 Buffer<Triangle<1, uint04>> getTris();
272 inline void getFlipVars(uint04 tri_index, uint01 t_pos, const DelaunayTriangle& t1, const DelaunayTriangle& t2, Vector<5, uint04>& L, Vector<4, uint04>& p) const;
277 template<bool t_protected>
278 void checkTriAndFlip(uint04 tri_index, Buffer<uint04>& ids);
279 protected:
280 bool m_use_tree;
281 RTree<2, fltp04>* m_r_tree;
282 Buffer<uint04> m_point_cache;
283 Buffer<uint04> m_tri_cache;
284 Buffer<DelaunayPoint> m_cache_bounds;
285 Buffer<DelaunayPoint> m_points;
286 Buffer<DelaunayTriangle> m_tris;
287 RadialObject<2, fltp08> m_max_circle;
288 LogPtr m_log;
289 };
290};
291#endif
A core class where all Design Objects including models, materials, and geometries are stored.
A light-weight base class for Log that allows processes to update, without the need for additional in...
Responsible for turning a user interaction into a selection within a DesignObjectLookup.
Definition Selector.h:52
A three-vertex polygon representing a triangle in N-dimensional space.
Definition Triangle.hpp:142
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Inequality operator.
Definition Vector.hpp:673
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.