public MeshVertex AddVertex(MeshVertex v) { int i = vertices.Count; vertices.Add(v); v.SetGraphInfo(this, i); return(v); }
public MeshGraph Clone() { MeshGraph mg = new MeshGraph(); mg.triangles = this.triangles; foreach (MeshVertex v in vertices) { MeshVertex new_v = new MeshVertex(v.Position); new_v.SetGraphInfo(mg, mg.vertices.Count); mg.vertices.Add(new_v); } foreach (MeshEdge e in edges) { MeshEdge new_e = new MeshEdge(mg.Eqv(e.V1), mg.Eqv(e.V2)); new_e.SetGraphInfo(mg, mg.edges.Count); mg.edges.Add(new_e); } foreach (MeshFacet f in facets) { MeshFacet new_f = new MeshFacet(); foreach (MeshVertex v in f.vertices) { new_f.vertices.Add(mg.Eqv(v)); } new_f.SetGraphInfo(mg, mg.facets.Count); mg.facets.Add(new_f); } // Maintain adjacency cache foreach (MeshEdge e in mg.edges) { MeshEdge old_e = this.Eqv(e); e.f1 = mg.Eqv(old_e.f1); e.f2 = mg.Eqv(old_e.f2); } foreach (MeshVertex v in mg.vertices) { MeshVertex old_v = this.Eqv(v); foreach (var entry in old_v.adjacency) { v.adjacency.Add(mg.Eqv(entry.Key), mg.Eqv(entry.Value)); } } return(mg); }