Skip to content

Commit c5817d4

Browse files
committed
util fn to erode open spurs from 3D graph
1 parent b40112f commit c5817d4

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

curve/DGraph3Util.cs

+53
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,58 @@ public static List<int> WalkToNextNonRegularVtx(DGraph3 graph, int fromVtx, int
284284

285285

286286

287+
288+
289+
/// <summary>
290+
/// Erode inwards from open boundary vertices of graph (ie vtx with single edge).
291+
/// Resulting graph is not compact (!)
292+
/// </summary>
293+
public static void ErodeOpenSpurs(DGraph3 graph)
294+
{
295+
HashSet<int> used = new HashSet<int>(); // do we need this?
296+
297+
// find boundary and junction vertices
298+
HashSet<int> boundaries = new HashSet<int>();
299+
HashSet<int> junctions = new HashSet<int>();
300+
foreach (int vid in graph.VertexIndices()) {
301+
if (graph.IsBoundaryVertex(vid))
302+
boundaries.Add(vid);
303+
if (graph.IsJunctionVertex(vid))
304+
junctions.Add(vid);
305+
}
306+
307+
// walk paths from boundary vertices
308+
foreach (int start_vid in boundaries) {
309+
if (graph.IsVertex(start_vid) == false)
310+
continue;
311+
312+
int vid = start_vid;
313+
int eid = graph.GetVtxEdges(vid)[0];
314+
if (used.Contains(eid))
315+
continue;
316+
317+
List<int> pathE = new List<int>();
318+
if (pathE != null)
319+
pathE.Add(eid);
320+
while (true) {
321+
used.Add(eid);
322+
Index2i next = NextEdgeAndVtx(eid, vid, graph);
323+
eid = next.a;
324+
vid = next.b;
325+
if (boundaries.Contains(vid) || junctions.Contains(vid))
326+
break; // done!
327+
if (pathE != null)
328+
pathE.Add(eid);
329+
}
330+
331+
// delete this path
332+
foreach (int path_eid in pathE)
333+
graph.RemoveEdge(path_eid, true);
334+
}
335+
336+
}
337+
338+
339+
287340
}
288341
}

geometry3Sharp.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
2424
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
25+
<PlatformTarget>AnyCPU</PlatformTarget>
2526
</PropertyGroup>
2627
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2728
<DebugType>pdbonly</DebugType>
@@ -31,7 +32,7 @@
3132
<ErrorReport>prompt</ErrorReport>
3233
<WarningLevel>4</WarningLevel>
3334
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
34-
<PlatformTarget>x64</PlatformTarget>
35+
<PlatformTarget>AnyCPU</PlatformTarget>
3536
</PropertyGroup>
3637
<ItemGroup>
3738
<Reference Include="System" />

0 commit comments

Comments
 (0)