QGIS API Documentation
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 
63  class CORE_EXPORT PointSet
64  {
65  friend class FeaturePart;
66  friend class LabelPosition;
67  friend class CostCalculator;
68  friend class PolygonCostCalculator;
69  friend class Layer;
70 
71  public:
72  PointSet();
73  PointSet( int nbPoints, double *x, double *y );
74  virtual ~PointSet();
75 
76  PointSet* extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
77 
83  bool containsPoint( double x, double y ) const;
84 
93  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
94 
95  CHullBox * compute_chull_bbox();
96 
99  static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
100  QLinkedList<PointSet *> &shapes_final,
101  double xrm, double yrm );
102 
111  double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
112 
113  void getCentroid( double &px, double &py, bool forceInside = false ) const;
114 
115  int getGeosType() const { return type; }
116 
117  void getBoundingBox( double min[2], double max[2] ) const
118  {
119  min[0] = xmin;
120  min[1] = ymin;
121  max[0] = xmax;
122  max[1] = ymax;
123  }
124 
126  PointSet* getHoleOf() { return holeOf; }
127 
128  int getNumPoints() const { return nbPoints; }
129 
137  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
138 
141  const GEOSGeometry* geos() const;
142 
145  double length() const;
146 
147  protected:
148  mutable GEOSGeometry *mGeos;
149  mutable bool mOwnsGeom;
150 
151  int nbPoints;
152  double *x;
153  double *y; // points order is counterclockwise
154 
155  int *cHull;
157 
158  int type;
159 
162 
163  PointSet( double x, double y );
164 
165  PointSet( const PointSet &ps );
166 
167  void deleteCoords();
168  void createGeosGeom() const;
169  const GEOSPreparedGeometry* preparedGeom() const;
170  void invalidateGeos();
171 
172  double xmin;
173  double xmax;
174  double ymin;
175  double ymax;
176 
177  private:
178 
179  mutable const GEOSPreparedGeometry* mPreparedGeom;
180 
181  };
182 
183 } // namespace pal
184 
185 #endif
186 
double length
Definition: pointset.h:56
PointSet * getHoleOf()
Returns NULL if this isn&#39;t a hole.
Definition: pointset.h:126
A set of features which influence the labelling process.
Definition: layer.h:55
struct pal::_cHullBox CHullBox
int getGeosType() const
Definition: pointset.h:115
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:161
double * x
Definition: pointset.h:152
double ymax
Definition: pointset.h:175
double xmin
Definition: pointset.h:172
PointSet * holeOf
Definition: pointset.h:160
double ymin
Definition: pointset.h:174
int * cHull
Definition: pointset.h:155
Main class to handle feature.
Definition: feature.h:90
int getNumPoints() const
Definition: pointset.h:128
double * y
Definition: pointset.h:153
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:117
double x[4]
Definition: pointset.h:50
double y[4]
Definition: pointset.h:51
GEOSGeometry * mGeos
Definition: pointset.h:148
LabelPosition is a candidate feature label position.
Definition: labelposition.h:50
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:173
Data structure to compute polygon&#39;s candidates costs.
bool mOwnsGeom
Definition: pointset.h:149