2#include <NDEVR/Polygon.h>
3#include <NDEVR/Dictionary.h>
4#include <NDEVR/OpenMP.h>
11 template<
class t_type,
class t_vertex_type>
16 : t_vertex_type{ _position } {}
22 template<
class t_type,
class t_vertex = Vertex<2, t_type>>
38 fltp08 val = (q[
Y] - p[
Y]) * (r[
X] - q[
X]) - (q[
X] - p[
X]) * (r[
Y] - q[
Y]);
43 return (val > 0) ? 1 : 2;
53 static inline bool intersects(
const Line& s1,
const Line& s2)
61 if (o1 != o2 && o3 != o4)
107 static uint04 mod(
int x,
int m)
114 static t_type CalcHandedness(
const t_vertex& v1,
const t_vertex& v2,
const t_vertex& v3)
116 t_vertex edge1 = v2 - v1;
117 t_vertex edge2 = v3 - v2;
119 return cross(edge1, edge2);
139 t_type ls1Product =
cross(relativePos, ls1);
140 t_type ls2Product =
cross(relativePos, ls2);
142 if (ls1Product < t_type(0) && ls2Product > t_type(0))
155 if (isVertexInCone(ls1, ls2, origin, inputVerts.
vertex(i).template as<2, t_type>()))
163 lib_assert(origin != vertex_to_check,
"Bad visibility check");
164 Line ls(vertices.
vertex(vertex_to_check).template as<2, t_type>(), vertices.
vertex(origin).template as<2, t_type>());
167 for (
uint04 i = 0; i < vertex_count; ++i)
169 if (origin == i || ((i + 1) % vertex_count) == origin)
171 if (vertex_to_check == i || ((i + 1) % vertex_count) == vertex_to_check)
173 Line l = vertices.
edge(i).template as<2, t_type>();
174 if (intersects(ls, l))
177 auto center = ls.
center();
186 const t_vertex& currVert = vertices.
vertex(index);
187 const t_vertex& nextVert = vertices.
vertex(mod(index + 1, vertices.
vertexCount()));
188 return CalcHandedness(prevVert, currVert, nextVert) < 0.0f;
199 if (indices.
size() == 1)
201 if (checkVisibility(polygonVertices, origin_index, indices[0]))
204 else if (indices.
size() > 1)
209 if (indices[i] < origin_index)
211 if (!IsReflexPoint(indices[i], polygonVertices))
213 if (checkVisibility(polygonVertices, origin_index, indices[i]))
220 if (currDistance * 1000 < min_distance)
222 min_distance = currDistance;
229 if (indices[i] > origin_index && IsReflexPoint(indices[i], polygonVertices))
231 if (checkVisibility(polygonVertices, origin_index, indices[i]))
238 if (currDistance * 1000 < min_distance)
240 min_distance = currDistance;
255 if (IsReflexPoint(i, polygonVertices) && checkVisibility(polygonVertices, origin_index, i))
261 if (i == origin_index || i == neighbor_a || i == neighbor_b)
263 if (i > origin_index && IsReflexPoint(i, polygonVertices))
266 if (currDistance < min_distance)
270 if (checkVisibility(polygonVertices, origin_index, i))
272 min_distance = currDistance;
275 else if(currDistance * 1000 < min_distance)
277 min_distance = currDistance;
294 if (IsReflexPoint(i, _vertices))
303 flipPolygon(vertices);
307 typedef std::pair<int, Vertex<2, fltp08>> VertexIntPair;
312 : vertices{ _vertices }
334 while (next_sub_polygons_to_process.
size() > 0)
336 sub_polygons_to_process.
clear();
337 for (
uint04 i = 0; i < next_sub_polygons_to_process.
size(); i++)
339 if (next_sub_polygons_to_process[i].vertexCount() > 3)
340 sub_polygons_to_process.
add(next_sub_polygons_to_process[i]);
341 else if(next_sub_polygons_to_process[i].vertexCount() == 3)
342 processed_polygons.
add(next_sub_polygons_to_process[i]);
344 next_sub_polygons_to_process.
clear();
345 next_sub_polygons_to_process.
setSize(2 * sub_polygons_to_process.
size());
346 int size = sub_polygons_to_process.
size();
349 std::unique_lock<std::mutex> lck(mtx, std::defer_lock);
352 uint04 reflexIndex = findFirstReflexVertex(_vertices);
353 if (
isNaN(reflexIndex))
365 IntArray vertsInCone = findVerticesInCone(prev_ray, next_ray, currVertPos, _vertices);
367 uint04 bestVert = getBestVertexToConnect(vertsInCone, _vertices, currVertPos, reflexIndex);
373 next_sub_polygons_to_process[2 * i + 0].addVertices(_vertices.
begin(), start + 1);
374 next_sub_polygons_to_process[2 * i + 1].addVertices(_vertices.
begin() + start, (end + 1) - start);
375 next_sub_polygons_to_process[2 * i + 0].addVertices(_vertices.
begin() + end, _vertices.
vertexCount() - end);
379 lib_assert(next_sub_polygons_to_process[2 * i + 0].vertexCount() > 2,
"Bad a size");
380 lib_assert(next_sub_polygons_to_process[2 * i + 1].vertexCount() > 2,
"Bad b size");
385 for (
uint04 i = 0; i < sub_polygons_to_process.
size(); i++)
387 if (sub_polygons_to_process[i].vertexCount() > 3)
389 lib_assert(sub_polygons_to_process[i].isConvex(),
"Should be convex");
390 processed_polygons.
add(sub_polygons_to_process[i]);
404 returnArr.addAll(processed_polygons);
409 if (index >= 0 && index < vertices.size())
410 return vertices[index];
412 return t_vertex(0.0f);
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
#define _parallel_for
Definition OpenMP.hpp:18
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
constexpr void addToBounds(const t_vertex &vector)
Adds to the bounds such that the new bounds fully encompasses the argument.
Definition Bounds.hpp:498
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
bool contains(const t_type &element) const
Definition Buffer.hpp:674
constexpr t_index_type size() const
Definition Buffer.hpp:1461
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
void clear()
Definition Buffer.hpp:572
Definition ConcaveToConvexPolygon.h:24
void returnLowestLevelPolys(Buffer< Polygon< t_type, t_vertex >, uint04, ObjectAllocator< false > > &returnArr)
Definition ConcaveToConvexPolygon.h:402
t_vertex getPoint(uint04 index) const
Definition ConcaveToConvexPolygon.h:407
bool checkIfRightHanded()
Definition ConcaveToConvexPolygon.h:320
void convexDecomp()
Definition ConcaveToConvexPolygon.h:324
int getPointCount() const
Definition ConcaveToConvexPolygon.h:415
ConcavePolygon()
Definition ConcaveToConvexPolygon.h:318
const VertexArray & getVertices() const
Definition ConcaveToConvexPolygon.h:396
ConcavePolygon(const VertexArray &_vertices)
Definition ConcaveToConvexPolygon.h:311
Definition Dictionary.h:48
A line segment represented by two vertices, a start and end.
Definition Line.hpp:55
constexpr const t_vertex & vertex(uint01 index) const
Definition Line.hpp:171
constexpr t_vertex center() const
Definition Line.hpp:151
Definition MemoryManager.h:283
An N-sided polygon.
Definition Polygon.hpp:58
LineSegment< 2, t_type, t_vertex > edge(uint04 index) const
Definition Polygon.hpp:185
void flip()
Definition Polygon.hpp:401
bool contains(const Vertex< 2, t_type > &vector) const
Definition Polygon.hpp:515
uint04 vertexCount() const
Definition Polygon.hpp:219
bool hasClockwiseWinding() const
Definition Polygon.hpp:735
decltype(auto) begin()
Definition Polygon.hpp:602
bool isConvex() const
Definition Polygon.hpp:240
const t_vertex & vertex(uint04 index) const
Definition Polygon.hpp:165
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
A vertex.
Definition Vertex.hpp:54
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator.
Definition BaseFunctions.hpp:116
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:42
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
Definition VectorFunctions.hpp:954
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
@ B
Definition BaseValues.hpp:203
@ A
Definition BaseValues.hpp:201
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator.
Definition BaseFunctions.hpp:67
Definition BaseValues.hpp:272
Definition ConcaveToConvexPolygon.h:13
SliceVertex()
Definition ConcaveToConvexPolygon.h:14
int index
Definition ConcaveToConvexPolygon.h:18
t_type distanceToSlice
Definition ConcaveToConvexPolygon.h:19
SliceVertex(t_vertex_type const &_position)
Definition ConcaveToConvexPolygon.h:15