예제 #1
0
 public static VoronoiGraph ComputeVoronoiGraph(IEnumerable Datapoints)
 {
     BinaryPriorityQueue PQ = new BinaryPriorityQueue();
     Hashtable CurrentCircles = new Hashtable();
     VoronoiGraph VG = new VoronoiGraph();
     VNode RootNode = null;
     foreach(Vector V in Datapoints)
     {
         PQ.Push(new VDataEvent(V));
     }
     while(PQ.Count>0)
     {
         VEvent VE = PQ.Pop() as VEvent;
         VDataNode[] CircleCheckList;
         if(VE is VDataEvent)
         {
             RootNode = VNode.ProcessDataEvent(VE as VDataEvent,RootNode,VG,VE.Y,out CircleCheckList);
         }
         else if(VE is VCircleEvent)
         {
             CurrentCircles.Remove(((VCircleEvent)VE).NodeN);
             if(!((VCircleEvent)VE).Valid)
                 continue;
             RootNode = VNode.ProcessCircleEvent(VE as VCircleEvent,RootNode,VG,VE.Y,out CircleCheckList);
         }
         else throw new Exception("Got event of type "+VE.GetType().ToString()+"!");
         foreach(VDataNode VD in CircleCheckList)
         {
             if(CurrentCircles.ContainsKey(VD))
             {
                 ((VCircleEvent)CurrentCircles[VD]).Valid=false;
                 CurrentCircles.Remove(VD);
             }
             VCircleEvent VCE = VNode.CircleCheckDataNode(VD,VE.Y);
             if(VCE!=null)
             {
                 PQ.Push(VCE);
                 CurrentCircles[VD]=VCE;
             }
         }
         if(VE is VDataEvent)
         {
             Vector DP = ((VDataEvent)VE).DataPoint;
             foreach(VCircleEvent VCE in CurrentCircles.Values)
             {
                 if(MathTools.Dist(DP[0],DP[1],VCE.Center[0],VCE.Center[1])<VCE.Y-VCE.Center[1] && Math.Abs(MathTools.Dist(DP[0],DP[1],VCE.Center[0],VCE.Center[1])-(VCE.Y-VCE.Center[1]))>1e-10)
                     VCE.Valid = false;
             }
         }
     }
     return VG;
 }
