GEOS 3.14.0dev
ConcaveHull.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 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/geom/Triangle.h>
18#include <geos/triangulate/tri/Tri.h>
19#include <geos/triangulate/tri/TriList.h>
20#include <geos/triangulate/quadedge/TriangleVisitor.h>
21#include <geos/algorithm/hull/HullTri.h>
22
23#include <queue>
24#include <deque>
25
26namespace geos {
27namespace geom {
28class Coordinate;
29class Geometry;
30class GeometryFactory;
31}
32namespace triangulate {
33namespace quadedge {
34class Quadedge;
36}
37}
38}
39
40namespace geos {
41namespace algorithm { // geos::algorithm
42namespace hull { // geos::algorithm::hull
43
44
45typedef std::priority_queue<HullTri*, std::vector<HullTri*>, HullTri::HullTriCompare> HullTriQueue;
46
47
85class GEOS_DLL ConcaveHull {
93 template<typename TriType>
95
96public:
97
98 ConcaveHull(const Geometry* geom);
99
112 static double uniformEdgeLength(const Geometry* geom);
113
122 static std::unique_ptr<Geometry> concaveHullByLength(
123 const Geometry* geom, double maxLength);
124
125 static std::unique_ptr<Geometry> concaveHullByLength(
126 const Geometry* geom, double maxLength, bool isHolesAllowed);
127
139 static std::unique_ptr<Geometry> concaveHullByLengthRatio(
140 const Geometry* geom, double lengthRatio);
141
155 static std::unique_ptr<Geometry> concaveHullByLengthRatio(
156 const Geometry* geom,
157 double lengthRatio,
158 bool isHolesAllowed);
159
169 static std::unique_ptr<Geometry> alphaShape(
170 const Geometry* geom,
171 double alpha,
172 bool isHolesAllowed);
173
189 void setMaximumEdgeLength(double edgeLength);
190
202 void setMaximumEdgeLengthRatio(double edgeLengthRatio);
203
209 void setHolesAllowed(bool holesAllowed);
210
218 void setAlpha(double newAlpha);
219
225 std::unique_ptr<Geometry> getHull();
226
227
228private:
229
230 // Constants
231 static constexpr int PARAM_EDGE_LENGTH = 1;
232 static constexpr int PARAM_ALPHA = 2;
233
234 // Members
235 const Geometry* inputGeometry;
236 double maxEdgeLengthRatio;
237 double alpha;
238 bool isHolesAllowed;
239 int criteriaType;
240 double maxSizeInHull;
241 const GeometryFactory* geomFactory;
242
243 // Methods
244 static double computeTargetEdgeLength(
245 TriList<HullTri>& triList,
246 double edgeLengthFactor);
247
248 void computeHull(TriList<HullTri>& triList);
249 void computeHullBorder(TriList<HullTri>& triList);
250 void createBorderQueue(HullTriQueue& queue, TriList<HullTri>& triList);
251
262 void addBorderTri(HullTri* tri, HullTriQueue& queue);
263 void computeHullHoles(TriList<HullTri>& triList);
264 void setSize(HullTri* tri);
265
266
279 static std::vector<HullTri*> findCandidateHoles(
280 TriList<HullTri>& triList, double maxSizeInHull);
281
282 void removeHole(TriList<HullTri>& triList, HullTri* triHole);
283 void setSize(TriList<HullTri>& triList);
284
292 bool isInHull(const HullTri* tri) const;
293
294 bool isRemovableBorder(const HullTri* tri) const;
295 bool isRemovableHole(const HullTri* tri) const;
296
297 std::unique_ptr<Geometry> toGeometry(
298 TriList<HullTri>& triList,
299 const GeometryFactory* factory);
300
301
302};
303
304
305} // geos::algorithm::hull
306} // geos::algorithm
307} // geos
308
Definition ConcaveHull.h:85
static std::unique_ptr< Geometry > concaveHullByLengthRatio(const Geometry *geom, double lengthRatio, bool isHolesAllowed)
static std::unique_ptr< Geometry > concaveHullByLengthRatio(const Geometry *geom, double lengthRatio)
void setHolesAllowed(bool holesAllowed)
void setAlpha(double newAlpha)
static double uniformEdgeLength(const Geometry *geom)
static std::unique_ptr< Geometry > alphaShape(const Geometry *geom, double alpha, bool isHolesAllowed)
static std::unique_ptr< Geometry > concaveHullByLength(const Geometry *geom, double maxLength)
void setMaximumEdgeLength(double edgeLength)
void setMaximumEdgeLengthRatio(double edgeLengthRatio)
std::unique_ptr< Geometry > getHull()
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
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
Represents a planar triangle, and provides methods for calculating various properties of triangles.
Definition Triangle.h:28
A class that contains the QuadEdges representing a planar subdivision that models a triangulation.
Definition QuadEdgeSubdivision.h:78
A class that represents the edge data structure which implements the quadedge algebra.
Definition QuadEdge.h:53
Definition TriList.h:50
Definition Tri.h:45
Basic namespace for all GEOS functionalities.
Definition geos.h:39