From f23639cdda4a36da01d45b1f062148790ab18e13 Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Thu, 10 May 2018 15:52:23 -0400 Subject: [PATCH] utility fn --- mesh_selection/MeshConnectedComponents.cs | 27 +++++++++++++++++++ mesh_selection/MeshVertexSelection.cs | 32 +++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/mesh_selection/MeshConnectedComponents.cs b/mesh_selection/MeshConnectedComponents.cs index 3c95befb..2c71559a 100644 --- a/mesh_selection/MeshConnectedComponents.cs +++ b/mesh_selection/MeshConnectedComponents.cs @@ -224,5 +224,32 @@ public static DMesh3 LargestT(DMesh3 meshIn) return submesh.SubMesh; } + + + + /// + /// Utility function that finds set of triangles connected to tSeed. Does not use MeshConnectedComponents class. + /// + public static HashSet FindConnectedT(DMesh3 mesh, int tSeed) + { + HashSet found = new HashSet(); + found.Add(tSeed); + List queue = new List(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; + } + + } } diff --git a/mesh_selection/MeshVertexSelection.cs b/mesh_selection/MeshVertexSelection.cs index 9fb8f0a2..cda76921 100644 --- a/mesh_selection/MeshVertexSelection.cs +++ b/mesh_selection/MeshVertexSelection.cs @@ -149,6 +149,38 @@ public void SelectInteriorVertices(MeshFaceSelection triangles) + /// + /// Select set of boundary vertices connected to vSeed. + /// + public void SelectConnectedBoundaryV(int vSeed) + { + if ( ! Mesh.IsBoundaryVertex(vSeed)) + throw new Exception("MeshConnectedComponents.FindConnectedBoundaryV: vSeed is not a boundary vertex"); + + HashSet found = (Selected.Count == 0) ? Selected : new HashSet(); + found.Add(vSeed); + List 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) {