QGIS API Documentation  2.17.0-Master (bf77d09)
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 #include "qgsgeometry.h"
34 #include "rtree.hpp"
35 #include <cfloat>
36 #include <cmath>
37 #include <QLinkedList>
38 
39 namespace pal
40 {
41 
42  class Pal;
43  class Projection;
44  class LabelPosition;
45 
46  class PointSet;
47 
48  typedef struct _cHullBox
49  {
50  double x[4];
51  double y[4];
52 
53  double alpha;
54 
55  double width;
56  double length;
57  } CHullBox;
58 
64  class CORE_EXPORT PointSet
65  {
66  friend class FeaturePart;
67  friend class LabelPosition;
68  friend class CostCalculator;
69  friend class PolygonCostCalculator;
70  friend class Layer;
71 
72  public:
73  PointSet();
74  PointSet( int nbPoints, double *x, double *y );
75  virtual ~PointSet();
76 
77  PointSet* extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
78 
84  bool containsPoint( double x, double y ) const;
85 
94  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
95 
96  CHullBox * compute_chull_bbox();
97 
100  static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
101  QLinkedList<PointSet *> &shapes_final,
102  double xrm, double yrm );
103 
112  double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
113 
114  void getCentroid( double &px, double &py, bool forceInside = false ) const;
115 
116  int getGeosType() const { return type; }
117 
118  void getBoundingBox( double min[2], double max[2] ) const
119  {
120  min[0] = xmin;
121  min[1] = ymin;
122  max[0] = xmax;
123  max[1] = ymax;
124  }
125 
127  PointSet* getHoleOf() { return holeOf; }
128 
129  int getNumPoints() const { return nbPoints; }
130 
138  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
139 
142  const GEOSGeometry* geos() const;
143 
146  double length() const;
147 
148  protected:
149  mutable GEOSGeometry *mGeos;
150  mutable bool mOwnsGeom;
151 
152  int nbPoints;
153  double *x;
154  double *y; // points order is counterclockwise
155 
156  int *cHull;
158 
159  int type;
160 
163 
164  PointSet( double x, double y );
165 
166  PointSet( const PointSet &ps );
167 
168  void deleteCoords();
169  void createGeosGeom() const;
170  const GEOSPreparedGeometry* preparedGeom() const;
171  void invalidateGeos();
172 
173  double xmin;
174  double xmax;
175  double ymin;
176  double ymax;
177 
178  private:
179 
180  mutable const GEOSPreparedGeometry* mPreparedGeom;
181 
182  };
183 
184 } // namespace pal
185 
186 #endif
187 
double length
Definition: pointset.h:56
PointSet * getHoleOf()
Returns NULL if this isn&#39;t a hole.
Definition: pointset.h:127
A set of features which influence the labelling process.
Definition: layer.h:58
struct pal::_cHullBox CHullBox
int getGeosType() const
Definition: pointset.h:116
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
double width
Definition: pointset.h:55
PointSet * parent
Definition: pointset.h:162
double * x
Definition: pointset.h:153
double ymax
Definition: pointset.h:176
double xmin
Definition: pointset.h:173
PointSet * holeOf
Definition: pointset.h:161
double ymin
Definition: pointset.h:175
int * cHull
Definition: pointset.h:156
Main class to handle feature.
Definition: feature.h:91
int getNumPoints() const
Definition: pointset.h:129
double * y
Definition: pointset.h:154
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:118
double x[4]
Definition: pointset.h:50
double y[4]
Definition: pointset.h:51
GEOSGeometry * mGeos
Definition: pointset.h:149
LabelPosition is a candidate feature label position.
Definition: labelposition.h:51
double alpha
Definition: pointset.h:53
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
double xmax
Definition: pointset.h:174
Data structure to compute polygon&#39;s candidates costs.
bool mOwnsGeom
Definition: pointset.h:150