Search in sources :

Example 6 with DirectedEdge

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;
}
Also used : PointList(com.revolsys.geometry.model.PointList) DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge)

Example 7 with DirectedEdge

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);
}
Also used : DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge) LineString(com.revolsys.geometry.model.LineString) Node(com.revolsys.geometry.planargraph.Node) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.planargraph.Edge) DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge)

Example 8 with DirectedEdge

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);
            }
        }
    }
}
Also used : DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge) Node(com.revolsys.geometry.planargraph.Node) Point(com.revolsys.geometry.model.Point)

Example 9 with DirectedEdge

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;
}
Also used : DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge) Node(com.revolsys.geometry.planargraph.Node) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList)

Example 10 with DirectedEdge

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;
}
Also used : DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge)

Aggregations

DirectedEdge (com.revolsys.geometry.planargraph.DirectedEdge)13 Node (com.revolsys.geometry.planargraph.Node)9 LineString (com.revolsys.geometry.model.LineString)3 Point (com.revolsys.geometry.model.Point)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 ListIterator (java.util.ListIterator)3 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)2 Edge (com.revolsys.geometry.planargraph.Edge)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 PointList (com.revolsys.geometry.model.PointList)1