Force ID in given points

Aug 22, 2015 at 5:11 PM
I'm trying to use Triangle.NET lib to mesh a planar area starting from points that already have an ID.
Is it possible to force the IDs of the given vertices used to build a Polygon?
It will be very important for what I'm doing; actually I have to renumber the vertices and the triangles created, because their numbering starts from 0 and, as said, I cannot set the ID for the original vertices of the Polygon.

Aug 23, 2015 at 11:26 PM
At the moment, vertex ids get overwritten in the Mesh.TransferNodes method. I opened a workitem here. A fix should be available soon.
Aug 24, 2015 at 9:31 AM
Please download the latest source code and let me know if this solves the issue.
Aug 24, 2015 at 6:35 PM
Edited Aug 25, 2015 at 4:42 PM
Thanks for your help. I tried the new code but I get a 'System.Collections.Generic.KeyNotFoundException' at line 225 of "Triangle\Meshing\ConstraintMesher.cs" when I call "Triangulate".
The line is:
endpoint1 = mesh.vertices[end1];

and end1 = 0. This is just because mesh.vertices is a dictionary where keys are the vertex.IDs, while seg.P0 is compiled in Polygon.AddCountour with a simple for (int i = 0; i < count; i++) cycle.

Anyway, I see that the mesh skip the ID = 0, it is very useful, I'll wait for your updade of code (I tried to change it by myself, but I don't know how to write the correct input.segments).

Aug 26, 2015 at 11:28 AM
Edited Aug 26, 2015 at 11:28 AM
I've updated the code. Seems to work now:
public static void TestFixedIds()
    var poly = new Polygon(5);

    var c = new Vertex[5]
        new Vertex(0.3, 0.0) { ID = 5 },
        new Vertex(1.1, 0.2) { ID = 6 },
        new Vertex(1.0, 1.1) { ID = 2 },
        new Vertex(0.3, 0.9) { ID = 3 },
        new Vertex(0.0, 0.1) { ID = 9 }

    poly.AddContour(c, 1);

    var ok = PolygonValidator.IsConsistent(poly);


    var options = new ConstraintOptions() { ConformingDelaunay = true };
    var quality = new QualityOptions() { MinimumAngle = 20.0 };

    var mesh = (Mesh)poly.Triangulate(options, quality);

    var delaunay = MeshValidator.IsDelaunay(mesh);
    var consistent = MeshValidator.IsConsistent(mesh);

    Console.WriteLine("{0} {1}", delaunay, consistent);
Aug 26, 2015 at 5:10 PM
Thanks, now I can triangulate and refine the mesh keeping the vertices IDs.

Can the Renumber function be used focing the ID = 0 to be excluded too?

Aug 27, 2015 at 12:02 PM
Edited Aug 27, 2015 at 12:03 PM
You mean linear numbering from 1 to N? You could use an extension method:
public static void Renumber(this Mesh mesh, int offset)
    foreach (var node in mesh.Vertices)
        node.ID = offset++;
Aug 27, 2015 at 1:32 PM
No, I mean using a renumbering method, like:
I was asking if it is possible to start the renumbering from 1 (for both nodes and triangles) instead that from 0.
Aug 27, 2015 at 2:56 PM
Well, no. But you can call the built-in routines and then increment all ids.