QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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#define SIP_NO_FILE
34
35
36#include "qgis_core.h"
37#include <list>
38#include <QList>
39#include "palrtree.h"
40#include "qgsrendercontext.h"
41#include <memory>
42#include <vector>
43
44namespace pal
45{
46
47 class LabelPosition;
48 class Label;
49 class PriorityQueue;
50
58 struct Chain
59 {
60 int degree;
61 double delta;
62 int *feat = nullptr;
63 int *label = nullptr;
64 };
65
72 class CORE_EXPORT Problem
73 {
74 friend class Pal;
75
76 public:
77
83 Problem( const QgsRectangle &extent );
84
85 //Problem(char *lorena_file, bool displayAll);
86
88
90 Problem( const Problem &other ) = delete;
92 Problem &operator=( const Problem &other ) = delete;
93
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 mFeatNbLp[feature]; }
110
114 LabelPosition *featureCandidate( int feature, int candidate ) const { return mLabelPositions[ mFeatStartId[feature] + candidate ].get(); }
115
116 void reduce();
117
121 void chainSearch( QgsRenderContext &context );
122
135 QList<LabelPosition *> getSolution( bool returnInactive, QList<LabelPosition *> *unlabeled = nullptr );
136
137 /* useful only for postscript post-conversion*/
138 //void toFile(char *label_file);
139
140 void init_sol_falp();
141
148 std::vector< std::unique_ptr< LabelPosition > > *positionsWithNoCandidates()
149 {
150 return &mPositionsWithNoCandidates;
151 }
152
156 PalRtree< LabelPosition > &allCandidatesIndex() { return mAllCandidatesIndex; }
157
158 private:
159
163 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
164
168 int mLayerCount = 0;
169
173 QStringList labelledLayersName;
174
178 int mTotalCandidates = 0;
179
183 int mAllNblp = 0;
184
188 std::size_t mFeatureCount = 0;
189
193 bool mDisplayAll = false;
194
198 double mMapExtentBounds[4] = {0, 0, 0, 0};
199
200 std::vector< std::unique_ptr< LabelPosition > > mLabelPositions;
201
202 PalRtree<LabelPosition> mAllCandidatesIndex;
203 PalRtree<LabelPosition> mActiveCandidatesIndex;
204
205 std::vector< std::unique_ptr< LabelPosition > > mPositionsWithNoCandidates;
206
207 std::vector< int > mFeatStartId;
208 std::vector< int > mFeatNbLp;
209 std::vector< double > mInactiveCost;
210
211 class Sol
212 {
213 public:
214
216 std::vector< int > activeLabelIds;
217
218 void init( std::size_t featureCount )
219 {
220 activeLabelIds.resize( featureCount, -1 );
221 }
222 };
223
224 Sol mSol;
225 double mNbOverlap = 0.0;
226
227 Chain *chain( int seed );
228
229 Pal *pal = nullptr;
230
231 void solution_cost();
232 void ignoreLabel( const LabelPosition *lp, pal::PriorityQueue &list, PalRtree<LabelPosition> &candidatesIndex );
233 };
234
235} // namespace
236
237#endif
A rtree spatial index for use in the pal labeling engine.
Definition palrtree.h:36
A rectangle specified with double values.
Contains information about the context of a rendering operation.
LabelPosition is a candidate feature label position.
Main Pal labeling class.
Definition pal.h:83
Custom priority queue for use in pal labeling engine.
Representation of a labeling problem.
Definition problem.h:73
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
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:156
Problem & operator=(const Problem &other)=delete
Problem cannot be copied.
Problem(const Problem &other)=delete
Problem cannot be copied.
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:148
Chain solution parameters.
double delta
Definition problem.h:61
int * label
Definition problem.h:63
int * feat
Definition problem.h:62
int degree
Definition problem.h:60