GEOS 3.11.1
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
19#include <set>
20#include <deque>
21#include <map>
22
23namespace geos {
24namespace geom {
25class Coordinate;
27class Envelope;
28class Geometry;
30class GeometryFactory;
31class LinearRing;
32class Polygon;
33}
34namespace triangulate {
35namespace tri {
36class Tri;
37}
38}
39}
40
41#include <geos/triangulate/tri/Tri.h>
42
43
54
55
56namespace geos {
57namespace algorithm { // geos::algorithm
58namespace hull { // geos::algorithm::hull
59
60
97class GEOS_DLL ConcaveHullOfPolygons {
98
99private:
100
101 /* Members */
102
103 static constexpr int FRAME_EXPAND_FACTOR = 4;
104
105 const Geometry* inputPolygons;
106 const GeometryFactory* geomFactory;
107 double maxEdgeLength;
108 double maxEdgeLengthRatio;
109 bool isHolesAllowed;
110 bool isTight;
111
112 std::set<Tri*> hullTris;
113 std::deque<Tri*> borderTriQue;
114 std::vector<const LinearRing*> polygonRings;
115 TriList<Tri> triList;
116
121 std::map<Tri*, TriIndex> borderEdgeMap;
122
123 /* Methods */
124
125 std::unique_ptr<Geometry> createEmptyHull();
126
127 static void extractShellRings(
128 const Geometry* polygons,
129 std::vector<const LinearRing*>& rings);
130
131 void buildHullTris();
132
144 std::unique_ptr<Polygon> createFrame(
145 const Envelope* polygonsEnv);
146
147 double computeTargetEdgeLength(
148 TriList<Tri>& triList,
149 const CoordinateSequence* frameCorners,
150 double edgeLengthRatio) const;
151
152 bool isFrameTri(
153 const Tri* tri,
154 const CoordinateSequence* frameCorners) const;
155
156 void removeFrameCornerTris(
157 TriList<Tri>& tris,
158 const CoordinateSequence* frameCorners);
159
168 TriIndex vertexIndex(
169 const Tri* tri,
170 const CoordinateSequence* pts) const;
171
172 void removeBorderTris();
173
174 void removeHoleTris();
175
176 Tri* findHoleSeedTri() const;
177
178 bool isHoleSeedTri(const Tri* tri) const;
179
180 bool isBorderTri(const Tri* tri) const;
181
182 bool isRemovable(const Tri* tri) const;
183
193 bool isTouchingSinglePolygon(const Tri* tri) const;
194
195 void addBorderTris(Tri* tri);
196
209 void addBorderTri(Tri* tri, TriIndex index);
210
211 void removeBorderTri(Tri* tri);
212
213 bool hasAllVertices(const LinearRing* ring, const Tri* tri) const;
214
215 bool hasVertex(const LinearRing* ring, const Coordinate& v) const;
216
217 void envelope(const Tri* tri, Envelope& env) const;
218
219 std::unique_ptr<Geometry> createHullGeometry(bool isIncludeInput);
220
221
222public:
223
232 static std::unique_ptr<Geometry>
233 concaveHullByLength(const Geometry* polygons, double maxLength);
234
247 static std::unique_ptr<Geometry>
249 const Geometry* polygons, double maxLength,
250 bool isTight, bool isHolesAllowed);
251
260 static std::unique_ptr<Geometry>
261 concaveHullByLengthRatio(const Geometry* polygons, double lengthRatio);
262
275 static std::unique_ptr<Geometry>
277 const Geometry* polygons, double lengthRatio,
278 bool isTight, bool isHolesAllowed);
279
288 static std::unique_ptr<Geometry>
289 concaveFillByLength(const Geometry* polygons, double maxLength);
290
299 static std::unique_ptr<Geometry>
300 concaveFillByLengthRatio(const Geometry* polygons, double lengthRatio);
301
308
322 void setMaximumEdgeLength(double edgeLength);
323
338 void setMaximumEdgeLengthRatio(double edgeLengthRatio);
339
345 void setHolesAllowed(bool p_isHolesAllowed);
346
353 void setTight(bool p_isTight);
354
360 std::unique_ptr<Geometry> getHull();
361
368 std::unique_ptr<Geometry> getFill();
369
370
371};
372
373
374
375} // geos::algorithm::hull
376} // geos::algorithm
377} // geos
Definition: ConcaveHullOfPolygons.h:97
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:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:52
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Definition: TriList.h:54
Definition: Tri.h:49
Basic namespace for all GEOS functionalities.
Definition: geos.h:39