9#include "UI/DefineForDebug.h"
58#ifdef DEBUG_BOWYERWATSON
64#ifdef DEBUG_BOWYERWATSON
80#ifdef DEBUG_BOWYERWATSON_STEP
87 EdgeVertexIndices.
Reserve(TriangleSet.Num() * 6);
91 int32 VertexIndex = 0;
100 VertexIndex = VerticesCount - 1 -
VIndex / 2;
103 SelectedTriangleIndices.
Reset(VerticesCount);
104 AdditionalTriangleIndices.
Reset(VerticesCount);
106 const FVector2d& NewVertex = Vertices[VertexIndex].Value;
108#ifdef DEBUG_BOWYERWATSON_STEP
133 for (
int32 TriangleIndex = 0; TriangleIndex < TriangleSet.Num(); TriangleIndex++)
145 SelectedTriangleIndices.
Add(TriangleIndex);
155 if (DoesTriangleContainingNewVertex(NewVertex, TriangleIndex))
157 SelectedTriangleIndices.
Add(TriangleIndex);
161 AdditionalTriangleIndices.
Add(TriangleIndex);
168#ifdef DEBUG_BOWYERWATSON_STEP
177 bHaveDoubt = !DoSelectedTrianglesFormSinglePartition();
180 if (SelectedTriangleIndices.
Num() == 0)
182 for (
int32& TriangleIndex : AdditionalTriangleIndices)
184 if (DoesTriangleContainingNewVertex(NewVertex, TriangleIndex))
186 SelectedTriangleIndices.
Add(TriangleIndex);
203 if (TriangleIndex >= 0)
205 AdditionalTriangleIndices.
Add(TriangleIndex);
210#ifdef DEBUG_BOWYERWATSON_STEP
218 if (AdditionalTriangleIndices.
Num() > 0)
227 for (
int32 TriangleIndex : SelectedTriangleIndices)
231 const int32 StartVertex = TriangleSet[TriangleIndex].VertexIndices[
Index];
251 for (
int32& TriangleIndex : AdditionalTriangleIndices)
253 if (TriangleIndex < 0)
282#ifdef DEBUG_BOWYERWATSON_STEP_2
300 int32 StartIndex = -1;
321#ifdef DEBUG_BOWYERWATSON_STEP_2
341 SelectedTriangleIndices.
Add(TriangleIndex);
343#ifdef DEBUG_BOWYERWATSON_STEP_2
356#ifdef DEBUG_BOWYERWATSON_STEP
364 EdgeVertexIndices.
Reset(VerticesCount);
365 FindBoundaryEdgesOfSelectedTriangles(EdgeVertexIndices);
368#ifdef DEBUG_BOWYERWATSON_STEP
372 for (
int32 EdgeIndex = 0; EdgeIndex < EdgeVertexIndices.
Num(); EdgeIndex += 2)
374 if (EdgeVertexIndices[EdgeIndex] < 0)
384#ifdef DEBUG_BOWYERWATSON_STEP
390 for (
int32 TriangleIndex : SelectedTriangleIndices)
392 while (EdgeVertexIndices[EdgeIndex] < 0)
396 TriangleSet[TriangleIndex].Set(EdgeVertexIndices[EdgeIndex + 1], EdgeVertexIndices[EdgeIndex], VertexIndex, Vertices);
397#ifdef DEBUG_BOWYERWATSON_STEP
409 for (; EdgeIndex < EdgeVertexIndices.
Num(); EdgeIndex += 2)
411 if (EdgeVertexIndices[EdgeIndex] < 0)
415 TriangleSet.Emplace(EdgeVertexIndices[EdgeIndex + 1], EdgeVertexIndices[EdgeIndex], VertexIndex, Vertices);
416#ifdef DEBUG_BOWYERWATSON_STEP
427#ifdef DEBUG_BOWYERWATSON_STEP
436#ifdef DEBUG_BOWYERWATSON
446 EdgeVertexIndices.
Reset(TriangleSet.Num() * 6);
448 for (
int32 TriangleIndex = 0; TriangleIndex < TriangleSet.Num(); TriangleIndex++)
453 if (TriangleSet[TriangleIndex].VertexIndices[
Index] >= VerticesCount)
462 int32 EndVertex = TriangleSet[TriangleIndex].VertexIndices[2];
465 int32 StartVertex = TriangleSet[TriangleIndex].VertexIndices[
Index];
466 if (StartVertex < VerticesCount && EndVertex < VerticesCount)
472 if (EdgeVertexIndices[
Endex] == EndVertex && EdgeVertexIndices[
Endex + 1] == StartVertex)
476 EdgeInstanceCount[
Endex / 2]++;
482 if (
Endex == EdgeVertexIndices.
Num())
485 EdgeVertexIndices.
Add(StartVertex);
486 EdgeVertexIndices.
Add(EndVertex);
490 EndVertex = StartVertex;
493#ifdef DEBUG_BOWYERWATSON
499 Vertices.SetNum(VerticesCount);
512 if (EdgeInstanceCount[
Index] < 2)
529 if (EdgeInstanceCount[EdgeIndex] < 2)
547 if (EdgeInstanceCount[EdgeIndex] < 2)
563 return OuterVertices.Array();
568 Triangles.
Reset(TriangleSet.Num() * 3);
575#ifdef DEBUG_BOWYERWATSON
576 static bool bDisplay;
602 void MakeBoundingMesh()
619 TriangleSet.
Emplace(VerticesCount, VerticesCount + 1, VerticesCount + 2, Vertices);
620 TriangleSet.
Emplace(VerticesCount + 2, VerticesCount + 3, VerticesCount, Vertices);
625 VerticesCount = Vertices.
Num();
626 Vertices.
Reserve(VerticesCount + 4);
627 TriangleSet.
Reserve(VerticesCount);
628 SelectedTriangleIndices.
Reserve(VerticesCount);
629 AdditionalTriangleIndices.
Reserve(VerticesCount);
630 EdgeVertexIndices.
Reserve(4 * VerticesCount);
631 EdgeInstanceCount.
Reserve(2 * VerticesCount);
643 for (
int32 TriangleIndex : SelectedTriangleIndices)
645 int32 EndVertex = TriangleSet[TriangleIndex].VertexIndices[2];
648 int32 StartVertex = TriangleSet[TriangleIndex].VertexIndices[
Index];
665 EndVertex = StartVertex;
670 bool DoSelectedTrianglesFormSinglePartition()
672 FindBoundaryEdgesOfSelectedTriangles(EdgeVertexIndices);
674 int32 StartIndex = -1;
675 int32 LastIndex = -1;
678 if (EdgeVertexIndices[EdgeIndex] < 0)
682 StartIndex = EdgeVertexIndices[
EdgeIndex];
683 LastIndex = EdgeVertexIndices[
EdgeIndex + 1];
690 while (LastIndex != StartIndex)
695 if (EdgeVertexIndices[EdgeIndex] == LastIndex)
697 LastIndex = EdgeVertexIndices[
EdgeIndex + 1];
712 if (EdgeVertexIndices[EdgeIndex] > 0)
740 if(DoesTriangleContainingNewVertex(NewVertex, TriangleIndex))
742 SelectedTriangleIndices.
Add(TriangleIndex);
751 FindBoundaryEdgesOfSelectedTriangles(EdgeVertexIndices);
759 if (TriangleIndex < 0)
764 int32 EndVertex = TriangleSet[TriangleIndex].VertexIndices[2];
770 int32 StartVertex = TriangleSet[TriangleIndex].VertexIndices[
Index];
774 if (EdgeVertexIndices[
Endex] == EndVertex && EdgeVertexIndices[
Endex + 1] == StartVertex)
776 EdgeVertexIndices[
Endex] = -1;
777 EdgeVertexIndices[
Endex + 1] = -1;
786 EndVertex = StartVertex;
791 SelectedTriangleIndices.
Add(TriangleIndex);
792 EndVertex = TriangleSet[TriangleIndex].VertexIndices[2];
795 int32 StartVertex = TriangleSet[TriangleIndex].VertexIndices[
Endex];
798 EdgeVertexIndices.
Add(StartVertex);
799 EdgeVertexIndices.
Add(EndVertex);
801 EndVertex = StartVertex;
810#ifdef DEBUG_BOWYERWATSON
818 F3DDebugSession
_(
TEXT(
"Edges"));
821 if (EdgeInstanceCount[
Index / 2] < 2)
839 F3DDebugSession
_(
TEXT(
"Triangles"));
854 F3DDebugSession
_(
TEXT(
"Selected Triangles"));
873 F3DDebugSession
A(bDisplay,
TEXT(
"Select Triangles Add"));
874 for (
int32 TriangleIndex : AdditionalTriangleIndices)
876 if (TriangleIndex < 0)
901 F3DDebugSession
A(
TEXT(
"Selected Triangles Boundary"));
915 F3DDebugSession
B(
TEXT(
"Voronoi Diagram"));
917 F3DDebugSession
A(
TEXT(
"New Vertex"));
921 F3DDebugSession
A(
TEXT(
"Candidate"));
925 F3DDebugSession
A(
TEXT(
"Start"));
929 constexpr double HalfPi = -
DOUBLE_PI / 2.;
939 F3DDebugSession
A(
TEXT(
"Start - Candidate"));
944 F3DDebugSession
A(
TEXT(
"End"));
948 constexpr double HalfPi =
DOUBLE_PI / 2.;
958 F3DDebugSession
A(
TEXT(
"End - Candidate"));
@ INDEX_NONE
Definition CoreMiscDefines.h:150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FVector
Definition IOSSystemIncludes.h:8
#define DOUBLE_PI
Definition UnrealMathUtility.h:71
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_FORCEINLINE_HINT SizeType Emplace(ArgsType &&... Args)
Definition Array.h:2561
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
void Append(const TArray< OtherElementType, OtherAllocatorType > &Source)
Definition Array.h:2412
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition BowyerWatsonTriangulator.h:16
int32 OuterEdgeCount() const
Definition BowyerWatsonTriangulator.h:507
TArray< int32 > GetOuterVertices() const
Definition BowyerWatsonTriangulator.h:559
void GetMesh(TArray< int32 > &Triangles)
Definition BowyerWatsonTriangulator.h:566
void GetOuterVertices(TSet< int32 > &OuterVertexIndices) const
Definition BowyerWatsonTriangulator.h:541
FBowyerWatsonTriangulator(TArray< TPair< int32, FVector2d > > &InVertices, TArray< int32 > &OutEdgeVertices)
Definition BowyerWatsonTriangulator.h:47
void GetOuterEdges(TArray< int32 > &OuterEdgeIndices) const
Definition BowyerWatsonTriangulator.h:523
void Triangulate()
Definition BowyerWatsonTriangulator.h:55
static const FTimePoint Now()
Definition Chrono.h:34
double DiagonalLength() const
Definition Aabb.h:108
const FName EdgeIndex("EdgeIndex")
Definition MeshAttributes.h:40
constexpr double PiSlope
Definition SlopeUtils.h:76
constexpr double RightSlope
Definition SlopeUtils.h:59
constexpr double ThreeRightSlope
Definition SlopeUtils.h:66
constexpr double TwoPiSlope
Definition SlopeUtils.h:81
Definition CADEntity.cpp:23
void DisplaySegment(const FVector &Point1, const FVector &Point2, FIdent Ident, EVisuProperty Property)
Definition Display.cpp:1268
void Wait(bool bMakeWait=true)
Definition Display.h:55
void DisplayPoint(const TPoint &Point, FIdent Ident)
Definition Display.h:145
double ComputeSlope(const FVector2d &StartPoint, const FVector2d &EndPoint)
Definition SlopeUtils.h:180
double ComputePositiveSlope(const FVector2d &StartPoint, const FVector2d &EndPoint, double ReferenceSlope)
Definition SlopeUtils.h:290
EVisuProperty
Definition Visu.h:15
@ YellowCurve
Definition Visu.h:29
@ PurpleCurve
Definition Visu.h:35
@ RedPoint
Definition Visu.h:32
@ BluePoint
Definition Visu.h:30
@ OrangeCurve
Definition Visu.h:41
@ GreenPoint
Definition Visu.h:36
@ OrangePoint
Definition Visu.h:40
@ YellowPoint
Definition Visu.h:28
@ BlueCurve
Definition Visu.h:31
@ GreenCurve
Definition Visu.h:37
uint64 FTimePoint
Definition Chrono.h:26
U16 Index
Definition radfft.cpp:71
Definition BowyerWatsonTriangulator.h:19
double SquareRadius
Definition BowyerWatsonTriangulator.h:21
FVector Center
Definition BowyerWatsonTriangulator.h:22
void Set(const int32 &Index0, const int32 &Index1, const int32 &Index2, const TArray< TPair< int32, FVector2d > > &InVertices)
Definition BowyerWatsonTriangulator.h:29
FTriangle(const int32 &Index0, const int32 &Index1, const int32 &Index2, const TArray< TPair< int32, FVector2d > > &InVertices)
Definition BowyerWatsonTriangulator.h:24
int32 VertexIndices[3]
Definition BowyerWatsonTriangulator.h:20
Definition Geometry.h:428
bool Normalize(T Tolerance=UE_SMALL_NUMBER)
Definition Vector2D.h:1154
static UE_FORCEINLINE_HINT double DistSquared(const TVector2< double > &V1, const TVector2< double > &V2)
Definition Vector2D.h:935