QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
55  struct CHullBox
56  {
57  double x[4];
58  double y[4];
59 
60  double alpha;
61 
62  double width;
63  double length;
64  };
65 
71  class CORE_EXPORT PointSet
72  {
73  friend class FeaturePart;
74  friend class LabelPosition;
75  friend class CostCalculator;
76  friend class PolygonCostCalculator;
77  friend class Layer;
78 
79  public:
80  PointSet();
81  PointSet( int nbPoints, double *x, double *y );
82  virtual ~PointSet();
83 
87  std::unique_ptr< PointSet > extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
88 
92  std::unique_ptr< PointSet > clone() const;
93 
100  bool containsPoint( double x, double y ) const;
101 
111  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
112 
117  CHullBox compute_chull_bbox();
118 
122  static void splitPolygons( QLinkedList<PointSet *> &inputShapes,
123  QLinkedList<PointSet *> &outputShapes,
124  double xrm, double yrm );
125 
134  void extendLineByDistance( double startDistance, double endDistance, double smoothDistance );
135 
145  double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
146 
147  void getCentroid( double &px, double &py, bool forceInside = false ) const;
148 
149  int getGeosType() const { return type; }
150 
155  {
156  return QgsRectangle( xmin, ymin, xmax, ymax );
157  }
158 
163  bool boundingBoxIntersects( const PointSet *other ) const;
164 
166  PointSet *getHoleOf() const { return holeOf; }
167 
168  int getNumPoints() const { return nbPoints; }
169 
178  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
179 
183  const GEOSGeometry *geos() const;
184 
188  double length() const;
189 
193  double area() const;
194 
198  bool isClosed() const;
199 
200  int nbPoints;
201  std::vector< double > x;
202  std::vector< double > y; // points order is counterclockwise
203 
204  protected:
205  mutable GEOSGeometry *mGeos = nullptr;
206  mutable bool mOwnsGeom = false;
207 
208  int *cHull = nullptr;
209  int cHullSize = 0;
210 
211  int type;
212 
213  PointSet *holeOf = nullptr;
214  PointSet *parent = nullptr;
215 
216  mutable double mArea = -1;
217  mutable double mLength = -1;
218 
219 
220  PointSet( double x, double y );
221 
222  PointSet( const PointSet &ps );
223 
224  void deleteCoords();
225  void createGeosGeom() const;
226  const GEOSPreparedGeometry *preparedGeom() const;
227  void invalidateGeos();
228 
229  double xmin = std::numeric_limits<double>::max();
230  double xmax = std::numeric_limits<double>::lowest();
231  double ymin = std::numeric_limits<double>::max();
232  double ymax = std::numeric_limits<double>::lowest();
233 
234  private:
235 
236  mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
237 
238  PointSet &operator= ( const PointSet & ) = delete;
239 
240  };
241 
242 } // namespace pal
243 
244 #endif
245 
pal::CHullBox::width
double width
Definition: pointset.h:62
qgsrectangle.h
pal::PointSet::boundingBox
QgsRectangle boundingBox() const
Returns the point set bounding box.
Definition: pointset.h:154
pal::LabelPosition
LabelPosition is a candidate feature label position.
Definition: labelposition.h:56
geos
Contains geos related utilities and functions.
Definition: qgsgeos.h:42
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
pal
Definition: qgsdiagramrenderer.h:49
pal::CHullBox::alpha
double alpha
Definition: pointset.h:60
pal::PointSet::getGeosType
int getGeosType() const
Definition: pointset.h:149
pal::PointSet::getNumPoints
int getNumPoints() const
Definition: pointset.h:168
pal::PointSet::x
std::vector< double > x
Definition: pointset.h:201
pal::PointSet::type
int type
Definition: pointset.h:211
pal::CostCalculator
Definition: costcalculator.h:38
pal::FeaturePart
Main class to handle feature.
Definition: feature.h:96
pal::CHullBox::length
double length
Definition: pointset.h:63
pal::CHullBox
Definition: pointset.h:56
pal::PointSet::y
std::vector< double > y
Definition: pointset.h:202
pal::PointSet
Definition: pointset.h:72
pal::CHullBox::x
double x[4]
Definition: pointset.h:57
pal::Layer
A set of features which influence the labeling process.
Definition: layer.h:62
pal::PointSet::nbPoints
int nbPoints
Definition: pointset.h:200
pal::PointSet::getHoleOf
PointSet * getHoleOf() const
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
Definition: pointset.h:166
pal::CHullBox::y
double y[4]
Definition: pointset.h:58