/** * Removes an {@link Edge} and its associated {@link DirectedEdge}s * from their from-Nodes and from the graph. * Note: This method does not remove the {@link Node}s associated * with the {@link Edge}, even if the removal of the {@link Edge} * reduces the degree of a {@link Node} to zero. */ public void remove(Edge edge) { remove(edge.getDirEdge(0)); remove(edge.getDirEdge(1)); edges.remove(edge); edge.remove(); }
private void buildEdgeStringsStartingAt(Node node) { for (Iterator i = node.getOutEdges().iterator(); i.hasNext(); ) { LineMergeDirectedEdge directedEdge = (LineMergeDirectedEdge) i.next(); if (directedEdge.getEdge().isMarked()) { continue; } edgeStrings.add(buildEdgeStringStartingWith(directedEdge)); } }
/** * 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(Node node) { DirectedEdge wellOrientedDE = null; DirectedEdge unvisitedDE = null; for (Iterator i = node.getOutEdges().iterator(); i.hasNext(); ) { DirectedEdge de = (DirectedEdge) i.next(); if (! de.getEdge().isVisited()) { unvisitedDE = de; if (de.getEdgeDirection()) wellOrientedDE = de; } } if (wellOrientedDE != null) return wellOrientedDE; return unvisitedDE; }
/** * Constructs an Edge initialized with the given DirectedEdges, and for each * DirectedEdge: sets the Edge, sets the symmetric DirectedEdge, and adds * this Edge to its from-Node. */ public Edge(DirectedEdge de0, DirectedEdge de1) { setDirectedEdges(de0, de1); }
/** * Adds the Edge and its DirectedEdges with this PlanarGraph. * Assumes that the Edge has already been created with its associated DirectEdges. * Only subclasses can add Edges, to ensure the edges added are of the right class. */ protected void add(Edge edge) { edges.add(edge); add(edge.getDirEdge(0)); add(edge.getDirEdge(1)); }
private EdgeString buildEdgeStringStartingWith(LineMergeDirectedEdge start) { EdgeString edgeString = new EdgeString(factory); LineMergeDirectedEdge current = start; do { edgeString.add(current); current.getEdge().setMarked(true); current = current.getNext(); } while (current != null && current != start); return edgeString; }
private void addReverseSubpath(DirectedEdge de, ListIterator lit, boolean expectedClosed) { // trace an unvisited path *backwards* from this de Node endNode = de.getToNode(); Node fromNode = null; while (true) { lit.add(de.getSym()); de.getEdge().setVisited(true); fromNode = de.getFromNode(); 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"); } }
/** * Constructs an Edge initialized with the given DirectedEdges, and for each * DirectedEdge: sets the Edge, sets the symmetric DirectedEdge, and adds * this Edge to its from-Node. */ public Edge(DirectedEdge de0, DirectedEdge de1) { setDirectedEdges(de0, de1); }
/** * Adds an {@link Edge} to the subgraph. * The associated {@link DirectedEdge}s and {@link Node}s * are also added. * * @param e the edge to add */ public void add(Edge e) { if (edges.contains(e)) return; edges.add(e); dirEdges.add(e.getDirEdge(0)); dirEdges.add(e.getDirEdge(1)); nodeMap.add(e.getDirEdge(0).getFromNode()); nodeMap.add(e.getDirEdge(1).getFromNode()); }
private EdgeString buildEdgeStringStartingWith(LineMergeDirectedEdge start) { EdgeString edgeString = new EdgeString(factory); LineMergeDirectedEdge current = start; do { edgeString.add(current); current.getEdge().setMarked(true); current = current.getNext(); } while (current != null && current != start); return edgeString; }
private void addReverseSubpath(DirectedEdge de, ListIterator lit, boolean expectedClosed) { // trace an unvisited path *backwards* from this de Node endNode = de.getToNode(); Node fromNode = null; while (true) { lit.add(de.getSym()); de.getEdge().setVisited(true); fromNode = de.getFromNode(); 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"); } }
/** * Removes an {@link Edge} and its associated {@link DirectedEdge}s * from their from-Nodes and from the graph. * Note: This method does not remove the {@link Node}s associated * with the {@link Edge}, even if the removal of the {@link Edge} * reduces the degree of a {@link Node} to zero. */ public void remove(Edge edge) { remove(edge.getDirEdge(0)); remove(edge.getDirEdge(1)); edges.remove(edge); edge.remove(); }
/** * Add a {@link LineString} forming an edge of the polygon graph. * @param line the line to add */ public void addEdge(LineString line) { if (line.isEmpty()) { return; } Coordinate[] linePts = CoordinateArrays.removeRepeatedPoints(line.getCoordinates()); if (linePts.length < 2) { return; } Coordinate startPt = linePts[0]; Coordinate endPt = linePts[linePts.length - 1]; Node nStart = getNode(startPt); Node nEnd = getNode(endPt); DirectedEdge de0 = new PolygonizeDirectedEdge(nStart, nEnd, linePts[1], true); DirectedEdge de1 = new PolygonizeDirectedEdge(nEnd, nStart, linePts[linePts.length - 2], false); Edge edge = new PolygonizeEdge(line); edge.setDirectedEdges(de0, de1); add(edge); }
public List getConnectedSubgraphs() { List subgraphs = new ArrayList(); GraphComponent.setVisited(graph.nodeIterator(), false); for (Iterator i = graph.edgeIterator(); i.hasNext(); ) { Edge e = (Edge) i.next(); Node node = e.getDirEdge(0).getFromNode(); if (! node.isVisited()) { subgraphs.add(findSubgraph(node)); } } return subgraphs; }
private void buildEdgeStringsStartingAt(Node node) { for (Iterator i = node.getOutEdges().iterator(); i.hasNext(); ) { LineMergeDirectedEdge directedEdge = (LineMergeDirectedEdge) i.next(); if (directedEdge.getEdge().isMarked()) { continue; } edgeStrings.add(buildEdgeStringStartingWith(directedEdge)); } }
/** * 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(Node node) { DirectedEdge wellOrientedDE = null; DirectedEdge unvisitedDE = null; for (Iterator i = node.getOutEdges().iterator(); i.hasNext(); ) { DirectedEdge de = (DirectedEdge) i.next(); if (! de.getEdge().isVisited()) { unvisitedDE = de; if (de.getEdgeDirection()) wellOrientedDE = de; } } if (wellOrientedDE != null) return wellOrientedDE; return unvisitedDE; }
/** * 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 lineString the linestring to add to the graph */ public void addEdge(LineString lineString) { if (lineString.isEmpty()) { return; } Coordinate[] coordinates = CoordinateArrays.removeRepeatedPoints(lineString.getCoordinates()); // don't add lines with all coordinates equal if (coordinates.length <= 1) return; Coordinate startCoordinate = coordinates[0]; Coordinate endCoordinate = coordinates[coordinates.length - 1]; Node startNode = getNode(startCoordinate); Node endNode = getNode(endCoordinate); DirectedEdge directedEdge0 = new LineMergeDirectedEdge(startNode, endNode, coordinates[1], true); DirectedEdge directedEdge1 = new LineMergeDirectedEdge(endNode, startNode, coordinates[coordinates.length - 2], false); Edge edge = new LineMergeEdge(lineString); edge.setDirectedEdges(directedEdge0, directedEdge1); add(edge); }
/** * Adds the Edge and its DirectedEdges with this PlanarGraph. * Assumes that the Edge has already been created with its associated DirectEdges. * Only subclasses can add Edges, to ensure the edges added are of the right class. */ protected void add(Edge edge) { edges.add(edge); add(edge.getDirEdge(0)); add(edge.getDirEdge(1)); }
/** * Add a {@link LineString} forming an edge of the polygon graph. * @param line the line to add */ public void addEdge(LineString line) { if (line.isEmpty()) { return; } Coordinate[] linePts = CoordinateArrays.removeRepeatedPoints(line.getCoordinates()); if (linePts.length < 2) { return; } Coordinate startPt = linePts[0]; Coordinate endPt = linePts[linePts.length - 1]; Node nStart = getNode(startPt); Node nEnd = getNode(endPt); DirectedEdge de0 = new PolygonizeDirectedEdge(nStart, nEnd, linePts[1], true); DirectedEdge de1 = new PolygonizeDirectedEdge(nEnd, nStart, linePts[linePts.length - 2], false); Edge edge = new PolygonizeEdge(line); edge.setDirectedEdges(de0, de1); add(edge); }
/** * Adds an {@link Edge} to the subgraph. * The associated {@link DirectedEdge}s and {@link Node}s * are also added. * * @param e the edge to add */ public void add(Edge e) { if (edges.contains(e)) return; edges.add(e); dirEdges.add(e.getDirEdge(0)); dirEdges.add(e.getDirEdge(1)); nodeMap.add(e.getDirEdge(0).getFromNode()); nodeMap.add(e.getDirEdge(1).getFromNode()); }