QGIS API Documentation 3.39.0-Master (3aed037ce22)
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
95 Pal();
97
98 Pal( const Pal &other ) = delete;
99 Pal &operator=( const Pal &other ) = delete;
100
113 Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel );
114
120 void removeLayer( Layer *layer );
121
122 typedef bool ( *FnIsCanceled )( void *ctx );
123
125 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
126
128 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
129
137 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
138
151 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
152
158 void setShowPartialLabels( bool show );
159
165 bool showPartialLabels() const;
166
172 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
173
179 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
180
186 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
187
193 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
194
200 Qgis::LabelPlacementEngineVersion placementVersion() const;
201
207 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
208
219 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
220
231 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
232
243 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
244
248 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
249
250 private:
251
252 std::unordered_map< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > mLayers;
253
254 QMutex mMutex;
255
256 /*
257 * POPMUSIC Tuning
258 */
259 int mPopmusicR = 30;
260
261 int mTabuMaxIt = 4;
262 int mTabuMinIt = 2;
263
264 int mEjChainDeg = 50;
265 int mTenure = 10;
266 double mCandListSize = 0.2;
267
268 unsigned int mNextCandidateId = 1;
269 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
270
274 bool mShowPartialLabels = true;
275
276 double mMaxLineCandidatesPerMapUnit = 0;
277 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
278
279 int mGlobalCandidatesLimitPoint = 0;
280 int mGlobalCandidatesLimitLine = 0;
281 int mGlobalCandidatesLimitPolygon = 0;
282
284
286 FnIsCanceled fnIsCanceled = nullptr;
288 void *fnIsCanceledContext = nullptr;
289
294 void setPopmusicR( int r );
295
300 void setMinIt( int min_it );
301
306 void setMaxIt( int max_it );
307
312 void setTenure( int tenure );
313
318 void setEjChainDeg( int degree );
319
324 void setCandListSize( double fact );
325
326
331 int getMinIt() const;
332
337 int getMaxIt() const;
338
339 };
340
341} // end namespace pal
342
343#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition qgis.h:1028
LabelPlacementEngineVersion
Labeling placement engine version.
Definition qgis.h:2534
@ 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:172
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition pal.h:219
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition pal.h:186
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition pal.h:193
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition pal.h:231
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:179
bool isCanceled()
Check whether the job has been canceled.
Definition pal.h:128
Pal(const Pal &other)=delete
int globalCandidatesLimitPolygon() const
Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
Definition pal.h:243
Pal & operator=(const Pal &other)=delete
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