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