UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshEdgeSelection.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3sharp MeshEdgeSelection
4
5#pragma once
6
8#include "CoreMinimal.h"
9#include "Containers/Set.h"
11
12namespace UE
13{
14namespace Geometry
15{
16
17
22{
23private:
24 const FDynamicMesh3* Mesh;
25
26 TSet<int> Selected;
27
28public:
29
31 {
32 Mesh = mesh;
33 }
34
35
36 // convert vertex selection to edge selection. Require at least minCount verts of edge to be selected
38
39 // convert face selection to edge selection. Require at least minCount tris of edge to be selected
41
42
43
45 {
46 return Selected;
47 }
49 {
50 return Selected.Array();
51 }
53 {
54 TBitArray<FDefaultBitArrayAllocator> Bitmap(false, Mesh->MaxEdgeID());
55 for (int tid : Selected)
56 {
57 Bitmap[tid] = true;
58 }
59 return Bitmap;
60 }
61
62public:
67 TSet<int>::TRangedForIterator begin() { return Selected.begin(); }
68 TSet<int>::TRangedForConstIterator begin() const { return Selected.begin(); }
69 TSet<int>::TRangedForIterator end() { return Selected.end(); }
70 TSet<int>::TRangedForConstIterator end() const { return Selected.end(); }
71
72private:
73 void add(int eid)
74 {
75 Selected.Add(eid);
76 }
77 void remove(int eid)
78 {
79 Selected.Remove(eid);
80 }
81
82
83public:
84 int Num()
85 {
86 return Selected.Num();
87 }
88
89
90
91 bool IsSelected(int eid)
92 {
93 return Selected.Contains(eid);
94 }
95
96
97 void Select(int eid)
98 {
99 ensure(Mesh->IsEdge(eid));
100 if (Mesh->IsEdge(eid))
101 {
102 add(eid);
103 }
104 }
105
106 void Select(const TArray<int>& edges)
107 {
108 for (int eid : edges)
109 {
110 if (Mesh->IsEdge(eid))
111 {
112 add(eid);
113 }
114 }
115 }
117 {
118 for (int eid : edges)
119 {
120 if (Mesh->IsEdge(eid))
121 {
122 add(eid);
123 }
124 }
125 }
126 void Select(TFunctionRef<bool(int)> SelectF)
127 {
128 int NT = Mesh->MaxEdgeID();
129 for (int eid = 0; eid < NT; ++eid)
130 {
131 if (Mesh->IsEdge(eid) && SelectF(eid))
132 {
133 add(eid);
134 }
135 }
136 }
137
139 {
140 for (int vid : vertices) {
141 for (int eid : Mesh->VtxEdgesItr(vid))
142 {
143 add(eid);
144 }
145 }
146 }
147
149 {
150 for (int tid : Triangles)
151 {
152 FIndex3i et = Mesh->GetTriEdges(tid);
153 add(et.A); add(et.B); add(et.C);
154 }
155 }
156
157private:
158 template<bool bHasFilter, typename ExpandContainerType>
159 void ExpandToOneRingNeighbors_FindNeighborsHelper(const ExpandContainerType& ToExpand, TArray<int32>& ToAdd, TFunctionRef<bool(int)> FilterF)
160 {
161 for (int EID : ToExpand)
162 {
163 FIndex2i EdgeV = Mesh->GetEdgeV(EID);
164 for (int32 SubIdx = 0; SubIdx < 2; ++SubIdx)
165 {
166 for (int32 NbrEID : Mesh->VtxEdgesItr(EdgeV[SubIdx]))
167 {
168 if constexpr (bHasFilter)
169 {
170 if (!FilterF(NbrEID))
171 {
172 continue;
173 }
174 }
175 if (!IsSelected(NbrEID))
176 {
177 ToAdd.Add(NbrEID);
178 }
179 }
180 }
181 }
182 }
183
184 template<bool bHasFilter>
185 void ExpandToOneRingNeighbors_Helper(int32 NumRings, TFunctionRef<bool(int)> FilterF)
186 {
187 if (NumRings <= 0)
188 {
189 return;
190 }
191
192 // ToAdd can have the same edge multiple times, so to avoid accumulating duplicates
193 // this will clean up the extra copies as it add to the selection
195 {
196 for (int32 Idx = 0; Idx < ToAdd.Num(); ++Idx)
197 {
198 bool bAlreadyInSet;
199 Selected.Add(ToAdd[Idx], &bAlreadyInSet);
200 if (bAlreadyInSet)
201 {
202 ToAdd.RemoveAtSwap(Idx, EAllowShrinking::No);
203 --Idx;
204 }
205 }
206 };
207
210 if (NumRings == 1)
211 {
212 // In the one ring case, no need to clean duplicates from ToAdd since we'll never use it again
213 // (note: could also do this on the final iteration for the NumRings > 1 case ...)
214 for (int32 ID : ToAdd)
215 {
216 add(ID);
217 }
218 return;
219 }
220 else
221 {
224 for (int32 Iter = 1; Iter < NumRings; ++Iter)
225 {
227 ToAdd.Reset();
230 }
231 }
232 }
233
234public:
235
247
249 {
250 ExpandToOneRingNeighbors_Helper<false>(1, [](int32) {return true;});
251 }
252
257
262
263
269 {
270 // find set of boundary edges
272 for (int32 k = 0; k < nRings; ++k)
273 {
275
276 for (int EID : Selected)
277 {
278 FIndex2i EdgeV = Mesh->GetEdgeV(EID);
279 bool bEitherSideBoundary = false;
280 for (int32 SubIdx = 0; SubIdx < 2; ++SubIdx)
281 {
282 bool bIsBoundary = false;
283 for (int32 NbrEID : Mesh->VtxEdgesItr(EdgeV[SubIdx]))
284 {
285 if (NbrEID != EID && !IsSelected(NbrEID))
286 {
287 bIsBoundary = true;
288 }
289 }
290 if (bIsBoundary)
291 {
292 bEitherSideBoundary = true;
293 break;
294 }
295 }
297 {
298 BorderEdges.Add(EID);
299 }
300 }
302 }
303 }
304
305
307
308 void Deselect(int tid) {
309 remove(tid);
310 }
312 for (int tid : edges)
313 {
314 remove(tid);
315 }
316 }
318 {
319 Selected.Empty();
320 }
321
322};
323
324} // end namespace UE::Geometry
325} // end namespace UE
#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
Definition ArrayView.h:139
Definition Array.h:670
void Reset(SizeType NewSize=0)
Definition Array.h:2246
Definition BitArray.h:350
Definition AssetRegistryState.h:50
Definition DynamicMesh3.h:108
Definition MeshEdgeSelection.h:22
FMeshEdgeSelection(const FDynamicMesh3 *mesh)
Definition MeshEdgeSelection.h:30
int Num()
Definition MeshEdgeSelection.h:84
void DeselectAll()
Definition MeshEdgeSelection.h:317
void ExpandToOneRingNeighbors()
Definition MeshEdgeSelection.h:248
void Select(const TArray< int > &edges)
Definition MeshEdgeSelection.h:106
void Select(TFunctionRef< bool(int)> SelectF)
Definition MeshEdgeSelection.h:126
void SelectTriangleEdges(TArrayView< const int > Triangles)
Definition MeshEdgeSelection.h:148
void Select(int eid)
Definition MeshEdgeSelection.h:97
TSet< int > AsSet() const
Definition MeshEdgeSelection.h:44
void Select(TArrayView< const int > edges)
Definition MeshEdgeSelection.h:116
TSet< int >::TRangedForConstIterator end() const
Definition MeshEdgeSelection.h:70
void Deselect(int tid)
Definition MeshEdgeSelection.h:308
TSet< int >::TRangedForConstIterator begin() const
Definition MeshEdgeSelection.h:68
TSet< int >::TRangedForIterator begin()
Definition MeshEdgeSelection.h:67
bool IsSelected(int eid)
Definition MeshEdgeSelection.h:91
void ExpandToOneRingNeighbors(int NumRings)
Definition MeshEdgeSelection.h:258
void ExpandToOneRingNeighbors(TFunctionRef< bool(int32)> FilterF)
Definition MeshEdgeSelection.h:243
TArray< int > AsArray() const
Definition MeshEdgeSelection.h:48
GEOMETRYCORE_API void SelectBoundaryTriEdges(const FMeshFaceSelection &Triangles)
Definition MeshEdgeSelection.cpp:54
void Deselect(TArrayView< const int > edges)
Definition MeshEdgeSelection.h:311
void ContractByBorderEdges(int32 nRings=1)
Definition MeshEdgeSelection.h:268
TBitArray< FDefaultBitArrayAllocator > AsBitArray() const
Definition MeshEdgeSelection.h:52
void SelectVertexEdges(TArrayView< const int > vertices)
Definition MeshEdgeSelection.h:138
TSet< int >::TRangedForIterator end()
Definition MeshEdgeSelection.h:69
void ExpandToOneRingNeighbors(int NumRings, TFunctionRef< bool(int32)> FilterF)
Definition MeshEdgeSelection.h:253
Definition MeshFaceSelection.h:21
Definition MeshVertexSelection.h:19
@ Selected
Definition SkeletalDebugRendering.h:20
Definition AdvancedWidgetsModule.cpp:13
Definition IndexTypes.h:27
Definition IndexTypes.h:158