~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/core/pal/pal.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#ifdef HAVE_CONFIG_H
 
31
#include <config.h>
 
32
#endif
 
33
 
 
34
#ifndef _PAL_H
 
35
#define _PAL_H
 
36
 
 
37
 
 
38
#include <list>
 
39
#include <iostream>
 
40
#include <ctime>
 
41
 
 
42
// TODO ${MAJOR} ${MINOR} etc instead of 0.2
 
43
 
 
44
/**
 
45
 * \mainpage Pal Libray
 
46
 *
 
47
 * \section intro_sec Introduction
 
48
 *
 
49
 * Pal is a labelling library released under the GPLv3 license
 
50
 *
 
51
 */
 
52
 
 
53
namespace pal
 
54
{
 
55
 
 
56
  template <class Type> class LinkedList;
 
57
 
 
58
  class Layer;
 
59
  class LabelPosition;
 
60
  class PalStat;
 
61
  class Problem;
 
62
  class PointSet;
 
63
  class SimpleMutex;
 
64
 
 
65
  /** Units for label sizes and distlabel */
 
66
  enum _Units
 
67
  {
 
68
    PIXEL = 0, /**< pixel [px]*/
 
69
    METER, /**< meter [m]*/
 
70
    FOOT, /**< foot [ft]*/
 
71
    DEGREE /**< degree [°] */
 
72
  };
 
73
 
 
74
  /** Typedef for _Units enumeration */
 
75
  typedef enum _Units Units;
 
76
 
 
77
  /** Search method to use */
 
78
  enum _searchMethod
 
79
  {
 
80
    CHAIN = 0, /**< is the worst but fastest method */
 
81
    POPMUSIC_TABU_CHAIN = 1, /**< is the best but slowest */
 
82
    POPMUSIC_TABU = 2, /**< is a little bit better than CHAIN but slower*/
 
83
    POPMUSIC_CHAIN = 3, /**< is slower and best than TABU, worse and faster than TABU_CHAIN */
 
84
    FALP = 4 /** only initial solution */
 
85
  };
 
86
 
 
87
  /** Typedef for _Units enumeration */
 
88
  typedef enum _searchMethod SearchMethod;
 
89
 
 
90
  /** The way to arrange labels against spatial entities
 
91
   *
 
92
   * \image html arrangement.png "Arrangement modes" width=7cm
 
93
   * */
 
94
  enum _arrangement
 
95
  {
 
96
    P_POINT = 0, /**< arranges candidates around a point (centroid for polygon)*/
 
97
    P_POINT_OVER, /** arranges candidates over a point (centroid for polygon)*/
 
98
    P_LINE, /**< Only for lines and polygons, arranges candidates over the line or the polygon perimeter */
 
99
    P_CURVED, /** Only for lines, labels along the line */
 
100
    P_HORIZ, /**< Only for polygon, arranges candidates horizontaly */
 
101
    P_FREE /**< Only for polygon, arranges candidates with respect of polygon orientation */
 
102
  };
 
103
 
 
104
  /** typedef for _arrangement enumeration */
 
105
  typedef enum _arrangement Arrangement;
 
106
 
 
107
  /** enumeration line arrangement flags. Flags can be combined. */
 
108
  enum LineArrangementFlags
 
109
  {
 
110
    FLAG_ON_LINE     = 1,
 
111
    FLAG_ABOVE_LINE  = 2,
 
112
    FLAG_BELOW_LINE  = 4,
 
113
    FLAG_MAP_ORIENTATION = 8
 
114
  };
 
115
 
 
116
  /**
 
117
   *  \brief Pal main class.
 
118
   *
 
119
   *  A pal object will contains layers and global informations such as which search method
 
120
   *  will be used, the map resolution (dpi) ....
 
121
   *
 
122
   *  \author Maxence Laurent <maxence _dot_ laurent _at_ heig-vd _dot_ ch>
 
123
   */
 
124
  class CORE_EXPORT Pal
 
125
  {
 
126
      friend class Problem;
 
127
      friend class FeaturePart;
 
128
      friend class Layer;
 
129
    private:
 
130
      std::list<Layer*> * layers;
 
131
 
 
132
      SimpleMutex *lyrsMutex;
 
133
 
 
134
      // TODO remove after tests !!!
 
135
      clock_t tmpTime;
 
136
 
 
137
      Units map_unit;
 
138
 
 
139
      /**
 
140
       * \brief maximum # candidates for a point
 
141
       */
 
142
      int point_p;
 
143
 
 
144
      /**
 
145
       * \brief maximum # candidates for a line
 
146
       */
 
147
      int line_p;
 
148
 
 
149
      /**
 
150
       * \brief maximum # candidates for a polygon
 
151
       */
 
152
      int poly_p;
 
153
 
 
154
      SearchMethod searchMethod;
 
155
 
 
156
      /*
 
157
       * POPMUSIC Tuning
 
158
       */
 
159
      int popmusic_r;
 
160
 
 
161
      int tabuMaxIt;
 
162
      int tabuMinIt;
 
163
 
 
164
      int dpi;
 
165
 
 
166
      int ejChainDeg;
 
167
      int tenure;
 
168
      double candListSize;
 
169
 
 
170
      /**
 
171
       * \brief Problem factory
 
172
       * Extract features to label and generates candidates for them,
 
173
       * respects to a bounding box and a map scale
 
174
       *
 
175
       * @param nbLayers  number of layers to extract
 
176
       * @param layersName layers name to be extracted
 
177
       * @param layersFactor layer's factor (priority between layers, 0 is the best, 1 the worst)
 
178
       * @param lambda_min xMin bounding-box
 
179
       * @param phi_min yMin bounding-box
 
180
       * @param lambda_max xMax bounding-box
 
181
       * @param phi_max yMax bounding-box
 
182
       * @param scale the scale (1:scale)
 
183
       * @param svgmap stream to wrtie the svg map (need _EXPORT_MAP_ #defined to work)
 
184
       */
 
185
      Problem* extract( int nbLayers, char **layersName, double *layersFactor,
 
186
                        double lambda_min, double phi_min,
 
187
                        double lambda_max, double phi_max,
 
188
                        double scale, std::ofstream *svgmap );
 
189
 
 
190
 
 
191
      /**
 
192
       * \brief Choose the size of popmusic subpart's
 
193
       * @param r subpart size
 
194
       */
 
195
      void setPopmusicR( int r );
 
196
 
 
197
 
 
198
 
 
199
      /**
 
200
       * \brief minimum # of iteration for search method POPMUSIC_TABU, POPMUSIC_CHAIN and POPMUSIC_TABU_CHAIN
 
201
       * @param min_it Sub part optimization min # of iteration
 
202
       */
 
203
      void setMinIt( int min_it );
 
204
 
 
205
      /**
 
206
       * \brief maximum \# of iteration for search method POPMUSIC_TABU, POPMUSIC_CHAIN and POPMUSIC_TABU_CHAIN
 
207
       * @param max_it Sub part optimization max # of iteration
 
208
       */
 
209
      void setMaxIt( int max_it );
 
210
 
 
211
      /**
 
212
       * \brief For tabu search : how many iteration a feature will be tabu
 
213
       * @param tenure consiser a feature as tabu for tenure iteration after updating feature in solution
 
214
       */
 
215
      void setTenure( int tenure );
 
216
 
 
217
      /**
 
218
       * \brief For *CHAIN, select the max size of a transformation chain
 
219
       * @param degree maximum soze of a transformation chain
 
220
       */
 
221
      void setEjChainDeg( int degree );
 
222
 
 
223
      /**
 
224
       * \brief How many candidates will be tested by a tabu iteration
 
225
       * @param fact the ration (0..1) of candidates to test
 
226
       */
 
227
      void setCandListSize( double fact );
 
228
 
 
229
 
 
230
      /**
 
231
       * \brief Get the minimum # of iteration doing in POPMUSIC_TABU, POPMUSIC_CHAIN and POPMUSIC_TABU_CHAIN
 
232
       * @return minimum # of iteration
 
233
       */
 
234
      int getMinIt();
 
235
      /**
 
236
       * \brief Get the maximum # of iteration doing in POPMUSIC_TABU, POPMUSIC_CHAIN and POPMUSIC_TABU_CHAIN
 
237
       * @return maximum # of iteration
 
238
       */
 
239
      int getMaxIt();
 
240
 
 
241
 
 
242
    public:
 
243
 
 
244
      /**
 
245
       * \brief Create an new pal instance
 
246
       */
 
247
      Pal();
 
248
 
 
249
      /**
 
250
       * \brief delete an instance
 
251
       */
 
252
      ~Pal();
 
253
 
 
254
      /**
 
255
       * \brief add a new layer
 
256
       *
 
257
       * @param lyrName layer's name
 
258
       * @param min_scale bellow this scale: no labelling (-1 to disable)
 
259
       * @param max_scale above this scale: no labelling (-1 to disable)
 
260
       * @param arrangement Howto place candidates
 
261
       * @param label_unit Unit for labels sizes
 
262
       * @param defaultPriority layer's prioriry (0 is the best, 1 the worst)
 
263
       * @param obstacle 'true' will discourage other label to be placed above features of this layer
 
264
       * @param active is the layer is active (currently displayed)
 
265
       * @param toLabel the layer will be labeled only if toLablel is true
 
266
       *
 
267
       * @throws PalException::LayerExists
 
268
       *
 
269
       * @todo add symbolUnit
 
270
       */
 
271
      Layer * addLayer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel );
 
272
 
 
273
      /**
 
274
       * \brief Look for a layer
 
275
       *
 
276
       * @param lyrName name of layer to search
 
277
       *
 
278
       * @throws PalException::UnkownLayer
 
279
       *
 
280
       * @return a pointer on layer or NULL if layer not exist
 
281
       */
 
282
      Layer *getLayer( const char *lyrName );
 
283
 
 
284
      /**
 
285
       * \brief get all layers
 
286
       *
 
287
       * @return a list of all layers
 
288
       */
 
289
      std::list<Layer*> *getLayers();
 
290
 
 
291
      /**
 
292
       * \brief remove a layer
 
293
       *
 
294
       * @param layer layer to remove
 
295
       */
 
296
      void removeLayer( Layer *layer );
 
297
 
 
298
      /**
 
299
       * \brief the labeling machine
 
300
       * Will extract all active layers
 
301
       *
 
302
       * @param scale map scale is 1:scale
 
303
       * @param bbox map extent
 
304
       * @param stats A PalStat object (can be NULL)
 
305
       * @param displayAll if true, all feature will be labelled evan though overlaps occurs
 
306
       *
 
307
       * @return A list of label to display on map
 
308
       */
 
309
      std::list<LabelPosition*> *labeller( double scale, double bbox[4], PalStat **stats, bool displayAll );
 
310
 
 
311
 
 
312
      /**
 
313
       * \brief the labeling machine
 
314
       * Active layers are specifiend through layersName array
 
315
       * @todo add obstacles and tolabel arrays
 
316
       *
 
317
       * @param nbLayers # layers
 
318
       * @param layersName names of layers to label
 
319
       * @param layersFactor layers priorities array
 
320
       * @param scale map scale is  '1:scale'
 
321
       * @param bbox map extent
 
322
       * @param stat will be filled with labelling process statistics, can be NULL
 
323
       * @param displayAll if true, all feature will be labelled evan though overlaps occurs
 
324
       *
 
325
       * @todo UnknownLayer will be ignored ? should throw exception or not ???
 
326
       *
 
327
       * @return A list of label to display on map
 
328
       */
 
329
      std::list<LabelPosition*> *labeller( int nbLayers,
 
330
                                           char **layersName,
 
331
                                           double *layersFactor,
 
332
                                           double scale, double bbox[4],
 
333
                                           PalStat **stat,
 
334
                                           bool displayAll );
 
335
 
 
336
 
 
337
      Problem* extractProblem( double scale, double bbox[4] );
 
338
 
 
339
      std::list<LabelPosition*>* solveProblem( Problem* prob, bool displayAll );
 
340
 
 
341
      /**
 
342
       * \brief Set map resolution
 
343
       *
 
344
       * @param dpi map resolution (dot per inch)
 
345
       */
 
346
      void setDpi( int dpi );
 
347
 
 
348
      /**
 
349
       * \brief get map resolution
 
350
       *
 
351
       * @return map resolution (dot per inch)
 
352
       */
 
353
      int getDpi();
 
354
 
 
355
 
 
356
 
 
357
      /**
 
358
       * \brief set # candidates to generate for points features
 
359
       * Higher the value is, longer Pal::labeller will spend time
 
360
       *
 
361
       * @param point_p # candidates for a point
 
362
       */
 
363
      void setPointP( int point_p );
 
364
 
 
365
      /**
 
366
       * \brief set maximum # candidates to generate for lines features
 
367
       * Higher the value is, longer Pal::labeller will spend time
 
368
       *
 
369
       * @param line_p maximum # candidates for a line
 
370
       */
 
371
      void setLineP( int line_p );
 
372
 
 
373
      /**
 
374
       * \brief set maximum # candidates to generate for polygon features
 
375
       * Higher the value is, longer Pal::labeller will spend time
 
376
       *
 
377
       * @param poly_p maximum # candidate for a polygon
 
378
       */
 
379
      void setPolyP( int poly_p );
 
380
 
 
381
      /**
 
382
       *  \brief get # candidates to generate for point features
 
383
       */
 
384
      int getPointP();
 
385
 
 
386
      /**
 
387
       *  \brief get maximum  # candidates to generate for line features
 
388
       */
 
389
      int getLineP();
 
390
 
 
391
      /**
 
392
       *  \brief get maximum # candidates to generate for polygon features
 
393
       */
 
394
      int getPolyP();
 
395
 
 
396
      /**
 
397
       * \brief get current map unit
 
398
       */
 
399
      Units getMapUnit();
 
400
 
 
401
      /**
 
402
       * \brief set map unit
 
403
       */
 
404
      void setMapUnit( Units map_unit );
 
405
 
 
406
      /**
 
407
       * \brief Select the search method to use.
 
408
       *
 
409
       * For interactive mapping using CHAIN is a good
 
410
       * idea because it is the fastest. Other methods, ordered by speedness, are POPMUSIC_TABU,
 
411
       * POPMUSIC_CHAIN and POPMUSIC_TABU_CHAIN, defined in pal::_searchMethod enumeration
 
412
       * @param method the method to use
 
413
       */
 
414
      void setSearch( SearchMethod method );
 
415
 
 
416
      /**
 
417
       * \brief get the search method in use
 
418
       *
 
419
       * @return the search method
 
420
       */
 
421
      SearchMethod getSearch();
 
422
  };
 
423
} // end namespace pal
 
424
#endif