GEOS 3.11.1
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
49
50namespace geos {
51namespace algorithm { // geos::algorithm
52namespace hull { // geos::algorithm::hull
53
54
55typedef std::priority_queue<HullTri*, std::vector<HullTri*>, HullTri::HullTriCompare> HullTriQueue;
56
57
89class GEOS_DLL ConcaveHull {
90
91public:
92
93 ConcaveHull(const Geometry* geom)
94 : inputGeometry(geom)
95 , maxEdgeLength(0.0)
96 , maxEdgeLengthRatio(-1.0)
97 , isHolesAllowed(false)
98 , geomFactory(geom->getFactory())
99 {};
100
113 static double uniformEdgeLength(const Geometry* geom);
114
123 static std::unique_ptr<Geometry> concaveHullByLength(
124 const Geometry* geom, double maxLength);
125
126 static std::unique_ptr<Geometry> concaveHullByLength(
127 const Geometry* geom, double maxLength, bool isHolesAllowed);
128
140 static std::unique_ptr<Geometry> concaveHullByLengthRatio(
141 const Geometry* geom, double lengthRatio);
142
156 static std::unique_ptr<Geometry> concaveHullByLengthRatio(
157 const Geometry* geom, double lengthRatio, bool isHolesAllowed);
158
174 void setMaximumEdgeLength(double edgeLength);
175
187 void setMaximumEdgeLengthRatio(double edgeLengthRatio);
188
194 void setHolesAllowed(bool holesAllowed);
195
201 std::unique_ptr<Geometry> getHull();
202
203
204private:
205
206 // Members
207 const Geometry* inputGeometry;
208 double maxEdgeLength;
209 double maxEdgeLengthRatio;
210 bool isHolesAllowed;
211 const GeometryFactory* geomFactory;
212
213 static double computeTargetEdgeLength(
214 TriList<HullTri>& triList,
215 double edgeLengthFactor);
216
217 void computeHull(TriList<HullTri>& triList);
218 void computeHullBorder(TriList<HullTri>& triList);
219 void createBorderQueue(HullTriQueue& queue, TriList<HullTri>& triList);
220
229 void addBorderTri(HullTri* tri, HullTriQueue& queue);
230 bool isBelowLengthThreshold(const HullTri* tri) const;
231 void computeHullHoles(TriList<HullTri>& triList);
232
233 static std::vector<HullTri*> findCandidateHoles(
234 TriList<HullTri>& triList, double minEdgeLen);
235
236 void removeHole(TriList<HullTri>& triList, HullTri* triHole);
237
238 bool isRemovableBorder(const HullTri* tri) const;
239 bool isRemovableHole(const HullTri* tri) const;
240
241 std::unique_ptr<Geometry> toGeometry(
242 TriList<HullTri>& triList,
243 const GeometryFactory* factory);
244
245
246};
247
248
249} // geos::algorithm::hull
250} // geos::algorithm
251} // geos
252
Definition: ConcaveHull.h:89
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)
static double uniformEdgeLength(const Geometry *geom)
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:58
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
const GeometryFactory * getFactory() const
Gets the factory which contains the context in which this geometry was created.
Definition: Geometry.h:216
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:83
A class that represents the edge data structure which implements the quadedge algebra.
Definition: QuadEdge.h:53
An interface for algorithms which process the triangles in a QuadEdgeSubdivision.
Definition: TriangleVisitor.h:33
Definition: TriList.h:54
Definition: Tri.h:49
Basic namespace for all GEOS functionalities.
Definition: geos.h:39