use of com.revolsys.geometry.planargraph.DirectedEdge in project com.revolsys.open by revolsys.
the class EdgeRing method getCoordinates.
/**
* Computes the list of coordinates which are contained in this ring.
* The coordinatea are computed once only and cached.
*
* @return an array of the {@link Coordinates}s in this ring
*/
private Point[] getCoordinates() {
if (this.ringPts == null) {
final PointList coordList = new PointList();
for (final DirectedEdge de : this.deList) {
final PolygonizeEdge edge = (PolygonizeEdge) de.getEdge();
addEdge(edge.getLine(), de.getEdgeDirection(), coordList);
}
this.ringPts = coordList.toPointArray();
}
return this.ringPts;
}
use of com.revolsys.geometry.planargraph.DirectedEdge in project com.revolsys.open by revolsys.
the class PolygonizeGraph method addEdge.
/**
* Add a {@link LineString} forming an edge of the polygon graph.
* @param line the line to add
*/
public void addEdge(final LineString line) {
final LineString cleanLine = line.removeDuplicatePoints();
if (cleanLine.isEmpty()) {
return;
}
if (cleanLine.getVertexCount() < 2) {
return;
}
final Point startPt = cleanLine.getVertex(0).newPoint2D();
final Point endPt = cleanLine.getToVertex(0).newPoint2D();
final Node nStart = getNode(startPt);
final Node nEnd = getNode(endPt);
final DirectedEdge de0 = new PolygonizeDirectedEdge(nStart, nEnd, cleanLine.getVertex(1).newPoint2D(), true);
final DirectedEdge de1 = new PolygonizeDirectedEdge(nEnd, nStart, cleanLine.getVertex(-2).newPoint2D(), false);
final Edge edge = new PolygonizeEdge(line);
edge.setDirectedEdges(de0, de1);
add(edge);
}
use of com.revolsys.geometry.planargraph.DirectedEdge in project com.revolsys.open by revolsys.
the class LineMergeGraph method removeEdge.
public void removeEdge(final LineString line) {
final Point point = line.getFromPoint();
final Node node = findNode(point);
if (node != null) {
for (final DirectedEdge outEdge : Lists.toArray(node.getOutEdges())) {
final LineMergeEdge edge = (LineMergeEdge) outEdge.getEdge();
if (line.equals(edge.getLine())) {
remove(edge);
}
}
}
}
use of com.revolsys.geometry.planargraph.DirectedEdge in project com.revolsys.open by revolsys.
the class LineSequencer method findSequence.
private List findSequence(final Subgraph graph) {
GraphComponent.setVisited(graph.edgeIterator(), false);
final Node startNode = findLowestDegreeNode(graph);
final DirectedEdge startDE = startNode.getOutEdges().iterator().next();
final DirectedEdge startDESym = startDE.getSym();
final List seq = new LinkedList();
final ListIterator lit = seq.listIterator();
addReverseSubpath(startDESym, lit, false);
while (lit.hasPrevious()) {
final DirectedEdge prev = (DirectedEdge) lit.previous();
final DirectedEdge unvisitedOutDE = findUnvisitedBestOrientedDE(prev.getFromNode());
if (unvisitedOutDE != null) {
addReverseSubpath(unvisitedOutDE.getSym(), lit, true);
}
}
/**
* At this point, we have a valid sequence of graph DirectedEdges, but it
* is not necessarily appropriately oriented relative to the underlying
* geometry.
*/
final List orientedSeq = orient(seq);
return orientedSeq;
}
use of com.revolsys.geometry.planargraph.DirectedEdge in project com.revolsys.open by revolsys.
the class LineSequencer method findUnvisitedBestOrientedDE.
/**
* Finds an {@link DirectedEdge} for an unvisited edge (if any),
* choosing the dirEdge which preserves orientation, if possible.
*
* @param node the node to examine
* @return the dirEdge found, or <code>null</code> if none were unvisited
*/
private static DirectedEdge findUnvisitedBestOrientedDE(final Node node) {
DirectedEdge wellOrientedDE = null;
DirectedEdge unvisitedDE = null;
for (final Object element : node.getOutEdges()) {
final DirectedEdge de = (DirectedEdge) element;
if (!de.getEdge().isVisited()) {
unvisitedDE = de;
if (de.getEdgeDirection()) {
wellOrientedDE = de;
}
}
}
if (wellOrientedDE != null) {
return wellOrientedDE;
}
return unvisitedDE;
}
Aggregations