Collection<QuadEdge> quadEdges = qes.getEdges(); List<QuadEdgeTriangle> qeTriangles = QuadEdgeTriangle.createOn(qes); Collection<com.vividsolutions.jts.triangulate.quadedge.Vertex> qeVertices = qes.getVertices(false); if (qes.isFrameBorderEdge(qe)) { qeFrameBorder.add(qe); if (qes.isFrameEdge(qe)) { qeFrame.add(qe); qes.delete(qe);
/** * Gets the geometry for the edges in the subdivision as a {@link MultiLineString} * containing 2-point lines. * * @param geomFact the GeometryFactory to use * @return a MultiLineString */ public Geometry getEdges(GeometryFactory geomFact) { List quadEdges = getPrimaryEdges(false); LineString[] edges = new LineString[quadEdges.size()]; int i = 0; for (Iterator it = quadEdges.iterator(); it.hasNext();) { QuadEdge qe = (QuadEdge) it.next(); edges[i++] = geomFact.createLineString(new Coordinate[] { qe.orig().getCoordinate(), qe.dest().getCoordinate() }); } return geomFact.createMultiLineString(edges); }
/** * Gets the geometry for the triangles in a triangulated subdivision as a {@link GeometryCollection} * of triangular {@link Polygon}s. * * @param geomFact the GeometryFactory to use * @return a GeometryCollection of triangular Polygons */ public Geometry getTriangles(GeometryFactory geomFact) { List triPtsList = getTriangleCoordinates(false); Polygon[] tris = new Polygon[triPtsList.size()]; int i = 0; for (Iterator it = triPtsList.iterator(); it.hasNext();) { Coordinate[] triPt = (Coordinate[]) it.next(); tris[i++] = geomFact .createPolygon(geomFact.createLinearRing(triPt), null); } return geomFact.createGeometryCollection(tris); }
/** * Gets a List of {@link Polygon}s for the Voronoi cells * of this triangulation. * <p> * The userData of each polygon is set to be the {@link Coordinate} * of the cell site. This allows easily associating external * data associated with the sites to the cells. * * @param geomFact a geometry factory * @return a List of Polygons */ public List getVoronoiCellPolygons(GeometryFactory geomFact) { /* * Compute circumcentres of triangles as vertices for dual edges. * Precomputing the circumcentres is more efficient, * and more importantly ensures that the computed centres * are consistent across the Voronoi cells. */ visitTriangles(new TriangleCircumcentreVisitor(), true); List cells = new ArrayList(); Collection edges = getVertexUniqueEdges(false); for (Iterator i = edges.iterator(); i.hasNext(); ) { QuadEdge qe = (QuadEdge) i.next(); cells.add(getVoronoiCellPolygon(qe, geomFact)); } return cells; }
/** * Computes the Delaunay triangulation of the initial sites. */ public void formInitialDelaunay() { computeBoundingBox(); subdiv = new QuadEdgeSubdivision(computeAreaEnv, tolerance); subdiv.setLocator(new LastFoundQuadEdgeLocator(subdiv)); incDel = new IncrementalDelaunayTriangulator(subdiv); insertSites(initialVertices); }
QuadEdge e = subdiv.locate(v); if (subdiv.isVertexOfEdge(e, v)) { else if (subdiv.isOnEdge(e, v.getCoordinate())) { subdiv.delete(e.oNext()); QuadEdge base = subdiv.makeEdge(e.orig(), v); QuadEdge.splice(base, e); QuadEdge startEdge = base; do { base = subdiv.connect(e, base.sym()); e = base.oPrev(); } while (e.lNext() != startEdge);
private QuadEdge findEdge() { Collection edges = subdiv.getEdges(); // assume there is an edge - otherwise will get an exception return (QuadEdge) edges.iterator().next(); }
/** * Gets the coordinates for each triangle in the subdivision as an array. * * @param includeFrame * true if the frame triangles should be included * @return a list of Coordinate[4] representing each triangle */ public List getTriangleCoordinates(boolean includeFrame) { TriangleCoordinatesVisitor visitor = new TriangleCoordinatesVisitor(); visitTriangles(visitor, includeFrame); return visitor.getTriangles(); }
/** * Gets the cells in the Voronoi diagram for this triangulation. * The cells are returned as a {@link GeometryCollection} of {@link Polygon}s * <p> * The userData of each polygon is set to be the {@link Coordinate} * of the cell site. This allows easily associating external * data associated with the sites to the cells. * * @param geomFact a geometry factory * @return a GeometryCollection of Polygons */ public Geometry getVoronoiDiagram(GeometryFactory geomFact) { List vorCells = getVoronoiCellPolygons(geomFact); return geomFact.createGeometryCollection(GeometryFactory.toGeometryArray(vorCells)); }
List<LinearRing> rings = new ArrayList<LinearRing>(); for (QuadEdge e : ((Collection<QuadEdge>) triangulation.getPrimaryEdges(true))) { processQ.add(e); if (triangulation.isFrameVertex(e.orig())) { cC = moveEpsilonTowards(e.dest().getCoordinate(), e.orig().getCoordinate()); } else if (triangulation.isFrameVertex(e.dest())) { cC = moveEpsilonTowards(e.orig().getCoordinate(), e.dest().getCoordinate()); } else {
triEdges[edgeCount] = curr; if (isFrameEdge(curr)) isFrame = true;
/** * Tests whether a QuadEdge is an edge incident on a frame triangle vertex. * * @param e * the edge to test * @return true if the edge is connected to the frame triangle */ public boolean isFrameEdge(QuadEdge e) { if (isFrameVertex(e.orig()) || isFrameVertex(e.dest())) return true; return false; }
/** * Tests whether a QuadEdge is an edge on the border of the frame facets and * the internal facets. E.g. an edge which does not itself touch a frame * vertex, but which touches an edge which does. * * @param e * the edge to test * @return true if the edge is on the border of the frame */ public boolean isFrameBorderEdge(QuadEdge e) { // MD debugging QuadEdge[] leftTri = new QuadEdge[3]; getTriangleEdges(e, leftTri); // System.out.println(new QuadEdgeTriangle(leftTri).toString()); QuadEdge[] rightTri = new QuadEdge[3]; getTriangleEdges(e.sym(), rightTri); // System.out.println(new QuadEdgeTriangle(rightTri).toString()); // check other vertex of triangle to left of edge Vertex vLeftTriOther = e.lNext().dest(); if (isFrameVertex(vLeftTriOther)) return true; // check other vertex of triangle to right of edge Vertex vRightTriOther = e.sym().lNext().dest(); if (isFrameVertex(vRightTriOther)) return true; return false; }
List<Vertex[]> triangleVertices = (List<Vertex[]>)subdivision.getTriangleVertices(false); for (Vertex[] vs : triangleVertices) { putNeighbours(vs[0], vs[1], nCities); @SuppressWarnings("unchecked") Collection<Polygon> cityVoronoiPolygons = subdivision.getVoronoiCellPolygons(fatory);
public static double interpolateZ(DelaunayTriangulationBuilder triangulation, Coordinate coordinate) { QuadEdgeSubdivision quadEdgeSubdivision = triangulation.getSubdivision(); QuadEdge edge = quadEdgeSubdivision.locate(coordinate); return new Vertex(coordinate.x, coordinate.y) .interpolateZValue(edge.orig(), edge.dest(), edge.oNext().dest()); }
private void create() { if (subdiv != null) return; Envelope siteEnv = envelope(siteCoords); List vertices = toVertices(siteCoords); subdiv = new QuadEdgeSubdivision(siteEnv, tolerance); IncrementalDelaunayTriangulator triangulator = new IncrementalDelaunayTriangulator(subdiv); triangulator.insertSites(vertices); }
QuadEdge e = subdiv.locate(v); if (subdiv.isVertexOfEdge(e, v)) { else if (subdiv.isOnEdge(e, v.getCoordinate())) { subdiv.delete(e.oNext()); QuadEdge base = subdiv.makeEdge(e.orig(), v); QuadEdge.splice(base, e); QuadEdge startEdge = base; do { base = subdiv.connect(e, base.sym()); e = base.oPrev(); } while (e.lNext() != startEdge);
/** * Gets the edges of the computed triangulation as a {@link MultiLineString}. * * @param geomFact the geometry factory to use to create the output * @return the edges of the triangulation */ public Geometry getEdges(GeometryFactory geomFact) { create(); return subdiv.getEdges(geomFact); }
/** * Gets a list of the triangles in the subdivision, * specified as an array of the triangle {@link Vertex}es. * * @param includeFrame * true if the frame triangles should be included * @return a List of Vertex[3] arrays */ public List getTriangleVertices(boolean includeFrame) { TriangleVertexListVisitor visitor = new TriangleVertexListVisitor(); visitTriangles(visitor, includeFrame); return visitor.getTriangleVertices(); }