UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IsoCell.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 "Core/Types.h"
6#include "Mesh/MeshEnum.h"
11#include "Mesh/Structure/Grid.h"
13
14namespace UE::CADKernel
15{
16class FGrid;
17class FIsoTriangulator;
18struct FLoopConnexion;
19
21{
26 bool bIsOuterLoop = false;
27 bool bIsConnected = false;
28
30 : Id(InIndex)
31 , Barycenter(FVector2d::ZeroVector)
32 , Nodes(InNodes)
33 , bIsOuterLoop(Nodes[0]->GetLoopIndex() == 0)
34 {
35 for (const FLoopNode* Node : Nodes)
36 {
37 Barycenter += Node->Get2DPoint(EGridSpace::UniformScaled, Grid);
38 }
39 Barycenter /= (double)Nodes.Num();
40 }
41
43 : Id(InIndex)
44 , Barycenter(FVector::ZeroVector)
45 {
46 }
47
48 virtual ~FCellLoop() = default;
49
50 virtual bool IsCellCorner() const
51 {
52 return false;
53 }
54
55 virtual bool IsCellCornerOrOuterLoop() const
56 {
57 return bIsOuterLoop;
58 }
59
61};
62
63struct FCellCorner : public FCellLoop
64{
66
73
74 virtual bool IsCellCorner() const override
75 {
76 return true;
77 }
78
79 virtual bool IsCellCornerOrOuterLoop() const
80 {
81 return true;
82 }
83
84};
85
87{
91
93
94 FLoopNode* NodeA = nullptr;
95 FIsoNode* NodeB = nullptr;
96
97 FIsoSegment* Segment = nullptr;
98
107
109 {
110 return (Loop == &Loop1) ? &Loop2 : &Loop1;
111 }
112
114 {
115 return (Loop == &Loop1) ? &Loop2 : &Loop1;
116 }
117
118 bool IsShortestPath(const int32 MaxLoopCount)
119 {
121 DistanceToLoops.Reserve(MaxLoopCount);
122 DistanceToLoops.Add(&Loop2, 0.);
124 while (true)
125 {
127 TPair<const FCellLoop*, double>* CurrentLoop = nullptr;
129 {
130 if (DistanceToLoop.Value >= 0. && DistanceToLoop.Value < DistanceToCurrent)
131 {
133 CurrentLoop = &DistanceToLoop;
134 }
135 }
136
137 if (!CurrentLoop || CurrentLoop->Value > MinDistance)
138 {
139 return true;
140 }
141
142 if (CurrentLoop->Key == &Loop1)
143 {
144 return (CurrentLoop->Value > MinDistance);
145 }
146
147 for (FCellConnexion* Connexion : CurrentLoop->Key->Connexions)
148 {
149 if (Connexion == this)
150 {
151 continue;
152 }
153
154 const FCellLoop* NextLoop = Connexion->GetOtherLoop(CurrentLoop->Key);
155 if (NextLoop->IsCellCorner())
156 {
157 continue;
158 }
159
160 if (NextLoop->bIsOuterLoop)
161 {
162 continue;
163 }
164
165 const double DistanceToNextByCurrent = CurrentLoop->Value + Connexion->MinDistance;
166
169 {
171 {
173 }
174 }
175 else
176 {
178 }
179 }
180
181 CurrentLoop->Value = -HUGE_VALUE;
182 }
183
184 return true;
185 }
186
187 bool IsShortestPathToOuterLoop(const int32 MaxLoopCount)
188 {
190 DistanceToLoops.Reserve(MaxLoopCount);
191 DistanceToLoops.Add(&Loop2, 0.);
193
194 while (true)
195 {
199 {
200 if (DistanceToLoop.Value >= 0. && DistanceToLoop.Value < DistanceToCurrent)
201 {
204 }
205 }
206
208 {
209 return true;
210 }
211
212 const FCellLoop* CurrentLoop = CurrentLoopPair->Key;
213 double& CurrentLoopDistance = CurrentLoopPair->Value;
214
215 for (FCellConnexion* Connexion : CurrentLoop->Connexions)
216 {
217 if (Connexion == this)
218 {
219 continue;
220 }
221
222 const FCellLoop* NextLoop = Connexion->GetOtherLoop(CurrentLoop);
223 if (NextLoop->IsCellCorner())
224 {
225 continue;
226 }
227
228 const double DistanceToNextByCurrent = CurrentLoopDistance + Connexion->MinDistance;
229 if (NextLoop->bIsOuterLoop)
230 {
232 {
233 return false;
234 }
235 continue;
236 }
237
240 {
242 {
244 }
245 }
246 else
247 {
249 }
250 }
251
253 }
254
255 return true;
256 }
257
258 bool IsShortestPathToCorner(const int32 MaxLoopCount)
259 {
261 DistanceToLoops.Reserve(MaxLoopCount);
262 DistanceToLoops.Add(&Loop2, 0.);
264
265 while (true)
266 {
270 {
271 if (DistanceToLoop.Value >= 0. && DistanceToLoop.Value < DistanceToCurrent)
272 {
275 }
276 }
277
279 {
280 return true;
281 }
282
283 const FCellLoop* CurrentLoop = CurrentLoopPair->Key;
284 double& CurrentLoopDistance = CurrentLoopPair->Value;
285
286 for (FCellConnexion* Connexion : CurrentLoop->Connexions)
287 {
288 if (Connexion == this)
289 {
290 continue;
291 }
292
293 const FCellLoop* NextLoop = Connexion->GetOtherLoop(CurrentLoop);
294 if (NextLoop->bIsOuterLoop)
295 {
296 continue;
297 }
298
299 const double DistanceToNextByCurrent = CurrentLoopDistance + Connexion->MinDistance;
300 if (NextLoop->IsCellCorner())
301 {
303 {
304 return false;
305 }
306 continue;
307 }
308
311 {
313 {
315 }
316 }
317 else
318 {
320 }
321 }
322
324 }
325
326 return true;
327 }
328};
329
336
337struct FCell
338{
340 const FGrid& Grid;
342
345
348
350
355
358 , Grid(Triangulator.GetGrid())
359 , Id(InLoopIndex)
361 {
362 const int32 NodeCount = InNodes.Num();
363 ensureCADKernel(NodeCount > 0);
364
365 // Subdivide InNodes in SubLoop
367 {
368 return LoopNode1->GetGlobalIndex() < LoopNode2->GetGlobalIndex();
369 });
370
371 int32 LoopCount = 0;
372 FLoopNode* PreviousNode = nullptr;
373 for (FLoopNode* Node : InNodes)
374 {
375 if (&Node->GetPreviousNode() != PreviousNode)
376 {
377 LoopCount++;
378 }
379 PreviousNode = Node;
380 }
381
382 CellLoops.Reserve(LoopCount);
383
384 LoopCount = 0;
385 TArray<FLoopNode*> LoopNodes;
386 LoopNodes.Reserve(NodeCount);
387
388 int32 LoopIndex = -1;
389 FCellLoop* FirstLoopCell = nullptr;
390
392 {
393 if (LoopNodes.Num())
394 {
395 if ((LoopIndex == LoopNodes[0]->GetLoopIndex()) && (&LoopNodes.Last()->GetNextNode() == FirstLoopCell->Nodes[0]))
396 {
397 LoopNodes.Append(FirstLoopCell->Nodes);
398 FirstLoopCell->Nodes = LoopNodes;
399 }
400 else
401 {
402 CellLoops.Emplace(CellLoops.Num(), LoopNodes, Grid);
403 }
404
405 if (LoopIndex != LoopNodes[0]->GetLoopIndex())
406 {
407 LoopIndex = LoopNodes[0]->GetLoopIndex();
409 }
410 }
411 };
412
413 PreviousNode = nullptr;
414 for (FLoopNode* Node : InNodes)
415 {
416 Node->SetMarker1();
417 }
418
419 for (FLoopNode* Node : InNodes)
420 {
421 if (Node->IsDeleteOrHasMarker2() )
422 {
423 continue;
424 }
425
426 FLoopNode* StartNode = &Node->GetPreviousNode();
427 while (StartNode->HasMarker1() && (StartNode != Node))
428 {
429 StartNode = &StartNode->GetPreviousNode();
430 }
431 if (!StartNode->HasMarker1())
432 {
433 StartNode = &StartNode->GetNextNode();
434 }
435
436 LoopNodes.Reset(NodeCount);
437 FLoopNode* NextNode = StartNode;
438 while (NextNode->HasMarker1NotMarker2())
439 {
440 LoopNodes.Add(NextNode);
441 NextNode->SetMarker2();
442 NextNode = &NextNode->GetNextNode();
443 }
444
445 MakeLoopCell(LoopNodes);
446 }
447
448 for (FLoopNode* Node : InNodes)
449 {
450 Node->ResetMarkers();
451 }
452
453 for(const FCellLoop& LoopCell : CellLoops)
454 {
455 if (LoopCell.bIsOuterLoop)
456 {
458 }
459 else
460 {
462 }
463 }
464 }
465
466 void InitLoopConnexions();
467
469 {
472 for (const FCellLoop& LoopCell : CellLoops)
473 {
474 if(!LoopCell.bIsOuterLoop)
475 {
476 LoopBarycenters.Emplace(LoopCell.Id, LoopCell.Barycenter);
477 }
478 }
480 }
481
484
488
489 //void ConnectLoopsByNeighborhood2();
490
504
506};
507
508} // namespace UE::CADKernel
509
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
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 ensureCADKernel(InExpression)
Definition Types.h:115
#define HUGE_VALUE
Definition Types.h:16
#define HUGE_VALUE_SQUARE
Definition Types.h:19
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT ElementType & Last(SizeType IndexFromTheEnd=0) UE_LIFETIMEBOUND
Definition Array.h:1263
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 AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition Grid.h:46
Definition IntersectionSegmentTool.h:395
Definition IsoNode.h:442
virtual const FVector2d & Get2DPoint(EGridSpace Space, const FGrid &Grid) const override
Definition IsoNode.h:505
Definition IsoNode.h:62
bool HasMarker1NotMarker2() const
Definition IsoNode.h:242
bool HasMarker1() const
Definition IsoNode.h:226
void SetMarker2()
Definition IsoNode.h:253
Definition IsoSegment.h:52
Definition IsoTriangulator.h:79
Definition IsoNode.h:285
FLoopNode & GetPreviousNode() const
Definition IsoNode.h:341
FLoopNode & GetNextNode() const
Definition IsoNode.h:346
Definition Factory.h:18
UE_REWRITE void Sort(RangeType &&Range)
Definition Sort.h:16
Definition CADEntity.cpp:23
@ UniformScaled
Definition MeshEnum.h:20
Definition Tuple.h:652
Definition IsoCell.h:87
FCellLoop & Loop1
Definition IsoCell.h:89
FIsoNode * NodeB
Definition IsoCell.h:95
bool IsShortestPathToOuterLoop(const int32 MaxLoopCount)
Definition IsoCell.h:187
FCellLoop & Loop2
Definition IsoCell.h:90
FIsoSegment * Segment
Definition IsoCell.h:97
bool IsShortestPath(const int32 MaxLoopCount)
Definition IsoCell.h:118
FLoopNode * NodeA
Definition IsoCell.h:94
FCellLoop * GetOtherLoop(const FCellLoop *Loop)
Definition IsoCell.h:113
bool bIsConnexionWithOuter
Definition IsoCell.h:88
double MinDistance
Definition IsoCell.h:92
FCellConnexion(FCellLoop &InLoop1, FCellLoop &InLoop2)
Definition IsoCell.h:99
const FCellLoop * GetOtherLoop(const FCellLoop *Loop) const
Definition IsoCell.h:108
bool IsShortestPathToCorner(const int32 MaxLoopCount)
Definition IsoCell.h:258
Definition IsoCell.h:64
virtual bool IsCellCornerOrOuterLoop() const
Definition IsoCell.h:79
FCellCorner(const int32 InIndex, FIsoInnerNode &InNode, const FGrid &Grid)
Definition IsoCell.h:67
FIsoInnerNode & CornerNode
Definition IsoCell.h:65
virtual bool IsCellCorner() const override
Definition IsoCell.h:74
Definition IsoCell.h:21
FVector2d Barycenter
Definition IsoCell.h:23
virtual bool IsCellCornerOrOuterLoop() const
Definition IsoCell.h:55
bool bIsOuterLoop
Definition IsoCell.h:26
TArray< FLoopNode * > Nodes
Definition IsoCell.h:24
void PropagateAsConnected()
Definition IsoTriangulator.cpp:1790
virtual bool IsCellCorner() const
Definition IsoCell.h:50
FCellLoop(const int32 InIndex, TArray< FLoopNode * > &InNodes, const FGrid &Grid)
Definition IsoCell.h:29
FCellLoop(const int32 InIndex)
Definition IsoCell.h:42
TArray< FCellConnexion * > Connexions
Definition IsoCell.h:25
bool bIsConnected
Definition IsoCell.h:27
virtual ~FCellLoop()=default
int32 Id
Definition IsoCell.h:22
Definition IsoCell.h:331
double Length
Definition IsoCell.h:332
TArray< FCellLoop > Path
Definition IsoCell.h:334
FCellLoop * CurrentLoop
Definition IsoCell.h:333
Definition IsoCell.h:338
int32 Id
Definition IsoCell.h:341
void TryToConnectTwoSubLoopsWithShortestSegment(FCellConnexion &LoopConnexion)
Definition IsoTriangulator.cpp:1927
FIsoTriangulator & Triangulator
Definition IsoCell.h:339
int32 OuterLoopCount
Definition IsoCell.h:344
TArray< FCellConnexion > LoopConnexions
Definition IsoCell.h:353
TArray< FIsoSegment * > CandidateSegments
Definition IsoCell.h:346
void InitLoopConnexions()
Definition IsoTriangulator.cpp:1858
int32 InnerLoopCount
Definition IsoCell.h:343
const FGrid & Grid
Definition IsoCell.h:340
FCell(const int32 InLoopIndex, TArray< FLoopNode * > &InNodes, FIsoTriangulator &InTriangulator)
Definition IsoCell.h:356
TArray< FIsoSegment * > FinalSegments
Definition IsoCell.h:347
TArray< FCellLoop > CellLoops
Definition IsoCell.h:351
void FindCandidateToConnectLoopsByNeighborhood()
Definition IsoTriangulator.cpp:1657
TArray< FCellCorner > CellCorners
Definition IsoCell.h:352
void SelectSegmentToConnectLoopToCorner(TFactory< FIsoSegment > &SegmentFactory)
Definition IsoTriangulator.cpp:1725
void FindCandidateToConnectCellCornerToLoops()
FIntersectionSegmentTool IntersectionTool
Definition IsoCell.h:349
void CheckAllLoopsConnectedTogetherAndConnect()
Definition IsoTriangulator.cpp:1808
void SelectSegmentToConnectLoops(TFactory< FIsoSegment > &SegmentFactory)
Definition IsoTriangulator.cpp:1669
void TryToCreateSegment(FCellConnexion &LoopConnexion)
Definition IsoTriangulator.cpp:1824
TArray< int32 > LoopCellBorderIndices
Definition IsoCell.h:354
TArray< TPair< int32, FVector2d > > GetLoopBarycenters()
Definition IsoCell.h:468