QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #ifndef _FEATURE_H
35 #define _FEATURE_H
36 
37 #include <iostream>
38 #include <fstream>
39 #include <cmath>
40 
41 #include <geos_c.h>
42 
43 #include <pal/palgeometry.h>
44 
45 #include "pointset.h"
46 #include "util.h"
47 
48 
49 namespace pal
50 {
52  class CORE_EXPORT LabelInfo
53  {
54  public:
55  typedef struct
56  {
57  unsigned short chr;
58  double width;
59  } CharacterInfo;
60 
61  LabelInfo( int num, double height, double maxinangle = 20.0, double maxoutangle = -20.0 )
62  {
63  max_char_angle_inside = maxinangle;
64  // outside angle should be negative
65  max_char_angle_outside = maxoutangle > 0 ? -maxoutangle : maxoutangle;
66  label_height = height;
67  char_num = num;
68  char_info = new CharacterInfo[num];
69  }
70  ~LabelInfo() { delete [] char_info; }
71 
74  double label_height;
75  int char_num;
77  };
78 
79  class LabelPosition;
80  class FeaturePart;
81 
82  class CORE_EXPORT Feature
83  {
84  friend class FeaturePart;
85 
86  public:
87  Feature( Layer* l, const char* id, PalGeometry* userG, double lx, double ly );
88  ~Feature();
89 
90  void setLabelInfo( LabelInfo* info ) { labelInfo = info; }
91  void setDistLabel( double dist ) { distlabel = dist; }
92  //Set label position of the feature to fixed x/y values
93  void setFixedPosition( double x, double y ) { fixedPos = true; fixedPosX = x; fixedPosY = y;}
94  void setQuadOffset( double x, double y ) { quadOffset = true; quadOffsetX = x; quadOffsetY = y;}
95  void setPosOffset( double x, double y ) { offsetPos = true; offsetPosX = x; offsetPosY = y;}
96  bool fixedPosition() const { return fixedPos; }
97  //Set label rotation to fixed value
98  void setFixedAngle( double a ) { fixedRotation = true; fixedAngle = a; }
99  void setRepeatDistance( double dist ) { repeatDist = dist; }
100  double repeatDistance() const { return repeatDist; }
101  void setAlwaysShow( bool bl ) { alwaysShow = bl; }
102 
103  protected:
106  double label_x;
107  double label_y;
108  double distlabel;
109  LabelInfo* labelInfo; // optional
110 
111  char *uid;
112 
113  bool fixedPos; //true in case of fixed position (only 1 candidate position with cost 0)
114  double fixedPosX;
115  double fixedPosY;
116  bool quadOffset; // true if a quadrant offset exists
117  double quadOffsetX;
118  double quadOffsetY;
119  bool offsetPos; //true if position is to be offset by set amount
120  double offsetPosX;
121  double offsetPosY;
122  //Fixed (e.g. data defined) angle only makes sense together with fixed position
124  double fixedAngle; //fixed angle value (in rad)
125  double repeatDist;
126 
127  bool alwaysShow; //true is label is to always be shown (but causes overlapping)
128 
129 
130  // array of parts - possibly not necessary
131  //int nPart;
132  //FeaturePart** parts;
133  };
134 
138  class CORE_EXPORT FeaturePart : public PointSet
139  {
140 
141  protected:
143 
144  int nbHoles;
146 
147  GEOSGeometry *the_geom;
148  bool ownsGeom;
149 
151  void extractCoords( const GEOSGeometry* geom );
152 
156  void removeDuplicatePoints();
157 
158  public:
159 
166  FeaturePart( Feature *feat, const GEOSGeometry* geom );
167 
171  virtual ~FeaturePart();
172 
184  int setPositionForPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );
185 
189  int setPositionOverPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );
190 
200  int setPositionForLine( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );
201 
202  LabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
203  int orientation, int index, double distance );
204 
208  int setPositionForLineCurved( LabelPosition ***lPos, PointSet* mapShape );
209 
219  int setPositionForPolygon( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );
220 
221 #if 0
222 
230  LinkedList<Feature*> *splitFeature( double bbox[4] );
231 
232 
237  int getId();
238 #endif
239 
244  Feature* getFeature() { return f; }
245 
250  const GEOSGeometry* getGeometry() const { return the_geom; }
251 
256  Layer * getLayer();
257 
258 #if 0
259 
264  void save( std::ofstream *file );
265 #endif
266 
278  int setPosition( double scale, LabelPosition ***lPos, double bbox_min[2], double bbox_max[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>*candidates
279 #ifdef _EXPORT_MAP_
280  , std::ofstream &svgmap
281 #endif
282  );
283 
288  const char *getUID();
289 
290 
295  void print();
296 
297 
299 
300  void setLabelSize( double lx, double ly ) { f->label_x = lx; f->label_y = ly; }
301  double getLabelWidth() const { return f->label_x; }
302  double getLabelHeight() const { return f->label_y; }
303  void setLabelDistance( double dist ) { f->distlabel = dist; }
304  double getLabelDistance() const { return f->distlabel; }
305  void setLabelInfo( LabelInfo* info ) { f->labelInfo = info; }
306 
307  bool getFixedRotation() { return f->fixedRotation; }
308  double getLabelAngle() { return f->fixedAngle; }
309  bool getFixedPosition() { return f->fixedPos; }
310  bool getAlwaysShow() { return f->alwaysShow; }
311 
312  int getNumSelfObstacles() const { return nbHoles; }
313  PointSet* getSelfObstacle( int i ) { return holes[i]; }
314 
316  bool isConnected( FeaturePart* p2 );
317 
320  bool mergeWithFeaturePart( FeaturePart* other );
321 
322  void addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4] );
323 
324  };
325 
326 } // end namespace pal
327 
328 #endif
bool getAlwaysShow()
Definition: feature.h:310
double fixedAngle
Definition: feature.h:124
static unsigned index
double fixedPosY
Definition: feature.h:115
bool getFixedRotation()
Definition: feature.h:307
void setLabelInfo(LabelInfo *info)
Definition: feature.h:305
bool fixedRotation
Definition: feature.h:123
double max_char_angle_outside
Definition: feature.h:73
Feature * getFeature()
return the feature
Definition: feature.h:244
bool fixedPos
Definition: feature.h:113
double getLabelHeight() const
Definition: feature.h:302
int getNumSelfObstacles() const
Definition: feature.h:312
A layer of spacial entites.
Definition: layer.h:65
double offsetPosX
Definition: feature.h:120
void setFixedAngle(double a)
Definition: feature.h:98
double quadOffsetY
Definition: feature.h:118
double getLabelWidth() const
Definition: feature.h:301
double repeatDist
Definition: feature.h:125
bool offsetPos
Definition: feature.h:119
LabelInfo(int num, double height, double maxinangle=20.0, double maxoutangle=-20.0)
Definition: feature.h:61
double distlabel
Definition: feature.h:108
PalGeometry * getUserGeometry()
Definition: feature.h:298
void setDistLabel(double dist)
Definition: feature.h:91
CharacterInfo * char_info
Definition: feature.h:76
void setPosOffset(double x, double y)
Definition: feature.h:95
Layer * layer
Definition: feature.h:104
void setQuadOffset(double x, double y)
Definition: feature.h:94
Feature * f
Definition: feature.h:142
PointSet ** holes
Definition: feature.h:145
double getLabelDistance() const
Definition: feature.h:304
bool getFixedPosition()
Definition: feature.h:309
const GEOSGeometry * getGeometry() const
return the geometry
Definition: feature.h:250
void setAlwaysShow(bool bl)
Definition: feature.h:101
void setRepeatDistance(double dist)
Definition: feature.h:99
void setLabelInfo(LabelInfo *info)
Definition: feature.h:90
double quadOffsetX
Definition: feature.h:117
optional additional info about label (for curved labels)
Definition: feature.h:52
PointSet * getSelfObstacle(int i)
Definition: feature.h:313
double label_height
Definition: feature.h:74
double offsetPosY
Definition: feature.h:121
bool quadOffset
Definition: feature.h:116
Main class to handle feature.
Definition: feature.h:138
double getLabelAngle()
Definition: feature.h:308
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:93
QString file
Definition: qgssvgcache.cpp:76
GEOSGeometry * the_geom
Definition: feature.h:147
LabelInfo * labelInfo
Definition: feature.h:109
double label_y
Definition: feature.h:107
void setLabelSize(double lx, double ly)
Definition: feature.h:300
double max_char_angle_inside
Definition: feature.h:72
PalGeometry * userGeom
Definition: feature.h:105
char * uid
Definition: feature.h:111
double label_x
Definition: feature.h:106
void setLabelDistance(double dist)
Definition: feature.h:303
LabelPositon is a candidate feature label position.
Definition: labelposition.h:53
Interface that allows Pal to access user's geometries.
Definition: palgeometry.h:42
bool alwaysShow
Definition: feature.h:127
double fixedPosX
Definition: feature.h:114
int char_num
Definition: feature.h:75
double repeatDistance() const
Definition: feature.h:100
bool fixedPosition() const
Definition: feature.h:96