private static int MinDistToMapEdge(PlanarGraph graph, Node n, int limit)
        {
            if (n.Coordinate.X == 0 || n.Coordinate.X == Size ||
                n.Coordinate.Y == 0 || n.Coordinate.Y == Size)
                return 0;

            int ret = int.MaxValue;
            Stack<Tuple<int, Node>> stack = new Stack<Tuple<int, Node>>();
            HashSet<Node> visited = new HashSet<Node>();
            stack.Push(new Tuple<int, Node>(0, n));
            do
            {
                Tuple<int, Node> state = stack.Pop();
                if (state.Item2.Coordinate.X == 0 || state.Item2.Coordinate.X == Size ||
                    state.Item2.Coordinate.Y == 0 || state.Item2.Coordinate.Y == Size)
                {
                    if (state.Item1 < ret)
                        ret = state.Item1;
                    if (ret == 0) return 0;

                    continue;
                }
                visited.Add(state.Item2);

                if (state.Item1 > limit) continue;
                foreach (EdgeEnd i in state.Item2.Edges)
                {
                    Node node = graph.Find(i.DirectedCoordinate);
                    if (!visited.Contains(node))
                        stack.Push(new Tuple<int, Node>(state.Item1 + 1, node));
                }
            } while (stack.Count > 0);
            return ret;
        }
 /// <summary>
 /// Adds all nodes and edges reachable from this node to the subgraph.
 /// Uses an explicit stack to avoid a large depth of recursion.
 /// </summary>
 /// <param name="startNode">A node known to be in the subgraph.</param>
 private void AddReachable(Node startNode)
 {
     Stack<Node> nodeStack = new Stack<Node>();
     nodeStack.Push(startNode);
     while (nodeStack.Count != 0) 
     {
         Node node = nodeStack.Pop();
         Add(node, nodeStack);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="n"></param>
 /// <returns></returns>
 public Node AddNode(Node n)
 {
     Node node = _nodeMap[n.Coordinate];
     if (node == null)
     {
         _nodeMap.Add(n.Coordinate, n);
         return n;
     }
     node.MergeLabel(n);
     return node;
 }
 /// <summary>
 /// Label an isolated node with its relationship to the target point.
 /// </summary>
 /// <param name="n"></param>
 /// <param name="targetIndex"></param>
 private void LabelIsolatedNode(Node n, int targetIndex)
 {
     Location loc = _ptLocator.Locate(n.Coordinate, _arg[targetIndex].Geometry);
     n.Label.SetAllLocations(targetIndex, loc);        
 }
Esempio n. 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="n"></param>
 public void MergeLabel(Node n)
 {
     MergeLabel(n.Label);
 }
Esempio n. 6
0
 /// <summary>
 /// Converts non-covered nodes to Point objects and adds them to the result.
 /// </summary>
 /// <remarks>
 /// A node is covered if it is contained in another element Geometry
 /// with higher dimension (e.g. a node point might be contained in a polygon,
 /// in which case the point can be eliminated from the result).
 /// </remarks>
 /// <param name="n">The node to test</param>
 private void FilterCoveredNodeToPoint(Node n)
 {
     Coordinate coord = n.Coordinate;
     if (!_op.IsCoveredByLA(coord))
     {
         var pt = _geometryFactory.CreatePoint(coord);
         _resultPointList.Add(pt);
     }
 }
 /// <summary>
 /// Adds the argument node and all its out edges to the subgraph
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <param name="nodeStack">The current set of nodes being traversed.</param>
 private void Add(Node node, Stack<Node> nodeStack)
 {
     node.Visited = true;
     _nodes.Add(node);
     foreach (DirectedEdge de in (DirectedEdgeStar)node.Edges)
     {
         _dirEdgeList.Add(de);
         DirectedEdge sym = de.Sym;
         Node symNode = sym.Node;
         /*
         * NOTE: this is a depth-first traversal of the graph.
         * This will cause a large depth of recursion.
         * It might be better to do a breadth-first traversal.
         */
         if (! symNode.IsVisited)
             nodeStack.Push(symNode);
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="n"></param>
        private static void ComputeNodeDepth(Node n)
        {
            // find a visited dirEdge to start at
            DirectedEdge startEdge = null;
            foreach (DirectedEdge de in (DirectedEdgeStar)n.Edges)
            {
                if (de.IsVisited || de.Sym.IsVisited)
                {
                    startEdge = de;
                    break;
                }
            }

            // MD - testing  Result: breaks algorithm
            // only compute string append if assertion would fail
            if (startEdge == null)
                //Assert.IsTrue(false, "unable to find edge to compute depths at " + n.Coordinate);
                throw new TopologyException("unable to find edge to compute depths at " + n.Coordinate);

            ((DirectedEdgeStar) n.Edges).ComputeDepths(startEdge);

            // copy depths to sym edges
            foreach (DirectedEdge de in (DirectedEdgeStar)n.Edges)
            {
                de.Visited = true;
                CopySymDepths(de);
            }
        }
 /// <summary>
 /// Creates the subgraph consisting of all edges reachable from this node.
 /// Finds the edges in the graph and the rightmost coordinate.
 /// </summary>
 /// <param name="node">A node to start the graph traversal from.</param>
 public void Create(Node node)
 {
     AddReachable(node);
     _finder.FindEdge(_dirEdgeList);
     _rightMostCoord = _finder.Coordinate;
 }
Esempio n. 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public Node AddNode(Node node) 
 { 
     return _nodes.AddNode(node); 
 }