UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SurfacicPolyline.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Core/Types.h"
5
7#include "Geo/Curves/Curve.h"
8#include "Geo/GeoEnum.h"
9#include "Geo/GeoPoint.h"
12#include "Math/Boundary.h"
13#include "Math/MatrixH.h"
14#include "Math/Point.h"
15#include "UI/Display.h"
17
19#include "Algo/AllOf.h"
20
21namespace UE::CADKernel
22{
23
24class FCurve;
25class FEntityGeom;
26class FInfoEntity;
27class FSurface;
28
30{
31
32public:
33
39
41
44
46
48
49 FSurfacicPolyline(TSharedRef<FSurface> InCarrierSurface, TSharedRef<FCurve> InCurve2D, const double ChordTolerance, const double ParamTolerance, bool bInWithNormals/* = false*/, bool bWithTangent/* = false*/);
50
52 : bWithNormals(bInWithNormals)
53 , bWithTangent(bInWithTangent)
54 {
55 }
56
58 {
59 Ar.Serialize(Points3D);
60 Ar.Serialize(Points2D);
62 Ar.Serialize(Coordinates);
64 Ar << bWithNormals;
65 Ar << bWithTangent;
66 }
67
69
71
72 void CheckIfDegenerated(const double Tolerance3D, const FSurfacicTolerance& Tolerances2D, const FLinearBoundary& Boudary, bool& bDegeneration2D, bool& bDegeneration3D, double& Length3D) const;
73
74 void GetExtremities(const FLinearBoundary& InBoundary, const double Tolerance3D, const FSurfacicTolerance& Tolerances2D, FSurfacicCurveExtremities& Extremities) const;
75
77 {
79 return Approximator3D.ApproximatePoint(InCoordinate);
80 }
81
87
89 {
90 TPolylineApproximator<FVector2d> Approximator(Coordinates, Points2D);
91 return Approximator.ApproximatePoint(InCoordinate);
92 }
93
95 {
96 FDichotomyFinder Finder(Coordinates);
98 return Points3D[Index + 1] - Points3D[Index];
99 }
100
102 {
103 FDichotomyFinder Finder(Coordinates);
105 return Points2D[Index + 1] - Points2D[Index];
106 }
107
108 FSurfacicTolerance ComputeTolerance(const double Tolerance3D, const FSurfacicTolerance& MinToleranceIso, const int32 Index) const
109 {
110 double Distance3D = FVector::Distance(Points3D[Index], Points3D[Index + 1]);
112 {
113 return FVectorUtil::FarawayPoint2D;
114 }
115 else
116 {
117 FSurfacicTolerance Tolerance2D = Points2D[Index] - Points2D[Index + 1];
118 return FVector2D::Max(Tolerance2D.GetAbs() * Tolerance3D / Distance3D, MinToleranceIso);
119 }
120 };
121
122 double ComputeLinearToleranceAt(const double Tolerance3D, const double MinLinearTolerance, const int32 Index) const
123 {
124 double Distance3D = FVector::Distance(Points3D[Index], Points3D[Index + 1]);
126 {
127 return (Coordinates.Last() - Coordinates[0]) / 10.;
128 }
129 else
130 {
131 double LinearDistance = Coordinates[Index + 1] - Coordinates[Index];
132 return FMath::Max(LinearDistance / Distance3D * Tolerance3D, MinLinearTolerance);
133 }
134 };
135
137 {
138 TPolylineApproximator<FVector2d> Approximator(Coordinates, Points2D);
140 }
141
143 {
144 if (OutPolyline.Coordinates.IsEmpty())
145 {
146 return;
147 }
148
150 {
151 int32 CoordinateCount = OutPolyline.Coordinates.Num();
152
155
158
159
160 //for (int32 Index = 0; Index < CoordinateCount; ++Index)
161 for (const double Coordinate : OutPolyline.Coordinates)
162 {
163 const int32& Index = SegmentIndexes.Emplace_GetRef(Finder.Find(Coordinate));
164 SegmentCoordinates.Emplace(PolylineTools::SectionCoordinate(Coordinates, Index, Coordinate));
165 }
166
167 OutPolyline.Points2D.Reserve(CoordinateCount);
168 for (int32 Index = 0; Index < CoordinateCount; ++Index)
169 {
170 int32 SegmentIndex = SegmentIndexes[Index];
172 OutPolyline.Points2D.Emplace(PolylineTools::LinearInterpolation(Points2D, SegmentIndex, SegmentCoordinate));
173 }
174
175 OutPolyline.Points3D.Reserve(CoordinateCount);
176 for (int32 Index = 0; Index < CoordinateCount; ++Index)
177 {
178 int32 SegmentIndex = SegmentIndexes[Index];
180 OutPolyline.Points3D.Emplace(PolylineTools::LinearInterpolation(Points3D, SegmentIndex, SegmentCoordinate));
181 }
182
183 if (bWithNormals)
184 {
185 for (int32 Index = 0; Index < CoordinateCount; ++Index)
186 {
187 int32 SegmentIndex = SegmentIndexes[Index];
189 OutPolyline.Normals.Emplace(PolylineTools::LinearInterpolation(Normals, SegmentIndex, SegmentCoordinate));
190 }
191 }
192
193 if (bWithTangent)
194 {
195 for (int32 Index = 0; Index < CoordinateCount; ++Index)
196 {
197 int32 SegmentIndex = SegmentIndexes[Index];
199 OutPolyline.Tangents.Emplace(PolylineTools::LinearInterpolation(Tangents, SegmentIndex, SegmentCoordinate));
200 }
201 }
202 };
203
205 int32 StartIndex = 0;
206 int32 EndIndex;
207
208 bool bUseDichotomy = false;
209 StartIndex = DichotomyFinder.Find(OutPolyline.Coordinates[0]);
210 EndIndex = DichotomyFinder.Find(OutPolyline.Coordinates.Last());
211 bUseDichotomy = PolylineTools::IsDichotomyToBePreferred(EndIndex - StartIndex, Coordinates.Num());
212
213
214 if (bUseDichotomy)
215 {
216 DichotomyFinder.StartLower = StartIndex;
217 DichotomyFinder.StartUpper = EndIndex;
219 }
220 else
221 {
222 FLinearFinder LinearFinder(Coordinates, StartIndex);
224 }
225 }
226
227
228 void Sample(const FLinearBoundary& Boundary, const double DesiredSegmentLength, TArray<double>& OutCoordinates) const
229 {
230 TPolylineApproximator<FVector> Approximator3D(Coordinates, Points3D);
231 Approximator3D.SamplePolyline(Boundary, DesiredSegmentLength, OutCoordinates);
232 }
233
235 {
236 TPolylineApproximator<FVector> Approximator3D(Coordinates, Points3D);
237 return Approximator3D.ProjectPointToPolyline(Boundary, PointOnEdge, ProjectedPoint);
238 }
239
241 {
243 return Approximator2D.ProjectPointToPolyline(Boundary, PointOnEdge, ProjectedPoint);
244 }
245
251
257
267
271 void ComputeIntersectionsWithIsos(const FLinearBoundary& InBoundary, const TArray<double>& InIsoCoordinates, const EIso InTypeIso, const FSurfacicTolerance& ToleranceIso, TArray<double>& OutIntersection) const;
272
274 {
275 return Coordinates;
276 }
277
279 {
280 return Points2D;
281 }
282
284 {
285 return Points3D[Index];
286 }
287
289 {
290 return Points3D;
291 }
292
294 {
295 return Normals;
296 }
297
299 {
300 return Tangents;
301 }
302
304 {
305 Swap(NewCoordinates, Coordinates);
306 Points2D.Empty(Coordinates.Num());
307 Points3D.Empty(Coordinates.Num());
308 if (bWithNormals)
309 {
310 Normals.Empty(Coordinates.Num());
311 }
312 if (bWithTangent)
313 {
314 Tangents.Empty(Coordinates.Num());
315 }
316 }
317
321 int32 Size() const
322 {
323 return Points2D.Num();
324 }
325
330 {
331 TPolylineApproximator<FVector2d> Approximator(Coordinates, Points2D);
333 }
334
343
352
361
368 {
369 Points3D.Reserve(Number);
370 Points2D.Reserve(Number);
371 Coordinates.Reserve(Number);
372 if (bWithNormals)
373 {
374 Normals.Reserve(Number);
375 }
376 }
377
383 void Empty(int32 Slack = 0)
384 {
385 Points3D.Empty(Slack);
386 Points2D.Empty(Slack);
387 Normals.Empty(Slack);
388 Coordinates.Empty(Slack);
389 }
390
392 {
393 Coordinates.EmplaceAt(Index, Polyline.Coordinates[PointIndex]);
394
395 Points2D.EmplaceAt(Index, Polyline.Points2D[PointIndex]);
396 Points3D.EmplaceAt(Index, Polyline.Points3D[PointIndex]);
397 if (bWithNormals)
398 {
399 Normals.EmplaceAt(Index, Polyline.Normals[PointIndex]);
400 }
401 if (bWithTangent)
402 {
403 Tangents.EmplaceAt(Index, Polyline.Tangents[PointIndex]);
404 }
405 }
406
408 {
409 const int32 Count = Points2D.Num();
410
411 TBitArray<> Markers(true, Count);
412
413 for (int32 Index = Count - 1; Index >= 0; Index -= Offset)
414 {
415 Markers[Index] = false;
416 }
417
418 int32 CurrentIndex = 0;
419 for (int32 Index = 0; Index < Count; ++Index)
420 {
421 if (Markers[Index])
422 {
423 Coordinates[CurrentIndex] = Coordinates[Index];
424 Points2D[CurrentIndex] = Points2D[Index];
425 Points3D[CurrentIndex] = Points3D[Index];
426 if (bWithNormals)
427 {
428 Normals[CurrentIndex] = Normals[Index];
429 }
430 if (bWithTangent)
431 {
432 Tangents[CurrentIndex] = Tangents[Index];
433 }
434 ++CurrentIndex;
435 }
436 }
437
438 Coordinates.SetNum(CurrentIndex, EAllowShrinking::No);
439 Points2D.SetNum(CurrentIndex, EAllowShrinking::No);
440 Points3D.SetNum(CurrentIndex, EAllowShrinking::No);
441 if (bWithNormals)
442 {
443 Normals.SetNum(CurrentIndex, EAllowShrinking::No);
444 }
445 if (bWithTangent)
446 {
447 Tangents.SetNum(CurrentIndex, EAllowShrinking::No);
448 }
449 }
450
451 void Pop()
452 {
453 Coordinates.Pop(EAllowShrinking::No);
454 Points2D.Pop(EAllowShrinking::No);
455 Points3D.Pop(EAllowShrinking::No);
456 if (bWithNormals)
457 {
459 }
460 if (bWithTangent)
461 {
463 }
464 }
465
466 void Reverse()
467 {
468 Algo::Reverse(Coordinates);
469 Algo::Reverse(Points2D);
470 Algo::Reverse(Points3D);
471 if (bWithNormals)
472 {
474 }
475 if (bWithTangent)
476 {
478 }
479 }
480
482 {
483 TPolylineApproximator<FVector> Approximator3D(Coordinates, Points3D);
484 return Approximator3D.ComputeLengthOfSubPolyline(InBoundary);
485 }
486
488 {
489 TPolylineApproximator<FVector2d> Approximator(Coordinates, Points2D);
490 return Approximator.ComputeLengthOfSubPolyline(InBoundary);
491 }
492
493 bool IsIso(EIso Iso, double ErrorTolerance = DOUBLE_SMALL_NUMBER) const
494 {
495 FVector2d StartPoint = Points2D[0];
496 return Algo::AllOf(Points2D, [&](const FVector2d& Point) {
497 return FMath::IsNearlyEqual(Point[Iso], StartPoint[Iso], ErrorTolerance);
498 });
499 }
500
501};
502
503} // ns UE::CADKernel
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 DOUBLE_SMALL_NUMBER
Definition UnrealMathUtility.h:72
uint32 Offset
Definition VulkanMemory.cpp:4033
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void SetNum(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2308
ElementType Pop(EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:1196
UE_FORCEINLINE_HINT void EmplaceAt(SizeType Index, ArgsType &&... Args)
Definition Array.h:2665
void Empty(SizeType Slack=0)
Definition Array.h:2273
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition AndroidPlatformMisc.h:14
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Definition CADKernelArchive.h:19
void Serialize(void *Value, int64 Length)
Definition CADKernelArchive.h:118
Definition IndexOfCoordinateFinder.h:85
Definition IndexOfCoordinateFinder.h:20
Definition IndexOfCoordinateFinder.h:33
Definition MatrixH.h:14
Definition Boundary.h:248
Definition SurfacicPolyline.h:30
int32 Size() const
Definition SurfacicPolyline.h:321
void Reverse()
Definition SurfacicPolyline.h:466
TSharedPtr< FEntityGeom > ApplyMatrix(const FMatrixH &) const
FVector2d Approximate2DPoint(double InCoordinate) const
Definition SurfacicPolyline.h:88
void Empty(int32 Slack=0)
Definition SurfacicPolyline.h:383
double GetCoordinateOfProjectedPoint(const FLinearBoundary &Boundary, const FVector2d &PointOnEdge, FVector2d &ProjectedPoint) const
Definition SurfacicPolyline.h:240
TArray< FVector3f > Normals
Definition SurfacicPolyline.h:37
void ProjectPoints(const FLinearBoundary &InBoundary, const TArray< FVector > &InPointsToProject, TArray< double > &ProjectedPointCoordinates, TArray< FVector > &ProjectedPoints) const
Definition SurfacicPolyline.h:246
TArray< FVector > Points3D
Definition SurfacicPolyline.h:36
void ProjectPoints(const FLinearBoundary &InBoundary, const TArray< FVector2d > &InPointsToProject, TArray< double > &ProjectedPointCoordinates, TArray< FVector2d > &ProjectedPoints) const
Definition SurfacicPolyline.h:252
const TArray< double > & GetCoordinates() const
Definition SurfacicPolyline.h:273
FVector2d GetTangent2DAt(double InCoordinate) const
Definition SurfacicPolyline.h:101
void Serialize(FCADKernelArchive &Ar)
Definition SurfacicPolyline.h:57
void Approximate2DPoints(const TArray< double > &InCoordinates, TArray< FVector2d > &OutPoints) const
Definition SurfacicPolyline.h:136
TArray< double > Coordinates
Definition SurfacicPolyline.h:34
const TArray< FVector > & GetTangents() const
Definition SurfacicPolyline.h:298
bool bWithNormals
Definition SurfacicPolyline.h:42
FVector GetTangentAt(double InCoordinate) const
Definition SurfacicPolyline.h:94
double ComputeLinearToleranceAt(const double Tolerance3D, const double MinLinearTolerance, const int32 Index) const
Definition SurfacicPolyline.h:122
FSurfacicTolerance ComputeTolerance(const double Tolerance3D, const FSurfacicTolerance &MinToleranceIso, const int32 Index) const
Definition SurfacicPolyline.h:108
void Sample(const FLinearBoundary &Boundary, const double DesiredSegmentLength, TArray< double > &OutCoordinates) const
Definition SurfacicPolyline.h:228
void GetSubPolyline(const FLinearBoundary &InBoundary, TArray< double > &OutCoordinates, TArray< FVector2d > &OutPoints) const
Definition SurfacicPolyline.h:338
bool IsIso(EIso Iso, double ErrorTolerance=DOUBLE_SMALL_NUMBER) const
Definition SurfacicPolyline.h:493
void GetSubPolyline(const FLinearBoundary &InBoundary, const EOrientation InOrientation, TArray< FVector > &OutPoints) const
Definition SurfacicPolyline.h:347
bool bWithTangent
Definition SurfacicPolyline.h:43
void GetSubPolyline(const FLinearBoundary &InBoundary, const EOrientation InOrientation, TArray< FVector2d > &OutPoints) const
Definition SurfacicPolyline.h:329
FSurfacicBoundary BoundingBox
Definition SurfacicPolyline.h:40
void Approximate3DPoints(const TArray< double > &InCoordinates, TArray< FVector > &OutPoints) const
Definition SurfacicPolyline.h:82
const FVector & GetPointAt(int32 Index) const
Definition SurfacicPolyline.h:283
void Reserve(int32 Number)
Definition SurfacicPolyline.h:367
void ProjectCoincidentalPolyline(const FLinearBoundary &InBoundary, const TArray< FVector > &InPointsToProject, bool bSameOrientation, TArray< double > &OutProjectedPointCoordinates, double ToleranceOfProjection) const
Definition SurfacicPolyline.h:262
void GetSubPolyline(const FLinearBoundary &InBoundary, TArray< double > &OutCoordinates, TArray< FVector > &OutPoints) const
Definition SurfacicPolyline.h:356
FVector Approximate3DPoint(double InCoordinate) const
Definition SurfacicPolyline.h:76
FInfoEntity & GetInfo(FInfoEntity &) const
TArray< FVector > Tangents
Definition SurfacicPolyline.h:38
TArray< FVector2d > Points2D
Definition SurfacicPolyline.h:35
void EmplaceAt(int32 Index, FSurfacicPolyline &Polyline, int32 PointIndex)
Definition SurfacicPolyline.h:391
const TArray< FVector2d > & Get2DPoints() const
Definition SurfacicPolyline.h:278
const TArray< FVector > & GetPoints() const
Definition SurfacicPolyline.h:288
void Pop()
Definition SurfacicPolyline.h:451
void ApproximatePolyline(FSurfacicPolyline &OutPolyline) const
Definition SurfacicPolyline.h:142
void SwapCoordinates(TArray< double > &NewCoordinates)
Definition SurfacicPolyline.h:303
double GetLength(const FLinearBoundary &InBoundary) const
Definition SurfacicPolyline.h:481
const TArray< FVector3f > & GetNormals() const
Definition SurfacicPolyline.h:293
double GetCoordinateOfProjectedPoint(const FLinearBoundary &Boundary, const FVector &PointOnEdge, FVector &ProjectedPoint) const
Definition SurfacicPolyline.h:234
double Get2DLength(const FLinearBoundary &InBoundary) const
Definition SurfacicPolyline.h:487
void RemoveComplementaryPoints(int32 Offset)
Definition SurfacicPolyline.h:407
FSurfacicPolyline(bool bInWithNormals=false, bool bInWithTangent=false)
Definition SurfacicPolyline.h:51
Definition PolylineTools.h:194
void ApproximatePoints(const TArray< double > &InCoordinates, TArray< CurvePointType > &OutPoints, int32 InDerivativeOrder=0) const
Definition PolylineTools.h:360
void GetSubPolyline(const FLinearBoundary &InBoundary, const EOrientation Orientation, TArray< PointType > &OutPoints) const
Definition PolylineTools.h:673
PointType ApproximatePoint(const double InCoordinate) const
Definition PolylineTools.h:319
double ComputeLengthOfSubPolyline(const int BoundaryIndex[2], const FLinearBoundary &InBoundary) const
Definition PolylineTools.h:779
void ProjectPointsToPolyline(const FLinearBoundary &InBoundary, const TArray< PointType > &InPointsToProject, TArray< double > &OutProjectedPointCoords, TArray< PointType > &OutProjectedPoints) const
Definition PolylineTools.h:552
UE_REWRITE void Reverse(T(&Array)[ArraySize])
Definition Reverse.h:28
bool AllOf(const RangeType &Range)
Definition AllOf.h:19
Definition CADEntity.cpp:23
EOrientation
Definition GeoEnum.h:82
EIso
Definition GeoEnum.h:66
@ Iso
Definition Visu.h:20
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT bool IsNearlyEqual(float A, float B, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:388
static UE_FORCEINLINE_HINT bool IsNearlyZero(float Value, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:407
Definition Boundary.h:18
static UE_FORCEINLINE_HINT TVector2< double > Max(const TVector2< double > &A, const TVector2< double > &B)
Definition Vector2D.h:953
static UE_FORCEINLINE_HINT double Distance(const TVector< double > &V1, const TVector< double > &V2)
Definition Vector.h:1018