QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <fstream>
37
38#include "palrtree.h"
39#include "pointset.h"
40#include "qgis_core.h"
41
42namespace pal
43{
44
45 class FeaturePart;
46 class Pal;
47 class Label;
48
49
56 class CORE_EXPORT LabelPosition : public PointSet
57 {
58 friend class CostCalculator;
60
61 public:
62
67 {
68 SameDirection,
69 Reversed
70 };
71
86 LabelPosition( int id, double x1, double y1,
87 double w, double h,
88 double alpha, double cost,
89 FeaturePart *feature,
90 LabelDirectionToLine directionToLine = LabelDirectionToLine::SameDirection,
92
93 LabelPosition( const LabelPosition &other );
94
95 ~LabelPosition() override;
96
102 bool intersects( const GEOSPreparedGeometry *geometry );
103
109 bool within( const GEOSPreparedGeometry *geometry );
110
119 bool isInConflict( const LabelPosition *ls ) const;
120
127 void getBoundingBox( double amin[2], double amax[2] ) const;
128
134 QgsRectangle outerBoundingBox() const;
135
141 QgsRectangle boundingBoxForCandidateConflicts( Pal *pal ) const;
142
147 bool outerBoundingBoxIntersects( const LabelPosition *other ) const;
148
156 double getDistanceToPoint( double xp, double yp, bool useOuterBounds ) const;
157
163 bool crossesLine( PointSet *line ) const;
164
170 bool crossesBoundary( PointSet *polygon ) const;
171
176 int polygonIntersectionCost( PointSet *polygon ) const;
177
183 bool intersectsWithPolygon( PointSet *polygon ) const;
184
188 int getId() const;
189
193 FeaturePart *getFeaturePart() const;
194
195 int getNumOverlaps() const { return nbOverlap; }
196 void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
197
202
207
208 int getProblemFeatureId() const { return probFeat; }
209
214 void setProblemIds( int probFid, int lpId )
215 {
216 probFeat = probFid;
217 id = lpId;
218 if ( mNextPart ) mNextPart->setProblemIds( probFid, lpId );
219 }
220
225 double cost() const { return mCost; }
226
232 void setCost( double newCost ) { mCost = newCost; }
233
240 void setConflictsWithObstacle( bool conflicts );
241
246 bool conflictsWithObstacle() const { return mHasObstacleConflict; }
247
254 void setHasHardObstacleConflict( bool conflicts );
255
262 bool hasHardObstacleConflict() const { return mHasHardConflict; }
263
265 void validateCost();
266
271 double getX( int i = 0 ) const;
272
277 double getY( int i = 0 ) const;
278
279 double getWidth() const { return w; }
280 double getHeight() const { return h; }
281
285 double getAlpha() const;
286
290 bool isReversedFromLineDirection() const { return mDirectionToLine == LabelDirectionToLine::Reversed; }
291
292 bool getUpsideDown() const { return upsideDown; }
293
297 Qgis::LabelQuadrantPosition quadrant() const { return mQuadrant; }
298
304 LabelPosition *nextPart() const { return mNextPart.get(); }
305
311 void setNextPart( std::unique_ptr< LabelPosition > next ) { mNextPart = std::move( next ); }
312
313 // -1 if not multi-part
314 int getPartId() const { return partId; }
315 void setPartId( int id ) { partId = id; }
316
322 void setUpsideDownCharCount( int count ) { mUpsideDownCharCount = count ; }
323
329 int upsideDownCharCount() const { return mUpsideDownCharCount; }
330
334 void removeFromIndex( PalRtree<LabelPosition> &index, Pal *pal );
335
339 void insertIntoIndex( PalRtree<LabelPosition> &index, Pal *pal );
340
346 const GEOSGeometry *multiPartGeom() const;
347
353 const GEOSPreparedGeometry *preparedMultiPartGeom() const;
354
360 const GEOSPreparedGeometry *preparedOuterBoundsGeom() const;
361
370 unsigned int globalId() const { return mGlobalId; }
371
378 void setGlobalId( unsigned int id ) { mGlobalId = id; }
379
383 double angleDifferential();
384
385 protected:
386
387 int id;
388
390
391 // bug # 1 (maxence 10/23/2008)
393
395
397 double alpha;
398
399 double w;
400 double h;
401
403
404
406
407 private:
408
410
412
413 unsigned int mGlobalId = 0;
414 std::unique_ptr< LabelPosition > mNextPart;
415
416 std::vector< double > mOuterBoundsX;
417 std::vector< double > mOuterBoundsY;
418
419 double mOuterBoundsXMin = std::numeric_limits<double>::max();
420 double mOuterBoundsXMax = std::numeric_limits<double>::lowest();
421 double mOuterBoundsYMin = std::numeric_limits<double>::max();
422 double mOuterBoundsYMax = std::numeric_limits<double>::lowest();
423
424 geos::unique_ptr mOuterBoundsGeos;
425 const GEOSPreparedGeometry *mPreparedOuterBoundsGeos = nullptr;
426
427 mutable QgsRectangle mBoundsForConflictIndex;
428
429 double mCost;
430 bool mHasObstacleConflict;
431 bool mHasHardConflict = false;
432 int mUpsideDownCharCount;
433
437 int partCount() const;
438
443 double polygonIntersectionCostForParts( PointSet *polygon ) const;
444
448 void createMultiPartGeosGeom() const;
449
450 bool isInConflictMultiPart( const LabelPosition *lp ) const;
451
452 void createOuterBoundsGeom();
453
454 LabelPosition &operator=( const LabelPosition & ) = delete;
455 };
456
457} // end namespace
458
459#endif
A rtree spatial index for use in the pal labeling engine.
Definition palrtree.h:37
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1255
@ AboveLeft
Above left.
Definition qgis.h:1256
@ Over
Center middle.
Definition qgis.h:1260
A rectangle specified with double values.
Represents a part of a label feature.
Definition feature.h:60
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.
LabelPosition(int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, LabelDirectionToLine directionToLine=LabelDirectionToLine::SameDirection, Qgis::LabelQuadrantPosition quadrant=Qgis::LabelQuadrantPosition::Over)
create a new LabelPosition
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.
FeaturePart * feature
friend class CostCalculator
friend class PolygonCostCalculator
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:84
The underlying raw pal geometry class.
Definition pointset.h:78
friend class FeaturePart
Definition pointset.h:79
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition qgsgeos.h:114
struct GEOSGeom_t GEOSGeometry
Definition util.h:42