QGIS API Documentation  2.99.0-Master (7fe5405)
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 #include <cmath>
35 #include <QLinkedList>
36 #include <geos_c.h>
37 
38 #include "qgis_core.h"
39 
40 namespace pal
41 {
42 
43  class Pal;
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 
65  class CORE_EXPORT PointSet
66  {
67  friend class FeaturePart;
68  friend class LabelPosition;
69  friend class CostCalculator;
70  friend class PolygonCostCalculator;
71  friend class Layer;
72 
73  public:
74  PointSet();
75  PointSet( int nbPoints, double *x, double *y );
76  virtual ~PointSet();
77 
78  PointSet* extractShape( int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty );
79 
85  bool containsPoint( double x, double y ) const;
86 
95  bool containsLabelCandidate( double x, double y, double width, double height, double alpha = 0 ) const;
96 
97  CHullBox * compute_chull_bbox();
98 
101  static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
102  QLinkedList<PointSet *> &shapes_final,
103  double xrm, double yrm );
104 
113  double minDistanceToPoint( double px, double py, double *rx = nullptr, double *ry = nullptr ) const;
114 
115  void getCentroid( double &px, double &py, bool forceInside = false ) const;
116 
117  int getGeosType() const { return type; }
118 
119  void getBoundingBox( double min[2], double max[2] ) const
120  {
121  min[0] = xmin;
122  min[1] = ymin;
123  max[0] = xmax;
124  max[1] = ymax;
125  }
126 
128  PointSet* getHoleOf() { return holeOf; }
129 
130  int getNumPoints() const { return nbPoints; }
131 
139  void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );
140 
143  const GEOSGeometry* geos() const;
144 
147  double length() const;
148 
149  protected:
150  mutable GEOSGeometry *mGeos;
151  mutable bool mOwnsGeom;
152 
153  int nbPoints;
154  double *x;
155  double *y; // points order is counterclockwise
156 
157  int *cHull;
159 
160  int type;
161 
164 
165  PointSet( double x, double y );
166 
167  PointSet( const PointSet &ps );
168 
169  void deleteCoords();
170  void createGeosGeom() const;
171  const GEOSPreparedGeometry* preparedGeom() const;
172  void invalidateGeos();
173 
174  double xmin;
175  double xmax;
176  double ymin;
177  double ymax;
178 
179  private:
180 
181  mutable const GEOSPreparedGeometry* mPreparedGeom;
182 
183  };
184 
185 } // namespace pal
186 
187 #endif
188 
double length
Definition: pointset.h:57
PointSet * getHoleOf()
Returns NULL if this isn&#39;t a hole. Otherwise returns pointer to parent pointset.
Definition: pointset.h:128
A set of features which influence the labeling process.
Definition: layer.h:60
struct pal::_cHullBox CHullBox
int getNumPoints() const
Definition: pointset.h:130
double width
Definition: pointset.h:56
PointSet * parent
Definition: pointset.h:163
double * x
Definition: pointset.h:154
double ymax
Definition: pointset.h:177
void getBoundingBox(double min[2], double max[2]) const
Definition: pointset.h:119
double xmin
Definition: pointset.h:174
PointSet * holeOf
Definition: pointset.h:162
double ymin
Definition: pointset.h:176
int * cHull
Definition: pointset.h:157
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
Main class to handle feature.
Definition: feature.h:92
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
double * y
Definition: pointset.h:155
double x[4]
Definition: pointset.h:51
double y[4]
Definition: pointset.h:52
int getGeosType() const
Definition: pointset.h:117
GEOSGeometry * mGeos
Definition: pointset.h:150
LabelPosition is a candidate feature label position.
Definition: labelposition.h:52
double alpha
Definition: pointset.h:54
double xmax
Definition: pointset.h:175
Data structure to compute polygon&#39;s candidates costs.
bool mOwnsGeom
Definition: pointset.h:151