GEOS 3.14.0dev
VoronoiDiagramBuilder.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2012 Excensus LLC.
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: triangulate/VoronoiDiagramBuilder.java r524
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/triangulate/quadedge/QuadEdgeSubdivision.h>
22#include <geos/geom/Envelope.h> // for composition
23#include <memory>
24#include <iostream>
25#include <unordered_map>
26
27namespace geos {
28namespace geom {
29class Geometry;
30class CoordinateSequence;
31class GeometryCollection;
32class GeometryFactory;
33}
34namespace triangulate { //geos.triangulate
35
46class GEOS_DLL VoronoiDiagramBuilder {
47public:
53
54 ~VoronoiDiagramBuilder() = default;
55
62 void setSites(const geom::Geometry& geom);
63
71
81 void setOrdered(bool isOrdered);
82
93 void setClipEnvelope(const geom::Envelope* clipEnv);
94
103 void setTolerance(double tolerance);
104
110 std::unique_ptr<quadedge::QuadEdgeSubdivision> getSubdivision();
111
119 std::unique_ptr<geom::GeometryCollection> getDiagram(const geom::GeometryFactory& geomFact);
120
128 std::unique_ptr<geom::MultiLineString> getDiagramEdges(const geom::GeometryFactory& geomFact);
129
130 void reorderCellsToInput(std::vector<std::unique_ptr<geom::Geometry>> & polys) const;
131
132private:
133 using CoordinateCellMap = std::unordered_map<geom::CoordinateXY, std::unique_ptr<geom::Geometry>, geom::Coordinate::HashCode>;
134
135 std::unique_ptr<geom::CoordinateSequence> siteCoords;
136 double tolerance;
137 std::unique_ptr<quadedge::QuadEdgeSubdivision> subdiv;
138 const geom::Envelope* clipEnv; // externally owned
139 const geom::Geometry* inputGeom;
140 const geom::CoordinateSequence* inputSeq;
141 geom::Envelope diagramEnv;
142 bool isOrdered;
143
144 void create();
145
146 std::size_t getNumInputPoints() const;
147
148 static std::unique_ptr<geom::GeometryCollection>
149 clipGeometryCollection(std::vector<std::unique_ptr<geom::Geometry>> & geoms, const geom::Envelope& clipEnv);
150
151
152 static void addCellsForCoordinates(CoordinateCellMap& cellMap, const geom::Geometry& g, std::vector<std::unique_ptr<geom::Geometry>> & polys);
153 static void addCellsForCoordinates(CoordinateCellMap& cellMap, const geom::CoordinateSequence& g, std::vector<std::unique_ptr<geom::Geometry>> & polys);
154};
155
156} //namespace geos.triangulate
157} //namespace geos
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
A utility class which creates Voronoi Diagrams from collections of points.
Definition VoronoiDiagramBuilder.h:46
void setClipEnvelope(const geom::Envelope *clipEnv)
Sets the envelope to clip the diagram to.
std::unique_ptr< geom::MultiLineString > getDiagramEdges(const geom::GeometryFactory &geomFact)
Gets the edges of the computed diagram as a geom::MultiLineString, clipped as specified.
void setOrdered(bool isOrdered)
Specify whether the geometries in the generated diagram should reflect the order of coordinates in th...
void setSites(const geom::CoordinateSequence &coords)
Sets the sites (point or vertices) which will be diagrammed from a collection of geom::Coordinates.
void setSites(const geom::Geometry &geom)
Sets the sites (point or vertices) which will be diagrammed. All vertices of the given geometry will ...
std::unique_ptr< quadedge::QuadEdgeSubdivision > getSubdivision()
Gets the quadedge::QuadEdgeSubdivision which models the computed diagram.
void setTolerance(double tolerance)
Sets the snapping tolerance which will be used to improved the robustness of the triangulation comput...
VoronoiDiagramBuilder()
Creates a new Voronoi diagram builder.
std::unique_ptr< geom::GeometryCollection > getDiagram(const geom::GeometryFactory &geomFact)
Gets the faces of the computed diagram as a geom::GeometryCollection of geom::Polygons,...
Basic namespace for all GEOS functionalities.
Definition geos.h:39