QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
Loading...
Searching...
No Matches
problem.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_PROBLEM_H
31#define PAL_PROBLEM_H
32
33
34
35#include <list>
36#include <memory>
37#include <vector>
38
39#include "palrtree.h"
40#include "qgis_core.h"
41#include "qgsrendercontext.h"
42
43#include <QList>
44
45#define SIP_NO_FILE
46
47namespace pal
48{
49
50 class LabelPosition;
51 class Label;
52 class PriorityQueue;
53
60
61 struct Chain
62 {
63 int degree;
64 double delta;
65 std::vector< int > feat;
66 std::vector< int > label;
67 };
68
75 class CORE_EXPORT Problem
76 {
77 friend class Pal;
78
79 public:
80
86 Problem( const QgsRectangle &extent );
87
88 //Problem(char *lorena_file, bool displayAll);
89
91
92 Problem( const Problem &other ) = delete;
93 Problem &operator=( const Problem &other ) = delete;
94
99 void addCandidatePosition( std::unique_ptr< LabelPosition > position );
100
104 std::size_t featureCount() const { return mFeatureCount; }
105
109 int featureCandidateCount( int feature ) const { return mCandidateCountForFeature[feature]; }
110
114 LabelPosition *featureCandidate( int feature, int candidate ) const { return mLabelPositions[ mFirstCandidateIndexForFeature[feature] + candidate ].get(); }
115
119 void reduce();
120
124 void chainSearch( QgsRenderContext &context );
125
138 QList<LabelPosition *> getSolution( bool returnInactive, QList<LabelPosition *> *unlabeled = nullptr );
139
140 /* useful only for postscript post-conversion*/
141 //void toFile(char *label_file);
142
143 void init_sol_falp();
144
151 std::vector< std::unique_ptr< LabelPosition > > *positionsWithNoCandidates()
152 {
153 return &mPositionsWithNoCandidates;
154 }
155
159 PalRtree< LabelPosition > &allCandidatesIndex() { return mAllCandidatesIndex; }
160
161 private:
162
166 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
167
171 int mLayerCount = 0;
172
176 QStringList labelledLayersName;
177
181 int mTotalCandidates = 0;
182
186 int mAllNblp = 0;
187
191 std::size_t mFeatureCount = 0;
192
196 bool mDisplayAll = false;
197
201 double mMapExtentBounds[4] = {0, 0, 0, 0};
202
203 std::vector< std::unique_ptr< LabelPosition > > mLabelPositions;
204
205 PalRtree<LabelPosition> mAllCandidatesIndex;
206 PalRtree<LabelPosition> mActiveCandidatesIndex;
207
208 std::vector< std::unique_ptr< LabelPosition > > mPositionsWithNoCandidates;
209
211 std::vector< int > mFirstCandidateIndexForFeature;
213 std::vector< int > mCandidateCountForFeature;
215 std::vector< double > mUnlabeledCostForFeature;
216
217 class Sol
218 {
219 public:
220
222 std::vector< int > activeLabelIds;
223
224 void init( std::size_t featureCount )
225 {
226 activeLabelIds.resize( featureCount, -1 );
227 }
228 };
229
230 Sol mSol;
231 double mNbOverlap = 0.0;
232
233 // seed is actually a feature ID, maybe it should be renamed?
234 std::unique_ptr< Chain > chain( int seed );
235
236 Pal *pal = nullptr;
237
238 void solution_cost();
239 void ignoreLabel( const LabelPosition *lp, pal::PriorityQueue &list, PalRtree<LabelPosition> &candidatesIndex );
240 };
241
242} // namespace
243
244#endif
A rtree spatial index for use in the pal labeling engine.
Definition palrtree.h:38
A rectangle specified with double values.
Contains information about the context of a rendering operation.
LabelPosition is a candidate feature label position.
friend class Pal
Definition problem.h:77
void addCandidatePosition(std::unique_ptr< LabelPosition > position)
Adds a candidate label position to the problem.
Definition problem.cpp:53
LabelPosition * featureCandidate(int feature, int candidate) const
Returns the candidate corresponding to the specified feature and candidate index.
Definition problem.h:114
int featureCandidateCount(int feature) const
Returns the number of candidates generated for the feature at the specified index.
Definition problem.h:109
Problem(const QgsRectangle &extent)
Constructor for Problem.
Definition problem.cpp:46
std::size_t featureCount() const
Returns the total number of features considered during the labeling problem.
Definition problem.h:104
PalRtree< LabelPosition > & allCandidatesIndex()
Returns the index containing all label candidates.
Definition problem.h:159
Problem & operator=(const Problem &other)=delete
Problem(const Problem &other)=delete
std::vector< std::unique_ptr< LabelPosition > > * positionsWithNoCandidates()
Returns a reference to the list of label positions which correspond to features with no candidates.
Definition problem.h:151
Chain solution parameters.
std::vector< int > feat
Definition problem.h:65
double delta
Definition problem.h:64
std::vector< int > label
Definition problem.h:66
int degree
Definition problem.h:63