Esempio n. 1
0
        /// <summary>
        /// Applies an optional cleanup method needed by Benjamine Ditter for laser data calculations.
        /// This is not used by the MapWindow calculations.
        /// </summary>
        /// <param name="vg">The output voronoi graph created in the Compute Voronoi Graph section</param>
        /// <param name="minLeftRightDist">A minimum left to right distance</param>
        /// <returns>The Voronoi Graph after it has been filtered.</returns>
        public static VoronoiGraph FilterVg(VoronoiGraph vg, double minLeftRightDist)
        {
            VoronoiGraph vgErg = new VoronoiGraph();

            foreach (VoronoiEdge ve in vg.Edges)
            {
                if (ve.LeftData.Distance(ve.RightData) >= minLeftRightDist)
                {
                    vgErg.Edges.Add(ve);
                }
            }

            foreach (VoronoiEdge ve in vgErg.Edges)
            {
                vgErg.Vertices.Add(ve.VVertexA);
                vgErg.Vertices.Add(ve.VVertexB);
            }

            return(vgErg);
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates a list of edges and junction vertices by using the specified points.
        /// This defaults to not using any tolerance for determining if points are equal,
        /// and will not use the cleanup algorithm, which breaks the HandleBoundaries
        /// method in the Voronoi class.
        /// </summary>
        /// <param name="vertices">The original points to use during the calculation</param>
        /// <returns>A VoronoiGraph structure containing the output geometries</returns>
        public static VoronoiGraph ComputeVoronoiGraph(double[] vertices)
        {
            //BinaryPriorityQueue pq = new BinaryPriorityQueue();
            SortedDictionary <VEvent, VEvent> pq = new SortedDictionary <VEvent, VEvent>();

            Dictionary <VDataNode, VCircleEvent> currentCircles = new Dictionary <VDataNode, VCircleEvent>();
            VoronoiGraph vg       = new VoronoiGraph();
            VNode        rootNode = null;

            for (int i = 0; i < vertices.Length / 2; i++)
            {
                //pq.Push(new VDataEvent(new Vector(vertex)));
                VDataEvent e = new VDataEvent(new Vector2(vertices, i * 2));
                if (pq.ContainsKey(e))
                {
                    continue;
                }
                pq.Add(e, e);
            }

            while (pq.Count > 0)
            {
                //VEvent ve = pq.Pop() as VEvent;
                VEvent ve = pq.First().Key;
                pq.Remove(ve);

                VDataNode[] circleCheckList = new VDataNode[] { };
                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, out circleCheckList);
                }
                else if (ve != null)
                {
                    throw new Exception("Got event of type " + ve.GetType() + "!");
                }
                foreach (VDataNode vd in circleCheckList)
                {
                    if (currentCircles.ContainsKey(vd))
                    {
                        currentCircles[vd].Valid = false;
                        currentCircles.Remove(vd);
                    }
                    if (ve == null)
                    {
                        continue;
                    }
                    VCircleEvent vce = VNode.CircleCheckDataNode(vd, ve.Y);
                    if (vce == null)
                    {
                        continue;
                    }
                    //pq.Push(vce);
                    pq.Add(vce, vce);

                    currentCircles[vd] = vce;
                }
                if (!(ve is VDataEvent))
                {
                    continue;
                }
                Vector2 dp = ((VDataEvent)ve).DataPoint;
                foreach (VCircleEvent vce in currentCircles.Values)
                {
                    if (MathTools.Dist(dp.X, dp.Y, vce.Center.X, vce.Center.Y) < vce.Y - vce.Center.Y && Math.Abs(MathTools.Dist(dp.X, dp.Y, vce.Center.X, vce.Center.Y) - (vce.Y - vce.Center.Y)) > 1e-10)
                    {
                        vce.Valid = false;
                    }
                }
            }

            // This is where the MapWindow version should exit since it uses the HandleBoundaries
            // function instead.  The following code is needed for Benjamin Ditter's original process to work.
            if (!DoCleanup)
            {
                return(vg);
            }

            VNode.CleanUpTree(rootNode);
            foreach (VoronoiEdge ve in vg.Edges)
            {
                if (ve.Done)
                {
                    continue;
                }
                if (ve.VVertexB != VVUnkown)
                {
                    continue;
                }
                ve.AddVertex(VVInfinite);
                if (Math.Abs(ve.LeftData.Y - ve.RightData.Y) < 1e-10 && ve.LeftData.X < ve.RightData.X)
                {
                    Vector2 t = ve.LeftData;
                    ve.LeftData  = ve.RightData;
                    ve.RightData = t;
                }
            }

            ArrayList minuteEdges = new ArrayList();

            foreach (VoronoiEdge ve in vg.Edges)
            {
                if (ve.IsPartlyInfinite || !ve.VVertexA.Equals(ve.VVertexB))
                {
                    continue;
                }
                minuteEdges.Add(ve);
                // prevent rounding errors from expanding to holes
                foreach (VoronoiEdge ve2 in vg.Edges)
                {
                    if (ve2.VVertexA.Equals(ve.VVertexA))
                    {
                        ve2.VVertexA = ve.VVertexA;
                    }
                    if (ve2.VVertexB.Equals(ve.VVertexA))
                    {
                        ve2.VVertexB = ve.VVertexA;
                    }
                }
            }
            foreach (VoronoiEdge ve in minuteEdges)
            {
                vg.Edges.Remove(ve);
            }

            return(vg);
        }