예제 #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 Bitmap GetDelaunayTriangulation(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 Datapoints)
            {
                Vector v = (Vector)o;
                g.DrawEllipse(Pens.Red, (int)v[0] - 1, (int)v[1] - 1, 2, 2);
                foreach (object obj in graph.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(bmp);
        }
 public VoronoiTemparature(List<TemperatureLocation> temp)
 {
     temperature = temp;
     List<Vector> vectors = new List<Vector>();
     foreach (TemperatureLocation t in temperature)
     {
         vectors.Add(new Vector(t.X, t.Y));
     }
     maxTemperature = GetMaxTemperature();
     minTemperature = GetMinTemperature();
     graph = Fortune.ComputeVoronoiGraph(vectors);
 }
예제 #4
0
        public static VNode ProcessCircleEvent(VCircleEvent e, VNode Root, VoronoiGraph VG, double ys, out VDataNode[] CircleCheckList)
        {
            VDataNode a, b, c;
            VEdgeNode eu, eo;

            b = e.NodeN;
            a = VNode.LeftDataNode(b);
            c = VNode.RightDataNode(b);
            if (a == null || b.Parent == null || c == null || !a.DataPoint.Equals(e.NodeL.DataPoint) || !c.DataPoint.Equals(e.NodeR.DataPoint))
            {
                CircleCheckList = new VDataNode[] {};
                return(Root);                // Abbruch da sich der Graph verändert hat
            }
            eu = (VEdgeNode)b.Parent;
            CircleCheckList = new VDataNode[] { a, c };
            //1. Create the new Vertex
            Vector VNew = new Vector(e.Center[0], e.Center[1]);

//			VNew[0] = Fortune.ParabolicCut(a.DataPoint[0],a.DataPoint[1],c.DataPoint[0],c.DataPoint[1],ys);
//			VNew[1] = (ys + a.DataPoint[1])/2 - 1/(2*(ys-a.DataPoint[1]))*(VNew[0]-a.DataPoint[0])*(VNew[0]-a.DataPoint[0]);
            VG.Vertizes.Add(VNew);
            //2. Find out if a or c are in a distand part of the tree (the other is then b's sibling) and assign the new vertex
            if (eu.Left == b)          // c is sibling
            {
                eo = VNode.EdgeToRightDataNode(a);

                // replace eu by eu's Right
                eu.Parent.Replace(eu, eu.Right);
            }
            else             // a is sibling
            {
                eo = VNode.EdgeToRightDataNode(b);

                // replace eu by eu's Left
                eu.Parent.Replace(eu, eu.Left);
            }
            eu.Edge.AddVertex(VNew);
//			///////////////////// uncertain
//			if(eo==eu)
//				return Root;
//			/////////////////////
            eo.Edge.AddVertex(VNew);
            //2. Replace eo by new Edge
            VoronoiEdge VE = new VoronoiEdge();

            VE.LeftData  = a.DataPoint;
            VE.RightData = c.DataPoint;
            VE.AddVertex(VNew);
            VG.Edges.Add(VE);

            VEdgeNode VEN = new VEdgeNode(VE, false);

            VEN.Left  = eo.Left;
            VEN.Right = eo.Right;
            if (eo.Parent == null)
            {
                return(VEN);
            }
            eo.Parent.Replace(eo, VEN);
            return(Root);
        }
예제 #5
0
        /// <summary>
        /// Will return the new root (unchanged except in start-up)
        /// </summary>
        public static VNode ProcessDataEvent(VDataEvent e, VNode Root, VoronoiGraph VG, double ys, out VDataNode[] CircleCheckList)
        {
            if(Root==null)
            {
                Root = new VDataNode(e.DataPoint);
                CircleCheckList = new VDataNode[] {(VDataNode)Root};
                return Root;
            }
            //1. Find the node to be replaced
            VNode C = VNode.FindDataNode(Root, ys, e.DataPoint[0]);
            //2. Create the subtree (ONE Edge, but two VEdgeNodes)
            VoronoiEdge VE = new VoronoiEdge();
            VE.LeftData = ((VDataNode)C).DataPoint;
            VE.RightData = e.DataPoint;
            VE.VVertexA = Fortune.VVUnkown;
            VE.VVertexB = Fortune.VVUnkown;
            VG.Edges.Add(VE);

            VNode SubRoot;
            if(Math.Abs(VE.LeftData[1]-VE.RightData[1])<1e-10)
            {
                if(VE.LeftData[0]<VE.RightData[0])
                {
                    SubRoot = new VEdgeNode(VE,false);
                    SubRoot.Left = new VDataNode(VE.LeftData);
                    SubRoot.Right = new VDataNode(VE.RightData);
                }
                else
                {
                    SubRoot = new VEdgeNode(VE,true);
                    SubRoot.Left = new VDataNode(VE.RightData);
                    SubRoot.Right = new VDataNode(VE.LeftData);
                }
                CircleCheckList = new VDataNode[] {(VDataNode)SubRoot.Left,(VDataNode)SubRoot.Right};
            }
            else
            {
                SubRoot = new VEdgeNode(VE,false);
                SubRoot.Left = new VDataNode(VE.LeftData);
                SubRoot.Right = new VEdgeNode(VE,true);
                SubRoot.Right.Left = new VDataNode(VE.RightData);
                SubRoot.Right.Right = new VDataNode(VE.LeftData);
                CircleCheckList = new VDataNode[] {(VDataNode)SubRoot.Left,(VDataNode)SubRoot.Right.Left,(VDataNode)SubRoot.Right.Right};
            }

            //3. Apply subtree
            if(C.Parent == null)
                return SubRoot;
            C.Parent.Replace(C,SubRoot);
            return Root;
        }
예제 #6
0
        public static VNode ProcessCircleEvent(VCircleEvent e, VNode Root, VoronoiGraph VG, double ys, out VDataNode[] CircleCheckList)
        {
            VDataNode a,b,c;
            VEdgeNode eu,eo;
            b = e.NodeN;
            a = VNode.LeftDataNode(b);
            c = VNode.RightDataNode(b);
            if(a==null || b.Parent==null || c==null || !a.DataPoint.Equals(e.NodeL.DataPoint) || !c.DataPoint.Equals(e.NodeR.DataPoint))
            {
                CircleCheckList = new VDataNode[]{};
                return Root; // Abbruch da sich der Graph verändert hat
            }
            eu = (VEdgeNode)b.Parent;
            CircleCheckList = new VDataNode[] {a,c};
            //1. Create the new Vertex
            Vector VNew = new Vector(e.Center[0],e.Center[1]);
            //			VNew[0] = Fortune.ParabolicCut(a.DataPoint[0],a.DataPoint[1],c.DataPoint[0],c.DataPoint[1],ys);
            //			VNew[1] = (ys + a.DataPoint[1])/2 - 1/(2*(ys-a.DataPoint[1]))*(VNew[0]-a.DataPoint[0])*(VNew[0]-a.DataPoint[0]);
            VG.Vertizes.Add(VNew);
            //2. Find out if a or c are in a distand part of the tree (the other is then b's sibling) and assign the new vertex
            if(eu.Left==b) // c is sibling
            {
                eo = VNode.EdgeToRightDataNode(a);

                // replace eu by eu's Right
                eu.Parent.Replace(eu,eu.Right);
            }
            else // a is sibling
            {
                eo = VNode.EdgeToRightDataNode(b);

                // replace eu by eu's Left
                eu.Parent.Replace(eu,eu.Left);
            }
            eu.Edge.AddVertex(VNew);
            //			///////////////////// uncertain
            //			if(eo==eu)
            //				return Root;
            //			/////////////////////
            eo.Edge.AddVertex(VNew);
            //2. Replace eo by new Edge
            VoronoiEdge VE = new VoronoiEdge();
            VE.LeftData = a.DataPoint;
            VE.RightData = c.DataPoint;
            VE.AddVertex(VNew);
            VG.Edges.Add(VE);

            VEdgeNode VEN = new VEdgeNode(VE, false);
            VEN.Left = eo.Left;
            VEN.Right = eo.Right;
            if(eo.Parent == null)
                return VEN;
            eo.Parent.Replace(eo,VEN);
            return Root;
        }