QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
labelposition.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 LABELPOSITION_H
31#define LABELPOSITION_H
32
33#define SIP_NO_FILE
34
35
36#include "qgis_core.h"
37#include "pointset.h"
38#include "palrtree.h"
39#include <fstream>
40
41namespace pal
42{
43
44 class FeaturePart;
45 class Pal;
46 class Label;
47
48
55 class CORE_EXPORT LabelPosition : public PointSet
56 {
57 friend class CostCalculator;
58 friend class PolygonCostCalculator;
59
60 public:
61
66 {
67 SameDirection,
68 Reversed
69 };
70
85 LabelPosition( int id, double x1, double y1,
86 double w, double h,
87 double alpha, double cost,
88 FeaturePart *feature,
89 LabelDirectionToLine directionToLine = LabelDirectionToLine::SameDirection,
91
92 LabelPosition( const LabelPosition &other );
93
94 ~LabelPosition() override;
95
101 bool intersects( const GEOSPreparedGeometry *geometry );
102
108 bool within( const GEOSPreparedGeometry *geometry );
109
118 bool isInConflict( const LabelPosition *ls ) const;
119
126 void getBoundingBox( double amin[2], double amax[2] ) const;
127
133 QgsRectangle outerBoundingBox() const;
134
140 QgsRectangle boundingBoxForCandidateConflicts( Pal *pal ) const;
141
146 bool outerBoundingBoxIntersects( const LabelPosition *other ) const;
147
155 double getDistanceToPoint( double xp, double yp, bool useOuterBounds ) const;
156
162 bool crossesLine( PointSet *line ) const;
163
169 bool crossesBoundary( PointSet *polygon ) const;
170
175 int polygonIntersectionCost( PointSet *polygon ) const;
176
182 bool intersectsWithPolygon( PointSet *polygon ) const;
183
187 int getId() const;
188
192 FeaturePart *getFeaturePart() const;
193
194 int getNumOverlaps() const { return nbOverlap; }
195 void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
196
200 void incrementNumOverlaps() { nbOverlap++; }
201
205 void decrementNumOverlaps() { nbOverlap++; }
206
207 int getProblemFeatureId() const { return probFeat; }
208
213 void setProblemIds( int probFid, int lpId )
214 {
215 probFeat = probFid;
216 id = lpId;
217 if ( mNextPart ) mNextPart->setProblemIds( probFid, lpId );
218 }
219
224 double cost() const { return mCost; }
225
231 void setCost( double newCost ) { mCost = newCost; }
232
239 void setConflictsWithObstacle( bool conflicts );
240
245 bool conflictsWithObstacle() const { return mHasObstacleConflict; }
246
253 void setHasHardObstacleConflict( bool conflicts );
254
261 bool hasHardObstacleConflict() const { return mHasHardConflict; }
262
264 void validateCost();
265
270 double getX( int i = 0 ) const;
271
276 double getY( int i = 0 ) const;
277
278 double getWidth() const { return w; }
279 double getHeight() const { return h; }
280
284 double getAlpha() const;
285
289 bool isReversedFromLineDirection() const { return mDirectionToLine == LabelDirectionToLine::Reversed; }
290
291 bool getUpsideDown() const { return upsideDown; }
292
296 Qgis::LabelQuadrantPosition quadrant() const { return mQuadrant; }
297
303 LabelPosition *nextPart() const { return mNextPart.get(); }
304
310 void setNextPart( std::unique_ptr< LabelPosition > next ) { mNextPart = std::move( next ); }
311
312 // -1 if not multi-part
313 int getPartId() const { return partId; }
314 void setPartId( int id ) { partId = id; }
315
321 void setUpsideDownCharCount( int count ) { mUpsideDownCharCount = count ; }
322
328 int upsideDownCharCount() const { return mUpsideDownCharCount; }
329
333 void removeFromIndex( PalRtree<LabelPosition> &index );
334
338 void insertIntoIndex( PalRtree<LabelPosition> &index );
339
345 const GEOSGeometry *multiPartGeom() const;
346
352 const GEOSPreparedGeometry *preparedMultiPartGeom() const;
353
359 const GEOSPreparedGeometry *preparedOuterBoundsGeom() const;
360
369 unsigned int globalId() const { return mGlobalId; }
370
377 void setGlobalId( unsigned int id ) { mGlobalId = id; }
378
382 double angleDifferential();
383
384 protected:
385
386 int id;
387
388 FeaturePart *feature = nullptr;
389
390 // bug # 1 (maxence 10/23/2008)
392
394
396 double alpha;
397
398 double w;
399 double h;
400
402
403
405
406 private:
407
409
410 LabelDirectionToLine mDirectionToLine = LabelDirectionToLine::SameDirection;
411
412 unsigned int mGlobalId = 0;
413 std::unique_ptr< LabelPosition > mNextPart;
414
415 std::vector< double > mOuterBoundsX;
416 std::vector< double > mOuterBoundsY;
417
418 double mOuterBoundsXMin = std::numeric_limits<double>::max();
419 double mOuterBoundsXMax = std::numeric_limits<double>::lowest();
420 double mOuterBoundsYMin = std::numeric_limits<double>::max();
421 double mOuterBoundsYMax = std::numeric_limits<double>::lowest();
422
423 geos::unique_ptr mOuterBoundsGeos;
424 const GEOSPreparedGeometry *mPreparedOuterBoundsGeos = nullptr;
425
426 double mCost;
427 bool mHasObstacleConflict;
428 bool mHasHardConflict = false;
429 int mUpsideDownCharCount;
430
434 int partCount() const;
435
440 double polygonIntersectionCostForParts( PointSet *polygon ) const;
441
445 void createMultiPartGeosGeom() const;
446
447 bool isInConflictMultiPart( const LabelPosition *lp ) const;
448
449 void createOuterBoundsGeom();
450
451 LabelPosition &operator=( const LabelPosition & ) = delete;
452 };
453
454} // end namespace
455
456#endif
A rtree spatial index for use in the pal labeling engine.
Definition palrtree.h:36
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1186
A rectangle specified with double values.
Calculates label candidate costs considering different factors.
Main class to handle feature.
Definition feature.h:65
LabelPosition is a candidate feature label position.
void incrementNumOverlaps()
Increases the number of overlaps recorded against this position by 1.
double getHeight() const
bool hasHardObstacleConflict() const
Returns whether the position is marked as having a hard conflict with an obstacle feature.
void setPartId(int id)
void setNextPart(std::unique_ptr< LabelPosition > next)
Sets the next part of this label position (i.e.
void setCost(double newCost)
Sets the candidate label position's geographical cost.
double alpha
Rotation in radians.
int upsideDownCharCount() const
Returns the number of upside down characters for this label position.
void setGlobalId(unsigned int id)
Sets the global id for the candidate, which is unique for a single run of the pal labelling engine.
void decrementNumOverlaps()
Decreases the number of overlaps recorded against this position by 1.
double cost() const
Returns the candidate label position's geographical cost.
bool conflictsWithObstacle() const
Returns whether the position is marked as conflicting with an obstacle feature.
double getWidth() const
int getNumOverlaps() const
void setProblemIds(int probFid, int lpId)
Set problem feature ID and assigned label candidate ID.
void setUpsideDownCharCount(int count)
Sets the count of upside down characters for this label position.
LabelDirectionToLine
Label directions in relation to line or polygon ring directions.
bool isReversedFromLineDirection() const
Returns true if the label direction is the reversed from the line or polygon ring direction.
unsigned int globalId() const
Returns the global ID for the candidate, which is unique for a single run of the pal labelling engine...
Qgis::LabelQuadrantPosition quadrant() const
Returns the quadrant associated with this label position.
int getPartId() const
int getProblemFeatureId() const
bool getUpsideDown() const
LabelPosition * nextPart() const
Returns the next part of this label position (i.e.
Main Pal labeling class.
Definition pal.h:83
The underlying raw pal geometry class.
Definition pointset.h:77
struct GEOSGeom_t GEOSGeometry
Definition util.h:41