QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
45 namespace pal
46 {
47 
48  class Pal;
49  class Projection;
50  class LabelPosition;
51 
52  class PointSet;
53 
54  typedef struct _cHullBox
55  {
56  double x[4];
57  double y[4];
58 
59  double alpha;
60 
61  double width;
62  double length;
63  } CHullBox;
64 
70  class CORE_EXPORT PointSet
71  {
72  friend class FeaturePart;
73  friend class LabelPosition;
74  friend class CostCalculator;
75  friend class PolygonCostCalculator;
76  friend class Layer;
77 
78  public:
79  PointSet();
80  PointSet( int nbPoints, double *x, double *y );
81  virtual ~PointSet();
82 
83  PointSet *extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
84 
88  std::unique_ptr< PointSet > clone() const;
89 
96  bool containsPoint( double x, double y ) const;
97 
107  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
108 
109  CHullBox *compute_chull_bbox();
110 
114  static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
115  QLinkedList<PointSet *> &shapes_final,
116  double xrm, double yrm );
117 
126  void extendLineByDistance( double startDistance, double endDistance, double smoothDistance );
127 
137  double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
138 
139  void getCentroid( double &px, double &py, bool forceInside = false ) const;
140 
141  int getGeosType() const { return type; }
142 
143  void getBoundingBox( double min[2], double max[2] ) const
144  {
145  min[0] = xmin;
146  min[1] = ymin;
147  max[0] = xmax;
148  max[1] = ymax;
149  }
150 
155  bool boundingBoxIntersects( const PointSet *other ) const;
156 
158  PointSet *getHoleOf() { return holeOf; }
159 
160  int getNumPoints() const { return nbPoints; }
161 
170  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
171 
175  const GEOSGeometry *geos() const;
176 
180  double length() const;
181 
185  bool isClosed() const;
186 
187  int nbPoints;
188  std::vector< double > x;
189  std::vector< double > y; // points order is counterclockwise
190 
191  protected:
192  mutable GEOSGeometry *mGeos = nullptr;
193  mutable bool mOwnsGeom = false;
194 
195  int *cHull = nullptr;
196  int cHullSize = 0;
197 
198  int type;
199 
200  PointSet *holeOf = nullptr;
201  PointSet *parent = nullptr;
202 
203  PointSet( double x, double y );
204 
205  PointSet( const PointSet &ps );
206 
207  void deleteCoords();
208  void createGeosGeom() const;
209  const GEOSPreparedGeometry *preparedGeom() const;
210  void invalidateGeos();
211 
212  double xmin = std::numeric_limits<double>::max();
213  double xmax = std::numeric_limits<double>::lowest();
214  double ymin = std::numeric_limits<double>::max();
215  double ymax = std::numeric_limits<double>::lowest();
216 
217  private:
218 
219  mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
220 
221  };
222 
223 } // namespace pal
224 
225 #endif
226 
double length
Definition: pointset.h:62
PointSet * getHoleOf()
Returns nullptr if this isn&#39;t a hole. Otherwise returns pointer to parent pointset.
Definition: pointset.h:158
A set of features which influence the labeling process.
Definition: layer.h:63
std::vector< double > x
Definition: pointset.h:188
struct pal::_cHullBox CHullBox
int getNumPoints() const
Definition: pointset.h:160
double width
Definition: pointset.h:61
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:143
Main class to handle feature.
Definition: feature.h:96
Contains geos related utilities and functions.
Definition: qgsgeos.h:41
double x[4]
Definition: pointset.h:56
double y[4]
Definition: pointset.h:57
int getGeosType() const
Definition: pointset.h:141
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
double alpha
Definition: pointset.h:59
std::vector< double > y
Definition: pointset.h:189
Data structure to compute polygon&#39;s candidates costs.