Esempio n. 3
0
        /// <summary>
        /// Processes the VCircleEvent.
        /// </summary>
        /// <param name="e">The VCircleEvent.</param>
        /// <param name="root">The root node.</param>
        /// <param name="vg">The VoronoiGraph.</param>
        /// <param name="circleCheckList">The circle check list.</param>
        /// <returns>The resulting root.</returns>
        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); // abbort because graph changed
            }

            VEdgeNode eu = (VEdgeNode)b.Parent;

            circleCheckList = new[] { a, c };

            // 1. Create the new Vertex
            Vector2 vNew = new Vector2(e.Center.X, e.Center.Y);

            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);
            eo.Edge.AddVertex(vNew);

            // 2. Replace eo by new Edge
            VoronoiEdge ve = new VoronoiEdge {
                LeftData = a.DataPoint, RightData = c.DataPoint
            };

            ve.AddVertex(vNew);
            vg.Edges.Add(ve);

            VEdgeNode ven = new VEdgeNode(ve, false)
            {
                Left = eo.Left, Right = eo.Right
            };

            if (eo.Parent == null)
            {
                return(ven);
            }
            eo.Parent.Replace(eo, ven);
            return(root);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        /// <summary>
        /// Processes the VCircleEvent.
        /// </summary>
        /// <param name="e">The VCircleEvent.</param>
        /// <param name="root">The root node.</param>
        /// <param name="vg">The VoronoiGraph.</param>
        /// <param name="circleCheckList">The circle check list.</param>
        /// <returns>The resulting root.</returns>
        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); // abbort because graph changed
            }

            VEdgeNode eu = (VEdgeNode)b.Parent;

            circleCheckList = new[] { a, c };

            // 1. Create the new Vertex
            Vector2 vNew = new(e.Center.X, e.Center.Y);

            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);
            eo.Edge.AddVertex(vNew);

            // 2. Replace eo by new Edge
            VoronoiEdge ve = new() { LeftData = a.DataPoint, RightData = c.DataPoint };

            ve.AddVertex(vNew);
            vg.Edges.Add(ve);

            VEdgeNode ven = new(ve, false) { Left = eo.Left, Right = eo.Right };

            if (eo.Parent == null)
            {
                return(ven);
            }
            eo.Parent.Replace(eo, ven);
            return(root);
        }

        /// <summary>
        /// Will return the new root (unchanged except in start-up).
        /// </summary>
        /// <param name="e">The VDataEvent.</param>
        /// <param name="root">The root node.</param>
        /// <param name="vg">The VoronoiGraph.</param>
        /// <param name="ys">The ys.</param>
        /// <param name="circleCheckList">The circle check list.</param>
        /// <returns>The new root.</returns>
        public static VNode ProcessDataEvent(VDataEvent e, VNode root, VoronoiGraph vg, double ys, out VDataNode[] circleCheckList)