UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshVertexSelection.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3sharp FMeshVertexSelection
4
5#pragma once
6
8
9namespace UE
10{
11namespace Geometry
12{
13
14
15class FMeshFaceSelection;
16class FMeshEdgeSelection;
17
19{
20private:
21 const FDynamicMesh3* Mesh;
22
23 TSet<int> Selected;
24
25public:
27 {
28 Mesh = mesh;
29 }
30
31 // convert face selection to vertex selection.
33
34 // convert edge selection to vertex selection.
36
37
39 {
40 return Selected;
41 }
43 {
44 return Selected.Array();
45 }
47 {
48 TBitArray<FDefaultBitArrayAllocator> Bitmap(false, Mesh->MaxVertexID());
49 for (int tid : Selected)
50 {
51 Bitmap[tid] = true;
52 }
53 return Bitmap;
54 }
55
56
57
58public:
63 TSet<int>::TRangedForIterator begin() { return Selected.begin(); }
64 TSet<int>::TRangedForConstIterator begin() const { return Selected.begin(); }
65 TSet<int>::TRangedForIterator end() { return Selected.end(); }
66 TSet<int>::TRangedForConstIterator end() const { return Selected.end(); }
67
68private:
69 void add(int vID)
70 {
71 Selected.Add(vID);
72 }
73 void remove(int vID)
74 {
75 Selected.Remove(vID);
76 }
77
78public:
79 int Num() const
80 {
81 return Selected.Num();
82 }
83
84 bool IsSelected(int vID) const
85 {
86 return Selected.Contains(vID);
87 }
88
89 void Select(int vID)
90 {
91 ensure(Mesh->IsVertex(vID));
92 if (Mesh->IsVertex(vID))
93 {
94 add(vID);
95 }
96 }
98 {
99 for (int VID : Vertices)
100 {
101 if (Mesh->IsVertex(VID))
102 {
103 add(VID);
104 }
105 }
106 }
107
111 template<typename PredicateFuncType>
113 {
114 int32 NumV = Mesh->MaxVertexID();
115 for (int32 vid = 0; vid < NumV; ++vid)
116 {
117 if (Mesh->IsVertex(vid) && PredicateFunc(vid) == bSelectTrue)
118 {
119 add(vid);
120 }
121 }
122 }
123
127 template<typename PredicateFuncType>
129 {
130 int32 NumV = Mesh->MaxVertexID();
131 for (int32 vid = 0; vid < NumV; ++vid)
132 {
133 if (Mesh->IsVertex(vid) && PredicateFunc(Mesh->GetVertex(vid)) == bSelectTrue)
134 {
135 add(vid);
136 }
137 }
138 }
139
140
142 {
143 for (int TID : Triangles)
144 {
145 FIndex3i tri = Mesh->GetTriangle(TID);
146 add(tri.A); add(tri.B); add(tri.C);
147 }
148 }
150
151
157
158
163 {
164 if (!ensureMsgf(Mesh->IsBoundaryVertex(vSeed), TEXT("MeshConnectedComponents.FindConnectedBoundaryV: vSeed is not a boundary vertex")))
165 {
166 return;
167 }
168
169 TSet<int> &found = Selected;
170 found.Add(vSeed);
171 TArray<int> queue;
172 queue.Add(vSeed);
173 while (queue.Num() > 0)
174 {
175 int vid = queue.Pop(EAllowShrinking::No);
176 for (int nbrid : Mesh->VtxVerticesItr(vid))
177 {
178 if (Mesh->IsBoundaryVertex(nbrid) && found.Contains(nbrid) == false)
179 {
180 found.Add(nbrid);
181 queue.Add(nbrid);
182 }
183 }
184 }
185 }
186
187
189 {
190 for (int EID : Edges)
191 {
192 FIndex2i ev = Mesh->GetEdgeV(EID);
193 add(ev.A); add(ev.B);
194 }
195 }
196
197
198 void Deselect(int vID)
199 {
200 remove(vID);
201 }
203 {
204 for (int VID : Vertices)
205 {
206 remove(VID);
207 }
208 }
210 {
211 FIndex2i ev = Mesh->GetEdgeV(eid);
212 remove(ev.A); remove(ev.B);
213 }
214
216 {
217 for (int EID : Edges)
218 {
219 FIndex2i ev = Mesh->GetEdgeV(EID);
220 remove(ev.A); remove(ev.B);
221 }
222 }
223
224
232 void ExpandToOneRingNeighbours(const TUniqueFunction<bool(int)>& FilterF = nullptr)
233 {
235
236 for (int vid : Selected)
237 {
238 for (int nbr_vid : Mesh->VtxVerticesItr(vid))
239 {
240 if (FilterF && FilterF(nbr_vid) == false)
241 {
242 continue;
243 }
244 if (IsSelected(nbr_vid) == false)
245 {
247 }
248 }
249 }
250
251 for (int ID : temp)
252 {
253 add(ID);
254 }
255 }
256
257
258 // [TODO] should do this more efficiently, like FMeshFaceSelection
259 void ExpandToOneRingNeighbours(int nRings, const TUniqueFunction<bool(int)>& FilterF = nullptr)
260 {
261 for (int k = 0; k < nRings; ++k)
262 {
264 }
265 }
266
267
273 {
274 // find set of boundary vertices
276 for (int32 k = 0; k < nRings; ++k)
277 {
279
280 for (int vid : Selected)
281 {
282 bool bAnyNeighbourDeselected = false;
283 for (int nbr_vid : Mesh->VtxVerticesItr(vid))
284 {
285 if (IsSelected(nbr_vid) == false)
286 {
288 break;
289 }
290 }
292 {
293 BorderVertices.Add(vid);
294 }
295 }
297 }
298 }
299
300
301
305 void FloodFill(int vSeed, const TUniqueFunction<bool(int)>& VertIncludedF = nullptr)
306 {
307 TArray<int> Seeds = { vSeed };
309 }
313 void FloodFill(const TArray<int>& Seeds, const TUniqueFunction<bool(int)>& VertIncludedF = nullptr)
314 {
316 for (int Seed : Seeds)
317 {
318 add(Seed);
319 }
320 while (stack.Num() > 0)
321 {
322 int vID = stack.Back();
323 stack.PopBack();
324
325 for (int nbr_vid : Mesh->VtxVerticesItr(vID))
326 {
327 if (IsSelected(nbr_vid) == true || (VertIncludedF && VertIncludedF(nbr_vid) == false))
328 {
329 continue;
330 }
331 add(nbr_vid);
332 stack.Add(nbr_vid);
333 }
334 }
335 }
336
337
338};
339
340
341} // end namespace UE::Geometry
342} // end namespace UE
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define ensure( InExpression)
Definition AssertionMacros.h:464
#define TEXT(x)
Definition Platform.h:1272
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
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
ElementType Pop(EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:1196
Definition BitArray.h:350
Definition FunctionFwd.h:19
Definition DynamicMesh3.h:108
Definition MeshEdgeSelection.h:22
Definition MeshFaceSelection.h:21
Definition MeshVertexSelection.h:19
void DeselectEdge(int eid)
Definition MeshVertexSelection.h:209
void ExpandToOneRingNeighbours(int nRings, const TUniqueFunction< bool(int)> &FilterF=nullptr)
Definition MeshVertexSelection.h:259
void Select(TArrayView< const int > Vertices)
Definition MeshVertexSelection.h:97
int Num() const
Definition MeshVertexSelection.h:79
void DeselectEdges(TArrayView< const int > Edges)
Definition MeshVertexSelection.h:215
void Deselect(int vID)
Definition MeshVertexSelection.h:198
void Deselect(TArrayView< const int > Vertices)
Definition MeshVertexSelection.h:202
TSet< int >::TRangedForConstIterator begin() const
Definition MeshVertexSelection.h:64
GEOMETRYCORE_API void SelectInteriorVertices(const FMeshFaceSelection &triangles)
Definition MeshVertexSelection.cpp:38
bool IsSelected(int vID) const
Definition MeshVertexSelection.h:84
void SelectByPosition(PredicateFuncType PredicateFunc, bool bSelectTrue=true)
Definition MeshVertexSelection.h:128
void FloodFill(int vSeed, const TUniqueFunction< bool(int)> &VertIncludedF=nullptr)
Definition MeshVertexSelection.h:305
void SelectConnectedBoundaryV(int vSeed)
Definition MeshVertexSelection.h:162
TArray< int > AsArray() const
Definition MeshVertexSelection.h:42
TBitArray< FDefaultBitArrayAllocator > AsBitArray() const
Definition MeshVertexSelection.h:46
void FloodFill(const TArray< int > &Seeds, const TUniqueFunction< bool(int)> &VertIncludedF=nullptr)
Definition MeshVertexSelection.h:313
void SelectEdgeVertices(TArrayView< const int > Edges)
Definition MeshVertexSelection.h:188
TSet< int >::TRangedForIterator end()
Definition MeshVertexSelection.h:65
TSet< int >::TRangedForIterator begin()
Definition MeshVertexSelection.h:63
void ContractByBorderVertices(int32 nRings=1)
Definition MeshVertexSelection.h:272
FMeshVertexSelection(const FDynamicMesh3 *mesh)
Definition MeshVertexSelection.h:26
TSet< int >::TRangedForConstIterator end() const
Definition MeshVertexSelection.h:66
void SelectTriangleVertices(TArrayView< const int > Triangles)
Definition MeshVertexSelection.h:141
void Select(int vID)
Definition MeshVertexSelection.h:89
void ExpandToOneRingNeighbours(const TUniqueFunction< bool(int)> &FilterF=nullptr)
Definition MeshVertexSelection.h:232
void SelectByVertexID(PredicateFuncType PredicateFunc, bool bSelectTrue=true)
Definition MeshVertexSelection.h:112
TSet< int > AsSet() const
Definition MeshVertexSelection.h:38
Definition DynamicVector.h:27
void Add(const Type &Data)
Definition DynamicVector.h:662
const Type & Back() const
Definition DynamicVector.h:167
void PopBack()
Definition DynamicVector.h:717
size_t Num() const
Definition DynamicVector.h:147
Definition AdvancedWidgetsModule.cpp:13
Definition IndexTypes.h:27
Definition IndexTypes.h:158