Esempio n. 1
0
 /// <summary>
 /// Adds a node to the map, replacing any that is already at that location.
 /// </summary>
 /// <param name="n"></param>
 /// <returns>The added node.</returns>
 public virtual Node Add(Node n)
 {
     Coordinate key = n.Coordinate;
     bool contains = _nodeMap.Contains(key);
     if (!contains) _nodeMap.Add(key, n);
     return n;
 }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="coordinate"></param>
 /// <returns></returns>
 private Node GetNode(Coordinate coordinate)
 {
     Node node = FindNode(coordinate);
     if (node == null)
     {
         node = new Node(coordinate);
         Add(node);
     }
     return node;
 }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="node"></param>
 /// <param name="label"></param>
 /// <returns></returns>
 private static int GetDegree(Node node, long label)
 {
     IList edges = node.OutEdges.Edges;
     int degree = 0;
     for (IEnumerator i = edges.GetEnumerator(); i.MoveNext(); )
     {
         PolygonizeDirectedEdge de = (PolygonizeDirectedEdge)i.Current;
         if (de.Label == label)
             degree++;
     }
     return degree;
 }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private static int GetDegreeNonDeleted(Node node)
 {
     IList edges = node.OutEdges.Edges;
     int degree = 0;
     for (IEnumerator i = edges.GetEnumerator(); i.MoveNext(); )
     {
         PolygonizeDirectedEdge de = (PolygonizeDirectedEdge)i.Current;
         if (!de.IsMarked)
             degree++;
     }
     return degree;
 }
