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);
}
}
}
}
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);
}
}
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);
}
}
}
Aggregations