QGIS API Documentation  2.99.0-Master (9fdd060)
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 
89  bool containsPoint( double x, double y ) const;
90 
100  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
101 
102  CHullBox *compute_chull_bbox();
103 
107  static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
108  QLinkedList<PointSet *> &shapes_final,
109  double xrm, double yrm );
110 
120  double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
121 
122  void getCentroid( double &px, double &py, bool forceInside = false ) const;
123 
124  int getGeosType() const { return type; }
125 
126  void getBoundingBox( double min[2], double max[2] ) const
127  {
128  min[0] = xmin;
129  min[1] = ymin;
130  max[0] = xmax;
131  max[1] = ymax;
132  }
133 
135  PointSet *getHoleOf() { return holeOf; }
136 
137  int getNumPoints() const { return nbPoints; }
138 
147  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
148 
152  const GEOSGeometry *geos() const;
153 
157  double length() const;
158 
159  protected:
160  mutable GEOSGeometry *mGeos = nullptr;
161  mutable bool mOwnsGeom = false;
162 
163  int nbPoints;
164  double *x = nullptr;
165  double *y; // points order is counterclockwise
166 
167  int *cHull = nullptr;
169 
170  int type;
171 
172  PointSet *holeOf = nullptr;
173  PointSet *parent = nullptr;
174 
175  PointSet( double x, double y );
176 
177  PointSet( const PointSet &ps );
178 
179  void deleteCoords();
180  void createGeosGeom() const;
181  const GEOSPreparedGeometry *preparedGeom() const;
182  void invalidateGeos();
183 
184  double xmin = DBL_MAX;
185  double xmax = -DBL_MAX;
186  double ymin = DBL_MAX;
187  double ymax = -DBL_MAX;
188 
189  private:
190 
191  mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
192 
193  };
194 
195 } // namespace pal
196 
197 #endif
198 
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:135
A set of features which influence the labeling process.
Definition: layer.h:63
struct pal::_cHullBox CHullBox
int getNumPoints() const
Definition: pointset.h:137
double width
Definition: pointset.h:59
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:126
Main class to handle feature.
Definition: feature.h:96
double * y
Definition: pointset.h:165
double x[4]
Definition: pointset.h:54
double y[4]
Definition: pointset.h:55
int getGeosType() const
Definition: pointset.h:124
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
double alpha
Definition: pointset.h:57
Data structure to compute polygon&#39;s candidates costs.