Esempio n. 5
0
 /// <summary>
 /// Deletes all edges at a node.
 /// </summary>
 /// <param name="node"></param>
 public static void DeleteAllEdges(Node node)
 {
     IList edges = node.OutEdges.Edges;
     for (IEnumerator i = edges.GetEnumerator(); i.MoveNext(); )
     {
         PolygonizeDirectedEdge de = (PolygonizeDirectedEdge)i.Current;
         de.IsMarked = true;
         PolygonizeDirectedEdge sym = (PolygonizeDirectedEdge)de.Sym;
         if (sym != null) sym.IsMarked = true;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Computes the next edge pointers going CCW around the given node, for the
        /// given edgering label.
        /// This algorithm has the effect of converting maximal edgerings into minimal edgerings
        /// </summary>
        /// <param name="node"></param>
        /// <param name="label"></param>
        private static void ComputeNextCcwEdges(Node node, long label)
        {
            DirectedEdgeStar deStar = node.OutEdges;
            //PolyDirectedEdge lastInDE = null;
            PolygonizeDirectedEdge firstOutDe = null;
            PolygonizeDirectedEdge prevInDe = null;

            // the edges are stored in CCW order around the star
            IList edges = deStar.Edges;
            //for (IEnumerator i = deStar.Edges.GetEnumerator(); i.MoveNext(); ) {
            for (int i = edges.Count - 1; i >= 0; i--)
            {
                PolygonizeDirectedEdge de = (PolygonizeDirectedEdge)edges[i];
                PolygonizeDirectedEdge sym = (PolygonizeDirectedEdge)de.Sym;

                PolygonizeDirectedEdge outDe = null;
                if (de.Label == label) outDe = de;

                PolygonizeDirectedEdge inDe = null;
                if (sym.Label == label) inDe = sym;

                if (outDe == null && inDe == null) continue;  // this edge is not in edgering

                if (inDe != null)
                    prevInDe = inDe;

                if (outDe != null)
                {
                    if (prevInDe != null)
                    {
                        prevInDe.Next = outDe;
                        prevInDe = null;
                    }
                    if (firstOutDe == null)
                        firstOutDe = outDe;
                }
            }
            if (prevInDe != null)
            {
                Assert.IsTrue(firstOutDe != null);
                prevInDe.Next = firstOutDe;
            }
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        private static void ComputeNextCwEdges(Node node)
        {
            DirectedEdgeStar deStar = node.OutEdges;
            PolygonizeDirectedEdge startDe = null;
            PolygonizeDirectedEdge prevDe = null;

            // the edges are stored in CCW order around the star
            for (IEnumerator i = deStar.Edges.GetEnumerator(); i.MoveNext(); )
            {
                PolygonizeDirectedEdge outDe = (PolygonizeDirectedEdge)i.Current;
                if (outDe.IsMarked) continue;

                if (startDe == null) startDe = outDe;
                if (prevDe != null)
                {
                    PolygonizeDirectedEdge sym = (PolygonizeDirectedEdge)prevDe.Sym;
                    sym.Next = outDe;
                }
                prevDe = outDe;
            }
            if (prevDe != null)
            {
                PolygonizeDirectedEdge sym = (PolygonizeDirectedEdge)prevDe.Sym;
                sym.Next = startDe;
            }
        }
Esempio n. 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pt"></param>
 /// <returns></returns>
 private Node GetNode(Coordinate pt)
 {
     Node node = FindNode(pt);
     if (node == null)
     {
         node = new Node(pt);
         // ensure node is only added once to graph
         Add(node);
     }
     return node;
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="node"></param>
 private void BuildEdgeStringsStartingAt(Node node)
 {
     IEnumerator i = node.OutEdges.GetEnumerator();
     while (i.MoveNext())
     {
         LineMergeDirectedEdge directedEdge = (LineMergeDirectedEdge)i.Current;
         if (directedEdge.Edge.IsMarked)
             continue;
         _edgeStrings.Add(BuildEdgeStringStartingWith(directedEdge));
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Returns all Edges that connect the two nodes (which are assumed to be different).
 /// </summary>
 /// <param name="node0"></param>
 /// <param name="node1"></param>
 /// <returns></returns>
 public static IList GetEdgesBetween(Node node0, Node node1)
 {
     IList edges0 = DirectedEdge.ToEdges(node0.OutEdges.Edges);
     ISet commonEdges = new HashedSet(edges0);
     IList edges1 = DirectedEdge.ToEdges(node1.OutEdges.Edges);
     commonEdges.RetainAll(edges1);
     return new ArrayList(commonEdges);
 }
Esempio n. 11
0
 /// <summary>
 /// Adds a node to the map, replacing any that is already at that location.
 /// Only subclasses can add Nodes, to ensure Nodes are of the right type.
 /// </summary>
 /// <param name="node"></param>
 protected virtual void Add(Node node)
 {
     _nodeMap.Add(node);
 }
Esempio n. 12
0
        /// <summary>
        /// Removes a node from the graph, along with any associated DirectedEdges and
        /// Edges.
        /// </summary>
        /// <param name="node"></param>
        public virtual void Remove(Node node)
        {
            // unhook all directed edges
            IList outEdges = node.OutEdges.Edges;
            for (IEnumerator i = outEdges.GetEnumerator(); i.MoveNext(); )
            {
                DirectedEdge de = (DirectedEdge)i.Current;
                DirectedEdge sym = de.Sym;
                // remove the diredge that points to this node
                if (sym != null)
                    Remove(sym);
                // remove this diredge from the graph collection
                _dirEdges.Remove(de);

                Edge edge = de.Edge;
                if (edge != null)
                    _edges.Remove(edge);
            }
            // remove the node from the graph
            _nodeMap.Remove(node.Coordinate);
            node.Remove();
        }
Esempio n. 13
0
 /// <summary>
 /// Returns all Edges that connect the two nodes (which are assumed to be different).
 /// </summary>
 /// <param name="node0"></param>
 /// <param name="node1"></param>
 /// <returns></returns>
 public static IList GetEdgesBetween(Node node0, Node node1)
 {
     var edges0 = DirectedEdge.ToEdges(node0.OutEdges.Edges);
     var edges1 = DirectedEdge.ToEdges(node1.OutEdges.Edges);
     var toRemove = edges1.Cast<Edge>().Where(edges0.Contains).ToList();
     foreach (var edge in toRemove)
     {
         edges0.Remove(edge);
     }
     return edges0;
 }
 /// <summary>
 /// Constructs a directed edge connecting the <c>from</c> node to the
 /// <c>to</c> node.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <param name="directionPt">
 /// Specifies this DirectedEdge's direction (given by an imaginary
 /// line from the <c>from</c> node to <c>directionPt</c>).
 /// </param>
 /// <param name="edgeDirection">
 /// Whether this DirectedEdge's direction is the same as or
 /// opposite to that of the parent Edge (if any).
 /// </param>
 public PolygonizeDirectedEdge(Node from, Node to, Coordinate directionPt, bool edgeDirection)
     : base(from, to, directionPt, edgeDirection) { }
 /// <summary>
 /// Constructs a LineMergeDirectedEdge connecting the <c>from</c> node to the <c>to</c> node.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <param name="directionPt">
 /// specifies this DirectedEdge's direction (given by an imaginary
 /// line from the <c>from</c> node to <c>directionPt</c>).
 /// </param>
 /// <param name="edgeDirection">
 /// whether this DirectedEdge's direction is the same as or
 /// opposite to that of the parent Edge (if any).
 /// </param>
 public LineMergeDirectedEdge(Node from, Node to, Coordinate directionPt, bool edgeDirection)
     : base(from, to, directionPt, edgeDirection) { }