Mesh converter: use singleton pattern instead of static methods.

This commit is contained in:
wo80
2022-02-28 00:27:51 +01:00
parent b3bfac11d1
commit 227e9d9c66
4 changed files with 21 additions and 11 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ namespace MeshExplorer.IO.Formats
} }
} }
return Converter.ToMesh(geometry, triangles); return Converter.Instance.ToMesh(geometry, triangles);
} }
public void Write(IMesh mesh, string filename) public void Write(IMesh mesh, string filename)
+1 -1
View File
@@ -42,7 +42,7 @@ namespace TriangleNet.IO
if (geometry != null && triangles != null) if (geometry != null && triangles != null)
{ {
return Converter.ToMesh(geometry, triangles.ToArray()); return Converter.Instance.ToMesh(geometry, triangles.ToArray());
} }
} }
+18 -8
View File
@@ -20,14 +20,25 @@ namespace TriangleNet.Meshing
/// <summary> /// <summary>
/// The Converter class provides methods for mesh reconstruction and conversion. /// The Converter class provides methods for mesh reconstruction and conversion.
/// </summary> /// </summary>
public static class Converter public class Converter
{ {
private static readonly Lazy<Converter> lazy = new Lazy<Converter>(() => new Converter());
/// <summary>
/// Gets the <see cref="Converter"/> instance.
/// </summary>
public static Converter Instance { get { return lazy.Value; } }
private Converter()
{
}
#region Triangle mesh conversion #region Triangle mesh conversion
/// <summary> /// <summary>
/// Reconstruct a triangulation from its raw data representation. /// Reconstruct a triangulation from its raw data representation.
/// </summary> /// </summary>
public static Mesh ToMesh(Polygon polygon, ICollection<ITriangle> triangles) public Mesh ToMesh(Polygon polygon, ICollection<ITriangle> triangles)
{ {
return ToMesh(polygon, triangles.ToArray()); return ToMesh(polygon, triangles.ToArray());
} }
@@ -35,7 +46,7 @@ namespace TriangleNet.Meshing
/// <summary> /// <summary>
/// Reconstruct a triangulation from its raw data representation. /// Reconstruct a triangulation from its raw data representation.
/// </summary> /// </summary>
public static Mesh ToMesh(Polygon polygon, ITriangle[] triangles, Configuration config = null) public Mesh ToMesh(Polygon polygon, ITriangle[] triangles, Configuration config = null)
{ {
Otri tri = default(Otri); Otri tri = default(Otri);
Osub subseg = default(Osub); Osub subseg = default(Osub);
@@ -82,7 +93,7 @@ namespace TriangleNet.Meshing
/// Finds the adjacencies between triangles by forming a stack of triangles for /// Finds the adjacencies between triangles by forming a stack of triangles for
/// each vertex. Each triangle is on three different stacks simultaneously. /// each vertex. Each triangle is on three different stacks simultaneously.
/// </summary> /// </summary>
private static List<Otri>[] SetNeighbors(Mesh mesh, ITriangle[] triangles) private List<Otri>[] SetNeighbors(Mesh mesh, ITriangle[] triangles)
{ {
Otri tri = default(Otri); Otri tri = default(Otri);
Otri triangleleft = default(Otri); Otri triangleleft = default(Otri);
@@ -199,7 +210,7 @@ namespace TriangleNet.Meshing
/// <summary> /// <summary>
/// Finds the adjacencies between triangles and subsegments. /// Finds the adjacencies between triangles and subsegments.
/// </summary> /// </summary>
private static void SetSegments(Mesh mesh, Polygon polygon, List<Otri>[] vertexarray) private void SetSegments(Mesh mesh, Polygon polygon, List<Otri>[] vertexarray)
{ {
Otri checktri = default(Otri); Otri checktri = default(Otri);
Otri nexttri; // Triangle Otri nexttri; // Triangle
@@ -224,7 +235,6 @@ namespace TriangleNet.Meshing
if (mesh.behavior.Poly) if (mesh.behavior.Poly)
{ {
// Link the segments to their neighboring triangles. // Link the segments to their neighboring triangles.
boundmarker = 0;
i = 0; i = 0;
foreach (var item in mesh.subsegs.Values) foreach (var item in mesh.subsegs.Values)
{ {
@@ -341,7 +351,7 @@ namespace TriangleNet.Meshing
#region DCEL conversion #region DCEL conversion
public static DcelMesh ToDCEL(Mesh mesh) public DcelMesh ToDCEL(Mesh mesh)
{ {
var dcel = new DcelMesh(); var dcel = new DcelMesh();
@@ -379,7 +389,7 @@ namespace TriangleNet.Meshing
} }
Otri tri = default(Otri), neighbor = default(Otri); Otri tri = default(Otri), neighbor = default(Otri);
TriangleNet.Geometry.Vertex org, dest; TVertex org, dest;
int id, nid, count = mesh.triangles.Count; int id, nid, count = mesh.triangles.Count;
+1 -1
View File
@@ -227,7 +227,7 @@ namespace TriangleNet.Meshing
} }
} }
return Converter.ToMesh(polygon, triangles); return Converter.Instance.ToMesh(polygon, triangles);
} }
} }
} }