QGIS API Documentation  3.9.0-Master (224899f119)
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 "rtree.hpp"
40 
41 namespace pal
42 {
43 
44  class LabelPosition;
45  class Label;
46 
52  class Sol
53  {
54  public:
55  int *s = nullptr;
56  double cost;
57  };
58 
59  typedef struct _chain
60  {
61  int degree;
62  double delta;
63  int *feat = nullptr;
64  int *label = nullptr;
65  } Chain;
66 
73  class CORE_EXPORT Problem
74  {
75 
76  friend class Pal;
77 
78  public:
79  Problem();
80 
81  //Problem(char *lorena_file, bool displayAll);
82 
83  ~Problem();
84 
86  Problem( const Problem &other ) = delete;
88  Problem &operator=( const Problem &other ) = delete;
89 
95  void addCandidatePosition( LabelPosition *position ) { mLabelPositions.append( position ); }
96 
98  // problem inspection functions
99  int getNumFeatures() { return nbft; }
100  // features counted 0...n-1
101  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
102  // both features and candidates counted 0..n-1
103  LabelPosition *getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
105 
106 
107  void reduce();
108 
112  void chain_search();
113 
126  QList<LabelPosition *> getSolution( bool returnInactive, QList<LabelPosition *> *unlabeled = nullptr );
127 
128  PalStat *getStats();
129 
130  /* useful only for postscript post-conversion*/
131  //void toFile(char *label_file);
132 
136  void init_sol_empty();
137  void init_sol_falp();
138 
139  static bool compareLabelArea( pal::LabelPosition *l1, pal::LabelPosition *l2 );
140 
147  QList<LabelPosition *> *positionsWithNoCandidates()
148  {
149  return &mPositionsWithNoCandidates;
150  }
151 
152  private:
153 
157  int nbLabelledLayers = 0;
158 
162  QStringList labelledLayersName;
163 
167  int nblp = 0;
168 
172  int all_nblp = 0;
173 
177  int nbft = 0;
178 
179 
183  bool displayAll = false;
184 
188  double bbox[4];
189 
190  QList< LabelPosition * > mLabelPositions;
191 
192  RTree<LabelPosition *, double, 2, double> *candidates = nullptr; // index all candidates
193  RTree<LabelPosition *, double, 2, double> *candidates_sol = nullptr; // index active candidates
194 
195  QList< LabelPosition * > mPositionsWithNoCandidates;
196 
197  //int *feat; // [nblp]
198  int *featStartId = nullptr; // [nbft]
199  int *featNbLp = nullptr; // [nbft]
200  double *inactiveCost = nullptr; //
201 
202  Sol *sol = nullptr; // [nbft]
203  double nbOverlap = 0.0;
204 
205  Chain *chain( int seed );
206 
207  Pal *pal = nullptr;
208 
209  void solution_cost();
210  };
211 
212 } // namespace
213 
214 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:95
int getFeatureCandidateCount(int i)
Definition: problem.h:101
double cost
Definition: problem.h:56
int degree
Definition: problem.h:61
Main Pal labeling class.
Definition: pal.h:87
void seed(uint32_t value)
struct pal::_chain Chain
QList< LabelPosition * > * positionsWithNoCandidates()
Returns a reference to the list of label positions which correspond to features with no candidates...
Definition: problem.h:147
int * s
Definition: problem.h:55
int getNumFeatures()
Definition: problem.h:99
Summary statistics of labeling problem.
Definition: palstat.h:48
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
Representation of a labeling problem.
Definition: problem.h:73
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:103
double delta
Definition: problem.h:62