This project is read-only.

Voronoi Polygon export

Jul 8, 2015 at 5:03 AM

How can I output/write/access the Voronoi polygons? This is what i have so far:
Mesh mesh = new Mesh();
var geometry = TriangleNet.IO.FileReader.ReadNodeFile(filename);
mesh.Behavior.MaxAngle = 95;
mesh.Behavior.MinAngle = 35;
mesh.Behavior.ConformingDelaunay = true;
mesh.Behavior.Convex = true;
mesh.Behavior.Quality = true;
mesh.Behavior.Poly = true;
but i am not sure how to use:
TriangleNet.Tools.Voronoi voronoi = new TriangleNet.Tools.Voronoi(mesh);
I also know how to WriteVoronoi to a file with
TriangleNet.IO.FileWriter.WriteVoronoi(mesh,  workdir + "voronoi.out");
However reading this text file back into my program and constructing the actual polygons is a bit tricky. I really like Triangle.NET, I just do not know (how to use it) how to get the Voronoi Polygons. What i am looking for is a string that looks something like that so i can feed it to SQL server.
POLYGON(120.0 30.0, 121.0 30.0,121.0 31.0, 120.0 31.0, 120.0 30.0)
The Voronoi Polygons are based on the behavior which i set for the triangulation, right?

Thanks and keep up the good work
Jul 8, 2015 at 1:28 PM
Edited Jul 8, 2015 at 2:21 PM
I don't think the built-in file format will be helpful. It stores the vertices and the edges, without any information about the topology. The format is
[#nodes] 2 [#attributes] 0
[#] [x] [y] <attributes>

[#edges] 0
1) [#] [i] [j]          // simple edge (i = index of start vertex, j = index of end vertex)
2) [#] [i] -1 [dx] [dy] // infinite edge (i = index of vertex, (dx, dy) direction vector)
I suggest you have a look at the IVoronoi interface and the VoronoiRegion class and take the information you need. For example:
public static void TestVoronoi()
    Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

    var geometry = RandomPoints(10);
    var mesh = CreateMesh(geometry);
    var voronoi = CreateVoronoi(mesh);

    foreach (var region in voronoi.Regions)
        var v = region.Vertices.ToArray();
        int n = v.Length;

        Console.Write("POLYGON({0:0.0} {1:0.0}", v[0].X, v[0].Y);

        for (int i = 1; i < n; i++)
            Console.Write(", {0:0.0} {1:0.0}", v[i].X, v[i].Y);

        if (region.Bounded)
            // Close the polygon.
            Console.WriteLine(", {0:0.0} {1:0.0})", v[0].X, v[0].Y);
            // Unbounded Voronoi cell.
Jul 9, 2015 at 8:12 AM
Thanks for the answer, this looks like it will do what i need. However, I cannot find
I am actually not a coder, but I tried this one: which seems to be wrong, since it gives an error.
TriangleNet.Tools.Voronoi voronoi = new TriangleNet.Tools.Voronoi(mesh);
Jul 13, 2015 at 1:09 PM
CreateMesh creates a mesh for a given geometry, CreateVoronoi creates a voronoi diagram for a given mesh. It's the same code you used in your opening post.

Since I don't know your mesh and you didn't tell me what error you get, I'm afraid I can't give you any advice.