QGIS API Documentation  2.12.0-Lyon
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 
59 
60  class CORE_EXPORT PointSet
61  {
62  friend class FeaturePart;
63  friend class LabelPosition;
64  friend class CostCalculator;
65  friend class PolygonCostCalculator;
66  friend class Layer;
67 
68  public:
69  PointSet();
70  PointSet( int nbPoints, double *x, double *y );
71  virtual ~PointSet();
72 
73  PointSet* extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
74 
80  bool containsPoint( double x, double y ) const;
81 
90  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
91 
92  CHullBox * compute_chull_bbox();
93 
96  static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
97  QLinkedList<PointSet *> &shapes_final,
98  double xrm, double yrm, const QgsFeatureId &uid );
99 
108  double minDistanceToPoint( double px, double py, double *rx = 0, double *ry = 0 ) const;
109 
110  void getCentroid( double &px, double &py, bool forceInside = false ) const;
111 
112  int getGeosType() const { return type; }
113 
114  void getBoundingBox( double min[2], double max[2] ) const
115  {
116  min[0] = xmin; min[1] = ymin;
117  max[0] = xmax; max[1] = ymax;
118  }
119 
121  PointSet* getHoleOf() { return holeOf; }
122 
123  int getNumPoints() const { return nbPoints; }
124 
132  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
133 
136  const GEOSGeometry* geos() const;
137 
140  double length() const;
141 
142  protected:
143  mutable GEOSGeometry *mGeos;
144  mutable bool mOwnsGeom;
145 
146  int nbPoints;
147  double *x;
148  double *y; // points order is counterclockwise
149 
150  int *cHull;
152 
153  int type;
154 
157 
158  PointSet( double x, double y );
159 
160  PointSet( const PointSet &ps );
161 
162  void deleteCoords();
163  void createGeosGeom() const;
164  const GEOSPreparedGeometry* preparedGeom() const;
165  void invalidateGeos();
166 
167  double xmin;
168  double xmax;
169  double ymin;
170  double ymax;
171 
172  private:
173 
174  mutable const GEOSPreparedGeometry* mPreparedGeom;
175 
176  };
177 
178 } // namespace pal
179 
180 #endif
181 
double length
Definition: pointset.h:56
PointSet * getHoleOf()
Returns NULL if this isn't a hole.
Definition: pointset.h:121
A layer of spacial entites.
Definition: layer.h:57
struct pal::_cHullBox CHullBox
int getGeosType() const
Definition: pointset.h:112
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:156
double * x
Definition: pointset.h:147
double ymax
Definition: pointset.h:170
double xmin
Definition: pointset.h:167
PointSet * holeOf
Definition: pointset.h:155
double ymin
Definition: pointset.h:169
int * cHull
Definition: pointset.h:150
Main class to handle feature.
Definition: feature.h:79
int getNumPoints() const
Definition: pointset.h:123
double * y
Definition: pointset.h:148
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:114
double x[4]
Definition: pointset.h:50
double y[4]
Definition: pointset.h:51
GEOSGeometry * mGeos
Definition: pointset.h:143
LabelPosition is a candidate feature label position.
Definition: labelposition.h:48
qint64 QgsFeatureId
Definition: qgsfeature.h:31
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:168
Data structure to compute polygon's candidates costs.
bool mOwnsGeom
Definition: pointset.h:144