UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IsoTriangulator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Core/Factory.h"
5#include "Math/Geometry.h"
6#include "Math/Point.h"
7#include "Math/SlopeUtils.h"
13#include "UI/Visu.h"
14
15#ifdef CADKERNEL_DEV
16#include "UI/DefineForDebug.h"
17#include "Mesh/Meshers/MesherReport.h"
18#endif
19
20namespace UE::CADKernel
21{
22
23class FGrid;
24class FIntersectionSegmentTool;
25class FFaceMesh;
26struct FCell;
27
29
30struct FCellConnexion;
31
33{
34 FDuration TriangulateDuration = FChrono::Init();
35 FDuration BuildIsoNodesDuration = FChrono::Init();
36 FDuration BuildLoopSegmentsDuration = FChrono::Init();
37 FDuration BuildInnerSegmentsDuration = FChrono::Init();
38 FDuration FindLoopSegmentOfInnerTriangulationDuration = FChrono::Init();
39 FDuration FindSegmentIsoUVSurroundingSmallLoopDuration = FChrono::Init();
40 FDuration FindIsoSegmentToLinkInnerToLoopDuration = FChrono::Init();
41 FDuration FindInnerSegmentToLinkLoopToLoopDuration = FChrono::Init();
42 FDuration FindSegmentToLinkLoopToLoopDuration = FChrono::Init();
43 FDuration FindSegmentToLinkInnerToLoopDuration = FChrono::Init();
44 FDuration TriangulateOverCycleDuration = FChrono::Init();
45 FDuration TriangulateInnerNodesDuration = FChrono::Init();
46
49
50 void PrintTimeElapse() const
51 {
52 FDuration IsoTriangulerDuration = FChrono::Init();
53 IsoTriangulerDuration += BuildIsoNodesDuration;
54 IsoTriangulerDuration += BuildLoopSegmentsDuration;
55 IsoTriangulerDuration += BuildInnerSegmentsDuration;
56 IsoTriangulerDuration += FindLoopSegmentOfInnerTriangulationDuration;
57 IsoTriangulerDuration += FindIsoSegmentToLinkInnerToLoopDuration;
58 IsoTriangulerDuration += FindSegmentToLinkLoopToLoopDuration;
59 IsoTriangulerDuration += FindSegmentToLinkInnerToLoopDuration;
60 IsoTriangulerDuration += TriangulateOverCycleDuration;
61 IsoTriangulerDuration += TriangulateInnerNodesDuration;
62
63 FChrono::PrintClockElapse(Log, TEXT(""), TEXT("IsoTrianguler"), IsoTriangulerDuration);
64 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("Triangulate"), TriangulateDuration);
65 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("BuildIsoNodes"), BuildIsoNodesDuration);
66 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("BuildLoopSegments"), BuildLoopSegmentsDuration);
67 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("BuildInnerSegments"), BuildInnerSegmentsDuration);
68 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("FindLoopSegmentOfInnerTriangulation"), FindLoopSegmentOfInnerTriangulationDuration);
69 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("FindSegmentIsoUVSurroundingSmallLoop"), FindSegmentIsoUVSurroundingSmallLoopDuration);
70 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("Find IsoSegment ToLink InnerToLoop"), FindIsoSegmentToLinkInnerToLoopDuration);
71 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("Find Segment ToLink LoopToLoop"), FindSegmentToLinkLoopToLoopDuration);
72 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("Find Segment ToLink InnerToLoop"), FindSegmentToLinkInnerToLoopDuration);
73 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("Mesh Over Cycle"), TriangulateOverCycleDuration);
74 FChrono::PrintClockElapse(Log, TEXT(" "), TEXT("Mesh Inner Nodes"), TriangulateInnerNodesDuration);
75 }
76};
77
79{
80 friend class FCycleTriangulator;
81 friend class FLoopCleaner;
82 friend class FParametricMesher;
83 friend struct FCell;
84
85protected:
86
89
94
99
105
107
112
118
125
128
131
134
141
148
153
154 bool bDisplay = false;
155
157
158public:
160
161public:
162
164
169 bool Triangulate();
170
171 void BuildNodes();
172
177 void BuildLoopSegments();
178
179 void BuildInnerSegments();
180
185 void GetThinZonesMesh();
187
191 void FillMeshNodes();
192
202
218
219 void ConnectCellLoops();
221
223
225
227
233 void TriangulateOverCycle(const EGridSpace Space);
234
239 bool FindCycle(FIsoSegment* StartSegment, bool bLeftSide, TArray<FIsoSegment*>& Cycle, TArray<bool>& CycleOrientation);
240
245 void MeshCycle(const TArray<FIsoSegment*>& Cycle, const TArray<bool>& CycleOrientation);
246 void MeshLargeCycle(const TArray<FIsoSegment*>& Cycle, const TArray<bool>& CycleOrientation);
247
248 template <uint32 Dim>
250 {
251 FIsoNode* Nodes[Dim];
252 for (int32 Index = 0; Index < Dim; ++Index)
253 {
254 Nodes[Index] = CycleOrientation[Index] ? &Cycle[Index]->GetFirstNode() : &Cycle[Index]->GetSecondNode();
255 }
256
257 MeshPolygonFunc(Grid, Nodes, Mesh);
258 }
259
260
261 bool CanCycleBeMeshed(const TArray<FIsoSegment*>& Cycle, FIntersectionSegmentTool& CycleIntersectionTool);
262
267
272 {
273 SortedLoopNodes.Reserve(LoopNodes.Num());
275 {
277 }
278
279 Algo::Sort(SortedLoopNodes, [this](const FLoopNode* Node1, const FLoopNode* Node2)
280 {
284 });
285 }
286
287 const FGrid& GetGrid() const
288 {
289 return Grid;
290 }
291
292private:
293
294 FIsoSegment* FindNextSegment(EGridSpace Space, const FIsoSegment* StartSegment, const FIsoNode* StartNode, SlopeMethod GetSlop) const;
295
296 // ==========================================================================================
297 // Create segments
298 // ==========================================================================================
299
300 void TryToConnectTwoLoopsWithIsocelesTriangle(FCell& Cell, const TArray<FLoopNode*>& SubLoopA, const TArray<FLoopNode*>& SubLoopB);
301
310 void TryToConnectTwoSubLoopsWithTheMostIsoSegment(FCell& Cell, const TArray<FLoopNode*>& SubLoopA, const TArray<FLoopNode*>& SubLoopB);
311
320 void TryToConnectVertexSubLoopWithTheMostIsoSegment(FCell& Cell, const TArray<FLoopNode*>& SubLoop);
321 FIsoSegment* GetOrTryToCreateSegment(FCell& Cell, FLoopNode* NodeA, const FVector2d& ACoordinates, FIsoNode* NodeB, const FVector2d& BCoordinates, const double FlatAngle);
322
323public:
324#ifdef CADKERNEL_DEV
326#endif
327
328#ifdef CADKERNEL_DEBUG
329 void DisplayPixels(TArray<uint8>& Pixel) const;
330
331 void DisplayPixel(const int32 Index) const;
332 void DisplayPixel(const int32 IndexU, const int32 IndexV) const;
333
334 void DisplayIsoNodes(EGridSpace Space) const;
335
336 void DisplayLoops(const TCHAR* Message, bool bOneNode = true, bool bSplitBySegment = false) const;
337 void DisplayLoopsByNextAndPrevious(const TCHAR* Message) const;
338
339 void DisplayCells(const TArray<FCell>& Cells) const;
340 void DisplayCell(const FCell& Cell) const;
342
344 void DisplayCellConnexions(const FString& Message, const TArray<FCellConnexion>& LoopConnexions, EVisuProperty Property) const;
345#endif
346
347};
348
349namespace IsoTriangulatorImpl
350{
351
357inline double CotangentCriteria(const FVector& APoint, const FVector& BPoint, const FVector& PPoint, FVector& OutNormal)
358{
359 const double BigValue = HUGE_VALUE;
360
363
364 // the ratio between the scalar product PA.PB (=|PA| |PB| cos (A,P,B) )
365 // with the norm of the cross product |PA^PB| (=|PA| |PB| |sin(A,P,B)|)
366 // is compute.
367 double ScalareProduct = PA | PB;
368 OutNormal = PA ^ PB;
369 double NormOFScalarProduct = sqrt(OutNormal | OutNormal);
370
371 // PPoint is aligned with (A,B)
373 {
374 return BigValue;
375 }
376
377 // return Cotangent value
379}
380
381inline double CotangentCriteria(const FVector2d& APoint, const FVector2d& BPoint, const FVector2d& PPoint)
382{
383 const double BigValue = HUGE_VALUE;
384
387
388 // the ratio between the scalar product PA.PB (=|PA| |PB| cos (A,P,B) )
389 // with the norm of the cross product |PA^PB| (=|PA| |PB| |sin(A,P,B)|)
390 // is compute.
391 double ScalareProduct = PA | PB;
392 double OutNormal = PA ^ PB;
393 double NormOFPointProduct = FMath::Abs(OutNormal);
394
396 {
397 // PPoint is aligned with (A,B)
398 return BigValue;
399 }
400
401 // return Cotangent value
403}
404
406{
407 double Value1;
408 double Value2;
409};
410
420
422{
424 return FMath::Max(Criteria.Value1, Criteria.Value2);
425}
426
428{
430 return FMath::Min(Criteria.Value1, Criteria.Value2);
431}
432
434{
435 const double SlopeAB = ComputeSlope(APoint, BPoint);
436 const double SlopeAC = ComputeSlope(APoint, CPoint);
437 const double SlopeBC = ComputeSlope(BPoint, CPoint);
438 const double SlopeBA = SwapSlopeOrientation(SlopeAB);
439 const double SlopeCA = SwapSlopeOrientation(SlopeAC);
440 const double SlopeCB = SwapSlopeOrientation(SlopeBC);
441
445
446 return FMath::Max3(A, B, C);
447}
448
449template<class PointType>
450inline double EquilateralCriteria(const PointType& SegmentA, const PointType& SegmentB, const PointType& Point)
451{
455 return Criteria1 + Criteria2 + Criteria3;
456}
457
458
459} // namespace FIsoTriangulatorImpl
460
461} // namespace UE::CADKernel
462
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define HUGE_VALUE
Definition Types.h:16
@ Pixel
Definition MetalRHIPrivate.h:224
#define DOUBLE_SMALL_NUMBER
Definition UnrealMathUtility.h:72
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition CycleTriangulator.h:116
Definition FaceMesh.h:16
Definition Grid.h:46
Definition IntersectionIsoSegmentTool.h:114
Definition IntersectionSegmentTool.h:395
Definition IsoNode.h:62
Definition IsoSegment.h:52
Definition IsoTriangulator.h:79
const FGrid & GetGrid() const
Definition IsoTriangulator.h:287
bool FindCycle(FIsoSegment *StartSegment, bool bLeftSide, TArray< FIsoSegment * > &Cycle, TArray< bool > &CycleOrientation)
Definition IsoTriangulator.cpp:1411
TArray< FIsoInnerNode > InnerNodes
Definition IsoTriangulator.h:103
bool bDisplay
Definition IsoTriangulator.h:154
FIntersectionIsoSegmentTool InnerToOuterIsoSegmentsIntersectionTool
Definition IsoTriangulator.h:130
void FillMeshNodes()
Definition IsoTriangulator.cpp:267
void GetThinZonesMesh()
Definition IsoTriangulator.cpp:359
void FindInnerGridCellSurroundingSmallLoop()
Definition IsoTriangulator.cpp:1194
TArray< FLoopNode > LoopNodes
Definition IsoTriangulator.h:91
void ConnectCellLoops()
Definition IsoTriangulator.cpp:926
TArray< FIsoInnerNode * > GlobalIndexToIsoInnerNodes
Definition IsoTriangulator.h:98
bool Triangulate()
Definition IsoTriangulator.cpp:84
TArray< FIsoSegment * > LoopSegments
Definition IsoTriangulator.h:108
void MeshCycleOf(const TArray< FIsoSegment * > &Cycle, const TArray< bool > &CycleOrientation, FMeshPolygonFunc MeshPolygonFunc)
Definition IsoTriangulator.h:249
const FMeshingTolerances & Tolerances
Definition IsoTriangulator.h:159
FFaceMesh & Mesh
Definition IsoTriangulator.h:88
TArray< FIsoSegment * > FinalToLoops
Definition IsoTriangulator.h:147
void TriangulateInnerNodes()
Definition IsoTriangulator.cpp:1586
FIntersectionSegmentTool LoopSegmentsIntersectionTool
Definition IsoTriangulator.h:124
FIntersectionSegmentTool ThinZoneIntersectionTool
Definition IsoTriangulator.h:133
TArray< FIsoSegment * > CandidateSegments
Definition IsoTriangulator.h:152
TArray< FIsoSegment * > FinalInnerSegments
Definition IsoTriangulator.h:110
FGrid & Grid
Definition IsoTriangulator.h:87
int32 LoopNodeCount
Definition IsoTriangulator.h:92
TArray< FLoopNode * > SortedLoopNodes
Definition IsoTriangulator.h:93
void BuildNodes()
Definition IsoTriangulator.cpp:214
void InitCellCorners(FCell &Cell)
Definition IsoTriangulator.cpp:2337
void TriangulateOverCycle(const EGridSpace Space)
Definition IsoTriangulator.cpp:1307
void FindCandidateToConnectCellCornerToLoops(FCell &Cell)
Definition IsoTriangulator.cpp:2356
void BuildInnerSegments()
Definition IsoTriangulator.cpp:522
void FindCellContainingBoundaryNodes(TArray< FCell > &Cells)
Definition IsoTriangulator.cpp:1002
TArray< int32 > IndexOfLowerLeftInnerNodeSurroundingALoop
Definition IsoTriangulator.h:140
TArray< FIsoSegment * > ThinZoneSegments
Definition IsoTriangulator.h:109
TArray< FIsoSegment * > InnerToOuterSegments
Definition IsoTriangulator.h:111
bool CanCycleBeMeshed(const TArray< FIsoSegment * > &Cycle, FIntersectionSegmentTool &CycleIntersectionTool)
Definition IsoTriangulator.cpp:1132
TArray< FIsoSegment * > InnerToLoopCandidateSegments
Definition IsoTriangulator.h:117
FIntersectionSegmentTool InnerSegmentsIntersectionTool
Definition IsoTriangulator.h:127
void SelectSegmentsToLinkInnerToLoop()
Definition IsoTriangulator.cpp:2455
void MeshLargeCycle(const TArray< FIsoSegment * > &Cycle, const TArray< bool > &CycleOrientation)
Definition IsoTriangulator.cpp:1176
void GetThinZoneMesh(const TMap< int32, FLoopNode * > &IndexToNode, const FThinZone2D &ThinZone)
Definition IsoTriangulator.cpp:382
bool bNeedCheckOrientation
Definition IsoTriangulator.h:156
TFactory< FIsoSegment > IsoSegmentFactory
Definition IsoTriangulator.h:106
void BuildLoopSegments()
Definition IsoTriangulator.cpp:323
TArray< int32 > LoopStartIndex
Definition IsoTriangulator.h:90
void MeshCycle(const TArray< FIsoSegment * > &Cycle, const TArray< bool > &CycleOrientation)
Definition IsoTriangulator.cpp:1159
void SortLoopNodes()
Definition IsoTriangulator.h:271
void BuildInnerSegmentsIntersectionTool()
Definition IsoTriangulator.cpp:771
int32 InnerNodeCount
Definition IsoTriangulator.h:104
Definition LoopCleaner.h:94
Definition IsoNode.h:285
virtual const FVector2d & Get2DPoint(EGridSpace Space, const FGrid &Grid) const override
Definition IsoNode.h:364
Definition ParametricMesherConstantes.h:17
Definition ParametricMesher.h:41
Definition ThinZone2D.h:157
Definition Factory.h:18
UE_REWRITE void Sort(RangeType &&Range)
Definition Sort.h:16
FPairOfDouble IsoscelesCriteria(const FVector2d &APoint, const FVector2d &BPoint, const FVector2d &CPoint)
Definition IsoTriangulator.h:411
double IsoscelesCriteriaMax(const FVector2d &APoint, const FVector2d &BPoint, const FVector2d &CPoint)
Definition IsoTriangulator.h:421
double CotangentCriteria(const FVector &APoint, const FVector &BPoint, const FVector &PPoint, FVector &OutNormal)
Definition IsoTriangulator.h:357
double IsoscelesCriteriaMin(const FVector2d &APoint, const FVector2d &BPoint, const FVector2d &CPoint)
Definition IsoTriangulator.h:427
double EquilateralSlopeCriteria(const FVector2d &APoint, const FVector2d &BPoint, const FVector2d &CPoint)
Definition IsoTriangulator.h:433
double EquilateralCriteria(const PointType &SegmentA, const PointType &SegmentB, const PointType &Point)
Definition IsoTriangulator.h:450
Definition CADEntity.cpp:23
uint64 FDuration
Definition Chrono.h:27
double TransformIntoOrientedSlope(double Slope)
Definition SlopeUtils.h:124
double SwapSlopeOrientation(double Slope)
Definition SlopeUtils.h:174
EGridSpace
Definition MeshEnum.h:17
@ Default2D
Definition MeshEnum.h:18
double ComputeSlope(const FVector2d &StartPoint, const FVector2d &EndPoint)
Definition SlopeUtils.h:180
EVisuProperty
Definition Visu.h:15
@ Point
Definition Visu.h:17
U16 Index
Definition radfft.cpp:71
static constexpr UE_FORCEINLINE_HINT T Max3(const T A, const T B, const T C)
Definition UnrealMathUtility.h:551
Definition IsoCell.h:87
Definition IsoCell.h:338
Definition IsoTriangulator.h:33
void PrintTimeElapse() const
Definition IsoTriangulator.h:50
FIsoTriangulatorChronos()
Definition IsoTriangulator.h:47
double Value1
Definition IsoTriangulator.h:407
double Value2
Definition IsoTriangulator.h:408