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