QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
162  bool isClosed() const;
163 
164  protected:
165  mutable GEOSGeometry *mGeos = nullptr;
166  mutable bool mOwnsGeom = false;
167 
168  int nbPoints;
169  double *x = nullptr;
170  double *y = nullptr; // points order is counterclockwise
171 
172  int *cHull = nullptr;
174 
175  int type;
176 
177  PointSet *holeOf = nullptr;
178  PointSet *parent = nullptr;
179 
180  PointSet( double x, double y );
181 
182  PointSet( const PointSet &ps );
183 
184  void deleteCoords();
185  void createGeosGeom() const;
186  const GEOSPreparedGeometry *preparedGeom() const;
187  void invalidateGeos();
188 
189  double xmin = std::numeric_limits<double>::max();
190  double xmax = std::numeric_limits<double>::lowest();
191  double ymin = std::numeric_limits<double>::max();
192  double ymax = std::numeric_limits<double>::lowest();
193 
194  private:
195 
196  mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;
197 
198  };
199 
200 } // namespace pal
201 
202 #endif
203 
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
Contains geos related utilities and functions.
Definition: qgsgeos.h:41
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.