public static void BoundaryShrink(TriMesh mesh) { List <List <TriMesh.HalfEdge> > holes = TriMeshUtil.RetrieveBoundaryEdgeAll(mesh); foreach (var hole in holes) { foreach (var hf in hole) { TriMeshModify.RemoveVertex(hf.FromVertex); } } }
public static void RepairSimpleHoles(TriMesh mesh) { List <List <TriMesh.HalfEdge> > holes = TriMeshUtil.RetrieveBoundaryEdgeAll(mesh); foreach (List <TriMesh.HalfEdge> hole in holes) { for (int i = 2; i < hole.Count; i++) { mesh.Faces.AddTriangles(hole[0].ToVertex, hole[i - 1].ToVertex, hole[i].ToVertex); } } TriMeshUtil.FixIndex(mesh); }
public SparseMatrix BuildMatrixArea(TriMesh mesh) { List <List <TriMesh.HalfEdge> > bounds = TriMeshUtil.RetrieveBoundaryEdgeAll(mesh); int n = mesh.Vertices.Count; SparseMatrix A = new SparseMatrix(2 * n, 2 * n); foreach (List <TriMesh.HalfEdge> oneBoundary in bounds) { foreach (TriMesh.HalfEdge currentHF in oneBoundary) { int Vi = currentHF.FromVertex.Index; int Vj = currentHF.ToVertex.Index; A[2 * Vi, 2 * Vj + 1] += -0.5; A[2 * Vj + 1, 2 * Vi] += -0.5; A[2 * Vj, 2 * Vi + 1] += 0.5; A[2 * Vi + 1, 2 * Vj] += 0.5; } } return(A); }
public static void BoundaryExpand(TriMesh mesh) { double length = TriMeshUtil.ComputeEdgeAvgLength(mesh); List <List <TriMesh.HalfEdge> > holes = TriMeshUtil.RetrieveBoundaryEdgeAll(mesh); foreach (var hole in holes) { TriMesh.Vertex[] arr = new HalfEdgeMesh.Vertex[hole.Count]; for (int i = 0; i < hole.Count; i++) { Vector3D normal = Vector3D.UnitX; if (hole[i].Opposite.Face != null) { normal = TriMeshUtil.ComputeNormalFace(hole[i].Opposite.Face); } Vector3D toPos = hole[i].ToVertex.Traits.Position; Vector3D fromPos = hole[i].FromVertex.Traits.Position; Vector3D hfDir = toPos - fromPos; Vector3D hfMid = (toPos + fromPos) / 2; Vector3D pos = hfMid + normal.Cross(hfDir).Normalize() * length; arr[i] = mesh.Vertices.Add(new VertexTraits(pos)); } for (int i = 0; i < hole.Count; i++) { int next = (i + 1) % hole.Count; TriMesh.Face face = mesh.Faces.Add(arr[i], hole[i].ToVertex, hole[next].ToVertex); face.Traits.SelectedFlag = 1; face = mesh.Faces.Add(arr[i], hole[next].ToVertex, arr[next]); face.Traits.SelectedFlag = 1; } } }
public static int CountBoundary(TriMesh mesh) { return(TriMeshUtil.RetrieveBoundaryEdgeAll(mesh).Count); }