Skip to content

Commit

Permalink
utility fn
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed May 10, 2018
1 parent bff0f42 commit f23639c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mesh_selection/MeshConnectedComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,32 @@ public static DMesh3 LargestT(DMesh3 meshIn)
return submesh.SubMesh;
}




/// <summary>
/// Utility function that finds set of triangles connected to tSeed. Does not use MeshConnectedComponents class.
/// </summary>
public static HashSet<int> FindConnectedT(DMesh3 mesh, int tSeed)
{
HashSet<int> found = new HashSet<int>();
found.Add(tSeed);
List<int> queue = new List<int>(64) { tSeed };
while ( queue.Count > 0 ) {
int tid = queue[queue.Count - 1];
queue.RemoveAt(queue.Count - 1);
Index3i nbr_t = mesh.GetTriNeighbourTris(tid);
for ( int j = 0; j < 3; ++j ) {
int nbrid = nbr_t[j];
if (nbrid == DMesh3.InvalidID || found.Contains(nbrid))
continue;
found.Add(nbrid);
queue.Add(nbrid);
}
}
return found;
}


}
}
32 changes: 32 additions & 0 deletions mesh_selection/MeshVertexSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,38 @@ public void SelectInteriorVertices(MeshFaceSelection triangles)



/// <summary>
/// Select set of boundary vertices connected to vSeed.
/// </summary>
public void SelectConnectedBoundaryV(int vSeed)
{
if ( ! Mesh.IsBoundaryVertex(vSeed))
throw new Exception("MeshConnectedComponents.FindConnectedBoundaryV: vSeed is not a boundary vertex");

HashSet<int> found = (Selected.Count == 0) ? Selected : new HashSet<int>();
found.Add(vSeed);
List<int> queue = temp; queue.Clear();
queue.Add(vSeed);
while (queue.Count > 0) {
int vid = queue[queue.Count - 1];
queue.RemoveAt(queue.Count - 1);
foreach (int nbrid in Mesh.VtxVerticesItr(vid)) {
if (Mesh.IsBoundaryVertex(nbrid) && found.Contains(nbrid) == false) {
found.Add(nbrid);
queue.Add(nbrid);
}
}
}
if ( found != Selected ) {
foreach (int vid in found)
add(vid);
}
temp.Clear();
}




public void SelectEdgeVertices(int[] edges)
{
for (int i = 0; i < edges.Length; ++i) {
Expand Down

0 comments on commit f23639c

Please sign in to comment.