QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
47 namespace pal
48 {
49 
50  class Pal;
51  class Projection;
52  class LabelPosition;
53 
54  class PointSet;
55 
60  {
61  double x[4];
62  double y[4];
63 
64  double alpha;
65 
66  double width;
67  double length;
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 );
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 
229  int nbPoints;
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 
qgsrectangle.h
pal::OrientedConvexHullBoundingBox::length
double length
Definition: pointset.h:67
pal::PointSet::boundingBox
QgsRectangle boundingBox() const
Returns the point set bounding box.
Definition: pointset.h:163
pal::LabelPosition
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
pal::OrientedConvexHullBoundingBox::y
double y[4]
Definition: pointset.h:62
geos
Contains geos related utilities and functions.
Definition: qgsgeos.h:41
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
pal
Definition: qgsdiagramrenderer.h:50
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
pal::PointSet::getGeosType
int getGeosType() const
Definition: pointset.h:158
pal::PointSet::getNumPoints
int getNumPoints() const
Definition: pointset.h:177
pal::PointSet::x
std::vector< double > x
Definition: pointset.h:230
pal::PointSet::type
int type
Definition: pointset.h:239
pal::CostCalculator
Calculates label candidate costs considering different factors.
Definition: costcalculator.h:38
pal::OrientedConvexHullBoundingBox::width
double width
Definition: pointset.h:66
pal::FeaturePart
Main class to handle feature.
Definition: feature.h:64
pal::OrientedConvexHullBoundingBox
Represents the minimum area, oriented bounding box surrounding a convex hull.
Definition: pointset.h:59
pal::PointSet::convexHull
std::vector< int > convexHull
Definition: pointset.h:237
pal::PointSet::y
std::vector< double > y
Definition: pointset.h:231
pal::PointSet
The underlying raw pal geometry class.
Definition: pointset.h:76
pal::OrientedConvexHullBoundingBox::alpha
double alpha
Definition: pointset.h:64
pal::Layer
A set of features which influence the labeling process.
Definition: layer.h:62
pal::OrientedConvexHullBoundingBox::x
double x[4]
Definition: pointset.h:61
pal::PointSet::nbPoints
int nbPoints
Definition: pointset.h:229
qgsgeos.h
pal::PointSet::getHoleOf
PointSet * getHoleOf() const
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
Definition: pointset.h:175