GEOS 3.14.0dev
ConcaveHullOfPolygons.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2022 Paul Ramsey <pramsey@cleverelephant.ca>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/triangulate/tri/TriList.h>
18#include <geos/triangulate/tri/Tri.h>
19
20#include <set>
21#include <deque>
22#include <map>
23
24namespace geos {
25namespace geom {
26class Coordinate;
27class CoordinateSequence;
28class Envelope;
29class Geometry;
30class GeometryCollection;
31class GeometryFactory;
32class LinearRing;
33class Polygon;
34}
35namespace triangulate {
36namespace tri {
37class Tri;
38}
39}
40}
41
42namespace geos {
43namespace algorithm { // geos::algorithm
44namespace hull { // geos::algorithm::hull
45
46
83class GEOS_DLL ConcaveHullOfPolygons {
93 template<typename TriType>
95
96private:
97
98 /* Members */
99
100 static constexpr int FRAME_EXPAND_FACTOR = 4;
101
102 const Geometry* inputPolygons;
103 const GeometryFactory* geomFactory;
104 double maxEdgeLength;
105 double maxEdgeLengthRatio;
106 bool isHolesAllowed;
107 bool isTight;
108
109 std::set<Tri*> hullTris;
110 std::deque<Tri*> borderTriQue;
111 std::vector<const LinearRing*> polygonRings;
112 TriList<Tri> triList;
113
118 std::map<Tri*, TriIndex> borderEdgeMap;
119
120 /* Methods */
121
122 std::unique_ptr<Geometry> createEmptyHull();
123
124 void buildHullTris();
125
137 std::unique_ptr<Polygon> createFrame(
138 const Envelope* polygonsEnv);
139
140 double computeTargetEdgeLength(
141 TriList<Tri>& triList,
142 const CoordinateSequence* frameCorners,
143 double edgeLengthRatio) const;
144
145 bool isFrameTri(
146 const Tri* tri,
147 const CoordinateSequence* frameCorners) const;
148
149 void removeFrameCornerTris(
150 TriList<Tri>& tris,
151 const CoordinateSequence* frameCorners);
152
161 TriIndex vertexIndex(
162 const Tri* tri,
163 const CoordinateSequence* pts) const;
164
165 void removeBorderTris();
166
167 void removeHoleTris();
168
169 Tri* findHoleSeedTri() const;
170
171 bool isHoleSeedTri(const Tri* tri) const;
172
173 bool isBorderTri(const Tri* tri) const;
174
175 bool isRemovable(const Tri* tri) const;
176
186 bool isTouchingSinglePolygon(const Tri* tri) const;
187
188 void addBorderTris(Tri* tri);
189
202 void addBorderTri(Tri* tri, TriIndex index);
203
204 void removeBorderTri(Tri* tri);
205
206 bool hasAllVertices(const LinearRing* ring, const Tri* tri) const;
207
208 bool hasVertex(const LinearRing* ring, const Coordinate& v) const;
209
210 void envelope(const Tri* tri, Envelope& env) const;
211
212 std::unique_ptr<Geometry> createHullGeometry(bool isIncludeInput);
213
214
215public:
216
225 static std::unique_ptr<Geometry>
226 concaveHullByLength(const Geometry* polygons, double maxLength);
227
240 static std::unique_ptr<Geometry>
242 const Geometry* polygons, double maxLength,
243 bool isTight, bool isHolesAllowed);
244
253 static std::unique_ptr<Geometry>
254 concaveHullByLengthRatio(const Geometry* polygons, double lengthRatio);
255
268 static std::unique_ptr<Geometry>
270 const Geometry* polygons, double lengthRatio,
271 bool isTight, bool isHolesAllowed);
272
281 static std::unique_ptr<Geometry>
282 concaveFillByLength(const Geometry* polygons, double maxLength);
283
292 static std::unique_ptr<Geometry>
293 concaveFillByLengthRatio(const Geometry* polygons, double lengthRatio);
294
301
315 void setMaximumEdgeLength(double edgeLength);
316
331 void setMaximumEdgeLengthRatio(double edgeLengthRatio);
332
338 void setHolesAllowed(bool p_isHolesAllowed);
339
346 void setTight(bool p_isTight);
347
353 std::unique_ptr<Geometry> getHull();
354
361 std::unique_ptr<Geometry> getFill();
362
363
364};
365
366
367
368} // geos::algorithm::hull
369} // geos::algorithm
370} // geos
Definition ConcaveHullOfPolygons.h:83
std::unique_ptr< Geometry > getFill()
static std::unique_ptr< Geometry > concaveHullByLengthRatio(const Geometry *polygons, double lengthRatio, bool isTight, bool isHolesAllowed)
static std::unique_ptr< Geometry > concaveHullByLength(const Geometry *polygons, double maxLength, bool isTight, bool isHolesAllowed)
static std::unique_ptr< Geometry > concaveHullByLength(const Geometry *polygons, double maxLength)
static std::unique_ptr< Geometry > concaveHullByLengthRatio(const Geometry *polygons, double lengthRatio)
void setMaximumEdgeLength(double edgeLength)
static std::unique_ptr< Geometry > concaveFillByLengthRatio(const Geometry *polygons, double lengthRatio)
std::unique_ptr< Geometry > getHull()
void setHolesAllowed(bool p_isHolesAllowed)
void setMaximumEdgeLengthRatio(double edgeLengthRatio)
static std::unique_ptr< Geometry > concaveFillByLength(const Geometry *polygons, double maxLength)
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
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
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Definition TriList.h:50
Definition Tri.h:45
Basic namespace for all GEOS functionalities.
Definition geos.h:39