public PolygonMesh TriMeshToDualB() { TriMeshModify.RepaireAllHole(mesh); PolygonMesh dualMesh = new PolygonMesh(); ComputeGeometryB(dualMesh); MakeTheTopologyB(dualMesh); return dualMesh; }
public static PolygonMesh BuildDual(TriMesh mesh, EnumDual type) { TriMeshModify.RepaireAllHole(mesh); PolygonMesh.Vertex[] faceMap = new HalfEdgeMesh.Vertex[mesh.Faces.Count]; PolygonMesh.Vertex[] edgeMap = new HalfEdgeMesh.Vertex[mesh.Edges.Count]; PolygonMesh pm = new PolygonMesh(); foreach (var face in mesh.Faces) { Vector3D center = Vector3D.Zero; switch (type) { case EnumDual.DualA: center = TriMeshUtil.GetMidPoint(face); break; case EnumDual.DualB: TriMesh.Vertex vertex0 = face.GetVertex(0); TriMesh.Vertex vertex1 = face.GetVertex(1); TriMesh.Vertex vertex2 = face.GetVertex(2); Triangle triangle = new Triangle(vertex0.Traits.Position, vertex1.Traits.Position, vertex2.Traits.Position); center = triangle.ComputeCircumCenter(); break; default: break; } PolygonMesh.Vertex v = new HalfEdgeMesh.Vertex(new VertexTraits(center)); faceMap[face.Index] = v; pm.AppendToVertexList(v); } foreach (var edge in mesh.Edges) { VertexTraits trait = new VertexTraits(TriMeshUtil.GetMidPoint(edge)); PolygonMesh.Vertex v = new HalfEdgeMesh.Vertex(trait); edgeMap[edge.Index] = v; pm.AppendToVertexList(v); } foreach (var v in mesh.Vertices) { List<PolygonMesh.Vertex> list = new List<HalfEdgeMesh.Vertex>(); foreach (var hf in v.HalfEdges) { list.Add(faceMap[hf.Face.Index]); list.Add(edgeMap[hf.Edge.Index]); } list.Reverse(); pm.Faces.Add(list.ToArray()); } return pm; }
public void ComputeGeometryB(PolygonMesh dualMesh) { TriMesh.Vertex[] edgeVertices = new TriMesh.Vertex[mesh.Faces.Count * 3]; foreach (TriMesh.Edge e in mesh.Edges) { Vector3D midVertex0 = TriMeshUtil.GetMidPoint(e); dualMesh.Vertices.Add(new VertexTraits(midVertex0.x, midVertex0.y, midVertex0.z)); } foreach (TriMesh.Face f in mesh.Faces) { Vector3D baryCenter = TriMeshUtil.GetMidPoint(f); dualMesh.Vertices.Add(new VertexTraits(baryCenter.x, baryCenter.y, baryCenter.z)); } }
public void DrawDualMeshLine(PolygonMesh mesh) { GL.ShadeModel(ShadingModel.Smooth); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); OpenGLManager.Instance.SetColor(GlobalSetting.DisplaySetting.DualColor); for (int i = 0; i < mesh.Faces.Count; i++) { GL.Begin(BeginMode.LineLoop); foreach (TriMesh.Vertex v in mesh.Faces[i].Vertices) { GL.Vertex3(v.Traits.Position.x, v.Traits.Position.y, v.Traits.Position.z); } GL.End(); } GL.Flush(); }
public static PolygonMesh AddOneTriangle() { PolygonMesh mesh = new PolygonMesh(); return mesh; }
public static PolygonMesh AddOneTriangle() { PolygonMesh mesh = new PolygonMesh(); return(mesh); }
public void MakeTheTopologyB(PolygonMesh dualMesh) { List<TriMesh.Vertex> boundaryVertices = new List<TriMesh.Vertex>(); boundaryVertices = TriMeshUtil.RetrieveAllBoundaryVertex(mesh); foreach (TriMesh.Face face in mesh.Faces) { int index = face.Index; int baryVertexIndex = mesh.Edges.Count; int edgeVertexIndex; int faceIndex = index; TriMesh.Edge boundaryEdge = new TriMesh.Edge(); TriMesh.HalfEdge tempHalfedge = new TriMesh.HalfEdge(); TriMesh.Vertex vertex0 = mesh.Faces[index].GetVertex(0); TriMesh.Vertex vertex1 = mesh.Faces[index].GetVertex(1); TriMesh.Vertex vertex2 = mesh.Faces[index].GetVertex(2); TriMesh.HalfEdge halfedge0 = vertex0.FindHalfedgeTo(vertex1); TriMesh.HalfEdge halfedge1 = vertex1.FindHalfedgeTo(vertex2); TriMesh.HalfEdge halfedge2 = vertex2.FindHalfedgeTo(vertex0); TriMesh.HalfEdge boundaryHalfedge = new TriMesh.HalfEdge(); tempHalfedge = halfedge0; edgeVertexIndex = halfedge0.Edge.Index; TriMesh.Vertex firstVertex = dualMesh.Vertices[baryVertexIndex + faceIndex]; TriMesh.Vertex secondVertex = dualMesh.Vertices[edgeVertexIndex]; if (firstVertex.FindHalfedgeTo(secondVertex) == null) { List<TriMesh.Vertex> ringVertices = new List<TriMesh.Vertex>(); do { ringVertices.Add(dualMesh.Vertices[baryVertexIndex + faceIndex]); ringVertices.Add(dualMesh.Vertices[edgeVertexIndex]); if (tempHalfedge.Opposite.Next.Face != null) { tempHalfedge = tempHalfedge.Opposite.Next; faceIndex = tempHalfedge.Face.Index; edgeVertexIndex = tempHalfedge.Edge.Index; } else { tempHalfedge = tempHalfedge.Opposite.Next; edgeVertexIndex = tempHalfedge.Edge.Index; faceIndex = tempHalfedge.Opposite.Next.Face.Index; } } while (tempHalfedge != halfedge0); TriMesh.Vertex[] newFaceVertices = new TriMesh.Vertex[ringVertices.Count]; for (int i = 0; i < ringVertices.Count; i++) { newFaceVertices[i] = ringVertices[i]; } dualMesh.Faces.Add(newFaceVertices); } tempHalfedge = halfedge1; edgeVertexIndex = halfedge1.Edge.Index; firstVertex = dualMesh.Vertices[baryVertexIndex + faceIndex]; secondVertex = dualMesh.Vertices[edgeVertexIndex]; if (firstVertex.FindHalfedgeTo(secondVertex) == null) { List<TriMesh.Vertex> ringVertices = new List<TriMesh.Vertex>(); do { ringVertices.Add(dualMesh.Vertices[baryVertexIndex + faceIndex]); ringVertices.Add(dualMesh.Vertices[edgeVertexIndex]); if (tempHalfedge.Opposite.Next != null) { tempHalfedge = tempHalfedge.Opposite.Next; faceIndex = tempHalfedge.Face.Index; edgeVertexIndex = tempHalfedge.Edge.Index; } else { continue; } } while (tempHalfedge != halfedge1); TriMesh.Vertex[] newFaceVertices = new TriMesh.Vertex[ringVertices.Count]; for (int i = 0; i < ringVertices.Count; i++) { newFaceVertices[i] = ringVertices[i]; } dualMesh.Faces.Add(newFaceVertices); } tempHalfedge = halfedge2; edgeVertexIndex = halfedge2.Edge.Index; firstVertex = dualMesh.Vertices[baryVertexIndex + faceIndex]; secondVertex = dualMesh.Vertices[edgeVertexIndex]; if (firstVertex.FindHalfedgeTo(secondVertex) == null) { List<TriMesh.Vertex> ringVertices = new List<TriMesh.Vertex>(); do { ringVertices.Add(dualMesh.Vertices[baryVertexIndex + faceIndex]); ringVertices.Add(dualMesh.Vertices[edgeVertexIndex]); if (tempHalfedge.Opposite.Next != null) { tempHalfedge = tempHalfedge.Opposite.Next; faceIndex = tempHalfedge.Face.Index; edgeVertexIndex = tempHalfedge.Edge.Index; } else { continue; } } while (tempHalfedge != halfedge2); TriMesh.Vertex[] newFaceVertices = new TriMesh.Vertex[ringVertices.Count]; for (int i = 0; i < ringVertices.Count; i++) { newFaceVertices[i] = ringVertices[i]; } dualMesh.Faces.Add(newFaceVertices); } } }
public void ComputeGeometryC(PolygonMesh dualMesh) { //get the mid-Vertex of each edges TriMesh.Vertex[] edgeVertices = new TriMesh.Vertex[mesh.Faces.Count * 3]; foreach (TriMesh.Edge e in mesh.Edges) { Vector3D midVertex0 = TriMeshUtil.GetMidPoint(e); dualMesh.Vertices.Add(new VertexTraits(midVertex0.x, midVertex0.y, midVertex0.z)); } //get circumcentre of each faces foreach (TriMesh.Face f in mesh.Faces) { TriMesh.Vertex vertex0 = f.GetVertex(0); TriMesh.Vertex vertex1 = f.GetVertex(1); TriMesh.Vertex vertex2 = f.GetVertex(2); Triangle triangle = new Triangle(vertex0.Traits.Position, vertex1.Traits.Position, vertex2.Traits.Position); Vector3D circumCenter = triangle.ComputeCircumCenter(); dualMesh.Vertices.Add(new VertexTraits(circumCenter.x, circumCenter.y, circumCenter.z)); } }