UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DynamicPointSet3.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "BoxTypes.h"
6#include "GeometryTypes.h"
7#include "MathUtil.h"
9#include "Util/IndexUtil.h"
10#include "Util/IteratorUtil.h"
11#include "Util/RefCountVector.h"
12#include "VectorTypes.h"
13#include "VectorUtil.h"
15
17
18namespace UE
19{
20namespace Geometry
21{
22
23using namespace UE::Math;
24
42template<typename RealType>
44{
45protected:
50
51
54
55
56 //
57 // Attribute Set Support. At the level of this class, we do not have a specific attribute set.
58 // Clients can provide a pointer to their attribute set so that functions like AppendVertex()
59 // or DeleteVertex() will work.
60 //
61public:
62
67
72
73
74
75 //
76 // Indices
77 //
78public:
79
81 int VertexCount() const
82 {
83 return (int)VertexRefCounts.GetCount();
84 }
85
87 int MaxVertexID() const
88 {
89 return (int)VertexRefCounts.GetMaxIndex();
90 }
91
92
94 inline bool IsVertex(int VertexID) const
95 {
96 return VertexRefCounts.IsValid(VertexID);
97 }
98
99
100
101 //
102 // Construction
103 //
104public:
105
107 void Clear()
108 {
109 Vertices.Clear();
111 BaseAttributeSet = nullptr;
112 }
113
114
117 {
118 int vid = VertexRefCounts.Allocate();
119 int i = 3 * vid;
120 Vertices.InsertAt(Position[2], i + 2);
121 Vertices.InsertAt(Position[1], i + 1);
123
124 if (GetBaseAttributeSet() != nullptr)
125 {
126 GetBaseAttributeSet()->OnNewVertex(vid, false);
127 }
128
129 return vid;
130 }
131
134 {
135 // do nothing...
136 }
137
143
149 EMeshResult InsertVertex(int VertexID, const TVector<RealType>& Position, bool bUnsafe = false)
150 {
151 if (VertexRefCounts.IsValid(VertexID))
152 {
154 }
155
156 bool bOK = (bUnsafe) ? VertexRefCounts.AllocateAtUnsafe(VertexID) : VertexRefCounts.AllocateAt(VertexID);
157 if (bOK == false)
158 {
160 }
161
162 int i = 3 * VertexID;
163 Vertices.InsertAt(Position[2], i + 2);
164 Vertices.InsertAt(Position[1], i + 1);
166
167 if (GetBaseAttributeSet() != nullptr)
168 {
169 GetBaseAttributeSet()->OnNewVertex(VertexID, true);
170 }
171
172 return EMeshResult::Ok;
173 }
174
175
176
177 //
178 // get/set
179 //
180public:
181
183 inline TVector<RealType> GetVertex(int VertexID) const
184 {
185 check(IsVertex(VertexID));
186 int i = 3 * VertexID;
187 return TVector<RealType>(Vertices[i], Vertices[i + 1], Vertices[i + 2]);
188 }
189
191 inline void SetVertex(int VertexID, const TVector<RealType>& vNewPos)
192 {
193 //check(VectorUtil::IsFinite(vNewPos));
194 check(IsVertex(VertexID));
195 int i = 3 * VertexID;
196 Vertices[i] = vNewPos.X;
197 Vertices[i + 1] = vNewPos.Y;
198 Vertices[i + 2] = vNewPos.Z;
199 }
200
201
202
203 //
204 // iterators
205 //
206public:
212
215 {
216 return VertexRefCounts.MappedIndices<TVector<RealType>>([this](int VertexID) {
217 int i = 3 * VertexID;
218 return TVector<RealType>(Vertices[i], Vertices[i + 1], Vertices[i + 2]);
219 });
220 }
221
222
223
224
226 bool IsCompact() const
227 {
228 return VertexRefCounts.IsDense();
229 }
230
232 RealType CompactMetric() const
233 {
234 return ((RealType)VertexCount() / (RealType)MaxVertexID());
235 }
236
237 //
238 // Geometric queries
239 //
240public:
241
244 {
246 for (int vi : VertexIndicesItr())
247 {
248 int k = 3 * vi;
249 Box.Contain( TVector<RealType>(Vertices[k], Vertices[k + 1], Vertices[k + 2]) );
250 }
251 return Box;
252 }
253
254
255
256 //
257 // direct buffer access (not a good idea to use)
258 //
259public:
261 {
262 return Vertices;
263 }
265 {
266 return VertexRefCounts;
267 }
268
269
270
271 //
272 // Edit operations
273 //
274public:
275
276 // @todo port this from DynamicMesh3
277 //void CompactInPlace(FCompactMaps* CompactInfo = nullptr);
278
283 {
284 if (VertexRefCounts.IsValid(VertexID) == false)
285 {
287 }
288 VertexRefCounts.Decrement(VertexID);
289 check(VertexRefCounts.IsValid(VertexID) == false);
290
291 if (GetBaseAttributeSet() != nullptr)
292 {
293 GetBaseAttributeSet()->OnRemoveVertex(VertexID);
294 }
295
296 return EMeshResult::Ok;
297 }
298
299};
300
301
302
305
306
307} // end namespace UE::Geometry
308} // end namespace UE
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition RefCountVector.h:445
Definition RefCountVector.h:25
MappedEnumerable< ToType > MappedIndices(TFunction< ToType(int)> MapFunc) const
Definition RefCountVector.h:497
bool AllocateAt(int Index)
Definition RefCountVector.h:158
void RebuildFreeList()
Definition RefCountVector.h:306
size_t GetMaxIndex() const
Definition RefCountVector.h:56
size_t GetCount() const
Definition RefCountVector.h:51
bool IsDense() const
Definition RefCountVector.h:61
void Decrement(int Index, unsigned short DecrementCount=1)
Definition RefCountVector.h:139
bool AllocateAtUnsafe(int Index)
Definition RefCountVector.h:200
bool IsValid(int Index) const
Definition RefCountVector.h:66
int Allocate()
Definition RefCountVector.h:102
IndexEnumerable Indices() const
Definition RefCountVector.h:458
Definition DynamicAttribute.h:264
Definition DynamicPointSet3.h:44
bool IsVertex(int VertexID) const
Definition DynamicPointSet3.h:94
FRefCountVector::IndexEnumerable VertexIndicesItr() const
Definition DynamicPointSet3.h:208
void SetExternallyManagedAttributes(TDynamicAttributeSetBase< TDynamicPointSet3< RealType > > *AttributeSet)
Definition DynamicPointSet3.h:63
int MaxVertexID() const
Definition DynamicPointSet3.h:87
void Clear()
Definition DynamicPointSet3.h:107
void SetVertex(int VertexID, const TVector< RealType > &vNewPos)
Definition DynamicPointSet3.h:191
TDynamicAttributeSetBase< TDynamicPointSet3< RealType > > * GetBaseAttributeSet() const
Definition DynamicPointSet3.h:68
TDynamicAttributeSetBase< TDynamicPointSet3< RealType > > * BaseAttributeSet
Definition DynamicPointSet3.h:53
TVector< RealType > GetVertex(int VertexID) const
Definition DynamicPointSet3.h:183
bool IsCompact() const
Definition DynamicPointSet3.h:226
FRefCountVector::MappedEnumerable< TVector< RealType > > VerticesItr() const
Definition DynamicPointSet3.h:214
TAxisAlignedBox3< RealType > GetBounds() const
Definition DynamicPointSet3.h:243
EMeshResult RemoveVertex(int VertexID)
Definition DynamicPointSet3.h:282
int VertexCount() const
Definition DynamicPointSet3.h:81
TDynamicVector< RealType > Vertices
Definition DynamicPointSet3.h:49
FRefCountVector VertexRefCounts
Definition DynamicPointSet3.h:47
EMeshResult InsertVertex(int VertexID, const TVector< RealType > &Position, bool bUnsafe=false)
Definition DynamicPointSet3.h:149
void EndUnsafeVerticesInsert()
Definition DynamicPointSet3.h:139
void BeginUnsafeVerticesInsert()
Definition DynamicPointSet3.h:133
RealType CompactMetric() const
Definition DynamicPointSet3.h:232
int AppendVertex(const TVector< RealType > &Position)
Definition DynamicPointSet3.h:116
const FRefCountVector & GetVerticesRefCounts()
Definition DynamicPointSet3.h:264
const TDynamicVector< double > & GetVerticesBuffer()
Definition DynamicPointSet3.h:260
Definition DynamicVector.h:27
void InsertAt(const Type &Data, unsigned int Index)
Definition DynamicVector.h:747
void Clear()
Definition DynamicVector.h:578
TDynamicPointSet3< float > FDynamicPointSet3f
Definition DynamicPointSet3.h:303
EMeshResult
Definition GeometryTypes.h:18
TDynamicPointSet3< double > FDynamicPointSet3d
Definition DynamicPointSet3.h:304
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition BoxTypes.h:247
static TAxisAlignedBox3< RealType > Empty()
Definition BoxTypes.h:382
Definition Vector.h:51