API Documentation
Loading...
Searching...
No Matches
DelaunayTriangulation.h
Go to the documentation of this file.
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 ProgressInfo;
45 class DesignObjectLookup;
46 /**--------------------------------------------------------------------------------------------------
47 \brief A Point or node used in DelaunayTriangulation
48 **/
49 class DelaunayPoint : public Vector<2, fltp08>
50 {
51 public:
52 DelaunayPoint();
53 DelaunayPoint(fltp08 a, fltp08 b);
54 DelaunayPoint(fltp08 a, fltp08 b, fltp08 x);
55 DelaunayPoint(const DelaunayPoint& p);
56
57 DelaunayPoint& operator=(const DelaunayPoint& p);
58 DelaunayPoint& operator=(const Vector<2, fltp08>& p);
59 bool operator==(const DelaunayPoint& p2) const;
60 bool operator!=(const DelaunayPoint& p2) const;
61 bool operator<(const DelaunayPoint& b) const;
62 public:
63 Vector<2, fltp08> t;//Connection graph point
64 uint04 id;//Original point id
65 uint04 trid;//Temp Id of triangle
66 fltp08 ro;//Used for consistant sorting from orginal max circle
67 };
68 /**--------------------------------------------------------------------------------------------------
69 \brief A triangle used in DelaunayTriangulation
70 **/
71 class DelaunayTriangle : public Triangle<1, uint04>
72 {
73 public:
74 DelaunayTriangle();
75 DelaunayTriangle(uint04 a, uint04 b);
76 DelaunayTriangle(uint04 a, uint04 b, uint04 c);
77 DelaunayTriangle(uint04 a, uint04 b, uint04 c, uint04 ab, uint04 bc, uint04 ac);
78 DelaunayTriangle(const DelaunayTriangle& p);
79 constexpr uint04& neighborTriangle(TriangleLocation location)
80 {
81 switch (location)
82 {
83 case edge_ab: return edges[0];
84 case edge_bc: return edges[1];
85 case edge_ca: return edges[2];
86 default: lib_assert(false, "Not a valid line segment request"); return edges[0];
87 }
88 }
89 constexpr const uint04& neighborTriangle(TriangleLocation location) const
90 {
91 switch (location)
92 {
93 case edge_ab: return edges[0];
94 case edge_bc: return edges[1];
95 case edge_ca: return edges[2];
96 default: lib_assert(false, "Not a valid line segment request"); return edges[0];
97 }
98 }
99
100 constexpr void swapNeighborTriangle(uint04 old_tri_index, uint04 new_tri_index)
101 {
102 if (neighborTriangle(edge_ab) == old_tri_index)
103 neighborTriangle(edge_ab) = new_tri_index;
104 else if (neighborTriangle(edge_bc) == old_tri_index)
105 neighborTriangle(edge_bc) = new_tri_index;
106 else if (neighborTriangle(edge_ca) == old_tri_index)
107 neighborTriangle(edge_ca) = new_tri_index;
108 else
109 lib_assert(false, "Did not swap valid edge");
110 }
111 DelaunayTriangle& operator=(const DelaunayTriangle& p);
112 public:
113 Vector<3, uint04> edges;
114 RadialObject<2, fltp08> circle;
115 };
116 /**--------------------------------------------------------------------------------------------------
117 \brief Creates a surface from random points using Delaunay Triangulation:
118 https://en.wikipedia.org/wiki/Delaunay_triangulation
119 **/
120 class DelaunayTriangulation : public GeometrySurfacing
121 {
122 public:
123 DelaunayTriangulation();
124 virtual ~DelaunayTriangulation() override = default;
125 virtual bool runSurfacing(GeometrySurfacingParameters & parameters) override;
126 virtual Buffer<SurfacingDescription> defaultSurfacingArguments() override;
127
128 static Buffer<Triangle<1, uint04>> Delaunay(const Matrix<fltp08> matrix, const Buffer<Vertex<3, fltp08>>& points, ProgressInfo* log = nullptr);
129 static void Delaunay(const Matrix<fltp08> matrix, Geometry& points, const void* lock, ProgressInfo* log = nullptr);
130 static bool isDelaunay(const Vector<2, fltp08>& A, const Vector<2, fltp08>& B, const Vector<2, fltp08>& C, const Vector<2, fltp08>& D);
131 NDEVR_SURFACING_API static void RegisterSurfacingEngine();
132 protected:
133 explicit DelaunayTriangulation(ProgressInfo* log);
134 void makeDelaunay();
135 void setPoints(const Matrix<fltp08> matrix, const Buffer<Vertex<3, fltp08>>& points);
136 void setPoints(const Matrix<fltp08> matrix, const Geometry& points);
137 void setupMaxCircle();
138 void fillLookupTable();
139 void triangulate();
140 void initHull();
141 void formHull(uint04 k);
142 void formHullConvex(uint04& hidx, Vector<2, fltp08>& d, const Vector<2, fltp08>& x, DelaunayPoint& point);
143 void formHullConcave(uint04& hidx, Vector<2, fltp08>& d, const Vector<2, fltp08>& x, DelaunayPoint& point);
144 Buffer<Triangle<1, uint04>> getTris();
145 inline void getFlipVars(uint04 tri_index, uint01 t_pos, const DelaunayTriangle& t1, const DelaunayTriangle& t2, Vector<5, uint04>& L, Vector<4, uint04>& p) const;
146 template<bool t_protected>
147 void checkTriAndFlip(uint04 tri_index, Buffer<uint04>& ids);
148 protected:
149 bool m_use_tree;
150 RTree<2, fltp04>* m_r_tree;
151 Buffer<uint04> m_point_cache;
152 Buffer<uint04> m_tri_cache;
153 Buffer<DelaunayPoint> m_cache_bounds;
154 Buffer<DelaunayPoint> m_points;
155 Buffer<DelaunayTriangle> m_tris;
156 Buffer<uint04> m_lookup_table;
157 RadialObject<2, fltp08> m_max_circle;
158 ProgressInfo* m_log;
159 };
160};
161#endif
#define lib_assert(expression, message)
Definition LibAssert.h:61
#define NDEVR_SURFACING_API
Definition DLLInfo.h:56
bool operator!=(const VkVertexInputAttributeDescription &a, const VkVertexInputAttributeDescription &b)
bool operator==(const VkVertexInputAttributeDescription &a, const VkVertexInputAttributeDescription &b)
Definition ACIColor.h:37
constexpr bool operator<(const Vector< vec_1_size, t_type > &v1, const Vector< vec_2_size, t_type > &v2)
Definition VectorFunctions.hpp:720
@ edge_ab
Definition Triangle.hpp:49
@ edge_bc
Definition Triangle.hpp:50
@ edge_ca
Definition Triangle.hpp:51
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149