QGIS API Documentation 3.29.0-Master (da8bb1db43)
pal.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 PAL_H
31#define PAL_H
32
33#define SIP_NO_FILE
34
35
36#include "qgis_core.h"
37#include "qgsgeometry.h"
38#include "qgsgeos.h"
39#include <QList>
40#include <iostream>
41#include <ctime>
42#include <QMutex>
43#include <QStringList>
44#include <unordered_map>
45
46// TODO ${MAJOR} ${MINOR} etc instead of 0.2
47
50
51namespace pal
52{
53 class Layer;
54 class LabelPosition;
55 class PalStat;
56 class Problem;
57 class PointSet;
58
61 {
62 CHAIN = 0,
66 FALP = 4
67 };
68
78 class CORE_EXPORT Pal
79 {
80 friend class Problem;
81 friend class FeaturePart;
82 friend class Layer;
83
84 public:
85
89 Pal();
90
92
94 Pal( const Pal &other ) = delete;
96 Pal &operator=( const Pal &other ) = delete;
97
110 Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel );
111
117 void removeLayer( Layer *layer );
118
119 typedef bool ( *FnIsCanceled )( void *ctx );
120
122 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
123
125 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
126
134 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
135
148 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
149
155 void setShowPartialLabels( bool show );
156
162 bool showPartialLabels() const;
163
169 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
170
176 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
177
183 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
184
190 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
191
197 Qgis::LabelPlacementEngineVersion placementVersion() const;
198
204 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
205
216 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
217
228 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
229
240 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
241
245 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
246
247 private:
248
249 std::unordered_map< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > mLayers;
250
251 QMutex mMutex;
252
253 /*
254 * POPMUSIC Tuning
255 */
256 int mPopmusicR = 30;
257
258 int mTabuMaxIt = 4;
259 int mTabuMinIt = 2;
260
261 int mEjChainDeg = 50;
262 int mTenure = 10;
263 double mCandListSize = 0.2;
264
265 unsigned int mNextCandidateId = 1;
266 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
267
271 bool mShowPartialLabels = true;
272
273 double mMaxLineCandidatesPerMapUnit = 0;
274 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
275
276 int mGlobalCandidatesLimitPoint = 0;
277 int mGlobalCandidatesLimitLine = 0;
278 int mGlobalCandidatesLimitPolygon = 0;
279
280 Qgis::LabelPlacementEngineVersion mPlacementVersion = Qgis::LabelPlacementEngineVersion::Version2;
281
283 FnIsCanceled fnIsCanceled = nullptr;
285 void *fnIsCanceledContext = nullptr;
286
291 void setPopmusicR( int r );
292
297 void setMinIt( int min_it );
298
303 void setMaxIt( int max_it );
304
309 void setTenure( int tenure );
310
315 void setEjChainDeg( int degree );
316
321 void setCandListSize( double fact );
322
323
328 int getMinIt() const;
329
334 int getMaxIt() const;
335
336 };
337
338} // end namespace pal
339
340#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition: qgis.h:593
LabelPlacementEngineVersion
Labeling placement engine version.
Definition: qgis.h:1634
The QgsAbstractLabelProvider class is an interface class.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
Main class to handle feature.
Definition: feature.h:65
LabelPosition is a candidate feature label position.
Definition: labelposition.h:56
A set of features which influence the labeling process.
Definition: layer.h:63
Main Pal labeling class.
Definition: pal.h:79
double maximumLineCandidatesPerMapUnit() const
Returns the maximum number of line label candidate positions per map unit.
Definition: pal.h:169
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition: pal.h:216
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition: pal.h:183
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition: pal.h:190
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition: pal.h:228
void setMaximumLineCandidatesPerMapUnit(double candidates)
Sets the maximum number of line label candidates per map unit.
Definition: pal.h:176
bool isCanceled()
Check whether the job has been canceled.
Definition: pal.h:125
Pal(const Pal &other)=delete
Pal cannot be copied.
int globalCandidatesLimitPolygon() const
Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
Definition: pal.h:240
Pal & operator=(const Pal &other)=delete
Pal cannot be copied.
Representation of a labeling problem.
Definition: problem.h:73
SearchMethod
Search method to use.
Definition: pal.h:61
@ FALP
Only initial solution.
Definition: pal.h:66
@ POPMUSIC_TABU
Is a little bit better than CHAIN but slower.
Definition: pal.h:64
@ POPMUSIC_CHAIN
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition: pal.h:65
@ CHAIN
Is the worst but fastest method.
Definition: pal.h:62
@ POPMUSIC_TABU_CHAIN
Is the best but slowest.
Definition: pal.h:63