@@ -219,9 +219,7 @@ namespace pal
219
219
*/
220
220
bool extractFeatCallback ( FeaturePart *ft_ptr, void *ctx )
221
221
{
222
-
223
- double min[2 ];
224
- double max[2 ];
222
+ double amin[2 ], amax[2 ];
225
223
226
224
FeatCallBackCtx *context = ( FeatCallBackCtx* ) ctx;
227
225
@@ -238,146 +236,63 @@ namespace pal
238
236
// all feature which are obstacle will be inserted into obstacles
239
237
if ( context->layer ->obstacle )
240
238
{
241
- ft_ptr->getBoundingBox (min, max );
242
- context->obstacles ->Insert ( min, max , ft_ptr );
239
+ ft_ptr->getBoundingBox (amin, amax );
240
+ context->obstacles ->Insert ( amin, amax , ft_ptr );
243
241
}
244
242
243
+ // first do some checks whether to extract candidates or not
245
244
246
245
// feature has to be labeled ?
247
- if ( context->layer ->toLabel && context->layer ->isScaleValid ( context->scale ) )
248
- {
249
- // is the feature well defined ? // TODO Check epsilon
250
- if ( ft_ptr->getLabelWidth () > 0.0000001 && ft_ptr->getLabelHeight () > 0.0000001 )
251
- {
252
-
253
- int i;
254
- // Hole of the feature are obstacles
255
- for ( i = 0 ;i < ft_ptr->getNumSelfObstacles ();i++ )
256
- {
257
- ft_ptr->getSelfObstacle (i)->getBoundingBox (min, max);
258
- context->obstacles ->Insert ( min, max, ft_ptr->getSelfObstacle (i) );
259
-
260
- if ( !ft_ptr->getSelfObstacle (i)->getHoleOf () )
261
- {
262
- std::cout << " ERROR: SHOULD HAVE A PARENT!!!!!" << std::endl;
263
- }
264
- }
265
-
266
-
267
- LinkedList<Feats*> *feats = new LinkedList<Feats*> ( ptrFeatsCompare );
268
-
269
- QTime t;
270
- t.start ();
271
-
272
- if (( ft_ptr->getGeosType () == GEOS_LINESTRING )
273
- || ft_ptr->getGeosType () == GEOS_POLYGON )
274
- {
275
-
276
- double bbx[4 ], bby[4 ];
246
+ if ( !context->layer ->toLabel )
247
+ return true ;
277
248
278
- bbx[0 ] = context->bbox_min [0 ]; bbx[1 ] = context->bbox_max [0 ];
279
- bbx[2 ] = context->bbox_max [0 ]; bbx[3 ] = context->bbox_min [0 ];
249
+ // are we in a valid scale range for the layer?
250
+ if ( !context->layer ->isScaleValid ( context->scale ) )
251
+ return true ;
280
252
281
- bby[0 ] = context->bbox_min [1 ]; bby[1 ] = context->bbox_min [1 ];
282
- bby[2 ] = context->bbox_max [1 ]; bby[3 ] = context->bbox_max [1 ];
253
+ // is the feature well defined ? // TODO Check epsilon
254
+ if ( ft_ptr->getLabelWidth () < 0.0000001 || ft_ptr->getLabelHeight () < 0.0000001 )
255
+ return true ;
283
256
284
- LinkedList<PointSet*> *shapes = new LinkedList<PointSet*> ( ptrPSetCompare );
285
- bool outside, inside;
257
+ // OK, everything's fine, let's process the feature part
286
258
287
- PointSet *shape = ft_ptr->createProblemSpecificPointSet ( bbx, bby, &outside, &inside );
288
-
289
-
290
- if ( inside )
291
- {
292
- // no extra treatment required
293
- shapes->push_back ( shape );
294
- }
295
- else
296
- {
297
- // feature isn't completly in the math
298
- if ( ft_ptr->getGeosType () == GEOS_LINESTRING )
299
- PointSet::reduceLine ( shape, shapes, bbx, bby );
300
- else
301
- {
302
- PointSet::reducePolygon ( shape, shapes, bbx, bby );
303
- }
304
- }
305
-
306
- while ( shapes->size () > 0 )
307
- {
308
- shape = shapes->pop_front ();
309
- Feats *ft = new Feats ();
310
- ft->feature = ft_ptr;
311
- ft->shape = shape;
312
- feats->push_back ( ft );
313
-
314
- #ifdef _EXPORT_MAP_
315
- if ( !svged )
316
- {
317
- toSVGPath ( shape->nbPoints , shape->type , shape->x , shape->y ,
318
- dpi , context->scale ,
319
- convert2pt ( context->bbox_min [0 ], context->scale , dpi ),
320
- convert2pt ( context->bbox_max [1 ], context->scale , dpi ),
321
- context->layer ->name , ft_ptr->uid , *context->svgmap );
322
- }
323
- #endif
324
- }
325
- delete shapes;
326
- }
327
- else
328
- {
329
- // Feat is a point
330
- Feats *ft = new Feats ();
331
- ft->feature = ft_ptr;
332
- ft->shape = NULL ;
333
- feats->push_back ( ft );
334
- }
259
+ // Holes of the feature are obstacles
260
+ for ( int i = 0 ;i < ft_ptr->getNumSelfObstacles ();i++ )
261
+ {
262
+ ft_ptr->getSelfObstacle (i)->getBoundingBox (amin, amax);
263
+ context->obstacles ->Insert ( amin, amax, ft_ptr->getSelfObstacle (i) );
335
264
336
- // for earch feature part extracted : generate candidates
337
- while ( feats->size () > 0 )
338
- {
339
- Feats *ft = feats->pop_front ();
265
+ if ( !ft_ptr->getSelfObstacle (i)->getHoleOf () )
266
+ {
267
+ std::cout << " ERROR: SHOULD HAVE A PARENT!!!!!" << std::endl;
268
+ }
269
+ }
340
270
341
- #ifdef _DEBUG_
342
- std::cout << " Compute candidates for feat " << ft->feature ->layer ->name << " /" << ft->feature ->uid << std::endl;
343
- #endif
344
- ft->nblp = ft->feature ->setPosition ( context->scale , & ( ft->lPos ), context->bbox_min , context->bbox_max , ft->shape , context->candidates
271
+ // generate candidates for the feature part
272
+ LabelPosition** lPos;
273
+ int nblp = ft_ptr->setPosition ( context->scale , &lPos, context->bbox_min , context->bbox_max , ft_ptr, context->candidates
345
274
#ifdef _EXPORT_MAP_
346
275
, *context->svgmap
347
276
#endif
348
277
);
349
278
350
- delete ft->shape ;
351
- ft->shape = NULL ;
352
-
353
- if ( ft->nblp > 0 )
354
- {
355
- // valid features are added to fFeats
356
- ft->priority = context->priority ;
357
- context->fFeats ->push_back ( ft );
358
- #ifdef _DEBUG_
359
- std::cout << ft->nblp << " labelPositions for feature : " << ft->feature ->layer ->name << " /" << ft->feature ->uid << std::endl;
360
- #endif
361
- }
362
- else
363
- {
364
- // Others are deleted
365
- #ifdef _VERBOSE_
366
- std::cout << " Unable to generate labelPosition for feature : " << ft->feature ->layer ->name << " /" << ft->feature ->uid << std::endl;
367
- #endif
368
- delete[] ft->lPos ;
369
- delete ft;
370
- }
371
- }
372
- delete feats;
373
- }
374
- else // check labelsize
375
- {
376
- #ifdef _VERBOSE_
377
- std::cerr << " Feature " << ft_ptr->layer ->name << " /" << ft_ptr->uid << " is skipped (label size = 0)" << std::endl;
378
- #endif
379
- }
279
+ if ( nblp > 0 )
280
+ {
281
+ // valid features are added to fFeats
282
+ Feats *ft = new Feats ();
283
+ ft->feature = ft_ptr;
284
+ ft->shape = NULL ;
285
+ ft->nblp = nblp;
286
+ ft->lPos = lPos;
287
+ ft->priority = context->priority ;
288
+ context->fFeats ->push_back ( ft );
380
289
}
290
+ else
291
+ {
292
+ // Others are deleted
293
+ delete[] lPos;
294
+ }
295
+
381
296
return true ;
382
297
}
383
298
0 commit comments