Ejemplo n.º 1
0
        /// <summary> Finds and removes all cut edges from the graph.</summary>
        /// <returns> a list of the <see cref="LineString"/>s forming the removed cut edges
        /// </returns>
        public ArrayList DeleteCutEdges()
        {
            ComputeNextCWEdges();
            // label the current set of edgerings
            FindLabeledEdgeRings(dirEdges);

            /// <summary> Cut Edges are edges where both dirEdges have the same label.
            /// Delete them, and record them
            /// </summary>
            ArrayList cutLines = new ArrayList();

            for (IEnumerator i = dirEdges.GetEnumerator(); i.MoveNext();)
            {
                PolygonizeDirectedEdge de = (PolygonizeDirectedEdge)i.Current;
                if (de.Marked)
                {
                    continue;
                }

                PolygonizeDirectedEdge sym = (PolygonizeDirectedEdge)de.Sym;

                if (de.Label == sym.Label)
                {
                    de.Marked  = true;
                    sym.Marked = true;

                    // save the line as a cut edge
                    PolygonizeEdge e = (PolygonizeEdge)de.Edge;

                    cutLines.Add(e.Line);
                }
            }
            return(cutLines);
        }
Ejemplo n.º 2
0
        /// <summary> Marks all edges from the graph which are "dangles".
        /// Dangles are which are incident on a node with degree 1.
        /// This process is recursive, since removing a dangling edge
        /// may result in another edge becoming a dangle.
        /// In order to handle large recursion depths efficiently,
        /// an explicit recursion stack is used
        ///
        /// </summary>
        /// <returns> a List containing the {@link LineStrings} that formed dangles
        /// </returns>
        public ICollection DeleteDangles()
        {
            ArrayList nodesToRemove = FindNodesOfDegree(1);
            ISet      dangleLines   = new HashedSet();

            Stack nodeStack = new Stack();

            for (IEnumerator i = nodesToRemove.GetEnumerator(); i.MoveNext();)
            {
                nodeStack.Push(i.Current);
            }

            while (!(nodeStack.Count == 0))
            {
                Node node = (Node)nodeStack.Pop();

                DeleteAllEdges(node);

                ArrayList nodeOutEdges = node.OutEdges.Edges;

                for (IEnumerator i = nodeOutEdges.GetEnumerator(); i.MoveNext();)
                {
                    PolygonizeDirectedEdge de = (PolygonizeDirectedEdge)i.Current;
                    // delete this edge and its sym
                    de.Marked = true;
                    PolygonizeDirectedEdge sym = (PolygonizeDirectedEdge)de.Sym;
                    if (sym != null)
                    {
                        sym.Marked = true;
                    }

                    // save the line as a dangle
                    PolygonizeEdge e = (PolygonizeEdge)de.Edge;
                    dangleLines.Add(e.Line);

                    Node toNode = de.ToNode;
                    // Add the toNode to the list to be processed, if it is now a dangle
                    if (GetDegreeNonDeleted(toNode) == 1)
                    {
                        nodeStack.Push(toNode);
                    }
                }
            }

            return(dangleLines);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a <see cref="LineString"/> forming an edge of the polygon graph.
        /// </summary>
        /// <param name="line">the line to Add
        /// </param>
        public void AddEdge(LineString line)
        {
            if (line.IsEmpty)
            {
                return;
            }

            ICoordinateList linePts =
                CoordinateCollection.RemoveRepeatedCoordinates(line.Coordinates);
            Coordinate startPt = linePts[0];
            Coordinate endPt   = linePts[linePts.Count - 1];

            Node nStart = GetNode(startPt);
            Node nEnd   = GetNode(endPt);

            DirectedEdge de0 = new PolygonizeDirectedEdge(nStart, nEnd, linePts[1], true);
            DirectedEdge de1 = new PolygonizeDirectedEdge(nEnd, nStart,
                                                          linePts[linePts.Count - 2], false);
            Edge edge = new PolygonizeEdge(line);

            edge.SetDirectedEdges(de0, de1);
            Add(edge);
        }