QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 <QLinkedList>
39#include <geos_c.h>
40#include <memory>
41#include <vector>
42
43#include "qgis_core.h"
44#include "qgsrectangle.h"
45#include "qgsgeos.h"
46
47namespace pal
48{
49
50 class Pal;
51 class Projection;
52 class LabelPosition;
53
54 class PointSet;
55
60 {
61 double x[4] = {0, 0, 0, 0};
62 double y[4] = {0, 0, 0, 0};
63
64 double alpha = 0;
65
66 double width = 0;
67 double length = 0;
68 };
69
76 class CORE_EXPORT PointSet
77 {
78 friend class FeaturePart;
79 friend class LabelPosition;
80 friend class CostCalculator;
81 friend class PolygonCostCalculator;
82 friend class Layer;
83
84 public:
85 PointSet();
86 PointSet( int nbPoints, double *x, double *y );
87 virtual ~PointSet();
88
92 std::unique_ptr< PointSet > extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
93
97 std::unique_ptr< PointSet > clone() const;
98
105 bool containsPoint( double x, double y ) const;
106
116 bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
117
121 OrientedConvexHullBoundingBox computeConvexHullOrientedBoundingBox( bool &ok ) const;
122
128 static QLinkedList<PointSet *> splitPolygons( PointSet *inputShape, double labelWidth, double labelHeight );
129
138 void extendLineByDistance( double startDistance, double endDistance, double smoothDistance );
139
143 void offsetCurveByDistance( double distance );
144
154 double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
155
156 void getCentroid( double &px, double &py, bool forceInside = false ) const;
157
158 int getGeosType() const { return type; }
159
164 {
165 return QgsRectangle( xmin, ymin, xmax, ymax );
166 }
167
172 bool boundingBoxIntersects( const PointSet *other ) const;
173
175 PointSet *getHoleOf() const { return holeOf; }
176
177 int getNumPoints() const { return nbPoints; }
178
187 void getPointByDistance( double *d, double *ad, double dl, double *px, double *py ) const;
188
192 geos::unique_ptr interpolatePoint( double distance ) const;
193
197 double lineLocatePoint( const GEOSGeometry *point ) const;
198
202 const GEOSGeometry *geos() const;
203
207 double length() const;
208
212 double area() const;
213
217 bool isClosed() const;
218
222 QString toWkt() const;
223
227 std::tuple< std::vector< double >, double > edgeDistances() const;
228
230 std::vector< double > x;
231 std::vector< double > y; // points order is counterclockwise
232
233 protected:
234 mutable GEOSGeometry *mGeos = nullptr;
235 mutable bool mOwnsGeom = false;
236
237 std::vector< int > convexHull;
238
239 int type;
240
241 PointSet *holeOf = nullptr;
242 PointSet *parent = nullptr;
243
244 mutable double mArea = -1;
245 mutable double mLength = -1;
246
247
248 PointSet( double x, double y );
249
250 PointSet( const PointSet &ps );
251
252 void deleteCoords();
253 void createGeosGeom() const;
254 const GEOSPreparedGeometry *preparedGeom() const;
255
256 void invalidateGeos() const;
257
258 double xmin = std::numeric_limits<double>::max();
259 double xmax = std::numeric_limits<double>::lowest();
260 double ymin = std::numeric_limits<double>::max();
261 double ymax = std::numeric_limits<double>::lowest();
262
263 private:
264
265 mutable const GEOSPreparedGeometry *mGeosPreparedBoundary = nullptr;
266 mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
267
268 mutable GEOSGeometry *mMultipartGeos = nullptr;
269 mutable const GEOSPreparedGeometry *mMultipartPreparedGeos = nullptr;
270
271 PointSet &operator= ( const PointSet & ) = delete;
272
273 };
274
275} // namespace pal
276
277#endif
278
A rectangle specified with double values.
Calculates label candidate costs considering different factors.
Main class to handle feature.
Definition feature.h:65
LabelPosition is a candidate feature label position.
A set of features which influence the labeling process.
Definition layer.h:63
The underlying raw pal geometry class.
Definition pointset.h:77
PointSet * getHoleOf() const
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
Definition pointset.h:175
std::vector< double > y
Definition pointset.h:231
QgsRectangle boundingBox() const
Returns the point set bounding box.
Definition pointset.h:163
std::vector< double > x
Definition pointset.h:230
std::vector< int > convexHull
Definition pointset.h:237
int getGeosType() const
Definition pointset.h:158
int getNumPoints() const
Definition pointset.h:177
Contains geos related utilities and functions.
Definition qgsgeos.h:75
Represents the minimum area, oriented bounding box surrounding a convex hull.
Definition pointset.h:60
struct GEOSGeom_t GEOSGeometry
Definition util.h:41