public ECEdge(ECVertex v1, ECVertex v2) { this.v1 = v1; v1.LinkEdge(this); AdjFace = new List <ECFace>(2); twin = new ECEdge(this, v2); }
public static VertexType ClassifyVertex(ECVertex v) { int count = 0; for (int i = 0; i < v.AdjEdges.Count; i++) { if (ECEdge.ClassifyEdge(v.AdjEdges[i]) == EdgeType.BORDER) { count++; } } if (count == v.AdjEdges.Count) { return(VertexType.BORDER_ONLY); } else if (count == 0) { return(VertexType.INTERIOR); } else if (count > 0) { return(VertexType.BORDER); } return(VertexType.BORDER_ONLY); }
public void CaculateFrom3Verts(ECVertex v0, ECVertex v1, ECVertex v2) { A = 0; B = 0; C = 0; D = 0; }
public int AddVertex(Point3d p) { ECVertex v = CreateVertex(p.X, p.Y, p.Z); Bounds.UpdataRange(p.X, p.Y, p.Z); return(Vertices.Count - 1); }
public Mesh GetMesh() { Mesh m = new Mesh(); int[] map = new int[Vertices.Count]; for (int i = 0; i < Vertices.Count; i++) { map[i] = -1; } for (int i = 0; i < Vertices.Count; i++) { ECVertex v = Vertices[i]; if (v.IsValid()) { map[i] = m.AddVertex(new Point3d(v.X, v.Y, v.Z)); } } for (int i = 0; i < Faces.Count; i++) { ECFace f = Faces[i]; if (f.IsValid()) { Triangle t = new Triangle(map[f.GetVertex(0).UId], map[f.GetVertex(1).UId], map[f.GetVertex(2).UId]); m.AddFace(t); } } return(m); }
private ECEdge(ECEdge twin, ECVertex org) { this.v1 = org; this.v1.LinkEdge(this); this.AdjFace = twin.AdjFace; this.twin = twin; }
public void ContractRegion(ECVertex v1, ECVertex v2, List <ECFace> tempList) { tempList.Clear(); ECFace.UnTagFaceLoop(v1); ECFace.UnTagFaceLoop(v2); ECFace.CollectFaceLoop(v1, tempList); ECFace.CollectFaceLoop(v2, tempList); }
public void Contract(ECVertex v1, ECVertex v2, Point3d to) { temp.Clear(); ContractRegion(v1, v2, temp); RelocateVertex(v1, to.X, to.Y, to.Z); v2.ReplaceBy(v1); RemoveDegenerateFaces(temp); }
public void KillVertex(ECVertex v) { if (v.IsValid()) { v.Kill(); ValidVerticesCount--; } }
public ECVertex CreateVertex(float x, float y, float z) { ECVertex v = new ECVertex(x, y, z); Vertices.Add(v); v.UId = Vertices.Count - 1; ValidVerticesCount++; return(v); }
public ECEdge CreateEdge(ECVertex v1, ECVertex v2) { ECEdge e = new ECEdge(v1, v2); Edges.Add(e); e.UId = Edges.Count - 1; e.Twin().UId = e.UId; ValidEdgesCount++; return(e); }
public static void UnTagFaceLoop(ECVertex v) { for (int j = 0; j < v.AdjEdges.Count; j++) { List <ECFace> faces = v.AdjEdges[j].AdjFace; for (int k = 0; k < faces.Count; k++) { faces[k].UnTag(); } } }
public void ReplaceBy(ECVertex v) { if (v != this) { for (int i = 0; i < AdjEdges.Count; i++) { AdjEdges[i].ReplacePoint(this, v); } Kill(); } }
public ECFace CreateFace(ECVertex v1, ECVertex v2, ECVertex v3) { ECEdge e0 = this.GetEdge(v1, v2); ECEdge e1 = this.GetEdge(v2, v3); ECEdge e2 = this.GetEdge(v3, v1); ECFace f = new ECFace(e0, e1, e2); Faces.Add(f); f.UId = Faces.Count - 1; ValidFacesCount++; return(f); }
public void InitTypes() { for (int i = 0; i < Vertices.Count; i++) { VertexType type = ECVertex.ClassifyVertex(Vertices[i]); Vertices[i].Type = type; } for (int i = 0; i < Edges.Count; i++) { EdgeType type = ECEdge.ClassifyEdge(Edges[i]); Edges[i].Type = type; } }
public ECEdge GetEdge(ECVertex org, ECVertex v) { List <ECEdge> eu = org.AdjEdges; for (int i = 0; i < eu.Count; i++) { if (eu[i].DestV() == v) { return(eu[i]); } } ECEdge e = CreateEdge(org, v); return(e); }
public static void CollectFaceLoop(ECVertex v, List <ECFace> loop) { for (int j = 0; j < v.AdjEdges.Count; j++) { List <ECFace> faces = v.AdjEdges[j].AdjFace; for (int k = 0; k < faces.Count; k++) { if (!faces[k].GetTag()) { loop.Add(faces[k]); faces[k].Tag(); } } } }
static void Main(string[] args) { Mesh m = Sample.GetSampleMesh2(100); PlyManager.Output(m, "D://VTKproj//sample.ply"); ECMesh ecm = ECMesh.GetECMesh(m); List <EdgeAndWeight> edgeWeights = new List <EdgeAndWeight>(ecm.Edges.Count); Random r = new Random(); for (int i = 0; i < ecm.Edges.Count; i++) { EdgeAndWeight ew = new EdgeAndWeight(); ew.edgeID = i; ew.weight = r.Next(0, 10000); edgeWeights.Add(ew); } edgeWeights.Sort(); int deciCount = ecm.Edges.Count / 10; int index = 0; while (deciCount != 0) { if (index == edgeWeights.Count) { break; } EdgeAndWeight ew = edgeWeights[index]; ECEdge edge = ecm.Edges[ew.edgeID]; if (edge.IsValid() && edge.OrgV().Type == VertexType.INTERIOR && edge.DestV().Type == VertexType.INTERIOR) { ECVertex v0 = edge.OrgV(); ECVertex v1 = edge.DestV(); Point3d mid = new Point3d(v0.X / 2 + v1.X / 2, v0.Y / 2 + v1.Y / 2, v0.Z / 2 + v1.Z / 2); ecm.Contract(v0, v1, mid); deciCount--; index++; } else { index++; continue; } } m = ecm.GetMesh(); PlyManager.Output(m, "test2.ply"); Console.WriteLine("\nCMP!"); Console.Read(); }
public void ReplacePoint(ECVertex from, ECVertex to) { if (OrgV() == from) { v1 = to; to.LinkEdge(this); } else if (DestV() == from) { twin.v1 = to; to.LinkEdge(twin); } else { throw new Exception(); } for (int i = 0; i < AdjFace.Count; i++) { AdjFace[i].MarkPlaneInvalid(); } }
public void MayFixFace(ECFace face) { ECVertex v0 = face.GetVertex(0); ECVertex v1 = face.GetVertex(1); ECVertex v2 = face.GetVertex(2); ECEdge e0 = face.GetEdge(0); ECEdge e1 = face.GetEdge(1); ECEdge e2 = face.GetEdge(2); bool a = (v0 == v1); bool b = (v0 == v2); bool c = (v1 == v2); if (a && c) { KillEdge(e0); KillEdge(e1); KillEdge(e2); KillFace(face); } else if (a) { KillEdge(e0); e1.ReplaceBy(e2.Twin()); KillFace(face); } else if (b) { KillEdge(e2); e0.ReplaceBy(e1.Twin()); KillFace(face); } else if (c) { KillEdge(e1); e0.ReplaceBy(e2.Twin()); KillFace(face); } }
public void RelocateVertex(ECVertex v, float x, float y, float z) { v.X = x; v.Y = y; v.Z = z; }
public Plane(ECVertex v0, ECVertex v1, ECVertex v2) { A = 0; B = 0; C = 0; D = 0; isValid = true; CaculateFrom3Verts(v0, v1, v2); }
public void ReplaceVertex(ECVertex from, ECVertex to) { from.ReplaceBy(to); }