QGIS API Documentation 3.39.0-Master (3aed037ce22)
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
77
92 LabelPosition( int id, double x1, double y1,
93 double w, double h,
94 double alpha, double cost,
95 FeaturePart *feature, bool isReversed = false, Quadrant quadrant = QuadrantOver );
96
97 LabelPosition( const LabelPosition &other );
98
99 ~LabelPosition() override;
100
106 bool intersects( const GEOSPreparedGeometry *geometry );
107
113 bool within( const GEOSPreparedGeometry *geometry );
114
123 bool isInConflict( const LabelPosition *ls ) const;
124
130 void getBoundingBox( double amin[2], double amax[2] ) const;
131
136 bool outerBoundingBoxIntersects( const LabelPosition *other ) const;
137
145 double getDistanceToPoint( double xp, double yp, bool useOuterBounds ) const;
146
152 bool crossesLine( PointSet *line ) const;
153
159 bool crossesBoundary( PointSet *polygon ) const;
160
165 int polygonIntersectionCost( PointSet *polygon ) const;
166
172 bool intersectsWithPolygon( PointSet *polygon ) const;
173
177 int getId() const;
178
182 FeaturePart *getFeaturePart() const;
183
184 int getNumOverlaps() const { return nbOverlap; }
185 void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
186
190 void incrementNumOverlaps() { nbOverlap++; }
191
195 void decrementNumOverlaps() { nbOverlap++; }
196
197 int getProblemFeatureId() const { return probFeat; }
198
203 void setProblemIds( int probFid, int lpId )
204 {
205 probFeat = probFid;
206 id = lpId;
207 if ( mNextPart ) mNextPart->setProblemIds( probFid, lpId );
208 }
209
214 double cost() const { return mCost; }
215
221 void setCost( double newCost ) { mCost = newCost; }
222
229 void setConflictsWithObstacle( bool conflicts );
230
235 bool conflictsWithObstacle() const { return mHasObstacleConflict; }
236
243 void setHasHardObstacleConflict( bool conflicts );
244
251 bool hasHardObstacleConflict() const { return mHasHardConflict; }
252
254 void validateCost();
255
260 double getX( int i = 0 ) const;
261
266 double getY( int i = 0 ) const;
267
268 double getWidth() const { return w; }
269 double getHeight() const { return h; }
270
274 double getAlpha() const;
275
276 bool getReversed() const { return reversed; }
277 bool getUpsideDown() const { return upsideDown; }
278
279 Quadrant getQuadrant() const { return quadrant; }
280
286 LabelPosition *nextPart() const { return mNextPart.get(); }
287
293 void setNextPart( std::unique_ptr< LabelPosition > next ) { mNextPart = std::move( next ); }
294
295 // -1 if not multi-part
296 int getPartId() const { return partId; }
297 void setPartId( int id ) { partId = id; }
298
304 void setUpsideDownCharCount( int count ) { mUpsideDownCharCount = count ; }
305
311 int upsideDownCharCount() const { return mUpsideDownCharCount; }
312
316 void removeFromIndex( PalRtree<LabelPosition> &index );
317
321 void insertIntoIndex( PalRtree<LabelPosition> &index );
322
328 const GEOSPreparedGeometry *preparedMultiPartGeom() const;
329
335 const GEOSPreparedGeometry *preparedOuterBoundsGeom() const;
336
345 unsigned int globalId() const { return mGlobalId; }
346
353 void setGlobalId( unsigned int id ) { mGlobalId = id; }
354
358 double angleDifferential();
359
360 protected:
361
362 int id;
363
364 FeaturePart *feature = nullptr;
365
366 // bug # 1 (maxence 10/23/2008)
368
370
372 double alpha;
373
374 double w;
375 double h;
376
378
379 //True if label direction is the same as line / polygon ring direction.
380 //Could be used by the application to draw a directional arrow ('<' or '>')
381 //if the layer arrangement is P_LINE
383
385
387
388 private:
389
390 unsigned int mGlobalId = 0;
391 std::unique_ptr< LabelPosition > mNextPart;
392
393 std::vector< double > mOuterBoundsX;
394 std::vector< double > mOuterBoundsY;
395
396 double mOuterBoundsXMin = std::numeric_limits<double>::max();
397 double mOuterBoundsXMax = std::numeric_limits<double>::lowest();
398 double mOuterBoundsYMin = std::numeric_limits<double>::max();
399 double mOuterBoundsYMax = std::numeric_limits<double>::lowest();
400
401 geos::unique_ptr mOuterBoundsGeos;
402 const GEOSPreparedGeometry *mPreparedOuterBoundsGeos = nullptr;
403
404 double mCost;
405 bool mHasObstacleConflict;
406 bool mHasHardConflict = false;
407 int mUpsideDownCharCount;
408
412 int partCount() const;
413
418 double polygonIntersectionCostForParts( PointSet *polygon ) const;
419
423 void createMultiPartGeosGeom() const;
424
425 bool isInConflictMultiPart( const LabelPosition *lp ) const;
426
427 void createOuterBoundsGeom();
428
429 LabelPosition &operator=( const LabelPosition & ) = delete;
430 };
431
432} // end namespace
433
434#endif
A rtree spatial index for use in the pal labeling engine.
Definition palrtree.h:36
Calculates label candidate costs considering different factors.
Main class to handle feature.
Definition feature.h:65
LabelPosition is a candidate feature label position.
Quadrant
Position of label candidate relative to feature.
void incrementNumOverlaps()
Increases the number of overlaps recorded against this position by 1.
LabelPosition::Quadrant quadrant
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.
bool getReversed() const
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.
Quadrant getQuadrant() const
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.
unsigned int globalId() const
Returns the global ID for the candidate, which is unique for a single run of the pal labelling engine...
int getPartId() const
int getProblemFeatureId() const
bool getUpsideDown() const
LabelPosition * nextPart() const
Returns the next part of this label position (i.e.
The underlying raw pal geometry class.
Definition pointset.h:77