Problem: Reconstruct a surface from unordered wireframe edges
The SurfaceReconstructor class provides methods to reconstruct a surface consisting of triangles and quads from unordered edges forming a wireframe model.
The off file of this example is taken from the Princeton Shape Benchmark.
Solution using G#
- public static void Reconstruct()
- {
- //-------------------------------------------------------------
- //Settings for best results.
- //-------------------------------------------------------------
- ceometric.VectorGeometry.Global.AbsoluteEpsilon = -1;
- ceometric.VectorGeometry.Global.RelativeEpsilon = -1;
- //-------------------------------------------------------------
- //Generate input edge data. This is done by reading triangles
- //from an .off file and extracting the edges of the triangles
- //into a list. The edge list will be randomly permuted and
- //contain many duplicate edges, which is OK for the algorithm.
- //-------------------------------------------------------------
- string offFile = @"E:\ceometric\ComputationalCAD\OFF\shark.off";
- or.Read(offFile);
- List<Edge> edges = GetEdges(or.Triangles);
- //-------------------------------------------------------------
- //Reconstruct surface. Measure elapsed time.
- //-------------------------------------------------------------
- tg.Start();
- sr.ReconstructSurface(6);
- tg.Stop();
- //-------------------------------------------------------------
- //Some statistics
- //-------------------------------------------------------------
- Console.WriteLine(
- "Triangles read : " + or.Triangles.Count);
- Console.WriteLine(
- "Edges extracted : " + edges.Count);
- Console.WriteLine(
- "Triangles reconstructed: " + or.Triangles.Count +
- " in " + tg.DurationInMilliSeconds.ToString() + "ms");
- //-------------------------------------------------------------
- //Visualize
- //-------------------------------------------------------------
- int failed = 0;
- sc.Add(sr.GetSurfaceAsTriangleList(ref failed), lay);
- sc.WriteDxf(@"e:\sr.dxf");
- Console.ReadLine();
- }
- /// <summary>A helper method to extract the edges from a
- /// list of triangles. Contains many duplicates.</summary>
- /// <param name="trs">A list of triangles.</param>
- /// <returns>Returns a list of randomly permuted edges.</returns>
- public static List<Edge> GetEdges(List<Triangle> trs)
- {
- for (int i = 0; i < trs.Count; i++)
- {
- edges.Add(trs[i].Edge1);
- edges.Add(trs[i].Edge2);
- edges.Add(trs[i].Edge3);
- }
- Edge.RandomPermute(ref edges);
- return edges;
- }

