QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 #include "qgsgeometry.h"
34 #include <QList>
35 #include <iostream>
36 #include <ctime>
37 #include <QMutex>
38 #include <QStringList>
39 
40 // TODO ${MAJOR} ${MINOR} etc instead of 0.2
41 
50 namespace pal
51 {
53  GEOSContextHandle_t geosContext();
54 
55  class Layer;
56  class LabelPosition;
57  class PalStat;
58  class Problem;
59  class PointSet;
60 
63  {
64  CHAIN = 0,
68  FALP = 4
69  };
70 
76  {
77  P_POINT = 0,
83  };
84 
87  {
92  };
93  Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )
94 
96  {
99  };
100 
109  class CORE_EXPORT Pal
110  {
111  friend class Problem;
112  friend class FeaturePart;
113  friend class Layer;
114 
115  public:
116 
120  Pal();
121 
125  ~Pal();
126 
142  Layer* addLayer( const QString& layerName, Arrangement arrangement, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll = false );
143 
153  Layer *getLayer( const QString &layerName );
154 
160  QList<Layer*> getLayers();
161 
167  void removeLayer( Layer *layer );
168 
179  std::list<LabelPosition*> *labeller( double bbox[4], PalStat **stats, bool displayAll );
180 
194  std::list<LabelPosition*> *labeller( const QStringList& layerNames,
195  double bbox[4],
196  PalStat **stat,
197  bool displayAll );
198 
199  typedef bool ( *FnIsCancelled )( void* ctx );
200 
202  void registerCancellationCallback( FnIsCancelled fnCancelled, void* context );
203 
205  inline bool isCancelled() { return fnIsCancelled ? fnIsCancelled( fnIsCancelledContext ) : false; }
206 
207  Problem* extractProblem( double bbox[4] );
208 
209  std::list<LabelPosition*>* solveProblem( Problem* prob, bool displayAll );
210 
216  void setShowPartial( bool show );
217 
223  bool getShowPartial();
224 
231  void setPointP( int point_p );
232 
239  void setLineP( int line_p );
240 
247  void setPolyP( int poly_p );
248 
252  int getPointP();
253 
257  int getLineP();
258 
262  int getPolyP();
263 
272  void setSearch( SearchMethod method );
273 
279  SearchMethod getSearch();
280 
281  private:
282 
283  QHash< QString, Layer* > mLayers;
284 
285  QMutex mMutex;
286 
290  int point_p;
291 
295  int line_p;
296 
300  int poly_p;
301 
302  SearchMethod searchMethod;
303 
304  /*
305  * POPMUSIC Tuning
306  */
307  int popmusic_r;
308 
309  int tabuMaxIt;
310  int tabuMinIt;
311 
312  int ejChainDeg;
313  int tenure;
314  double candListSize;
315 
319  bool showPartial;
320 
322  FnIsCancelled fnIsCancelled;
324  void* fnIsCancelledContext;
325 
336  Problem* extract( const QStringList& layersName,
337  double lambda_min, double phi_min,
338  double lambda_max, double phi_max );
339 
340 
345  void setPopmusicR( int r );
346 
351  void setMinIt( int min_it );
352 
357  void setMaxIt( int max_it );
358 
363  void setTenure( int tenure );
364 
369  void setEjChainDeg( int degree );
370 
375  void setCandListSize( double fact );
376 
377 
382  int getMinIt();
387  int getMaxIt();
388  };
389 
390 } // end namespace pal
391 
392 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
393 
394 #endif
Definition: pal.h:68
arranges candidates around a point (centroid for polygon)
Definition: pal.h:77
A layer of spacial entites.
Definition: layer.h:57
Pal main class.
Definition: pal.h:109
bool isCancelled()
Check whether the job has been cancelled.
Definition: pal.h:205
is slower and best than TABU, worse and faster than TABU_CHAIN
Definition: pal.h:67
Only for polygon, arranges candidates with respect of polygon orientation.
Definition: pal.h:82
is a little bit better than CHAIN but slower
Definition: pal.h:66
is the best but slowest
Definition: pal.h:65
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
Definition: pal.cpp:73
Main class to handle feature.
Definition: feature.h:203
Only for lines, labels along the line.
Definition: pal.h:81
Arrangement
The way to arrange labels against spatial entities.
Definition: pal.h:75
ObstacleType
Definition: pal.h:95
Summury of problem.
Definition: palstat.h:41
Represent a problem.
Definition: problem.h:92
LineArrangementFlag
Enumeration line arrangement flags.
Definition: pal.h:86
SearchMethod
Search method to use.
Definition: pal.h:62
is the worst but fastest method
Definition: pal.h:64
arranges candidates over a point (centroid for polygon)
Definition: pal.h:79