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 
24 namespace geos {
25 namespace geom {
26 class Coordinate;
27 class CoordinateSequence;
28 class Envelope;
29 class Geometry;
30 class GeometryCollection;
31 class GeometryFactory;
32 class LinearRing;
33 class Polygon;
34 }
35 namespace triangulate {
36 namespace tri {
37 class Tri;
38 }
39 }
40 }
41 
42 namespace geos {
43 namespace algorithm { // geos::algorithm
44 namespace hull { // geos::algorithm::hull
45 
46 
83 class GEOS_DLL ConcaveHullOfPolygons {
93  template<typename TriType>
95 
96 private:
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 
215 public:
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 > getHull()
static std::unique_ptr< Geometry > concaveHullByLength(const Geometry *polygons, double maxLength, bool isTight, bool isHolesAllowed)
std::unique_ptr< Geometry > getFill()
static std::unique_ptr< Geometry > concaveHullByLengthRatio(const Geometry *polygons, double lengthRatio)
static std::unique_ptr< Geometry > concaveFillByLength(const Geometry *polygons, double maxLength)
static std::unique_ptr< Geometry > concaveHullByLength(const Geometry *polygons, double maxLength)
static std::unique_ptr< Geometry > concaveFillByLengthRatio(const Geometry *polygons, double lengthRatio)
static std::unique_ptr< Geometry > concaveHullByLengthRatio(const Geometry *polygons, double lengthRatio, bool isTight, bool isHolesAllowed)
void setMaximumEdgeLength(double edgeLength)
void setHolesAllowed(bool p_isHolesAllowed)
void setMaximumEdgeLengthRatio(double edgeLengthRatio)
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: Angle.h:25