Search in sources :

Example 6 with DirectedEdgeStar

use of com.revolsys.geometry.geomgraph.DirectedEdgeStar in project com.revolsys.open by revolsys.

the class BufferSubgraph method computeDepths.

/**
 * Compute depths for all dirEdges via breadth-first traversal of nodes in graph
 * @param startEdge edge to start processing with
 */
// <FIX> MD - use iteration & queue rather than recursion, for speed and
// robustness
private void computeDepths(final DirectedEdge startEdge) {
    final Set<Node> nodesVisited = new HashSet<>();
    final LinkedList<Node> nodeQueue = new LinkedList<>();
    final Node startNode = startEdge.getNode();
    nodeQueue.addLast(startNode);
    nodesVisited.add(startNode);
    startEdge.setVisited(true);
    while (!nodeQueue.isEmpty()) {
        // System.out.println(nodes.size() + " queue: " + nodeQueue.size());
        final Node n = nodeQueue.removeFirst();
        nodesVisited.add(n);
        // compute depths around node, starting at this edge since it has depths
        // assigned
        computeNodeDepth(n);
        // unless the node has been visited already
        for (final Object element : (DirectedEdgeStar) n.getEdges()) {
            final DirectedEdge de = (DirectedEdge) element;
            final DirectedEdge sym = de.getSym();
            if (sym.isVisited()) {
                continue;
            }
            final Node adjNode = sym.getNode();
            if (!nodesVisited.contains(adjNode)) {
                nodeQueue.addLast(adjNode);
                nodesVisited.add(adjNode);
            }
        }
    }
}
Also used : DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) DirectedEdgeStar(com.revolsys.geometry.geomgraph.DirectedEdgeStar) Node(com.revolsys.geometry.geomgraph.Node) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 7 with DirectedEdgeStar

use of com.revolsys.geometry.geomgraph.DirectedEdgeStar in project com.revolsys.open by revolsys.

the class BufferSubgraph method computeNodeDepth.

private void computeNodeDepth(final Node n) {
    // find a visited dirEdge to start at
    DirectedEdge startEdge = null;
    for (final Object element : (DirectedEdgeStar) n.getEdges()) {
        final DirectedEdge de = (DirectedEdge) element;
        if (de.isVisited() || de.getSym().isVisited()) {
            startEdge = de;
            break;
        }
    }
    // only compute string append if assertion would fail
    if (startEdge == null) {
        throw new TopologyException("unable to find edge to compute depths at POINT(" + n.getX() + " " + n.getY() + ")");
    }
    ((DirectedEdgeStar) n.getEdges()).computeDepths(startEdge);
    // copy depths to sym edges
    for (final Object element : (DirectedEdgeStar) n.getEdges()) {
        final DirectedEdge de = (DirectedEdge) element;
        de.setVisited(true);
        copySymDepths(de);
    }
}
Also used : DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) DirectedEdgeStar(com.revolsys.geometry.geomgraph.DirectedEdgeStar) TopologyException(com.revolsys.geometry.model.TopologyException)

Example 8 with DirectedEdgeStar

use of com.revolsys.geometry.geomgraph.DirectedEdgeStar in project com.revolsys.open by revolsys.

the class BufferSubgraph method add.

/**
 * Adds the argument node and all its out edges to the subgraph
 * @param node the node to add
 * @param nodeStack the current set of nodes being traversed
 */
private void add(final Node node, final Stack<Node> nodeStack) {
    node.setVisited(true);
    this.nodes.add(node);
    for (final Object element : (DirectedEdgeStar) node.getEdges()) {
        final DirectedEdge de = (DirectedEdge) element;
        this.dirEdgeList.add(de);
        final DirectedEdge sym = de.getSym();
        final Node symNode = sym.getNode();
        /**
         * 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);
        }
    }
}
Also used : DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) DirectedEdgeStar(com.revolsys.geometry.geomgraph.DirectedEdgeStar) Node(com.revolsys.geometry.geomgraph.Node)

Aggregations

DirectedEdgeStar (com.revolsys.geometry.geomgraph.DirectedEdgeStar)8 Node (com.revolsys.geometry.geomgraph.Node)7 DirectedEdge (com.revolsys.geometry.geomgraph.DirectedEdge)5 Label (com.revolsys.geometry.geomgraph.Label)2 Edge (com.revolsys.geometry.geomgraph.Edge)1 TopologyException (com.revolsys.geometry.model.TopologyException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1