QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
feature.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 _FEATURE_H
31 #define _FEATURE_H
32 
33 #include <iostream>
34 #include <fstream>
35 #include <cmath>
36 
37 #include <geos_c.h>
38 
39 #include "palgeometry.h"
40 #include "pointset.h"
41 #include "util.h"
42 #include "labelposition.h"
43 
44 namespace pal
45 {
47  class CORE_EXPORT LabelInfo
48  {
49  public:
50  typedef struct
51  {
52  unsigned short chr;
53  double width;
54  } CharacterInfo;
55 
56  LabelInfo( int num, double height, double maxinangle = 20.0, double maxoutangle = -20.0 )
57  {
58  max_char_angle_inside = maxinangle;
59  // outside angle should be negative
60  max_char_angle_outside = maxoutangle > 0 ? -maxoutangle : maxoutangle;
61  label_height = height;
62  char_num = num;
63  char_info = new CharacterInfo[num];
64  }
65  ~LabelInfo() { delete [] char_info; }
66 
69  double label_height;
70  int char_num;
72  };
73 
74  class LabelPosition;
75  class FeaturePart;
76 
77  class CORE_EXPORT Feature
78  {
79  friend class FeaturePart;
80 
81  public:
82  Feature( Layer* l, const char* geom_id, PalGeometry* userG, double lx, double ly );
83  ~Feature();
84 
85  void setLabelInfo( LabelInfo* info ) { labelInfo = info; }
86  void setDistLabel( double dist ) { distlabel = dist; }
87  //Set label position of the feature to fixed x/y values
88  void setFixedPosition( double x, double y ) { fixedPos = true; fixedPosX = x; fixedPosY = y;}
89  void setQuadOffset( double x, double y ) { quadOffset = true; quadOffsetX = x; quadOffsetY = y;}
90  void setPosOffset( double x, double y ) { offsetPos = true; offsetPosX = x; offsetPosY = y;}
91  bool fixedPosition() const { return fixedPos; }
92  //Set label rotation to fixed value
93  void setFixedAngle( double a ) { fixedRotation = true; fixedAngle = a; }
94  void setRepeatDistance( double dist ) { repeatDist = dist; }
95  double repeatDistance() const { return repeatDist; }
96  void setAlwaysShow( bool bl ) { alwaysShow = bl; }
97 
98  protected:
101  double label_x;
102  double label_y;
103  double distlabel;
104  LabelInfo* labelInfo; // optional
105 
106  char *uid;
107 
108  bool fixedPos; //true in case of fixed position (only 1 candidate position with cost 0)
109  double fixedPosX;
110  double fixedPosY;
111  bool quadOffset; // true if a quadrant offset exists
112  double quadOffsetX;
113  double quadOffsetY;
114  bool offsetPos; //true if position is to be offset by set amount
115  double offsetPosX;
116  double offsetPosY;
117  //Fixed (e.g. data defined) angle only makes sense together with fixed position
119  double fixedAngle; //fixed angle value (in rad)
120  double repeatDist;
121 
122  bool alwaysShow; //true is label is to always be shown (but causes overlapping)
123 
124 
125  // array of parts - possibly not necessary
126  //int nPart;
127  //FeaturePart** parts;
128  };
129 
133  class CORE_EXPORT FeaturePart : public PointSet
134  {
135 
136  public:
137 
144  FeaturePart( Feature *feat, const GEOSGeometry* geom );
145 
149  virtual ~FeaturePart();
150 
162  int setPositionForPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );
163 
167  int setPositionOverPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );
168 
178  int setPositionForLine( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );
179 
180  LabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
181  int orientation, int index, double distance );
182 
186  int setPositionForLineCurved( LabelPosition ***lPos, PointSet* mapShape );
187 
197  int setPositionForPolygon( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );
198 
203  Feature* getFeature() { return f; }
204 
209  const GEOSGeometry* getGeometry() const { return the_geom; }
210 
215  Layer * getLayer();
216 
228  int setPosition( double scale, LabelPosition ***lPos, double bbox_min[2], double bbox_max[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>*candidates );
229 
234  const char *getUID();
235 
236 
241  void print();
242 
243 
244  PalGeometry* getUserGeometry() { return f->userGeom; }
245 
246  void setLabelSize( double lx, double ly ) { f->label_x = lx; f->label_y = ly; }
247  double getLabelWidth() const { return f->label_x; }
248  double getLabelHeight() const { return f->label_y; }
249  void setLabelDistance( double dist ) { f->distlabel = dist; }
250  double getLabelDistance() const { return f->distlabel; }
251  void setLabelInfo( LabelInfo* info ) { f->labelInfo = info; }
252 
253  bool getFixedRotation() { return f->fixedRotation; }
254  double getLabelAngle() { return f->fixedAngle; }
255  bool getFixedPosition() { return f->fixedPos; }
256  bool getAlwaysShow() { return f->alwaysShow; }
257 
258  int getNumSelfObstacles() const { return nbHoles; }
259  PointSet* getSelfObstacle( int i ) { return holes[i]; }
260 
262  bool isConnected( FeaturePart* p2 );
263 
266  bool mergeWithFeaturePart( FeaturePart* other );
267 
268  void addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4] );
269 
270  protected:
272 
273  int nbHoles;
275 
276  GEOSGeometry *the_geom;
277  bool ownsGeom;
278 
280  void extractCoords( const GEOSGeometry* geom );
281 
285  void removeDuplicatePoints();
286 
287  private:
288 
289  LabelPosition::Quadrant quadrantFromOffset() const;
290  };
291 
292 } // end namespace pal
293 
294 #endif
bool getAlwaysShow()
Definition: feature.h:256
double fixedAngle
Definition: feature.h:119
static unsigned index
double fixedPosY
Definition: feature.h:110
bool getFixedRotation()
Definition: feature.h:253
void setLabelInfo(LabelInfo *info)
Definition: feature.h:251
bool fixedRotation
Definition: feature.h:118
double max_char_angle_outside
Definition: feature.h:68
Feature * getFeature()
return the feature
Definition: feature.h:203
bool fixedPos
Definition: feature.h:108
double getLabelHeight() const
Definition: feature.h:248
int getNumSelfObstacles() const
Definition: feature.h:258
A layer of spacial entites.
Definition: layer.h:60
double offsetPosX
Definition: feature.h:115
void setFixedAngle(double a)
Definition: feature.h:93
double quadOffsetY
Definition: feature.h:113
double getLabelWidth() const
Definition: feature.h:247
double repeatDist
Definition: feature.h:120
bool offsetPos
Definition: feature.h:114
LabelInfo(int num, double height, double maxinangle=20.0, double maxoutangle=-20.0)
Definition: feature.h:56
double distlabel
Definition: feature.h:103
PalGeometry * getUserGeometry()
Definition: feature.h:244
void setDistLabel(double dist)
Definition: feature.h:86
CharacterInfo * char_info
Definition: feature.h:71
void setPosOffset(double x, double y)
Definition: feature.h:90
Layer * layer
Definition: feature.h:99
void setQuadOffset(double x, double y)
Definition: feature.h:89
Feature * f
Definition: feature.h:271
PointSet ** holes
Definition: feature.h:274
double getLabelDistance() const
Definition: feature.h:250
bool getFixedPosition()
Definition: feature.h:255
const GEOSGeometry * getGeometry() const
return the geometry
Definition: feature.h:209
void setAlwaysShow(bool bl)
Definition: feature.h:96
void setRepeatDistance(double dist)
Definition: feature.h:94
void setLabelInfo(LabelInfo *info)
Definition: feature.h:85
double quadOffsetX
Definition: feature.h:112
Optional additional info about label (for curved labels)
Definition: feature.h:47
PointSet * getSelfObstacle(int i)
Definition: feature.h:259
double label_height
Definition: feature.h:69
double offsetPosY
Definition: feature.h:116
bool quadOffset
Definition: feature.h:111
Main class to handle feature.
Definition: feature.h:133
double getLabelAngle()
Definition: feature.h:254
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void setFixedPosition(double x, double y)
Definition: feature.h:88
GEOSGeometry * the_geom
Definition: feature.h:276
LabelInfo * labelInfo
Definition: feature.h:104
double label_y
Definition: feature.h:102
void setLabelSize(double lx, double ly)
Definition: feature.h:246
double max_char_angle_inside
Definition: feature.h:67
PalGeometry * userGeom
Definition: feature.h:100
char * uid
Definition: feature.h:106
double label_x
Definition: feature.h:101
void setLabelDistance(double dist)
Definition: feature.h:249
LabelPosition is a candidate feature label position.
Definition: labelposition.h:50
Quadrant
Position of label candidate relative to feature.
Definition: labelposition.h:60
Interface that allows Pal to access user's geometries.
Definition: palgeometry.h:42
bool alwaysShow
Definition: feature.h:122
double fixedPosX
Definition: feature.h:109
int char_num
Definition: feature.h:70
double repeatDistance() const
Definition: feature.h:95
bool fixedPosition() const
Definition: feature.h:91