QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
34#include <cfloat>
35#include <cmath>
36#include <geos_c.h>
37#include <memory>
38#include <vector>
39
40#include "qgis_core.h"
41#include "qgsgeos.h"
42#include "qgsrectangle.h"
43
44#define SIP_NO_FILE
45
46namespace pal
47{
48
49 class Pal;
50 class Projection;
51 class LabelPosition;
52
53 class PointSet;
54
59 {
60 double x[4] = { 0, 0, 0, 0 };
61 double y[4] = { 0, 0, 0, 0 };
62
63 double alpha = 0;
64
65 double width = 0;
66 double length = 0;
67 };
68
75 class CORE_EXPORT PointSet
76 {
77 friend class FeaturePart;
78 friend class LabelPosition;
79 friend class CostCalculator;
81 friend class Layer;
82
83 public:
84 PointSet();
85 PointSet( int nbPoints, double *x, double *y );
86 virtual ~PointSet();
87
91 std::unique_ptr< PointSet > extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
92
96 std::unique_ptr< PointSet > clone() const;
97
104 bool containsPoint( double x, double y ) const;
105
115 bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
116
121
127 static QVector<PointSet *> splitPolygons( PointSet *inputShape, double labelWidth, double labelHeight );
128
137 void extendLineByDistance( double startDistance, double endDistance, double smoothDistance );
138
142 void offsetCurveByDistance( double distance );
143
153 double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
154
155 void getCentroid( double &px, double &py, bool forceInside = false ) const;
156
157 int getGeosType() const { return type; }
158
163
168 bool boundingBoxIntersects( const PointSet *other ) const;
169
171 PointSet *getHoleOf() const { return holeOf; }
172
173 int getNumPoints() const { return nbPoints; }
174
183 void getPointByDistance( double *d, double *ad, double dl, double *px, double *py ) const;
184
188 geos::unique_ptr interpolatePoint( double distance ) const;
189
193 double lineLocatePoint( const GEOSGeometry *point ) const;
194
198 const GEOSGeometry *geos() const;
199
203 double length() const;
204
208 double area() const;
209
213 bool isClosed() const;
214
218 QString toWkt() const;
219
223 std::tuple< std::vector< double >, double > edgeDistances() const;
224
226 std::vector< double > x;
227 std::vector< double > y; // points order is counterclockwise
228
229 protected:
230 mutable GEOSGeometry *mGeos = nullptr;
231 mutable bool mOwnsGeom = false;
232
233 std::vector< int > convexHull;
234
235 int type;
236
237 PointSet *holeOf = nullptr;
238 PointSet *parent = nullptr;
239
240 mutable double mArea = -1;
241 mutable double mLength = -1;
242
243
244 PointSet( double x, double y );
245
246 PointSet( const PointSet &ps );
247
248 void deleteCoords();
249 void createGeosGeom() const;
250 const GEOSPreparedGeometry *preparedGeom() const;
251
252 void invalidateGeos() const;
253
254 double xmin = std::numeric_limits<double>::max();
255 double xmax = std::numeric_limits<double>::lowest();
256 double ymin = std::numeric_limits<double>::max();
257 double ymax = std::numeric_limits<double>::lowest();
258
259 private:
260 mutable const GEOSPreparedGeometry *mGeosPreparedBoundary = nullptr;
261 mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
262
263 mutable GEOSGeometry *mMultipartGeos = nullptr;
264 mutable const GEOSPreparedGeometry *mMultipartPreparedGeos = nullptr;
265
266 PointSet &operator=( const PointSet & ) = delete;
267 };
268
269} // namespace pal
270
271#endif
A rectangle specified with double values.
The underlying raw pal geometry class.
Definition pointset.h:76
std::unique_ptr< PointSet > clone() const
Returns a copy of the point set.
Definition pointset.cpp:267
friend class LabelPosition
Definition pointset.h:78
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:290
void deleteCoords()
Definition pointset.cpp:234
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:627
double ymax
Definition pointset.h:257
double ymin
Definition pointset.h:256
PointSet * getHoleOf() const
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
Definition pointset.h:171
PointSet * holeOf
Definition pointset.h:237
static QVector< PointSet * > splitPolygons(PointSet *inputShape, double labelWidth, double labelHeight)
Split a polygon using some random logic into some other polygons.
Definition pointset.cpp:295
void createGeosGeom() const
Definition pointset.cpp:101
std::vector< double > y
Definition pointset.h:227
friend class CostCalculator
Definition pointset.h:79
friend class PolygonCostCalculator
Definition pointset.h:80
void getCentroid(double &px, double &py, bool forceInside=false) const
Definition pointset.cpp:921
OrientedConvexHullBoundingBox computeConvexHullOrientedBoundingBox(bool &ok) const
Computes an oriented bounding box for the shape's convex hull.
Definition pointset.cpp:714
friend class Layer
Definition pointset.h:81
QgsRectangle boundingBox() const
Returns the point set bounding box.
Definition pointset.h:162
std::vector< double > x
Definition pointset.h:226
void offsetCurveByDistance(double distance)
Offsets linestrings by the specified distance.
Definition pointset.cpp:541
std::vector< int > convexHull
Definition pointset.h:233
const GEOSPreparedGeometry * preparedGeom() const
Definition pointset.cpp:156
GEOSGeometry * mGeos
Definition pointset.h:230
double xmin
Definition pointset.h:254
int getGeosType() const
Definition pointset.h:157
void invalidateGeos() const
Definition pointset.cpp:168
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:864
friend class FeaturePart
Definition pointset.h:77
double xmax
Definition pointset.h:255
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:240
bool containsPoint(double x, double y) const
Tests whether point set contains a specified point.
Definition pointset.cpp:272
PointSet * parent
Definition pointset.h:238
double mLength
Definition pointset.h:241
double mArea
Definition pointset.h:240
int getNumPoints() const
Definition pointset.h:173
Contains geos related utilities and functions.
Definition qgsgeos.h:76
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition qgsgeos.h:112
Represents the minimum area, oriented bounding box surrounding a convex hull.
Definition pointset.h:59
struct GEOSGeom_t GEOSGeometry
Definition util.h:41