コード例 #1
0
ファイル: VNode.cs プロジェクト: zhongshuiyuan/mapwindowsix
 private void Replace(VNode childOld, VNode childNew)
 {
     if (Left == childOld)
         Left = childNew;
     else if (Right == childOld)
         Right = childNew;
     else throw new Exception("Child not found!");
     childOld.Parent = null;
 }
コード例 #2
0
ファイル: VNode.cs プロジェクト: zhongshuiyuan/mapwindowsix
 private static VDataNode LeftDataNode(VNode current)
 {
     VNode c = current;
     //1. Up
     do
     {
         if (c.Parent == null)
             return null;
         if (c.Parent.Left == c)
         {
             c = c.Parent;
             continue;
         }
         c = c.Parent;
         break;
     } while (true);
     //2. One Left
     c = c.Left;
     //3. Down
     while (c.Right != null)
         c = c.Right;
     return (VDataNode)c; // Cast statt 'as' damit eine Exception kommt
 }
コード例 #3
0
ファイル: VNode.cs プロジェクト: zhongshuiyuan/mapwindowsix
 public static void CleanUpTree(VNode Root)
 {
     if (Root is VDataNode)
         return;
     VEdgeNode ve = Root as VEdgeNode;
     if (ve != null)
     {
         while (ve.Edge.VVertexB == Fortune.VVUnkown)
         {
             ve.Edge.AddVertex(Fortune.VVInfinite);
         }
         if (ve.Flipped)
         {
             Vector2 t = ve.Edge.LeftData;
             ve.Edge.LeftData = ve.Edge.RightData;
             ve.Edge.RightData = t;
         }
         ve.Edge.Done = true;
     }
     CleanUpTree(Root.Left);
     CleanUpTree(Root.Right);
 }
コード例 #4
0
ファイル: VNode.cs プロジェクト: zhongshuiyuan/mapwindowsix
        public static VNode ProcessCircleEvent(VCircleEvent e, VNode root, VoronoiGraph vg, out VDataNode[] circleCheckList)
        {
            VEdgeNode eo;
            VDataNode b = e.NodeN;
            VDataNode a = LeftDataNode(b);
            VDataNode c = 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
            }
            VEdgeNode eu = (VEdgeNode)b.Parent;
            circleCheckList = new[] { a, c };
            //1. Create the new Vertex
            Vector2 vNew = new Vector2(e.Center.X, e.Center.Y);
            //			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.Vertices.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 = EdgeToRightDataNode(a);

                // replace eu by eu's Right
                eu.Parent.Replace(eu, eu.Right);
            }
            else // a is sibling
            {
                eo = 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
ファイル: VNode.cs プロジェクト: zhongshuiyuan/mapwindowsix
        /// <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)root };
                return root;
            }
            //1. Find the node to be replaced
            VNode c = FindDataNode(root, ys, e.DataPoint.X);
            //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.Y - ve.RightData.Y) < 1e-10)
            {
                if (ve.LeftData.X < ve.RightData.X)
                {
                    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)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)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
ファイル: VNode.cs プロジェクト: zhongshuiyuan/mapwindowsix
 private static VDataNode FindDataNode(VNode root, double ys, double x)
 {
     VNode c = root;
     do
     {
         if (c is VDataNode)
             return (VDataNode)c;
         if (((VEdgeNode)c).Cut(ys, x) < 0)
             c = c.Left;
         else
             c = c.Right;
     } while (true);
 }
コード例 #7
0
ファイル: VNode.cs プロジェクト: zhongshuiyuan/mapwindowsix
 private static VEdgeNode EdgeToRightDataNode(VNode current)
 {
     VNode c = current;
     //1. Up
     do
     {
         if (c.Parent == null)
             throw new Exception("No Left Leaf found!");
         if (c.Parent.Right == c)
         {
             c = c.Parent;
             continue;
         }
         c = c.Parent;
         break;
     } while (true);
     return (VEdgeNode)c;
 }