QGIS API Documentation  2.99.0-Master (7d4f81d)
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 
41 #include "qgis_core.h"
42 
43 namespace pal
44 {
45 
46  class Pal;
47  class Projection;
48  class LabelPosition;
49 
50  class PointSet;
51 
52  typedef struct _cHullBox
53  {
54  double x[4];
55  double y[4];
56 
57  double alpha;
58 
59  double width;
60  double length;
61  } CHullBox;
62 
68  class CORE_EXPORT PointSet
69  {
70  friend class FeaturePart;
71  friend class LabelPosition;
72  friend class CostCalculator;
73  friend class PolygonCostCalculator;
74  friend class Layer;
75 
76  public:
77  PointSet();
78  PointSet( int nbPoints, double *x, double *y );
79  virtual ~PointSet();
80 
81  PointSet *extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
82 
88  bool containsPoint( double x, double y ) const;
89 
98  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
99 
100  CHullBox *compute_chull_bbox();
101 
104  static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
105  QLinkedList<PointSet *> &shapes_final,
106  double xrm, double yrm );
107 
116  double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
117 
118  void getCentroid( double &px, double &py, bool forceInside = false ) const;
119 
120  int getGeosType() const { return type; }
121 
122  void getBoundingBox( double min[2], double max[2] ) const
123  {
124  min[0] = xmin;
125  min[1] = ymin;
126  max[0] = xmax;
127  max[1] = ymax;
128  }
129 
131  PointSet *getHoleOf() { return holeOf; }
132 
133  int getNumPoints() const { return nbPoints; }
134 
142  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
143 
146  const GEOSGeometry *geos() const;
147 
150  double length() const;
151 
152  protected:
153  mutable GEOSGeometry *mGeos;
154  mutable bool mOwnsGeom;
155 
156  int nbPoints;
157  double *x = nullptr;
158  double *y; // points order is counterclockwise
159 
160  int *cHull = nullptr;
162 
163  int type;
164 
165  PointSet *holeOf = nullptr;
166  PointSet *parent = nullptr;
167 
168  PointSet( double x, double y );
169 
170  PointSet( const PointSet &ps );
171 
172  void deleteCoords();
173  void createGeosGeom() const;
174  const GEOSPreparedGeometry *preparedGeom() const;
175  void invalidateGeos();
176 
177  double xmin;
178  double xmax;
179  double ymin;
180  double ymax;
181 
182  private:
183 
184  mutable const GEOSPreparedGeometry *mPreparedGeom;
185 
186  };
187 
188 } // namespace pal
189 
190 #endif
191 
double length
Definition: pointset.h:60
PointSet * getHoleOf()
Returns NULL if this isn&#39;t a hole. Otherwise returns pointer to parent pointset.
Definition: pointset.h:131
A set of features which influence the labeling process.
Definition: layer.h:63
struct pal::_cHullBox CHullBox
int getNumPoints() const
Definition: pointset.h:133
double width
Definition: pointset.h:59
double ymax
Definition: pointset.h:180
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:122
double xmin
Definition: pointset.h:177
double ymin
Definition: pointset.h:179
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
Main class to handle feature.
Definition: feature.h:95
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
double * y
Definition: pointset.h:158
double x[4]
Definition: pointset.h:54
double y[4]
Definition: pointset.h:55
int getGeosType() const
Definition: pointset.h:120
GEOSGeometry * mGeos
Definition: pointset.h:153
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
double alpha
Definition: pointset.h:57
double xmax
Definition: pointset.h:178
Data structure to compute polygon&#39;s candidates costs.
bool mOwnsGeom
Definition: pointset.h:154