Skip to content

Commit

Permalink
util fn to erode open spurs from 3D graph
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Jun 1, 2018
1 parent b40112f commit c5817d4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
53 changes: 53 additions & 0 deletions curve/DGraph3Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,58 @@ public static List<int> WalkToNextNonRegularVtx(DGraph3 graph, int fromVtx, int





/// <summary>
/// Erode inwards from open boundary vertices of graph (ie vtx with single edge).
/// Resulting graph is not compact (!)
/// </summary>
public static void ErodeOpenSpurs(DGraph3 graph)
{
HashSet<int> used = new HashSet<int>(); // do we need this?

// find boundary and junction vertices
HashSet<int> boundaries = new HashSet<int>();
HashSet<int> junctions = new HashSet<int>();
foreach (int vid in graph.VertexIndices()) {
if (graph.IsBoundaryVertex(vid))
boundaries.Add(vid);
if (graph.IsJunctionVertex(vid))
junctions.Add(vid);
}

// walk paths from boundary vertices
foreach (int start_vid in boundaries) {
if (graph.IsVertex(start_vid) == false)
continue;

int vid = start_vid;
int eid = graph.GetVtxEdges(vid)[0];
if (used.Contains(eid))
continue;

List<int> pathE = new List<int>();
if (pathE != null)
pathE.Add(eid);
while (true) {
used.Add(eid);
Index2i next = NextEdgeAndVtx(eid, vid, graph);
eid = next.a;
vid = next.b;
if (boundaries.Contains(vid) || junctions.Contains(vid))
break; // done!
if (pathE != null)
pathE.Add(eid);
}

// delete this path
foreach (int path_eid in pathE)
graph.RemoveEdge(path_eid, true);
}

}



}
}
3 changes: 2 additions & 1 deletion geometry3Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,7 +32,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down

0 comments on commit c5817d4

Please sign in to comment.