QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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#include <fstream>
35
36#include "palrtree.h"
37#include "pointset.h"
38#include "qgis_core.h"
39
40#define SIP_NO_FILE
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:
66 {
67 SameDirection,
68 Reversed
69 };
70
86 int id,
87 double x1,
88 double y1,
89 double w,
90 double h,
91 double alpha,
92 double cost,
93 FeaturePart *feature,
94 LabelDirectionToLine directionToLine = LabelDirectionToLine::SameDirection,
96 );
97
98 LabelPosition( const LabelPosition &other );
99
100 ~LabelPosition() override;
101
107 bool intersects( const GEOSPreparedGeometry *geometry );
108
114 bool within( const GEOSPreparedGeometry *geometry );
115
124 bool isInConflict( const LabelPosition *ls ) const;
125
132 void getBoundingBox( double amin[2], double amax[2] ) const;
133
139 QgsRectangle outerBoundingBox() const;
140
146 QgsRectangle boundingBoxForCandidateConflicts( Pal *pal ) const;
147
152 bool outerBoundingBoxIntersects( const LabelPosition *other ) const;
153
161 double getDistanceToPoint( double xp, double yp, bool useOuterBounds ) const;
162
168 bool crossesLine( PointSet *line ) const;
169
175 bool crossesBoundary( PointSet *polygon ) const;
176
181 int polygonIntersectionCost( PointSet *polygon ) const;
182
188 bool intersectsWithPolygon( PointSet *polygon ) const;
189
193 int getId() const;
194
198 FeaturePart *getFeaturePart() const;
199
200 int getNumOverlaps() const { return nbOverlap; }
201 void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
202
207
212
213 int getProblemFeatureId() const { return probFeat; }
214
219 void setProblemIds( int probFid, int lpId )
220 {
221 probFeat = probFid;
222 id = lpId;
223 if ( mNextPart )
224 mNextPart->setProblemIds( probFid, lpId );
225 }
226
231 double cost() const { return mCost; }
232
238 void setCost( double newCost ) { mCost = newCost; }
239
246 void setConflictsWithObstacle( bool conflicts );
247
252 bool conflictsWithObstacle() const { return mHasObstacleConflict; }
253
260 void setHasHardObstacleConflict( bool conflicts );
261
268 bool hasHardObstacleConflict() const { return mHasHardConflict; }
269
271 void validateCost();
272
277 double getX( int i = 0 ) const;
278
283 double getY( int i = 0 ) const;
284
285 double getWidth() const { return w; }
286 double getHeight() const { return h; }
287
291 double getAlpha() const;
292
296 bool isReversedFromLineDirection() const { return mDirectionToLine == LabelDirectionToLine::Reversed; }
297
298 bool getUpsideDown() const { return upsideDown; }
299
303 Qgis::LabelQuadrantPosition quadrant() const { return mQuadrant; }
304
310 LabelPosition *nextPart() const { return mNextPart.get(); }
311
317 void setNextPart( std::unique_ptr< LabelPosition > next ) { mNextPart = std::move( next ); }
318
319 // -1 if not multi-part
320 int getPartId() const { return partId; }
321 void setPartId( int id ) { partId = id; }
322
328 void setUpsideDownCharCount( int count ) { mUpsideDownCharCount = count; }
329
335 int upsideDownCharCount() const { return mUpsideDownCharCount; }
336
340 void removeFromIndex( PalRtree<LabelPosition> &index, Pal *pal );
341
345 void insertIntoIndex( PalRtree<LabelPosition> &index, Pal *pal );
346
352 const GEOSGeometry *multiPartGeom() const;
353
359 const GEOSPreparedGeometry *preparedMultiPartGeom() const;
360
366 const GEOSPreparedGeometry *preparedOuterBoundsGeom() const;
367
376 unsigned int globalId() const { return mGlobalId; }
377
384 void setGlobalId( unsigned int id ) { mGlobalId = id; }
385
389 double angleDifferential();
390
391 protected:
392 int id;
393
395
396 // bug # 1 (maxence 10/23/2008)
397 int probFeat = 0;
398
399 int nbOverlap = 0;
400
402 double alpha;
403
404 double w;
405 double h;
406
407 int partId = -1;
408
409
410 bool upsideDown = false;
411
412 private:
414
416
417 unsigned int mGlobalId = 0;
418 std::unique_ptr< LabelPosition > mNextPart;
419
420 std::vector< double > mOuterBoundsX;
421 std::vector< double > mOuterBoundsY;
422
423 double mOuterBoundsXMin = std::numeric_limits<double>::max();
424 double mOuterBoundsXMax = std::numeric_limits<double>::lowest();
425 double mOuterBoundsYMin = std::numeric_limits<double>::max();
426 double mOuterBoundsYMax = std::numeric_limits<double>::lowest();
427
428 geos::unique_ptr mOuterBoundsGeos;
429 const GEOSPreparedGeometry *mPreparedOuterBoundsGeos = nullptr;
430
431 mutable QgsRectangle mBoundsForConflictIndex;
432
433 double mCost;
434 bool mHasObstacleConflict = false;
435 bool mHasHardConflict = false;
436 int mUpsideDownCharCount = 0;
437
441 int partCount() const;
442
447 double polygonIntersectionCostForParts( PointSet *polygon ) const;
448
452 void createMultiPartGeosGeom() const;
453
454 bool isInConflictMultiPart( const LabelPosition *lp ) const;
455
456 void createOuterBoundsGeom();
457
458 LabelPosition &operator=( const LabelPosition & ) = delete;
459 };
460
461} //namespace pal
462
463#endif
A rtree spatial index for use in the pal labeling engine.
Definition palrtree.h:37
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1320
@ AboveLeft
Above left.
Definition qgis.h:1321
@ Over
Center middle.
Definition qgis.h:1325
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:87
The underlying raw pal geometry class.
Definition pointset.h:76
friend class FeaturePart
Definition pointset.h:77
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition qgsgeos.h:112
struct GEOSGeom_t GEOSGeometry
Definition util.h:41