QGIS API Documentation  3.21.0-Master (5b68dc587e)
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 
46 namespace pal
47 {
48 
49  class Pal;
50  class Projection;
51  class LabelPosition;
52 
53  class PointSet;
54 
59  {
60  double x[4];
61  double y[4];
62 
63  double alpha;
64 
65  double width;
66  double length;
67  };
68 
75  class CORE_EXPORT PointSet
76  {
77  friend class FeaturePart;
78  friend class LabelPosition;
79  friend class CostCalculator;
80  friend class PolygonCostCalculator;
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 
120  OrientedConvexHullBoundingBox computeConvexHullOrientedBoundingBox( bool &ok );
121 
127  static QLinkedList<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  {
164  return QgsRectangle( xmin, ymin, xmax, ymax );
165  }
166 
171  bool boundingBoxIntersects( const PointSet *other ) const;
172 
174  PointSet *getHoleOf() const { return holeOf; }
175 
176  int getNumPoints() const { return nbPoints; }
177 
186  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
187 
191  const GEOSGeometry *geos() const;
192 
196  double length() const;
197 
201  double area() const;
202 
206  bool isClosed() const;
207 
211  QString toWkt() const;
212 
216  std::tuple< std::vector< double >, double > edgeDistances() const;
217 
218  int nbPoints;
219  std::vector< double > x;
220  std::vector< double > y; // points order is counterclockwise
221 
222  protected:
223  mutable GEOSGeometry *mGeos = nullptr;
224  mutable bool mOwnsGeom = false;
225 
226  std::vector< int > convexHull;
227 
228  int type;
229 
230  PointSet *holeOf = nullptr;
231  PointSet *parent = nullptr;
232 
233  mutable double mArea = -1;
234  mutable double mLength = -1;
235 
236 
237  PointSet( double x, double y );
238 
239  PointSet( const PointSet &ps );
240 
241  void deleteCoords();
242  void createGeosGeom() const;
243  const GEOSPreparedGeometry *preparedGeom() const;
244 
245  void invalidateGeos();
246 
247  double xmin = std::numeric_limits<double>::max();
248  double xmax = std::numeric_limits<double>::lowest();
249  double ymin = std::numeric_limits<double>::max();
250  double ymax = std::numeric_limits<double>::lowest();
251 
252  private:
253 
254  mutable const GEOSPreparedGeometry *mGeosPreparedBoundary = nullptr;
255  mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
256 
257  mutable GEOSGeometry *mMultipartGeos = nullptr;
258  mutable const GEOSPreparedGeometry *mMultipartPreparedGeos = nullptr;
259 
260  PointSet &operator= ( const PointSet & ) = delete;
261 
262  };
263 
264 } // namespace pal
265 
266 #endif
267 
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Calculates label candidate costs considering different factors.
Main class to handle feature.
Definition: feature.h:65
LabelPosition is a candidate feature label position.
Definition: labelposition.h:56
A set of features which influence the labeling process.
Definition: layer.h:62
The underlying raw pal geometry class.
Definition: pointset.h:76
std::vector< double > y
Definition: pointset.h:220
QgsRectangle boundingBox() const
Returns the point set bounding box.
Definition: pointset.h:162
std::vector< double > x
Definition: pointset.h:219
std::vector< int > convexHull
Definition: pointset.h:226
int getGeosType() const
Definition: pointset.h:157
PointSet * getHoleOf() const
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
Definition: pointset.h:174
int getNumPoints() const
Definition: pointset.h:176
Contains geos related utilities and functions.
Definition: qgsgeos.h:42
Represents the minimum area, oriented bounding box surrounding a convex hull.
Definition: pointset.h:59