Make mesh.TransferNodes() private and instead pass input points to Mesh ctor.
This commit is contained in:
+23
-54
@@ -80,85 +80,52 @@ namespace TriangleNet
|
||||
/// <summary>
|
||||
/// Gets the mesh bounding box.
|
||||
/// </summary>
|
||||
public Rectangle Bounds
|
||||
{
|
||||
get { return this.bounds; }
|
||||
}
|
||||
public Rectangle Bounds => bounds;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mesh vertices.
|
||||
/// </summary>
|
||||
public ICollection<Vertex> Vertices
|
||||
{
|
||||
get { return this.vertices.Values; }
|
||||
}
|
||||
public ICollection<Vertex> Vertices => vertices.Values;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mesh holes.
|
||||
/// </summary>
|
||||
public IList<Point> Holes
|
||||
{
|
||||
get { return this.holes; }
|
||||
}
|
||||
public IList<Point> Holes => holes;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mesh triangles.
|
||||
/// </summary>
|
||||
public ICollection<Triangle> Triangles
|
||||
{
|
||||
get { return this.triangles; }
|
||||
}
|
||||
public ICollection<Triangle> Triangles => triangles;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mesh segments.
|
||||
/// </summary>
|
||||
public ICollection<SubSegment> Segments
|
||||
{
|
||||
get { return this.subsegs.Values; }
|
||||
}
|
||||
public ICollection<SubSegment> Segments => subsegs.Values;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mesh edges.
|
||||
/// </summary>
|
||||
public IEnumerable<Edge> Edges
|
||||
{
|
||||
get
|
||||
{
|
||||
return new EdgeIterator().EnumerateEdges(this);
|
||||
}
|
||||
}
|
||||
public IEnumerable<Edge> Edges => new EdgeIterator().EnumerateEdges(this);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of input vertices.
|
||||
/// </summary>
|
||||
public int NumberOfInputPoints
|
||||
{
|
||||
get { return invertices; }
|
||||
}
|
||||
public int NumberOfInputPoints => invertices;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of mesh edges.
|
||||
/// </summary>
|
||||
public int NumberOfEdges
|
||||
{
|
||||
get { return (3 * triangles.Count + hullsize) / 2; }
|
||||
}
|
||||
public int NumberOfEdges => (3 * triangles.Count + hullsize) / 2;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the input is a PSLG or a point set.
|
||||
/// </summary>
|
||||
public bool IsPolygon
|
||||
{
|
||||
get { return this.insegments > 0; }
|
||||
}
|
||||
public bool IsPolygon => insegments > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current node numbering.
|
||||
/// </summary>
|
||||
public NodeNumbering CurrentNumbering
|
||||
{
|
||||
get { return numbering; }
|
||||
}
|
||||
public NodeNumbering CurrentNumbering => numbering;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -227,13 +194,13 @@ namespace TriangleNet
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Mesh" /> class.
|
||||
/// </summary>
|
||||
public Mesh(Configuration config)
|
||||
public Mesh(Configuration config, IList<Vertex> points)
|
||||
{
|
||||
Initialize();
|
||||
|
||||
behavior = new Behavior();
|
||||
|
||||
vertices = new Dictionary<int, Vertex>();
|
||||
vertices = new Dictionary<int, Vertex>(points.Count);
|
||||
subsegs = new Dictionary<int, SubSegment>();
|
||||
|
||||
triangles = config.TrianglePool();
|
||||
@@ -245,9 +212,11 @@ namespace TriangleNet
|
||||
|
||||
steinerleft = -1;
|
||||
|
||||
this.predicates = config.Predicates();
|
||||
predicates = config.Predicates();
|
||||
|
||||
this.locator = new TriangleLocator(this, predicates);
|
||||
locator = new TriangleLocator(this, predicates);
|
||||
|
||||
TransferNodes(points);
|
||||
}
|
||||
|
||||
public void Refine(QualityOptions quality, bool delaunay = false)
|
||||
@@ -401,13 +370,13 @@ namespace TriangleNet
|
||||
/// Read the vertices from memory.
|
||||
/// </summary>
|
||||
/// <param name="data">The input data.</param>
|
||||
internal void TransferNodes(IList<Vertex> points)
|
||||
private void TransferNodes(IList<Vertex> points)
|
||||
{
|
||||
this.invertices = points.Count;
|
||||
this.mesh_dim = 2;
|
||||
this.bounds = new Rectangle();
|
||||
invertices = points.Count;
|
||||
mesh_dim = 2;
|
||||
bounds = new Rectangle();
|
||||
|
||||
if (this.invertices < 3)
|
||||
if (invertices < 3)
|
||||
{
|
||||
logger.Error("Input must have at least three input vertices.", "Mesh.TransferNodes()");
|
||||
throw new Exception("Input must have at least three input vertices.");
|
||||
@@ -439,8 +408,8 @@ namespace TriangleNet
|
||||
p.hash = p.id = hash_vtx++;
|
||||
}
|
||||
|
||||
this.vertices.Add(p.hash, p);
|
||||
this.bounds.Expand(p);
|
||||
vertices.Add(p.hash, p);
|
||||
bounds.Expand(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,16 +66,15 @@ namespace TriangleNet.Meshing.Algorithm
|
||||
/// </remarks>
|
||||
public IMesh Triangulate(IList<Vertex> points, Configuration config)
|
||||
{
|
||||
this.predicates = config.Predicates();
|
||||
predicates = config.Predicates();
|
||||
|
||||
this.mesh = new Mesh(config);
|
||||
this.mesh.TransferNodes(points);
|
||||
mesh = new Mesh(config, points);
|
||||
|
||||
Otri hullleft = default(Otri), hullright = default(Otri);
|
||||
int i, j, n = points.Count;
|
||||
|
||||
// Allocate an array of pointers to vertices for sorting.
|
||||
this.sortarray = new Vertex[n];
|
||||
sortarray = new Vertex[n];
|
||||
i = 0;
|
||||
foreach (var v in points)
|
||||
{
|
||||
@@ -94,7 +93,7 @@ namespace TriangleNet.Meshing.Algorithm
|
||||
if (Log.Verbose)
|
||||
{
|
||||
Log.Instance.Warning(
|
||||
String.Format("A duplicate vertex appeared and was ignored (ID {0}).", sortarray[j].id),
|
||||
string.Format("A duplicate vertex appeared and was ignored (ID {0}).", sortarray[j].id),
|
||||
"Dwyer.Triangulate()");
|
||||
}
|
||||
sortarray[j].type = VertexType.UndeadVertex;
|
||||
@@ -116,9 +115,9 @@ namespace TriangleNet.Meshing.Algorithm
|
||||
// Form the Delaunay triangulation.
|
||||
DivconqRecurse(0, i - 1, 0, ref hullleft, ref hullright);
|
||||
|
||||
this.mesh.hullsize = RemoveGhosts(ref hullleft);
|
||||
mesh.hullsize = RemoveGhosts(ref hullleft);
|
||||
|
||||
return this.mesh;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,8 +25,7 @@ namespace TriangleNet.Meshing.Algorithm
|
||||
/// triangulation.</returns>
|
||||
public IMesh Triangulate(IList<Vertex> points, Configuration config)
|
||||
{
|
||||
this.mesh = new Mesh(config);
|
||||
this.mesh.TransferNodes(points);
|
||||
mesh = new Mesh(config, points);
|
||||
|
||||
Otri starttri = new Otri();
|
||||
|
||||
@@ -50,9 +49,9 @@ namespace TriangleNet.Meshing.Algorithm
|
||||
}
|
||||
|
||||
// Remove the bounding box.
|
||||
this.mesh.hullsize = RemoveBox();
|
||||
mesh.hullsize = RemoveBox();
|
||||
|
||||
return this.mesh;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -35,10 +35,9 @@ namespace TriangleNet.Meshing.Algorithm
|
||||
|
||||
public IMesh Triangulate(IList<Vertex> points, Configuration config)
|
||||
{
|
||||
this.predicates = config.Predicates();
|
||||
predicates = config.Predicates();
|
||||
|
||||
this.mesh = new Mesh(config);
|
||||
this.mesh.TransferNodes(points);
|
||||
mesh = new Mesh(config, points);
|
||||
|
||||
// Nonexistent x value used as a flag to mark circle events in sweepline
|
||||
// Delaunay algorithm.
|
||||
|
||||
@@ -35,19 +35,15 @@ namespace TriangleNet.Meshing
|
||||
/// <summary>
|
||||
/// Reconstruct a triangulation from its raw data representation.
|
||||
/// </summary>
|
||||
public static Mesh ToMesh(Polygon polygon, ITriangle[] triangles)
|
||||
public static Mesh ToMesh(Polygon polygon, ITriangle[] triangles, Configuration config = null)
|
||||
{
|
||||
Otri tri = default(Otri);
|
||||
Osub subseg = default(Osub);
|
||||
int i = 0;
|
||||
|
||||
int elements = triangles == null ? 0 : triangles.Length;
|
||||
int segments = polygon.Segments.Count;
|
||||
|
||||
// TODO: Configuration should be a function argument.
|
||||
var mesh = new Mesh(new Configuration());
|
||||
|
||||
mesh.TransferNodes(polygon.Points);
|
||||
var mesh = new Mesh(config ?? new Configuration(), polygon.Points);
|
||||
|
||||
mesh.regions.AddRange(polygon.Regions);
|
||||
mesh.behavior.useRegions = polygon.Regions.Count > 0;
|
||||
@@ -59,7 +55,7 @@ namespace TriangleNet.Meshing
|
||||
}
|
||||
|
||||
// Create the triangles.
|
||||
for (i = 0; i < elements; i++)
|
||||
for (int i = 0; i < elements; i++)
|
||||
{
|
||||
mesh.MakeTriangle(ref tri);
|
||||
}
|
||||
@@ -69,7 +65,7 @@ namespace TriangleNet.Meshing
|
||||
mesh.insegments = segments;
|
||||
|
||||
// Create the subsegments.
|
||||
for (i = 0; i < segments; i++)
|
||||
for (int i = 0; i < segments; i++)
|
||||
{
|
||||
mesh.MakeSegment(ref subseg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user