2#include <NDEVR/Polygon.h>
3#include <NDEVR/Dictionary.h>
4#include <NDEVR/OpenMP.h>
11 template<
class t_type,
class t_vertex_type>
20 : t_vertex_type{ _position } {}
30 template<
class t_type,
class t_vertex = Vertex<2, t_type>>
46 fltp08 val = (q[
Y] - p[
Y]) * (r[
X] - q[
X]) - (q[
X] - p[
X]) * (r[
Y] - q[
Y]);
51 return (val > 0) ? 1 : 2;
61 static inline bool intersects(
const Line& s1,
const Line& s2)
69 if (o1 != o2 && o3 != o4)
115 static uint04 mod(
int x,
int m)
122 static t_type CalcHandedness(
const t_vertex& v1,
const t_vertex& v2,
const t_vertex& v3)
124 t_vertex edge1 = v2 - v1;
125 t_vertex edge2 = v3 - v2;
127 return cross(edge1, edge2);
147 t_type ls1Product =
cross(relativePos, ls1);
148 t_type ls2Product =
cross(relativePos, ls2);
150 if (ls1Product < t_type(0) && ls2Product > t_type(0))
163 if (isVertexInCone(ls1, ls2, origin, inputVerts.
vertex(i).template as<2, t_type>()))
171 lib_assert(origin != vertex_to_check,
"Bad visibility check");
172 Line ls(vertices.
vertex(vertex_to_check).template as<2, t_type>(), vertices.
vertex(origin).template as<2, t_type>());
175 for (
uint04 i = 0; i < vertex_count; ++i)
177 if (origin == i || ((i + 1) % vertex_count) == origin)
179 if (vertex_to_check == i || ((i + 1) % vertex_count) == vertex_to_check)
181 Line l = vertices.
edge(i).template as<2, t_type>();
182 if (intersects(ls, l))
185 auto center = ls.
center();
194 const t_vertex& currVert = vertices.
vertex(index);
195 const t_vertex& nextVert = vertices.
vertex(mod(index + 1, vertices.
vertexCount()));
196 return CalcHandedness(prevVert, currVert, nextVert) < 0.0f;
207 if (indices.
size() == 1)
209 if (checkVisibility(polygonVertices, origin_index, indices[0]))
212 else if (indices.
size() > 1)
217 if (indices[i] < origin_index)
219 if (!IsReflexPoint(indices[i], polygonVertices))
221 if (checkVisibility(polygonVertices, origin_index, indices[i]))
228 if (currDistance * 1000 < min_distance)
230 min_distance = currDistance;
237 if (indices[i] > origin_index && IsReflexPoint(indices[i], polygonVertices))
239 if (checkVisibility(polygonVertices, origin_index, indices[i]))
246 if (currDistance * 1000 < min_distance)
248 min_distance = currDistance;
263 if (IsReflexPoint(i, polygonVertices) && checkVisibility(polygonVertices, origin_index, i))
269 if (i == origin_index || i == neighbor_a || i == neighbor_b)
271 if (i > origin_index && IsReflexPoint(i, polygonVertices))
274 if (currDistance < min_distance)
278 if (checkVisibility(polygonVertices, origin_index, i))
280 min_distance = currDistance;
283 else if(currDistance * 1000 < min_distance)
285 min_distance = currDistance;
302 if (IsReflexPoint(i, _vertices))
311 flipPolygon(vertices);
315 typedef std::pair<int, Vertex<2, fltp08>> VertexIntPair;
320 : vertices{ _vertices }
342 while (next_sub_polygons_to_process.
size() > 0)
344 sub_polygons_to_process.
clear();
345 for (
uint04 i = 0; i < next_sub_polygons_to_process.
size(); i++)
347 if (next_sub_polygons_to_process[i].vertexCount() > 3)
348 sub_polygons_to_process.
add(next_sub_polygons_to_process[i]);
349 else if(next_sub_polygons_to_process[i].vertexCount() == 3)
350 processed_polygons.
add(next_sub_polygons_to_process[i]);
352 next_sub_polygons_to_process.
clear();
353 next_sub_polygons_to_process.
setSize(2 * sub_polygons_to_process.
size());
354 int size = sub_polygons_to_process.
size();
357 std::unique_lock<std::mutex> lck(mtx, std::defer_lock);
360 uint04 reflexIndex = findFirstReflexVertex(_vertices);
373 IntArray vertsInCone = findVerticesInCone(prev_ray, next_ray, currVertPos, _vertices);
375 uint04 bestVert = getBestVertexToConnect(vertsInCone, _vertices, currVertPos, reflexIndex);
381 next_sub_polygons_to_process[2 * i + 0].addVertices(_vertices.
begin(), start + 1);
382 next_sub_polygons_to_process[2 * i + 1].addVertices(_vertices.
begin() + start, (end + 1) - start);
383 next_sub_polygons_to_process[2 * i + 0].addVertices(_vertices.
begin() + end, _vertices.
vertexCount() - end);
387 lib_assert(next_sub_polygons_to_process[2 * i + 0].vertexCount() > 2,
"Bad a size");
388 lib_assert(next_sub_polygons_to_process[2 * i + 1].vertexCount() > 2,
"Bad b size");
393 for (
uint04 i = 0; i < sub_polygons_to_process.
size(); i++)
395 if (sub_polygons_to_process[i].vertexCount() > 3)
397 lib_assert(sub_polygons_to_process[i].isConvex(),
"Should be convex");
398 processed_polygons.
add(sub_polygons_to_process[i]);
412 returnArr.addAll(processed_polygons);
417 if (index >= 0 && index < vertices.size())
418 return vertices[index];
420 return t_vertex(0.0f);
#define lib_assert(expression, message)
Definition LibAssert.h:61
#define _parallel_for
Definition OpenMP.hpp:17
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:52
constexpr void addToBounds(const t_vertex &vector)
Definition Bounds.hpp:390
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:186
bool contains(const t_type &element) const
Definition Buffer.hpp:465
constexpr t_index_type size() const
Definition Buffer.hpp:823
void setSize(t_index_type new_size)
Definition Buffer.hpp:803
void clear()
Definition Buffer.hpp:422
Stores convenience functions for a concavec polygon Works on a Polygon object to decompose it into tr...
Definition ConcaveToConvexPolygon.h:32
void returnLowestLevelPolys(Buffer< Polygon< t_type, t_vertex >, uint04, ObjectAllocator< false > > &returnArr)
Definition ConcaveToConvexPolygon.h:410
t_vertex getPoint(uint04 index) const
Definition ConcaveToConvexPolygon.h:415
bool checkIfRightHanded()
Definition ConcaveToConvexPolygon.h:328
void convexDecomp()
Definition ConcaveToConvexPolygon.h:332
int getPointCount() const
Definition ConcaveToConvexPolygon.h:423
ConcavePolygon()
Definition ConcaveToConvexPolygon.h:326
const VertexArray & getVertices() const
Definition ConcaveToConvexPolygon.h:404
ConcavePolygon(const VertexArray &_vertices)
Definition ConcaveToConvexPolygon.h:319
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
A line segment represented by two vertices, a start and end.
Definition Line.hpp:49
constexpr const t_vertex & vertex(uint01 index) const
Definition Line.hpp:152
constexpr t_vertex center() const
Definition Line.hpp:135
Definition MemoryManager.h:261
An N-sided polygon.
Definition Polygon.hpp:53
LineSegment< 2, t_type, t_vertex > edge(uint04 index) const
Definition Polygon.hpp:174
void flip()
Definition Polygon.hpp:374
bool contains(const Vertex< 2, t_type > &vector) const
Definition Polygon.hpp:478
uint04 vertexCount() const
Definition Polygon.hpp:204
bool hasClockwiseWinding() const
Definition Polygon.hpp:694
decltype(auto) begin()
Definition Polygon.hpp:563
bool isConvex() const
Definition Polygon.hpp:223
const t_vertex & vertex(uint04 index) const
Definition Polygon.hpp:156
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
Definition BaseFunctions.hpp:94
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:46
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
Definition VectorFunctions.hpp:898
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
Definition AngleFunctions.h:645
@ B
Definition BaseValues.hpp:170
@ A
Definition BaseValues.hpp:168
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
Definition BaseFunctions.hpp:56
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Stores an index to a particular vertex used with ConcaveToConvexPolygon. The Slice index is used with...
Definition ConcaveToConvexPolygon.h:17
SliceVertex()
Definition ConcaveToConvexPolygon.h:18
int index
Definition ConcaveToConvexPolygon.h:22
t_type distanceToSlice
Definition ConcaveToConvexPolygon.h:23
SliceVertex(t_vertex_type const &_position)
Definition ConcaveToConvexPolygon.h:19