QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
pointset.h
Go to the documentation of this file.
1/*
2 * libpal - Automated Placement of Labels Library
3 *
4 * Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5 * University of Applied Sciences, Western Switzerland
6 * http://www.hes-so.ch
7 *
8 * Contact:
9 * maxence.laurent <at> heig-vd <dot> ch
10 * or
11 * eric.taillard <at> heig-vd <dot> ch
12 *
13 * This file is part of libpal.
14 *
15 * libpal is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * libpal is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with libpal. If not, see <http://www.gnu.org/licenses/>.
27 *
28 */
29
30#ifndef POINTSET_H
31#define POINTSET_H
32
33#define SIP_NO_FILE
34
35
36#include <cfloat>
37#include <cmath>
38#include <geos_c.h>
39#include <memory>
40#include <vector>
41
42#include "qgis_core.h"
43#include "qgsgeos.h"
44#include "qgsrectangle.h"
45
46#include <QLinkedList>
47
48namespace pal
49{
50
51 class Pal;
52 class Projection;
53 class LabelPosition;
54
55 class PointSet;
56
61 {
62 double x[4] = {0, 0, 0, 0};
63 double y[4] = {0, 0, 0, 0};
64
65 double alpha = 0;
66
67 double width = 0;
68 double length = 0;
69 };
70
77 class CORE_EXPORT PointSet
78 {
79 friend class FeaturePart;
80 friend class LabelPosition;
81 friend class CostCalculator;
83 friend class Layer;
84
85 public:
86 PointSet();
87 PointSet( int nbPoints, double *x, double *y );
88 virtual ~PointSet();
89
93 std::unique_ptr< PointSet > extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
94
98 std::unique_ptr< PointSet > clone() const;
99
106 bool containsPoint( double x, double y ) const;
107
117 bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
118
123
129 static QLinkedList<PointSet *> splitPolygons( PointSet *inputShape, double labelWidth, double labelHeight );
130
139 void extendLineByDistance( double startDistance, double endDistance, double smoothDistance );
140
144 void offsetCurveByDistance( double distance );
145
155 double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
156
157 void getCentroid( double &px, double &py, bool forceInside = false ) const;
158
159 int getGeosType() const { return type; }
160
165 {
166 return QgsRectangle( xmin, ymin, xmax, ymax );
167 }
168
173 bool boundingBoxIntersects( const PointSet *other ) const;
174
176 PointSet *getHoleOf() const { return holeOf; }
177
178 int getNumPoints() const { return nbPoints; }
179
188 void getPointByDistance( double *d, double *ad, double dl, double *px, double *py ) const;
189
193 geos::unique_ptr interpolatePoint( double distance ) const;
194
198 double lineLocatePoint( const GEOSGeometry *point ) const;
199
203 const GEOSGeometry *geos() const;
204
208 double length() const;
209
213 double area() const;
214
218 bool isClosed() const;
219
223 QString toWkt() const;
224
228 std::tuple< std::vector< double >, double > edgeDistances() const;
229
231 std::vector< double > x;
232 std::vector< double > y; // points order is counterclockwise
233
234 protected:
235 mutable GEOSGeometry *mGeos = nullptr;
236 mutable bool mOwnsGeom = false;
237
238 std::vector< int > convexHull;
239
240 int type;
241
242 PointSet *holeOf = nullptr;
243 PointSet *parent = nullptr;
244
245 mutable double mArea = -1;
246 mutable double mLength = -1;
247
248
249 PointSet( double x, double y );
250
251 PointSet( const PointSet &ps );
252
253 void deleteCoords();
254 void createGeosGeom() const;
255 const GEOSPreparedGeometry *preparedGeom() const;
256
257 void invalidateGeos() const;
258
259 double xmin = std::numeric_limits<double>::max();
260 double xmax = std::numeric_limits<double>::lowest();
261 double ymin = std::numeric_limits<double>::max();
262 double ymax = std::numeric_limits<double>::lowest();
263
264 private:
265
266 mutable const GEOSPreparedGeometry *mGeosPreparedBoundary = nullptr;
267 mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
268
269 mutable GEOSGeometry *mMultipartGeos = nullptr;
270 mutable const GEOSPreparedGeometry *mMultipartPreparedGeos = nullptr;
271
272 PointSet &operator= ( const PointSet & ) = delete;
273
274 };
275
276} // namespace pal
277
278#endif
279
A rectangle specified with double values.
The underlying raw pal geometry class.
Definition pointset.h:78
std::unique_ptr< PointSet > clone() const
Returns a copy of the point set.
Definition pointset.cpp:268
friend class LabelPosition
Definition pointset.h:80
bool containsLabelCandidate(double x, double y, double width, double height, double alpha=0) const
Tests whether a possible label candidate will fit completely within the shape.
Definition pointset.cpp:292
void deleteCoords()
Definition pointset.cpp:235
void extendLineByDistance(double startDistance, double endDistance, double smoothDistance)
Extends linestrings by the specified amount at the start and end of the line, by extending the existi...
Definition pointset.cpp:634
double ymax
Definition pointset.h:262
double ymin
Definition pointset.h:261
PointSet * getHoleOf() const
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
Definition pointset.h:176
PointSet * holeOf
Definition pointset.h:242
void createGeosGeom() const
Definition pointset.cpp:102
std::vector< double > y
Definition pointset.h:232
friend class CostCalculator
Definition pointset.h:81
friend class PolygonCostCalculator
Definition pointset.h:82
void getCentroid(double &px, double &py, bool forceInside=false) const
Definition pointset.cpp:920
OrientedConvexHullBoundingBox computeConvexHullOrientedBoundingBox(bool &ok) const
Computes an oriented bounding box for the shape's convex hull.
Definition pointset.cpp:721
friend class Layer
Definition pointset.h:83
QgsRectangle boundingBox() const
Returns the point set bounding box.
Definition pointset.h:164
std::vector< double > x
Definition pointset.h:231
void offsetCurveByDistance(double distance)
Offsets linestrings by the specified distance.
Definition pointset.cpp:548
std::vector< int > convexHull
Definition pointset.h:238
const GEOSPreparedGeometry * preparedGeom() const
Definition pointset.cpp:157
GEOSGeometry * mGeos
Definition pointset.h:235
double xmin
Definition pointset.h:259
int getGeosType() const
Definition pointset.h:159
void invalidateGeos() const
Definition pointset.cpp:169
double minDistanceToPoint(double px, double py, double *rx=nullptr, double *ry=nullptr) const
Returns the squared minimum distance between the point set geometry and the point (px,...
Definition pointset.cpp:863
friend class FeaturePart
Definition pointset.h:79
double xmax
Definition pointset.h:260
std::unique_ptr< PointSet > extractShape(int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty)
Does... something completely inscrutable.
Definition pointset.cpp:241
bool containsPoint(double x, double y) const
Tests whether point set contains a specified point.
Definition pointset.cpp:273
PointSet * parent
Definition pointset.h:243
double mLength
Definition pointset.h:246
double mArea
Definition pointset.h:245
int getNumPoints() const
Definition pointset.h:178
static QLinkedList< PointSet * > splitPolygons(PointSet *inputShape, double labelWidth, double labelHeight)
Split a polygon using some random logic into some other polygons.
Definition pointset.cpp:297
Contains geos related utilities and functions.
Definition qgsgeos.h:77
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition qgsgeos.h:114
Represents the minimum area, oriented bounding box surrounding a convex hull.
Definition pointset.h:61
struct GEOSGeom_t GEOSGeometry
Definition util.h:42