QGIS API Documentation 3.37.0-Master (4ace69f83af)
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 "qgis_core.h"
37#include "qgsgeometry.h"
38#include "qgsgeos.h"
39#include "qgssettingstree.h"
40
41#include <QList>
42#include <iostream>
43#include <ctime>
44#include <QMutex>
45#include <QStringList>
46#include <unordered_map>
47
49
50// TODO ${MAJOR} ${MINOR} etc instead of 0.2
51
54
55namespace pal
56{
57 class Layer;
58 class LabelPosition;
59 class PalStat;
60 class Problem;
61 class PointSet;
62
72
82 class CORE_EXPORT Pal
83 {
84 friend class Problem;
85 friend class FeaturePart;
86 friend class Layer;
87
88 public:
89 static inline QgsSettingsTreeNode *sTreePal = QgsSettingsTree::sTreeRendering->createChildNode( QStringLiteral( "pal" ) );
90
94
98 Pal();
99
101
103 Pal( const Pal &other ) = delete;
105 Pal &operator=( const Pal &other ) = delete;
106
119 Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel );
120
126 void removeLayer( Layer *layer );
127
128 typedef bool ( *FnIsCanceled )( void *ctx );
129
131 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
132
134 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
135
143 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
144
157 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
158
164 void setShowPartialLabels( bool show );
165
171 bool showPartialLabels() const;
172
178 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
179
185 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
186
192 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
193
199 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
200
206 Qgis::LabelPlacementEngineVersion placementVersion() const;
207
213 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
214
225 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
226
237 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
238
249 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
250
254 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
255
256 private:
257
258 std::unordered_map< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > mLayers;
259
260 QMutex mMutex;
261
262 /*
263 * POPMUSIC Tuning
264 */
265 int mPopmusicR = 30;
266
267 int mTabuMaxIt = 4;
268 int mTabuMinIt = 2;
269
270 int mEjChainDeg = 50;
271 int mTenure = 10;
272 double mCandListSize = 0.2;
273
274 unsigned int mNextCandidateId = 1;
275 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
276
280 bool mShowPartialLabels = true;
281
282 double mMaxLineCandidatesPerMapUnit = 0;
283 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
284
285 int mGlobalCandidatesLimitPoint = 0;
286 int mGlobalCandidatesLimitLine = 0;
287 int mGlobalCandidatesLimitPolygon = 0;
288
290
292 FnIsCanceled fnIsCanceled = nullptr;
294 void *fnIsCanceledContext = nullptr;
295
300 void setPopmusicR( int r );
301
306 void setMinIt( int min_it );
307
312 void setMaxIt( int max_it );
313
318 void setTenure( int tenure );
319
324 void setEjChainDeg( int degree );
325
330 void setCandListSize( double fact );
331
332
337 int getMinIt() const;
338
343 int getMaxIt() const;
344
345 };
346
347} // end namespace pal
348
349#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition qgis.h:914
LabelPlacementEngineVersion
Labeling placement engine version.
Definition qgis.h:2332
@ Version2
Version 2 (default for new projects since QGIS 3.12)
The QgsAbstractLabelProvider class is an interface class.
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.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QgsSettingsTreeNode * createChildNode(const QString &key)
Creates a normal tree node It will return the existing child node if it exists at the given key.
static QgsSettingsTreeNode * sTreeRendering
Main class to handle feature.
Definition feature.h:65
LabelPosition is a candidate feature label position.
A set of features which influence the labeling process.
Definition layer.h:63
Main Pal labeling class.
Definition pal.h:83
double maximumLineCandidatesPerMapUnit() const
Returns the maximum number of line label candidate positions per map unit.
Definition pal.h:178
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition pal.h:225
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition pal.h:192
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition pal.h:199
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition pal.h:237
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitLines
Definition pal.h:92
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPoints
Definition pal.h:91
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPolygons
Definition pal.h:93
void setMaximumLineCandidatesPerMapUnit(double candidates)
Sets the maximum number of line label candidates per map unit.
Definition pal.h:185
bool isCanceled()
Check whether the job has been canceled.
Definition pal.h:134
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:249
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:65
@ FALP
Only initial solution.
Definition pal.h:70
@ POPMUSIC_TABU
Is a little bit better than CHAIN but slower.
Definition pal.h:68
@ POPMUSIC_CHAIN
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition pal.h:69
@ CHAIN
Is the worst but fastest method.
Definition pal.h:66
@ POPMUSIC_TABU_CHAIN
Is the best but slowest.
Definition pal.h:67