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 <cfloat>
34 
35 #include <cmath>
36 #include <stddef.h>
37 #include <geos_c.h>
38 
39 #include "rtree.hpp"
40 #include "linkedlist.hpp"
41 
42 namespace pal
43 {
44 
45  class Pal;
46  class Feature;
47  class Projection;
48  class LabelPosition;
49 
50  typedef struct _cross
51  {
52  int pt;
53  double d;
54  double x;
55  double y;
56  int seg; // seg{0,1,2,3}
57  int nextCorner; // pt{0,1,2,3}
58  int way;
59 
60  } Crossing;
61 
62  class PointSet;
63 
64  typedef struct _cHullBox
65  {
66  double x[4];
67  double y[4];
68 
69  double alpha;
70 
71  double width;
72  double length;
73  } CHullBox;
74 
75 
76 
77  inline bool ptrCrossingCompare( Crossing * a, Crossing * b )
78  {
79  return a == b;
80  }
81 
82  inline bool crossingDist( void *a, void *b )
83  {
84  return (( Crossing* ) a )->d > (( Crossing* ) b )->d;
85  }
86 
87 
88  class CORE_EXPORT PointSet
89  {
90  friend class FeaturePart;
91  friend class LabelPosition;
92  friend class CostCalculator;
93  friend class PolygonCostCalculator;
94  friend class Layer;
95 
96  public:
97  PointSet();
98  PointSet( int nbPoints, double *x, double *y );
99  virtual ~PointSet();
100 
101  PointSet* extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
102 
103  PointSet* createProblemSpecificPointSet( double bbmin[2], double bbmax[2], bool *inside );
104 
105  CHullBox * compute_chull_bbox();
106 
107 
108  /*
109  * split a concave shape into several convex shapes
110  *
111  */
112  static void splitPolygons( LinkedList<PointSet*> *shapes_toProcess,
113  LinkedList<PointSet*> *shapes_final,
114  double xrm, double yrm, char *uid );
115 
116 
117 
129  double getDist( double px, double py, double *rx, double *ry );
130 
131 
132 
133  //double getDistInside(double px, double py);
134 
135  void getCentroid( double &px, double &py, bool forceInside = false );
136 
137 
138  int getGeosType() const { return type; }
139 
140  void getBoundingBox( double min[2], double max[2] ) const
141  {
142  min[0] = xmin; min[1] = ymin;
143  max[0] = xmax; max[1] = ymax;
144  }
145 
147  PointSet* getHoleOf() { return holeOf; }
148 
149  int getNumPoints() const { return nbPoints; }
150 
151  /*
152  * Iterate on line by real step of dl on x,y points
153  * @param nbPoint # point in line
154  * @param x x coord
155  * @param y y coord
156  * @param d ??
157  * @param ad distance from pt0 to each point (ad0 = pt0->pt0)
158  * @param dl ??
159  * @param px current x coord on line
160  * @param py current y coord on line
161  */
162  inline void getPoint( double *d, double *ad, double dl,
163  double *px, double *py )
164  {
165  int i;
166  double dx, dy, di;
167  double distr;
168 
169  i = 0;
170  if ( dl >= 0 )
171  {
172  while ( i < nbPoints && ad[i] <= dl ) i++;
173  i--;
174  }
175 
176  if ( i < nbPoints - 1 )
177  {
178  if ( dl < 0 )
179  {
180  dx = x[nbPoints-1] - x[0];
181  dy = y[nbPoints-1] - y[0];
182  di = sqrt( dx * dx + dy * dy );
183  }
184  else
185  {
186  dx = x[i+1] - x[i];
187  dy = y[i+1] - y[i];
188  di = d[i];
189  }
190 
191  distr = dl - ad[i];
192  *px = x[i] + dx * distr / di;
193  *py = y[i] + dy * distr / di;
194  }
195  else // just select last point...
196  {
197  *px = x[i];
198  *py = y[i];
199  }
200  }
201 
202  protected:
203  int nbPoints;
204  double *x;
205  double *y; // points order is counterclockwise
206 
207  int *cHull;
209 
210  int type;
211 
214 
215  PointSet( double x, double y );
216 
217  PointSet( PointSet &ps );
218 
219  void deleteCoords();
220 
221  double xmin;
222  double xmax;
223  double ymin;
224  double ymax;
225  };
226 
227 } // namespace pal
228 
229 #endif
230 
double y
Definition: pointset.h:55
double length
Definition: pointset.h:72
PointSet * getHoleOf()
Returns NULL if this isn't a hole.
Definition: pointset.h:147
A layer of spacial entites.
Definition: layer.h:60
struct pal::_cHullBox CHullBox
int getGeosType() const
Definition: pointset.h:138
double width
Definition: pointset.h:71
double d
Definition: pointset.h:53
PointSet * parent
Definition: pointset.h:213
double x
Definition: pointset.h:54
double * x
Definition: pointset.h:204
double ymax
Definition: pointset.h:224
double xmin
Definition: pointset.h:221
PointSet * holeOf
Definition: pointset.h:212
double ymin
Definition: pointset.h:223
int * cHull
Definition: pointset.h:207
bool crossingDist(void *a, void *b)
Definition: pointset.h:82
bool ptrCrossingCompare(Crossing *a, Crossing *b)
Definition: pointset.h:77
Main class to handle feature.
Definition: feature.h:133
struct pal::_cross Crossing
int getNumPoints() const
Definition: pointset.h:149
int min(int a, int b)
Definition: util.h:88
double * y
Definition: pointset.h:205
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:140
double x[4]
Definition: pointset.h:66
double y[4]
Definition: pointset.h:67
void getPoint(double *d, double *ad, double dl, double *px, double *py)
Definition: pointset.h:162
LabelPosition is a candidate feature label position.
Definition: labelposition.h:50
double alpha
Definition: pointset.h:69
int nextCorner
Definition: pointset.h:57
double xmax
Definition: pointset.h:222
int max(int a, int b)
Definition: util.h:82
Data structure to compute polygon's candidates costs.