Improved uniform data structure for Voronoi classes.

git-svn-id: https://triangle.svn.codeplex.com/svn@69976 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
This commit is contained in:
SND\wo80_cp
2012-10-14 22:08:33 +00:00
parent 894c3e6eba
commit 04c45ed41a
9 changed files with 610 additions and 198 deletions
+49 -2
View File
@@ -8,9 +8,7 @@ namespace MeshRenderer.Core
{
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using TriangleNet;
using TriangleNet.Data;
using TriangleNet.Geometry;
using TriangleNet.Tools;
@@ -156,6 +154,55 @@ namespace MeshRenderer.Core
/// </summary>
public void SetVoronoi(IVoronoi voro, int infCount)
{
int i, n = voro.Points.Length;
// Copy points
this.VoronoiPoints = new float[2 * n + infCount];
foreach (var v in voro.Points)
{
if (v == null)
{
continue;
}
i = v.ID;
this.VoronoiPoints[2 * i] = (float)v.X;
this.VoronoiPoints[2 * i + 1] = (float)v.Y;
}
// Copy edges
Point first, last;
var edges = new List<uint>(voro.Regions.Count * 4);
foreach (var region in voro.Regions)
{
first = null;
last = null;
foreach (var pt in region.Vertices)
{
if (first == null)
{
first = pt;
last = pt;
}
else
{
edges.Add((uint)last.ID);
edges.Add((uint)pt.ID);
last = pt;
}
}
if (region.Bounded && first != null)
{
edges.Add((uint)last.ID);
edges.Add((uint)first.ID);
}
}
this.VoronoiEdges = edges.ToArray();
/*
int i, n = voro.VertexList.Count;