From 40625d3c389834f79c2ae6122d410adf61a259a0 Mon Sep 17 00:00:00 2001 From: "SND\\wo80_cp" Date: Mon, 24 Aug 2015 09:28:12 +0000 Subject: [PATCH] Do not overwrite input vertex ids git-svn-id: https://triangle.svn.codeplex.com/svn@77158 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5 --- Triangle.NET/Triangle/Mesh.cs | 28 +++++++++++++------ .../Triangle/Meshing/Algorithm/Dwyer.cs | 2 +- .../Triangle/Meshing/Algorithm/Incremental.cs | 2 +- .../Triangle/Meshing/Algorithm/SweepLine.cs | 2 +- .../Triangle/Meshing/GenericMesher.cs | 2 +- .../Triangle/Meshing/ITriangulator.cs | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Triangle.NET/Triangle/Mesh.cs b/Triangle.NET/Triangle/Mesh.cs index 9b3b21f..17f4dad 100644 --- a/Triangle.NET/Triangle/Mesh.cs +++ b/Triangle.NET/Triangle/Mesh.cs @@ -586,7 +586,7 @@ namespace TriangleNet /// Read the vertices from memory. /// /// The input data. - internal void TransferNodes(ICollection points) + internal void TransferNodes(IList points) { this.invertices = points.Count; this.mesh_dim = 2; @@ -598,17 +598,29 @@ namespace TriangleNet throw new Exception("Input must have at least three input vertices."); } - bool first = true; + var v = points[0]; - foreach (Vertex p in points) + // Check attributes. + this.nextras = v.attributes == null ? 0 : v.attributes.Length; + + // Simple heuristic to check if ids are already set. We assume that if the + // first two vertex ids are distinct, then all input vertices have pairwise + // distinct ids. + bool userId = (v.ID != points[1].ID); + + foreach (var p in points) { - if (first) + if (userId) { - this.nextras = p.attributes == null ? 0 : p.attributes.Length; - first = false; - } + p.hash = p.id; - p.hash = p.id = this.hash_vtx++; + // Make sure the hash counter gets updated. + hash_vtx = Math.Max(p.hash, hash_vtx); + } + else + { + p.hash = p.id = hash_vtx++; + } this.vertices.Add(p.hash, p); this.bounds.Expand(p); diff --git a/Triangle.NET/Triangle/Meshing/Algorithm/Dwyer.cs b/Triangle.NET/Triangle/Meshing/Algorithm/Dwyer.cs index 91905ea..35cb035 100644 --- a/Triangle.NET/Triangle/Meshing/Algorithm/Dwyer.cs +++ b/Triangle.NET/Triangle/Meshing/Algorithm/Dwyer.cs @@ -60,7 +60,7 @@ namespace TriangleNet.Meshing.Algorithm /// Sorts the vertices, calls a recursive procedure to triangulate them, and /// removes the bounding box, setting boundary markers as appropriate. /// - public IMesh Triangulate(ICollection points) + public IMesh Triangulate(IList points) { this.mesh = new Mesh(); this.mesh.TransferNodes(points); diff --git a/Triangle.NET/Triangle/Meshing/Algorithm/Incremental.cs b/Triangle.NET/Triangle/Meshing/Algorithm/Incremental.cs index 7fd40f9..abf73ab 100644 --- a/Triangle.NET/Triangle/Meshing/Algorithm/Incremental.cs +++ b/Triangle.NET/Triangle/Meshing/Algorithm/Incremental.cs @@ -23,7 +23,7 @@ namespace TriangleNet.Meshing.Algorithm /// /// Returns the number of edges on the convex hull of the /// triangulation. - public IMesh Triangulate(ICollection points) + public IMesh Triangulate(IList points) { this.mesh = new Mesh(); this.mesh.TransferNodes(points); diff --git a/Triangle.NET/Triangle/Meshing/Algorithm/SweepLine.cs b/Triangle.NET/Triangle/Meshing/Algorithm/SweepLine.cs index 97175fc..b53fd19 100644 --- a/Triangle.NET/Triangle/Meshing/Algorithm/SweepLine.cs +++ b/Triangle.NET/Triangle/Meshing/Algorithm/SweepLine.cs @@ -31,7 +31,7 @@ namespace TriangleNet.Meshing.Algorithm double xminextreme; // Nonexistent x value used as a flag in sweepline. List splaynodes; - public IMesh Triangulate(ICollection points) + public IMesh Triangulate(IList points) { this.mesh = new Mesh(); this.mesh.TransferNodes(points); diff --git a/Triangle.NET/Triangle/Meshing/GenericMesher.cs b/Triangle.NET/Triangle/Meshing/GenericMesher.cs index 12a8fa6..d0eca4d 100644 --- a/Triangle.NET/Triangle/Meshing/GenericMesher.cs +++ b/Triangle.NET/Triangle/Meshing/GenericMesher.cs @@ -25,7 +25,7 @@ namespace TriangleNet.Meshing } /// - public IMesh Triangulate(ICollection points) + public IMesh Triangulate(IList points) { return triangulator.Triangulate(points); } diff --git a/Triangle.NET/Triangle/Meshing/ITriangulator.cs b/Triangle.NET/Triangle/Meshing/ITriangulator.cs index ea631c8..a8139bd 100644 --- a/Triangle.NET/Triangle/Meshing/ITriangulator.cs +++ b/Triangle.NET/Triangle/Meshing/ITriangulator.cs @@ -19,6 +19,6 @@ namespace TriangleNet.Meshing /// /// Collection of points. /// Mesh - IMesh Triangulate(ICollection points); + IMesh Triangulate(IList points); } }