use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class LineMergeGraph method addEdge.
/**
* Adds an Edge, DirectedEdges, and Nodes for the given LineString representation
* of an edge.
* Empty lines or lines with all coordinates equal are not added.
*
* @param line the linestring to add to the graph
*/
public void addEdge(final LineString line) {
if (line.isEmpty()) {
return;
}
final LineString points = line.removeDuplicatePoints();
final int vertexCount = points.getVertexCount();
if (vertexCount > 1) {
final Point fromPoint = points.getPoint(0);
final Point toPoint = points.getPoint(vertexCount - 1);
final Node startNode = getNode(fromPoint);
final Node endNode = getNode(toPoint);
final DirectedEdge directedEdge0 = new LineMergeDirectedEdge(startNode, endNode, points.getPoint(1).newPoint(), true);
final DirectedEdge directedEdge1 = new LineMergeDirectedEdge(endNode, startNode, points.getPoint(vertexCount - 2).newPoint(), false);
final Edge edge = new LineMergeEdge(line);
edge.setDirectedEdges(directedEdge0, directedEdge1);
add(edge);
}
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class LineSequencer method orient.
/**
* Computes a version of the sequence which is optimally
* oriented relative to the underlying geometry.
* <p>
* Heuristics used are:
* <ul>
* <li>If the path has a degree-1 node which is the start
* node of an linestring, use that node as the start of the sequence
* <li>If the path has a degree-1 node which is the end
* node of an linestring, use that node as the end of the sequence
* <li>If the sequence has no degree-1 nodes, use any node as the start
* (NOTE: in this case could orient the sequence according to the majority of the
* linestring orientations)
* </ul>
*
* @param seq a List of DirectedEdges
* @return a List of DirectedEdges oriented appropriately
*/
private List orient(final List seq) {
final DirectedEdge startEdge = (DirectedEdge) seq.get(0);
final DirectedEdge endEdge = (DirectedEdge) seq.get(seq.size() - 1);
final Node startNode = startEdge.getFromNode();
final Node endNode = endEdge.getToNode();
boolean flipSeq = false;
final boolean hasDegree1Node = startNode.getDegree() == 1 || endNode.getDegree() == 1;
if (hasDegree1Node) {
boolean hasObviousStartNode = false;
// (ie. if both are good starts, pick the actual start
if (endEdge.getToNode().getDegree() == 1 && endEdge.getEdgeDirection() == false) {
hasObviousStartNode = true;
flipSeq = true;
}
if (startEdge.getFromNode().getDegree() == 1 && startEdge.getEdgeDirection() == true) {
hasObviousStartNode = true;
flipSeq = false;
}
// since there is no obvious start node, use any node of degree 1
if (!hasObviousStartNode) {
// check if the start node should actually be the end node
if (startEdge.getFromNode().getDegree() == 1) {
flipSeq = true;
// if the end node is of degree 1, it is properly the end node
}
}
}
if (flipSeq) {
return reverse(seq);
}
return seq;
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class LineSequencer method findLowestDegreeNode.
private static Node findLowestDegreeNode(final Subgraph graph) {
int minDegree = Integer.MAX_VALUE;
Node minDegreeNode = null;
for (final Iterator i = graph.nodeIterator(); i.hasNext(); ) {
final Node node = (Node) i.next();
if (minDegreeNode == null || node.getDegree() < minDegree) {
minDegree = node.getDegree();
minDegreeNode = node;
}
}
return minDegreeNode;
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class LineSequencer method addReverseSubpath.
private void addReverseSubpath(DirectedEdge de, final ListIterator lit, final boolean expectedClosed) {
// trace an unvisited path *backwards* from this de
final Node endNode = de.getToNode();
Node fromNode = null;
while (true) {
lit.add(de.getSym());
de.getEdge().setVisited(true);
fromNode = de.getFromNode();
final DirectedEdge unvisitedOutDE = findUnvisitedBestOrientedDE(fromNode);
// this must terminate, since we are continually marking edges as visited
if (unvisitedOutDE == null) {
break;
}
de = unvisitedOutDE.getSym();
}
if (expectedClosed) {
// the path should end at the toNode of this de, otherwise we have an
// error
Assert.isTrue(fromNode == endNode, "path not contiguous");
}
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class PolygonizeGraph method findIntersectionNodes.
// private List labelledRings;
/**
* Finds all nodes in a maximal edgering which are self-intersection nodes
* @param startDE
* @param label
* @return the list of intersection nodes found,
* or <code>null</code> if no intersection nodes were found
*/
private static List findIntersectionNodes(final PolygonizeDirectedEdge startDE, final long label) {
PolygonizeDirectedEdge de = startDE;
List intNodes = null;
do {
final Node node = de.getFromNode();
if (getDegree(node, label) > 1) {
if (intNodes == null) {
intNodes = new ArrayList();
}
intNodes.add(node);
}
de = de.getNext();
Assert.isTrue(de != null, "found null DE in ring");
Assert.isTrue(de == startDE || !de.isInRing(), "found DE already in ring");
} while (de != startDE);
return intNodes;
}
Aggregations