ComputeVoronoiGraph() public static méthode

public static ComputeVoronoiGraph ( VoronoiCell>.Dictionary cells ) : VoronoiGraph
cells VoronoiCell>.Dictionary
Résultat VoronoiGraph
Exemple #1
0
        /// <summary>
        /// Visualization of 2D Voronoi map.
        /// </summary>
        /// <param name="weight">Weight of result image.</param>
        /// <param name="height">Height of result image.</param>
        /// <param name="Datapoints">Array of data points.</param>
        /// <returns>Result bitmap.</returns>
        public static Bitmap GetVoronoyMap(int weight, int height, IEnumerable Datapoints)
        {
            Bitmap       bmp   = new Bitmap(weight, height);
            VoronoiGraph graph = Fortune.ComputeVoronoiGraph(Datapoints);
            Graphics     g     = Graphics.FromImage(bmp);

            foreach (object o in graph.Vertizes)
            {
                Vector3 v = (Vector3)o;
                g.DrawEllipse(Pens.Black, (int)v[0] - 2, (int)v[1] - 2, 4, 4);
            }
            foreach (object o in Datapoints)
            {
                Vector3 v = (Vector3)o;
                g.DrawEllipse(Pens.Red, (int)v[0] - 1, (int)v[1] - 1, 2, 2);
            }
            foreach (object o in graph.Edges)
            {
                VoronoiEdge edge = (VoronoiEdge)o;
                try
                {
                    g.DrawLine(Pens.Brown, (int)edge.VVertexA[0], (int)edge.VVertexA[1], (int)edge.VVertexB[0], (int)edge.VVertexB[1]);
                }
                catch { }
            }
            return(bmp);
        }
Exemple #2
0
        /// <summary>
        /// Visualization of Delaunay Triangulation
        /// </summary>
        /// <param name="weight">Weight of result image.</param>
        /// <param name="height">Height of result image.</param>
        /// <param name="Datapoints">Result bitmap.</param>
        /// <returns></returns>
        public static List <Triangle> GetDelaunayTriangulation(IEnumerable Datapoints)
        {
            System.Collections.Generic.List <Triangle> list = new System.Collections.Generic.List <Triangle>();
            VoronoiGraph voronoiGraph = Fortune.ComputeVoronoiGraph(Datapoints);
            //Graphics g = Graphics.FromImage(bmp);
            List <Triangle> triangles = new List <Triangle>();

            for (int i = voronoiGraph.Edges.Count - 1; i >= 0; i--)
            {
                VoronoiEdge edge1 = voronoiGraph.Edges[i];
                for (int j = 0; j < i; j++)
                {
                    VoronoiEdge edge2 = voronoiGraph.Edges[j];
                    //if (edge1.LeftData.Index == edge2.LeftData.Index)
                    //{
                    //    triangles.Add(new Triangle(edge1.LeftData.Index, edge1.RightData.Index, edge2.RightData.Index));
                    //}
                    //if (edge1.RightData.Index == edge2.RightData.Index)
                    //{
                    //    triangles.Add(new Triangle(edge1.LeftData.Index, edge1.RightData.Index, edge2.LeftData.Index));
                    //}
                    //if (edge1.RightData.Index == edge2.LeftData.Index)
                    //{
                    //    triangles.Add(new Triangle(edge1.LeftData.Index, edge1.RightData.Index, edge2.RightData.Index));
                    //}
                    //if (edge1.LeftData.Index == edge2.RightData.Index)
                    //{
                    //    triangles.Add(new Triangle(edge1.LeftData.Index, edge1.RightData.Index, edge2.LeftData.Index));
                    //}
                }
                //if ((edge.LeftData[0] == v[0]) & (edge.LeftData[1] == v[1]))
                //{
                //    g.DrawLine(Pens.Black, (int)edge.LeftData[0], (int)edge.LeftData[1], (int)edge.RightData[0], (int)edge.RightData[1]);
                //}
            }


            ////Graphics g = Graphics.FromImage(bmp);
            //foreach (object o in Datapoints)
            //{
            //    Vector3 v = (Vector3)o;
            //    //g.DrawEllipse(Pens.Red, (int)v[0] - 1, (int)v[1] - 1, 2, 2);
            //    foreach (object obj in voronoiGraph.Edges)
            //    {
            //        VoronoiEdge edge = (VoronoiEdge)obj;
            //        if ((edge.LeftData[0] == v[0]) & (edge.LeftData[1] == v[1]))
            //        {
            //            g.DrawLine(Pens.Black, (int)edge.LeftData[0], (int)edge.LeftData[1], (int)edge.RightData[0], (int)edge.RightData[1]);
            //        }
            //    }
            //}
            return(triangles);
        }