/// <summary> /// This function checks all requirements to build a tessellation, basically the number of independent nodes. /// If they are enough this method call to the buildTesellation method. /// </summary> private bool TryBuildTesellation(INuclei[] PointsToRemake, List <ISimplice> oldSimplices) { //check enough points if (PointsToRemake.Length >= dimensions + 1) { //Candidate simplices will contain some old simplices //and some new maked up simplices IEnumerable <IEnumerable <INuclei> > candidateSimplicesNucleis = Helpers.Combinations(PointsToRemake, dimensions + 1); //the only thing we need is a combinatory function about the exploited points //generateCombinatorySimplicies(0,0, dimensions + 1, PointsToRemake, null, oldSimplices, candidateSimplices); List <ISimplice> candidateSimplices = new List <ISimplice>(); foreach (var nucSet in candidateSimplicesNucleis) { ISimplice existingSimplice = oldSimplices.FirstOrDefault(s => nucSet.All(n => s.Nucleis.Contains(n))); if (existingSimplice != null) { candidateSimplices.Add(existingSimplice); } else { INuclei[] nucs = nucSet.ToArray(); if (Nuclei.AssertRank(nucs, dimensions)) { candidateSimplices.Add(new Simplice(nucs)); } } } //check enough independent points if (candidateSimplices.Any()) { BuildTesellationAndSetNeiborghood(candidateSimplices, PointsToRemake, oldSimplices); return(true); } else { return(false); //not enough indepndent poitns to build a tessellation in this n-dimensional world } } else { return(false); //not enough points to build a teselation in this n-dimensional world } }
internal VoronoiVertex(int dimensionality, Simplice simp) { this.coordinates = new double[dimensionality]; this.Simplice = simp; }
void paint_event(object sender, PaintEventArgs e) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Simplices Count: " + voronoi.Simplices.Count()); sb.AppendLine("Nuclei Count: " + voronoi.Nucleis.Count()); sb.AppendLine("Paint Stage: " + step); e.Graphics.DrawString(sb.ToString(), f, Brushes.Red, new Point(0, 0)); foreach (INuclei n in voronoi.Nucleis) { PointF npos = new PointF((float)n.Coordinates[0], (float)n.Coordinates[1]);; e.Graphics.DrawEllipse(Pens.Black, new RectangleF((float)n.Coordinates[0] - 1, (float)n.Coordinates[1] - 1, 3, 3)); if (cb_showNucleiInfo.Checked) { e.Graphics.DrawString("neigh:" + n.Neighbourgs.Count().ToString() + "\nsimps:" + n.Simplices.Count(), f, Brushes.Black, npos); } if (viewDelunay.Checked) { foreach (INuclei neighbour in n.Neighbourgs) { PointF pos = new PointF((float)neighbour.Coordinates[0], (float)neighbour.Coordinates[1]); e.Graphics.DrawLine(Pens.Red, pos, npos); } } } foreach (ISimplice s in voronoi.Simplices) { PointF npos = new PointF((float)s.VoronoiVertex.Coordinates[0], (float)s.VoronoiVertex.Coordinates[1]);; float radious = (float)s.Radious; if (viewCircumpheres.Checked) { e.Graphics.DrawEllipse(Pens.DarkGray, new RectangleF(new PointF(npos.X - radious, npos.Y - radious), new SizeF(radious * 2, radious * 2))); } if (viewVoronoi.Checked) { foreach (ISimplice s2 in s.NeighbourSimplices) { e.Graphics.DrawLine(Pens.Gray, s2.VoronoiVertex.ToPoint(), s.VoronoiVertex.ToPoint()); } } if (s.Facets.Any()) { /*e.Graphics.FillEllipse(Brushes.HotPink, new RectangleF(npos.X - 2, npos.Y - 2, 5, 5)); * * //pseudoInfiniteRadiousForPainting * float paintRadious = (float)Math.Sqrt(this.Width * this.Width + this.Height * this.Height); * * Nuclei[] points = s.InfiniteNeighbourVoronoiVertexes; * * * PointF middlePoint = new PointF * { * X = (float)(points[0].Coordinates[0] + points[1].Coordinates[0]) / 2.0f, * Y = (float)(points[0].Coordinates[1] + points[1].Coordinates[1]) / 2.0f * }; * * PointF directionVector = new PointF * { * X = (float)(middlePoint.X - s.VoronoiVertex.Coordinates[0]), * Y = (float)(middlePoint.Y - s.VoronoiVertex.Coordinates[1]) * * }; * * PointF infinitePoint = new PointF * { * X = npos.X + paintRadious * directionVector.X, * Y = npos.Y + paintRadious * directionVector.Y * }; */ foreach (ISimpliceFacet facet in s.Facets) { if (facet.IsConvexHullFacet && facet.Nucleis.Count() > 1) { e.Graphics.DrawLine(Pens.Lime, facet.Nucleis[0].Coordinates.ToPoint2F(), facet.Nucleis[1].Coordinates.ToPoint2F()); } } } } if (viewVoronoi.Checked) { if (voronoi.Simplices.Any()) { ISimplice s = voronoi.Simplices.ElementAt(step); PointF npos = new PointF((float)s.VoronoiVertex.Coordinates[0], (float)s.VoronoiVertex.Coordinates[1]);; float radious = (float)s.Radious; e.Graphics.FillEllipse(Brushes.Blue, new RectangleF((float)s.VoronoiVertex.Coordinates[0] - 2, (float)s.VoronoiVertex.Coordinates[1] - 2, 5, 5)); e.Graphics.FillEllipse(Brushes.Lime, (float)s.VoronoiVertex.Coordinates[0] - 2, (float)s.VoronoiVertex.Coordinates[1] - 2, 5, 5); e.Graphics.DrawString(s.GetHashCode().ToString(), f, Brushes.Black, s.VoronoiVertex.ToPoint()); foreach (ISimplice s2 in s.NeighbourSimplices) { e.Graphics.DrawLine(Pens.Blue, s2.VoronoiVertex.ToPoint(), s.VoronoiVertex.ToPoint()); e.Graphics.FillEllipse(Brushes.Blue, (float)s2.VoronoiVertex.Coordinates[0] - 1, (float)s2.VoronoiVertex.Coordinates[1] - 1, 3, 3); foreach (INuclei n in s2.Nucleis) { e.Graphics.FillEllipse(Brushes.Yellow, new RectangleF((float)n.Coordinates[0] - 2, (float)n.Coordinates[1] - 2, 5, 5)); } } } } }