/// <summary> /// Initializes a new instance of the class Delaunay_Voronoi_Library.Delaunay_Voronoi with the specified initial Delaunay_Voronoi class. /// </summary> /// <param name="delaunay_voronoi">The Delaunay_Voronoi class.</param> public Delaunay_Voronoi(Delaunay_Voronoi delaunay_voronoi) { Dictionary<Vertex, Vertex> dictionary_parallel_copy = new Dictionary<Vertex, Vertex>(); foreach (var w in delaunay_voronoi.GetVertices) { Vertex parallel_copy = new Vertex(w); dictionary_parallel_copy.Add(w, parallel_copy); this.GetVertices.Add(parallel_copy); } foreach (var w in delaunay_voronoi.triangles) { Vertex vertex1, vertex2, vertex3; dictionary_parallel_copy.TryGetValue(w.GetVertices[0], out vertex1); dictionary_parallel_copy.TryGetValue(w.GetVertices[1], out vertex2); dictionary_parallel_copy.TryGetValue(w.GetVertices[2], out vertex3); this.triangles.Add(new triangle(vertex1,vertex2,vertex3)); } foreach (var w in delaunay_voronoi.pol) { Vertex vertex; dictionary_parallel_copy.TryGetValue(w.GetCellCentr, out vertex); VoronoiCell newvc = new VoronoiCell(w,vertex); vertex.Voronoi_Cell = newvc; pol.Add(newvc); } }
/// <summary> /// Initializes a new instance of the class Delaunay_Voronoi_Library.VoronoiCell with the specified initial VoronoiCell and new central vertex. /// </summary> /// <param name="Voronoi_Cell">The Voronoi cell.</param> /// <param name="centr">The Voronoi cell central vertex.</param> public VoronoiCell(VoronoiCell Voronoi_Cell, Vertex centr) { this.CellCentr = centr; this.square = Voronoi_Cell.square; this.vertices = new List<Vertex>(); foreach (var w in Voronoi_Cell.vertices) this.vertices.Add(new Vertex(w)); }
/// <summary> /// Constructs voronoi diagram from delaunay triangulation. /// </summary> void Voronoi() { Vertex y0; foreach (var q in vertices) { List<Vertex> temp = new List<Vertex>(); triangle t = q.GetAdjacentTriangles[0]; Vertex y = t.GetVertices.First(a => a != q); for (int i = 0; i < q.GetAdjacentTriangles.Count; i++) { temp.Add(t.GetOR); y0 = y; y = t.GetVertices.Single(a => (a != y) && (a != q)); t = q.GetAdjacentTriangles.Single(a => a.GetVertices.Contains(y) && (!a.GetVertices.Contains(y0))); } VoronoiCell p = new VoronoiCell(q, temp); pol.Add(p); q.Voronoi_Cell = p; } }
void NatNearestInterpolation(Vertex vert, bool ExceptNaN) { pseudopol.Clear(); pseuvotr.Clear(); pseuvovert.Clear(); newtriangles.Clear(); if (addnewpoint(vert, false) == -1) return; List<Vertex> lv = new List<Vertex>(); foreach (var e1 in pseuvotr) foreach (var e2 in e1.GetVertices) { if (!lv.Contains(e2)) lv.Add(e2); } lv.Add(vert); foreach (var q in lv) { List<Vertex> temp = new List<Vertex>(); triangle t = q.GetAdjacentTriangles[0]; Vertex y = t.GetVertices.First(a => a != q); Vertex y0; for (int i = 0; i < q.GetAdjacentTriangles.Count; i++) { temp.Add(t.GetOR); y0 = y; y = t.GetVertices.Single(a => (a != y) && (a != q)); t = q.GetAdjacentTriangles.Single(a => a.GetVertices.Contains(y) && (!a.GetVertices.Contains(y0))); } VoronoiCell p = new VoronoiCell(q, temp); pseudopol.Add(p); } lv.Remove(vert); double sq = 0; //double sq = pseudopol.Single(a => a.GetCellCentr == vert).GetSquare; foreach (var q in lv) { if ((!ExceptNaN) || (ExceptNaN && !double.IsNaN(q.Value))) { double sqss = q.Voronoi_Cell.GetSquare; double sqs = pseudopol.Single(a => a.GetCellCentr == q).GetSquare; double delta = sqss - sqs; vert.Value += delta * q.Value; sq += delta; } } vert.Value /= sq; foreach (var n in newtriangles) { n.deltr(); triangles.Remove(n); } foreach (var n in pseuvotr) { var tem = new triangle(n.GetVertices[0], n.GetVertices[1], n.GetVertices[2]); triangles.Add(tem); } vertices.Remove(vert); }