QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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 <ctime>
37#include <iostream>
38#include <unordered_map>
39
40#include "qgis_core.h"
41#include "qgsgeometry.h"
42#include "qgsgeos.h"
43#include "qgssettingstree.h"
44
45#include <QList>
46#include <QMutex>
47#include <QString>
48#include <QStringList>
49
50using namespace Qt::StringLiterals;
51
53
54// TODO ${MAJOR} ${MINOR} etc instead of 0.2
55
59
60namespace pal
61{
62 class Layer;
63 class LabelPosition;
64 class Problem;
65 class PointSet;
66
76
86 class CORE_EXPORT Pal
87 {
88 friend class Problem;
89 friend class FeaturePart;
90 friend class Layer;
91
92 public:
93 static inline QgsSettingsTreeNode *sTreePal = QgsSettingsTree::sTreeRendering->createChildNode( u"pal"_s );
94
98
99 Pal();
101
102 Pal( const Pal &other ) = delete;
103 Pal &operator=( const Pal &other ) = delete;
104
117 Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel );
118
124 void removeLayer( Layer *layer );
125
127 typedef bool ( *FnIsCanceled )( void *ctx );
128
130 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
131
133 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
134
153 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
154
167 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
168
174 void setShowPartialLabels( bool show );
175
181 bool showPartialLabels() const;
182
188 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
189
195 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
196
202 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
203
209 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
210
216 Qgis::LabelPlacementEngineVersion placementVersion() const;
217
223 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
224
235 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
236
247 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
248
259 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
260
264 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
265
275 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
276
283 QList< QgsAbstractLabelingEngineRule * > rules() const { return mRules; }
284
285 private:
286
287 std::vector< std::pair< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > > mLayers;
288
289 QList< QgsAbstractLabelingEngineRule * > mRules;
290
291 QMutex mMutex;
292
293 /*
294 * POPMUSIC Tuning
295 */
296 int mPopmusicR = 30;
297
298 int mTabuMaxIt = 4;
299 int mTabuMinIt = 2;
300
301 int mEjChainDeg = 50;
302 int mTenure = 10;
303 double mCandListSize = 0.2;
304
305 unsigned int mNextCandidateId = 1;
306 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
307
311 bool mShowPartialLabels = true;
312
313 double mMaxLineCandidatesPerMapUnit = 0;
314 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
315
316 int mGlobalCandidatesLimitPoint = 0;
317 int mGlobalCandidatesLimitLine = 0;
318 int mGlobalCandidatesLimitPolygon = 0;
319
321
323 FnIsCanceled fnIsCanceled = nullptr;
325 void *fnIsCanceledContext = nullptr;
326
331 void setPopmusicR( int r );
332
337 void setMinIt( int min_it );
338
343 void setMaxIt( int max_it );
344
349 void setTenure( int tenure );
350
355 void setEjChainDeg( int degree );
356
361 void setCandListSize( double fact );
362
363
368 int getMinIt() const;
369
374 int getMaxIt() const;
375
376 };
377
378} // end namespace pal
379
380#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition qgis.h:1225
LabelPlacementEngineVersion
Labeling placement engine version.
Definition qgis.h:2930
@ Version2
Version 2 (default for new projects since QGIS 3.12).
Definition qgis.h:2932
An abstract interface class for label providers.
Abstract base class for labeling engine rules.
A geometry is the spatial representation of a feature.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
An integer settings entry.
A tree node for the settings tree to help organizing and introspecting the tree.
static QgsSettingsTreeNode * sTreeRendering
LabelPosition is a candidate feature label position.
double maximumLineCandidatesPerMapUnit() const
Returns the maximum number of line label candidate positions per map unit.
Definition pal.h:188
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition pal.h:235
static QgsSettingsTreeNode * sTreePal
Definition pal.h:93
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition pal.h:202
void removeLayer(Layer *layer)
remove a layer
Definition pal.cpp:76
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition pal.h:209
friend class Layer
Definition pal.h:90
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition pal.h:247
bool(* FnIsCanceled)(void *ctx)
Cancellation check callback function.
Definition pal.h:127
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitLines
Definition pal.h:96
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPoints
Definition pal.h:95
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPolygons
Definition pal.h:97
void setMaximumLineCandidatesPerMapUnit(double candidates)
Sets the maximum number of line label candidates per map unit.
Definition pal.h:195
Pal()
Definition pal.cpp:67
friend class Problem
Definition pal.h:88
bool isCanceled()
Check whether the job has been canceled.
Definition pal.h:133
Pal(const Pal &other)=delete
friend class FeaturePart
Definition pal.h:89
void registerCancellationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
Definition pal.cpp:655
int globalCandidatesLimitPolygon() const
Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
Definition pal.h:259
Pal & operator=(const Pal &other)=delete
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules which the labeling solution must satisfy.
Definition pal.h:283
Layer * addLayer(QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel)
add a new layer
Definition pal.cpp:94
Representation of a labeling problem.
Definition problem.h:75
SearchMethod
Search method to use.
Definition pal.h:69
@ FALP
Only initial solution.
Definition pal.h:74
@ POPMUSIC_TABU
Is a little bit better than CHAIN but slower.
Definition pal.h:72
@ POPMUSIC_CHAIN
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition pal.h:73
@ CHAIN
Is the worst but fastest method.
Definition pal.h:70
@ POPMUSIC_TABU_CHAIN
Is the best but slowest.
Definition pal.h:71