private async Task Generate() { PoissonDiscSampling sampling = new PoissonDiscSampling((double)items.Find(r => r.Name == "Radius").Value, (uint)items.Find(r => r.Name == "Seed").Value); sampling.Sample2D(new CP.Common.Maths.Vector3D((int)VisualElement.ResultImage.Width, (int)VisualElement.ResultImage.Height, 0)); PoissonDiscSampling sampling2 = new PoissonDiscSampling((double)items.Find(r => r.Name == "Radius").Value, (uint)items.Find(r => r.Name == "Seed").Value); sampling2.Sample2D(new CP.Common.Maths.Vector3D((int)VisualElement.ResultImage.Width, (int)VisualElement.ResultImage.Height, 0)); System.Drawing.Pen blue = new System.Drawing.Pen(System.Drawing.Color.Blue, 8); System.Drawing.Pen red = new System.Drawing.Pen(System.Drawing.Color.Red, 8); System.Drawing.Pen blackPoint = new System.Drawing.Pen(System.Drawing.Color.Black, 5); System.Drawing.Pen black = new System.Drawing.Pen(System.Drawing.Color.White, 10); Random rand = new Random(); Bitmap src = new Bitmap((int)VisualElement.ResultImage.Width, (int)VisualElement.ResultImage.Height); using var graphics = Graphics.FromImage(src); /* foreach (var sites in sampling.points) * { * graphics.DrawLine(blue, new PointF((float)sites.position.X - 1, (float)sites.position.Y - 1), new PointF((float)sites.position.X + 1, (float)sites.position.Y + 1)); * * } * foreach (var sites in sampling2.points) * { * graphics.DrawLine(red, new PointF((float)sites.position.X - 1, (float)sites.position.Y - 1), new PointF((float)sites.position.X + 1, (float)sites.position.Y + 1)); * * }*/ VisualElement.Image = Utilities.BitmapToImageSource(src); }
private async Task Generate() { BowyerAlgorithm2D voronoiGen = new BowyerAlgorithm2D((int)items.Find(r => r.Name == "Seed").Value) { PointCount = (int)items.Find(r => r.Name == "Point Count").Value, //UseDelaunay = (bool)items.Find(r => r.Name == "Use Delaunay").Value, //UseNoisyEdges = (int)items.Find(r => r.Name == "Noisy Edges").Value > 0, //NoisyEdgesNo = (int)items.Find(r => r.Name == "Noisy Edges").Value, MaxX = 400, MaxY = 400, }; int seed = (int)items.Find(r => r.Name == "Seed").Value; PoissonDiscSampling sampling = new PoissonDiscSampling(20, (uint)seed); List <PoissonDisc> points = sampling.Sample2D(new CP.Common.Maths.Vector3D(400, 400, 0)); List <Triangle> triangulation = voronoiGen.Generate(points.Select(point => point.position).ToList(), true); List <VoronoiCell> cells = voronoiGen.GenerateVoronoi(); //int relaxation = (int)items.Find(r => r.Name == "Relaxation").Value; //if(relaxation > 0) //voronoiGen.Relax(relaxation); System.Drawing.Pen blue = new System.Drawing.Pen(System.Drawing.Color.Blue, 2); System.Drawing.Pen red = new System.Drawing.Pen(System.Drawing.Color.Red, 2); System.Drawing.Pen blackPoint = new System.Drawing.Pen(System.Drawing.Color.Black, 5); System.Drawing.Pen black = new System.Drawing.Pen(System.Drawing.Color.White, 10); Random rand = new Random(); Bitmap src = new Bitmap((int)VisualElement.ResultImage.Width, (int)VisualElement.ResultImage.Height); using var graphics = Graphics.FromImage(src); /* foreach (var sites in triangulation) * { * foreach (var edge in sites.Edges) * { * graphics.DrawLine(blue, new PointF((float)edge.PointA.X + 300, (float)edge.PointA.Y + 300), new PointF((float)edge.PointB.X + 300, (float)edge.PointB.Y + 300)); * } * }*/ foreach (var sites in cells) { foreach (var edge in sites.Edges) { graphics.DrawLine(red, new PointF((float)edge.PointA.X + 300, (float)edge.PointA.Y + 300), new PointF((float)edge.PointB.X + 300, (float)edge.PointB.Y + 300)); } } VisualElement.Image = Utilities.BitmapToImageSource(src); }
private void runTest(int samples, double radius) { double[] times = new double[samples]; Stopwatch watch = new Stopwatch(); Random rand = new Random(); Console.WriteLine("Cores: " + Environment.ProcessorCount); Console.WriteLine("64bit:" + Environment.Is64BitProcess + Environment.NewLine); int count = 0; for (int s = 0; s < samples; s++) { watch.Restart(); List <PoissonDisc> discs = PoissonDiscSampling.Sample2D(13235, radius, new CP.Common.Maths.Vector3D(100, 100, 100), 8, false); watch.Stop(); count = discs.Count; times[s] = watch.Elapsed.TotalMilliseconds; } Console.WriteLine(samples + ": avg => " + times.Average() + " | best => " + times.Min() + " | worst => " + times.Max() + " | count => " + count); }