Пример #1
0
        // Runs a specific Voronoi Generation test and returns the time it took
        // to complete.
        static long RunTests(int trial, int numPoints, int max, TestMode t)
        {
            Stopwatch    timer = new Stopwatch();
            List <Point> sites = Point.GetRandomPoints(numPoints, 0, max);

            if (t == TestMode.BOWYER_WATSON)
            {
                timer.Start();
                DelaunayTriangulator generator = new DelaunayTriangulator(sites);
                generator.GenerateVoronoi();
                timer.Stop();
            }
            else
            {
                timer.Start();
                BruteForceVoronoi generator = new BruteForceVoronoi(sites);
                generator.GenerateVoronoi();
                timer.Stop();
            }

            long elapsed = timer.ElapsedMilliseconds;

            Console.WriteLine(trial + "\t\t" + numPoints + "\t\t" + max + "\t\t" + elapsed);
            return(elapsed);
        }
Пример #2
0
        // Renders a diagram based off of random points.
        // Uses same points with both methods.
        public static void RenderSameDiagram()
        {
            List <Point> points = Point.GetRandomPoints(numPointsForPic, 0, rangeForPic);

            DelaunayTriangulator tri           = new DelaunayTriangulator(points);
            VoronoiDiagram       voroEfficient = tri.GenerateVoronoi();


            BruteForceVoronoi voroBrute = new BruteForceVoronoi(points);

            voroBrute.GenerateVoronoi();

            RenderConfig config = voroBrute.FullFrameConfig;

            config.xPadding += 50;
            config.yPadding += 50;

            VoronoiRenderer.DrawDiagram(voroEfficient, config, "bowyer_output.bmp");
            VoronoiRenderer.DrawTriangulation(tri.WithoutSupertriangle(), config, "bowyer_triangulation_no_super.bmp");
            VoronoiRenderer.DrawTriangulation(tri, config, "bowyer_triangulation_super.bmp");

            VoronoiRenderer.DrawDiagram(voroBrute, config, "brute_force_output.bmp");
        }
Пример #3
0
        public static void DrawTriangulation(DelaunayTriangulator tri, RenderConfig config, string filename)
        {
            // Initialize surface:
            Bitmap   image = CreateBitmap(config);
            Graphics g     = Graphics.FromImage(image);

            g.Clear(Color.White);

            // Style for site centers:
            SolidBrush pointBrush  = new SolidBrush(Color.Black);
            SolidBrush centerBrush = new SolidBrush(Color.Red);

            // Style for lines:
            Pen linePen = new Pen(Brushes.SlateGray)
            {
                Width = 1.0F
            };

            Pen circlePen = new Pen(Brushes.GreenYellow)
            {
                Width = 0.75F
            };

            Font font = new Font("Arial", 10);


            foreach (Vertex vertex in tri.triangles)
            {
                System.Drawing.Point[] drawPoints = new System.Drawing.Point[4];

                for (int i = 0; i < vertex.points.Count; i++)
                {
                    Models.Point         p           = vertex.points[i];
                    System.Drawing.Point pWithOffset = TransposePoint(p, config);
                    g.DrawString(p.ToString(), font, centerBrush, pWithOffset);
                    drawPoints[i] = pWithOffset;
                }

                drawPoints[3] = drawPoints[0];

                g.DrawLines(linePen, drawPoints);


                Models.Point point = vertex.center;
                g.DrawPoint(point, centerBrush, config);


                g.DrawCircle(point, circlePen, vertex.radius, config);
            }

            foreach (Models.Point point in tri.allPoints)
            {
                g.DrawPoint(point, pointBrush, config);
            }
            image.Save(filename);

            linePen.Dispose();
            pointBrush.Dispose();
            centerBrush.Dispose();
            circlePen.Dispose();
        }