UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ConvexHull3.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
7#include "Containers/Set.h"
8#include "CoreMinimal.h"
9#include "HalfspaceTypes.h"
10#include "IndexTypes.h"
11#include "LineTypes.h"
12#include "Math/UnrealMathSSE.h"
13#include "Math/Vector.h"
14#include "MathUtil.h"
15#include "PlaneTypes.h"
16#include "Templates/Function.h"
18#include "Util/ProgressCancel.h"
19#include "VectorTypes.h"
20
21class FProgressCancel;
22
23namespace UE {
24namespace Geometry {
25
26using namespace UE::Math;
27
36template<typename RealType>
38{
39 int Dimension = 0;
40 int Extreme[4]{ 0, 0, 0, 0 };
41
42 // Coordinate frame spanned by input points
44 TVector<RealType> Basis[3]{ {0,0,0}, {0,0,0}, {0,0,0} };
45
46 TExtremePoints3(int32 NumPoints, TFunctionRef<TVector<RealType>(int32)> GetPointFunc, TFunctionRef<bool(int32)> FilterFunc = [](int32 Idx) {return true; }, RealType Epsilon = TMathUtil<RealType>::Epsilon)
47 {
48 Init(NumPoints, GetPointFunc, FilterFunc, Epsilon);
49 }
50
51private:
53};
54
55template<typename RealType>
71
75template<typename RealType>
77{
78public:
79
83
84 // Settings controlling whether and how to generate a simpler hull
86
87 // Helper to compute the a convex hull and return only its volume. If the hull cannot be constructed, a volume of 0 will be returned.
88 GEOMETRYCORE_API static double ComputeVolume(const TArrayView<const TVector<RealType>> Vertices);
89
102 {
103 return Solve(NumPoints, GetPointFunc, [](int32 Idx) {return true;});
104 }
105
115 template<typename VectorType>
116 bool Solve(TArrayView<const VectorType> Points, TFunctionRef<bool(int32)> FilterFunc)
117 {
118 return Solve(Points.Num(), [&Points](int32 Idx)
119 {
120 return Points[Idx];
121 }, FilterFunc);
122 }
123
124 // default FilterFunc version of the above Solve(); workaround for clang bug https://bugs.llvm.org/show_bug.cgi?id=25333
133 template<typename VectorType>
135 {
136 return Solve(Points.Num(), [&Points](int32 Idx)
137 {
138 return Points[Idx];
139 }, [](int32 Idx) {return true;});
140 }
141
144 {
145 return Dimension == 3;
146 }
147
152 {
153 for (FIndex3i Triangle : Hull)
154 {
156 }
157 }
158
161 {
162 return Hull;
163 }
164
171
181 RealType FaceAngleToleranceInDegrees = (RealType)1.0, RealType PlaneDistanceTolerance = (RealType)1.0) const;
182
183 // Polygon face array type: A nested array with inline allocator per face, optimizing for the case where most faces have less than 8 vertices
195 RealType FaceAngleToleranceInDegrees = (RealType)1.0, RealType PlaneDistanceTolerance = (RealType)1.0, TArray<TVector<RealType>>* OutPolygonNormals = nullptr) const;
196
202 {
204 return HullNeighbors;
205 }
206
209 {
210 return MoveTemp(Hull);
211 }
212
221 template<typename VectorType>
223 {
225 for (FIndex3i Tri : Hull)
226 {
227 THalfspace3<RealType> TriHalfspace(Points[Tri.A], Points[Tri.B], Points[Tri.C]);
229 }
230 return Halfspaces;
231 }
232
241 template<typename VectorType>
252
257 void Empty()
258 {
259 Dimension = 0;
260 NumHullPoints = 0;
261 Hull.Empty();
262 }
263
267 inline int GetDimension() const
268 {
269 return Dimension;
270 }
272 inline TLine3<RealType> const& GetLine() const
273 {
274 return Line;
275 }
277 inline TPlane3<RealType> const& GetPlane() const
278 {
279 return Plane;
280 }
281
284 {
285 return NumHullPoints;
286 }
287
288
291
292 // Useful helper for walking the border of a convex region, or of a QHull horizon. Will also work for extracting a group boundary for any closed triangle mesh.
293 // Note: Assumes TriangleNeighbors are listed such that the first neighbor is the tri across from the (Tri.A, Tri.B) edge
295
296protected:
297
301
304 // We can optionally also return the hull triangle adjacencies
306
307};
308
313
314
315} // end namespace UE::Geometry
316} // end namespace UE
317
#define ensure( InExpression)
Definition AssertionMacros.h:464
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
void Init()
Definition LockFreeList.h:4
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition ProgressCancel.h:187
Definition ArrayView.h:139
UE_FORCEINLINE_HINT constexpr SizeType Num() const
Definition ArrayView.h:380
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition MathUtil.h:150
Definition ConvexHull3.h:77
TArray< FIndex3i > const & GetTriangles() const
Definition ConvexHull3.h:160
TArray< FIndex3i > HullNeighbors
Definition ConvexHull3.h:305
TLine3< RealType > const & GetLine() const
Definition ConvexHull3.h:272
FProgressCancel * Progress
Definition ConvexHull3.h:290
GEOMETRYCORE_API void GetFaces(TFunctionRef< void(TArray< int32 > &, TVector< RealType >)> PolygonFunc, TFunctionRef< TVector< RealType >(int32)> GetPointFunc) const
Definition ConvexHull3.cpp:870
GEOMETRYCORE_API bool Solve(int32 NumPoints, TFunctionRef< TVector< RealType >(int32)> GetPointFunc, TFunctionRef< bool(int32)> FilterFunc)
Definition ConvexHull3.cpp:788
int GetDimension() const
Definition ConvexHull3.h:267
bool IsSolutionAvailable() const
Definition ConvexHull3.h:143
TArray< FIndex3i > && MoveTriangles()
Definition ConvexHull3.h:208
GEOMETRYCORE_API void GetSimplifiedFaces(TFunctionRef< void(TArray< int32 > &, TVector< RealType >)> PolygonFunc, TFunctionRef< TVector< RealType >(int32)> GetPointFunc, RealType FaceAngleToleranceInDegrees=(RealType) 1.0, RealType PlaneDistanceTolerance=(RealType) 1.0) const
Definition ConvexHull3.cpp:977
TPlane3< RealType > Plane
Definition ConvexHull3.h:300
static void WalkBorder(const TArray< FIndex3i > &Triangles, const TArray< FIndex3i > &TriangleNeighbors, TFunctionRef< bool(int32)> InGroupFunc, int32 StartIdx, TArray< int32 > &OutBorderVertexIndices)
Definition ConvexHull3.cpp:1463
bool bSaveTriangleNeighbors
Definition ConvexHull3.h:82
void GetTriangles(TFunctionRef< void(FIndex3i)> TriangleFunc)
Definition ConvexHull3.h:151
bool Solve(TArrayView< const VectorType > Points, TFunctionRef< bool(int32)> FilterFunc)
Definition ConvexHull3.h:116
void Empty()
Definition ConvexHull3.h:257
TArray< FIndex3i > Hull
Definition ConvexHull3.h:303
int NumHullPoints
Definition ConvexHull3.h:302
static GEOMETRYCORE_API double ComputeVolume(const TArrayView< const TVector< RealType > > Vertices)
Definition ConvexHull3.cpp:762
TArray< FIndex3i > const & GetTriangleNeighbors() const
Definition ConvexHull3.h:201
TConvexHullSimplificationSettings< RealType > SimplificationSettings
Definition ConvexHull3.h:85
bool Solve(int32 NumPoints, TFunctionRef< TVector< RealType >(int32)> GetPointFunc)
Definition ConvexHull3.h:101
int32 Dimension
Definition ConvexHull3.h:298
TLine3< RealType > Line
Definition ConvexHull3.h:299
TArray< THalfspace3< RealType > > GetAsHalfspaces(TArrayView< const VectorType > Points) const
Definition ConvexHull3.h:222
int GetNumHullPoints() const
Definition ConvexHull3.h:283
TArray< THalfspace3< RealType > > GetAsHalfspaces(TFunctionRef< VectorType(int32)> GetPointFunc) const
Definition ConvexHull3.h:242
bool Solve(TArrayView< const VectorType > Points)
Definition ConvexHull3.h:134
TPlane3< RealType > const & GetPlane() const
Definition ConvexHull3.h:277
TConvexHull3< double > FConvexHull3d
Definition ConvexHull3.h:312
TConvexHull3< float > FConvexHull3f
Definition ConvexHull3.h:311
TExtremePoints3< double > FExtremePoints3d
Definition ConvexHull3.h:310
TExtremePoints3< float > FExtremePoints3f
Definition ConvexHull3.h:309
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition IndexTypes.h:158
int32 MaxHullVertices
If positive, hulls generated will only have at most this many points.
Definition ConvexHull3.h:63
RealType DegenerateEdgeTolerance
Definition ConvexHull3.h:60
RealType SkipAtHullDistanceAsFraction
Definition ConvexHull3.h:69
RealType SkipAtHullDistanceAbsolute
If positive, skip adding points that are closer than this threshold to the in-progress hull.
Definition ConvexHull3.h:66
Definition ConvexHull3.h:38
TVector< RealType > Origin
Definition ConvexHull3.h:43
int Dimension
Definition ConvexHull3.h:39
TVector< RealType > Basis[3]
Definition ConvexHull3.h:44
int Extreme[4]
Definition ConvexHull3.h:40
TExtremePoints3(int32 NumPoints, TFunctionRef< TVector< RealType >(int32)> GetPointFunc, TFunctionRef< bool(int32)> FilterFunc=[](int32 Idx) {return true;}, RealType Epsilon=TMathUtil< RealType >::Epsilon)
Definition ConvexHull3.h:46
Definition HalfspaceTypes.h:22
Definition LineTypes.h:148
Definition PlaneTypes.h:21
Definition Vector.h:51