QGIS API Documentation  2.99.0-Master (37c43df)
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 "pointset.h"
34 #include "labelposition.h" // for LabelPosition enum
35 #include "qgslabelfeature.h"
36 #include "rtree.hpp"
37 #include <iostream>
38 #include <fstream>
39 #include <cmath>
40 #include <QString>
41 
47 namespace pal
48 {
50  class CORE_EXPORT LabelInfo
51  {
52  public:
53  typedef struct
54  {
55  double width;
56  } CharacterInfo;
57 
58  LabelInfo( int num, double height, double maxinangle = 20.0, double maxoutangle = -20.0 )
59  {
60  max_char_angle_inside = maxinangle;
61  // outside angle should be negative
62  max_char_angle_outside = maxoutangle > 0 ? -maxoutangle : maxoutangle;
63  label_height = height;
64  char_num = num;
65  char_info = new CharacterInfo[num];
66  }
67  ~LabelInfo() { delete [] char_info; }
68 
71  double label_height;
72  int char_num;
74  private:
75 
76  LabelInfo( const LabelInfo& rh );
77  LabelInfo& operator=( const LabelInfo& rh );
78  };
79 
80  class LabelPosition;
81  class FeaturePart;
82 
89  class CORE_EXPORT FeaturePart : public PointSet
90  {
91 
92  public:
93 
98  FeaturePart( QgsLabelFeature* lf, const GEOSGeometry* geom );
99 
100  FeaturePart( const FeaturePart& other );
101 
104  virtual ~FeaturePart();
105 
108  QgsLabelFeature* feature() { return mLF; }
109 
112  Layer* layer();
113 
116  QgsFeatureId featureId() const;
117 
126  int createCandidates( QList<LabelPosition *> &lPos, double bboxMin[2], double bboxMax[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>* candidates );
127 
135  int createCandidatesAroundPoint( double x, double y, QList<LabelPosition *> &lPos, double angle );
136 
144  int createCandidatesOverPoint( double x, double y, QList<LabelPosition *> &lPos, double angle );
145 
153  int createCandidatesAtOrderedPositionsOverPoint( double x, double y, QList<LabelPosition *> &lPos, double angle );
154 
160  int createCandidatesAlongLine( QList<LabelPosition *> &lPos, PointSet *mapShape );
161 
168  int createCandidatesAlongLineNearStraightSegments( QList<LabelPosition *> &lPos, PointSet *mapShape );
169 
178  int createCandidatesAlongLineNearMidpoint( QList<LabelPosition *> &lPos, PointSet *mapShape, double initialCost = 0.0 );
179 
190  LabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
191  int& orientation, int index, double distance, bool& reversed, bool& flip );
192 
198  int createCurvedCandidatesAlongLine( QList<LabelPosition *> &lPos, PointSet* mapShape );
199 
205  int createCandidatesForPolygon( QList<LabelPosition *> &lPos, PointSet *mapShape );
206 
212  bool hasSameLabelFeatureAs( FeaturePart* part ) const;
213 
214 #if 0
215 
220  void print();
221 #endif
222 
223  double getLabelWidth() const { return mLF->size().width(); }
224  double getLabelHeight() const { return mLF->size().height(); }
225  double getLabelDistance() const { return mLF->distLabel(); }
226 
228  bool hasFixedRotation() const { return mLF->hasFixedAngle(); }
229 
231  double fixedAngle() const { return mLF->fixedAngle(); }
232 
234  bool hasFixedPosition() const { return mLF->hasFixedPosition(); }
235 
238  bool alwaysShow() const { return mLF->alwaysShow(); }
239 
241  bool isObstacle() const { return mLF->isObstacle(); }
242 
245  double obstacleFactor() const { return mLF->obstacleFactor(); }
246 
248  double repeatDistance() const { return mLF->repeatDistance(); }
249 
251  int getNumSelfObstacles() const { return mHoles.count(); }
253  FeaturePart* getSelfObstacle( int i ) { return mHoles.at( i ); }
254 
256  bool isConnected( FeaturePart* p2 );
257 
260  bool mergeWithFeaturePart( FeaturePart* other );
261 
262  void addSizePenalty( int nbp, QList<LabelPosition *> &lPos, double bbx[4], double bby[4] );
263 
269  double calculatePriority() const;
270 
272  bool showUprightLabels() const;
273 
275  bool nextCharPosition( double charWidth, double segment_length, PointSet* path_positions, int& index, double& distance,
276  double& start_x, double& start_y, double& end_x, double& end_y ) const;
277 
278  protected:
279 
281  QList<FeaturePart*> mHoles;
282 
284  void extractCoords( const GEOSGeometry* geom );
285 
286  private:
287 
288  LabelPosition::Quadrant quadrantFromOffset() const;
289  };
290 
291 } // end namespace pal
292 
293 #endif
static unsigned index
double obstacleFactor() const
Returns the feature&#39;s obstacle factor, which represents the penalty incurred for a label to overlap t...
Definition: feature.h:245
double fixedAngle() const
Returns the fixed angle for the feature&#39;s label.
Definition: feature.h:231
QList< FeaturePart * > mHoles
Definition: feature.h:281
double max_char_angle_outside
Definition: feature.h:70
QgsLabelFeature * feature()
Returns the parent feature.
Definition: feature.h:108
bool hasFixedRotation() const
Returns true if the feature&#39;s label has a fixed rotation.
Definition: feature.h:228
A set of features which influence the labelling process.
Definition: layer.h:59
bool alwaysShow() const
Returns true if the feature&#39;s label should always been shown, even when it collides with other labels...
Definition: feature.h:238
int getNumSelfObstacles() const
Get number of holes (inner rings) - they are considered as obstacles.
Definition: feature.h:251
LabelInfo(int num, double height, double maxinangle=20.0, double maxoutangle=-20.0)
Definition: feature.h:58
double getLabelDistance() const
Definition: feature.h:225
CharacterInfo * char_info
Definition: feature.h:73
double repeatDistance() const
Returns the distance between repeating labels for this feature.
Definition: feature.h:248
bool isObstacle() const
Returns true if the feature should act as an obstacle to labels.
Definition: feature.h:241
Optional additional info about label (for curved labels)
Definition: feature.h:50
double label_height
Definition: feature.h:71
double getLabelHeight() const
Definition: feature.h:224
Main class to handle feature.
Definition: feature.h:89
bool hasFixedPosition() const
Returns true if the feature&#39;s label has a fixed position.
Definition: feature.h:234
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
double max_char_angle_inside
Definition: feature.h:69
FeaturePart * getSelfObstacle(int i)
Get hole (inner ring) - considered as obstacle.
Definition: feature.h:253
double getLabelWidth() const
Definition: feature.h:223
LabelPosition is a candidate feature label position.
Definition: labelposition.h:51
QgsLabelFeature * mLF
Definition: feature.h:280
qint64 QgsFeatureId
Definition: qgsfeature.h:32
Quadrant
Position of label candidate relative to feature.
Definition: labelposition.h:61
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)
Definition: MathUtils.cc:857
int char_num
Definition: feature.h:72