コード例 #1
0
        public override void PrepareTest(params string[] args)
        {
            Random rand = new Random();

            bowyer = new BowyerAlgorithm2D(rand.Next(0, 999999999));
            if (args.Length > 0)
            {
                bowyer.PointCount = int.Parse(args[0]);
            }
        }
コード例 #2
0
        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);
        }