QGIS API Documentation 3.99.0-Master (a8f284845db)
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
34
35#include <fstream>
36
37#include "palrtree.h"
38#include "pointset.h"
39#include "qgis_core.h"
40
41#define SIP_NO_FILE
42
43namespace pal
44{
45
46 class FeaturePart;
47 class Pal;
48 class Label;
49
50
57 class CORE_EXPORT LabelPosition : public PointSet
58 {
59 friend class CostCalculator;
61
62 public:
63
68 {
69 SameDirection,
70 Reversed
71 };
72
87 LabelPosition( int id, double x1, double y1,
88 double w, double h,
89 double alpha, double cost,
90 FeaturePart *feature,
91 LabelDirectionToLine directionToLine = LabelDirectionToLine::SameDirection,
93
94 LabelPosition( const LabelPosition &other );
95
96 ~LabelPosition() override;
97
103 bool intersects( const GEOSPreparedGeometry *geometry );
104
110 bool within( const GEOSPreparedGeometry *geometry );
111
120 bool isInConflict( const LabelPosition *ls ) const;
121
128 void getBoundingBox( double amin[2], double amax[2] ) const;
129
135 QgsRectangle outerBoundingBox() const;
136
142 QgsRectangle boundingBoxForCandidateConflicts( Pal *pal ) const;
143
148 bool outerBoundingBoxIntersects( const LabelPosition *other ) const;
149
157 double getDistanceToPoint( double xp, double yp, bool useOuterBounds ) const;
158
164 bool crossesLine( PointSet *line ) const;
165
171 bool crossesBoundary( PointSet *polygon ) const;
172
177 int polygonIntersectionCost( PointSet *polygon ) const;
178
184 bool intersectsWithPolygon( PointSet *polygon ) const;
185
189 int getId() const;
190
194 FeaturePart *getFeaturePart() const;
195
196 int getNumOverlaps() const { return nbOverlap; }
197 void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
198
203
208
209 int getProblemFeatureId() const { return probFeat; }
210
215 void setProblemIds( int probFid, int lpId )
216 {
217 probFeat = probFid;
218 id = lpId;
219 if ( mNextPart ) mNextPart->setProblemIds( probFid, lpId );
220 }
221
226 double cost() const { return mCost; }
227
233 void setCost( double newCost ) { mCost = newCost; }
234
241 void setConflictsWithObstacle( bool conflicts );
242
247 bool conflictsWithObstacle() const { return mHasObstacleConflict; }
248
255 void setHasHardObstacleConflict( bool conflicts );
256
263 bool hasHardObstacleConflict() const { return mHasHardConflict; }
264
266 void validateCost();
267
272 double getX( int i = 0 ) const;
273
278 double getY( int i = 0 ) const;
279
280 double getWidth() const { return w; }
281 double getHeight() const { return h; }
282
286 double getAlpha() const;
287
291 bool isReversedFromLineDirection() const { return mDirectionToLine == LabelDirectionToLine::Reversed; }
292
293 bool getUpsideDown() const { return upsideDown; }
294
298 Qgis::LabelQuadrantPosition quadrant() const { return mQuadrant; }
299
305 LabelPosition *nextPart() const { return mNextPart.get(); }
306
312 void setNextPart( std::unique_ptr< LabelPosition > next ) { mNextPart = std::move( next ); }
313
314 // -1 if not multi-part
315 int getPartId() const { return partId; }
316 void setPartId( int id ) { partId = id; }
317
323 void setUpsideDownCharCount( int count ) { mUpsideDownCharCount = count ; }
324
330 int upsideDownCharCount() const { return mUpsideDownCharCount; }
331
335 void removeFromIndex( PalRtree<LabelPosition> &index, Pal *pal );
336
340 void insertIntoIndex( PalRtree<LabelPosition> &index, Pal *pal );
341
347 const GEOSGeometry *multiPartGeom() const;
348
354 const GEOSPreparedGeometry *preparedMultiPartGeom() const;
355
361 const GEOSPreparedGeometry *preparedOuterBoundsGeom() const;
362
371 unsigned int globalId() const { return mGlobalId; }
372
379 void setGlobalId( unsigned int id ) { mGlobalId = id; }
380
384 double angleDifferential();
385
386 protected:
387
388 int id;
389
391
392 // bug # 1 (maxence 10/23/2008)
393 int probFeat = 0;
394
395 int nbOverlap = 0;
396
398 double alpha;
399
400 double w;
401 double h;
402
403 int partId = -1;
404
405
406 bool upsideDown = false;
407
408 private:
409
411
413
414 unsigned int mGlobalId = 0;
415 std::unique_ptr< LabelPosition > mNextPart;
416
417 std::vector< double > mOuterBoundsX;
418 std::vector< double > mOuterBoundsY;
419
420 double mOuterBoundsXMin = std::numeric_limits<double>::max();
421 double mOuterBoundsXMax = std::numeric_limits<double>::lowest();
422 double mOuterBoundsYMin = std::numeric_limits<double>::max();
423 double mOuterBoundsYMax = std::numeric_limits<double>::lowest();
424
425 geos::unique_ptr mOuterBoundsGeos;
426 const GEOSPreparedGeometry *mPreparedOuterBoundsGeos = nullptr;
427
428 mutable QgsRectangle mBoundsForConflictIndex;
429
430 double mCost;
431 bool mHasObstacleConflict = false;
432 bool mHasHardConflict = false;
433 int mUpsideDownCharCount = 0;
434
438 int partCount() const;
439
444 double polygonIntersectionCostForParts( PointSet *polygon ) const;
445
449 void createMultiPartGeosGeom() const;
450
451 bool isInConflictMultiPart( const LabelPosition *lp ) const;
452
453 void createOuterBoundsGeom();
454
455 LabelPosition &operator=( const LabelPosition & ) = delete;
456 };
457
458} // end namespace
459
460#endif
A rtree spatial index for use in the pal labeling engine.
Definition palrtree.h:38
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1315
@ AboveLeft
Above left.
Definition qgis.h:1316
@ Over
Center middle.
Definition qgis.h:1320
A rectangle specified with double values.
Represents a part of a label feature.
Definition feature.h:61
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:88
The underlying raw pal geometry class.
Definition pointset.h:77
friend class FeaturePart
Definition pointset.h:78
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition qgsgeos.h:114
struct GEOSGeom_t GEOSGeometry
Definition util.h:42