@@ -213,37 +213,50 @@ namespace pal
213213 return cost;
214214 }
215215
216- Feature * LabelPosition::getFeature ()
217- {
218- return feature;
219- }
220-
221- bool xGrow ( void *l, void *r )
216+ void LabelPosition::validateCost ()
222217 {
223- return (( LabelPosition* ) l )->x [0 ] > (( LabelPosition* ) r )->x [0 ];
218+ if ( cost >= 1 )
219+ {
220+ std::cout << " Warning: lp->cost == " << cost << " (from feat: " << feature->getUID () << " /" << getLayerName () << " )" << std::endl;
221+ cost -= int ( cost ); // label cost up to 1
222+ }
224223 }
225224
226- bool yGrow ( void *l, void *r )
225+ Feature * LabelPosition::getFeature ( )
227226 {
228- return (( LabelPosition* ) l )-> y [ 0 ] > (( LabelPosition* ) r )-> y [ 0 ] ;
227+ return feature ;
229228 }
230229
231- bool xShrink ( void *l, void *r )
230+ void LabelPosition::getBoundingBox ( double amin[ 2 ], double amax[ 2 ]) const
232231 {
233- return (( LabelPosition* ) l )->x [0 ] < (( LabelPosition* ) r )->x [0 ];
232+ amin[0 ] = DBL_MAX;
233+ amax[0 ] = -DBL_MAX;
234+ amin[1 ] = DBL_MAX;
235+ amax[1 ] = -DBL_MAX;
236+ for ( int c = 0 ;c < 4 ;c++ )
237+ {
238+ if ( x[c] < amin[0 ] )
239+ amin[0 ] = x[c];
240+ if ( x[c] > amax[0 ] )
241+ amax[0 ] = x[c];
242+ if ( y[c] < amin[1 ] )
243+ amin[1 ] = y[c];
244+ if ( y[c] > amax[1 ] )
245+ amax[1 ] = y[c];
246+ }
234247 }
235248
236- bool yShrink ( void *l, void *r )
249+ char * LabelPosition::getLayerName () const
237250 {
238- return (( LabelPosition* ) l )-> y [ 0 ] < (( LabelPosition* ) r )-> y [ 0 ] ;
251+ return feature-> getLayer ()-> name ;
239252 }
240253
241- bool costShrink ( void *l, void *r )
254+ bool LabelPosition:: costShrink ( void *l, void *r )
242255 {
243256 return (( LabelPosition* ) l )->cost < (( LabelPosition* ) r )->cost ;
244257 }
245258
246- bool costGrow ( void *l, void *r )
259+ bool LabelPosition:: costGrow ( void *l, void *r )
247260 {
248261 return (( LabelPosition* ) l )->cost > (( LabelPosition* ) r )->cost ;
249262 }
@@ -269,31 +282,31 @@ namespace pal
269282// #warning retourner les coord projeté ou pas ?
270283 // feature->layer->pal->proj->getLatLong(this->x[0], this->y[0], &x, &y);
271284
272- return new Label ( this ->x , this ->y , alpha, feature->uid , feature->layer -> name , feature->userGeom );
285+ return new Label ( this ->x , this ->y , alpha, feature->getUID () , feature->getLayer ()-> getName () , feature->getUserGeometry () );
273286 }
274287
275288
276- bool obstacleCallback ( PointSet *feat, void *ctx )
289+ bool LabelPosition:: obstacleCallback ( PointSet *feat, void *ctx )
277290 {
278291 LabelPosition::PolygonCostCalculator *pCost = ( LabelPosition::PolygonCostCalculator* ) ctx;
279292
280293 LabelPosition *lp = pCost->getLabel ();
281- if (( feat == lp->feature ) || ( feat->holeOf && feat->holeOf != lp->feature ) )
294+ if (( feat == lp->feature ) || ( feat->getHoleOf () && feat->getHoleOf () != lp->feature ) )
282295 {
283296 return true ;
284297 }
285298
286299 // if the feature is not a hole we have to fetch corrdinates
287300 // otherwise holes coordinates are still in memory (feature->selfObs)
288- if ( feat->holeOf == NULL )
301+ if ( feat->getHoleOf () == NULL )
289302 {
290303 (( Feature* ) feat )->fetchCoordinates ();
291304 }
292305
293306 pCost->update ( feat );
294307
295308
296- if ( feat->holeOf == NULL )
309+ if ( feat->getHoleOf () == NULL )
297310 {
298311 (( Feature* ) feat )->releaseCoordinates ();
299312 }
@@ -332,10 +345,7 @@ namespace pal
332345 amax[0] = amin[0] + 2 * dist;
333346 amax[1] = amin[1] + 2 * dist;
334347 } else {*/
335- amin[0 ] = feature->xmin ;
336- amin[1 ] = feature->ymin ;
337- amax[0 ] = feature->xmax ;
338- amax[1 ] = feature->ymax ;
348+ feature->getBoundingBox (amin, amax);
339349 // }
340350
341351 // std::cout << amin[0] << " " << amin[1] << " " << amax[0] << " " << amax[1] << std::endl;
@@ -351,24 +361,7 @@ namespace pal
351361 {
352362 double amin[2 ];
353363 double amax[2 ];
354- int c;
355-
356- amin[0 ] = DBL_MAX;
357- amax[0 ] = -DBL_MAX;
358- amin[1 ] = DBL_MAX;
359- amax[1 ] = -DBL_MAX;
360- for ( c = 0 ;c < 4 ;c++ )
361- {
362- if ( x[c] < amin[0 ] )
363- amin[0 ] = x[c];
364- if ( x[c] > amax[0 ] )
365- amax[0 ] = x[c];
366- if ( y[c] < amin[1 ] )
367- amin[1 ] = y[c];
368- if ( y[c] > amax[1 ] )
369- amax[1 ] = y[c];
370- }
371-
364+ getBoundingBox (amin, amax);
372365 index->Remove ( amin, amax, this );
373366 }
374367
@@ -377,24 +370,7 @@ namespace pal
377370 {
378371 double amin[2 ];
379372 double amax[2 ];
380- int c;
381-
382- amin[0 ] = DBL_MAX;
383- amax[0 ] = -DBL_MAX;
384- amin[1 ] = DBL_MAX;
385- amax[1 ] = -DBL_MAX;
386- for ( c = 0 ;c < 4 ;c++ )
387- {
388- if ( x[c] < amin[0 ] )
389- amin[0 ] = x[c];
390- if ( x[c] > amax[0 ] )
391- amax[0 ] = x[c];
392- if ( y[c] < amin[1 ] )
393- amin[1 ] = y[c];
394- if ( y[c] > amax[1 ] )
395- amax[1 ] = y[c];
396- }
397-
373+ getBoundingBox (amin, amax);
398374 index->Insert ( amin, amax, this );
399375 }
400376
@@ -603,5 +579,56 @@ namespace pal
603579 // return (a+b+c+d);
604580 return ( a*b*c*d );
605581 }
582+
583+ // ////////
584+
585+ bool LabelPosition::countOverlapCallback ( LabelPosition *lp, void *ctx )
586+ {
587+ LabelPosition *lp2 = ( LabelPosition* ) ctx;
588+
589+ if ( lp2->isInConflict ( lp ) )
590+ {
591+ lp2->nbOverlap ++;
592+ }
593+
594+ return true ;
595+ }
596+
597+ bool LabelPosition::countFullOverlapCallback ( LabelPosition *lp, void *ctx )
598+ {
599+ LabelPosition *lp2 = (( CountContext* ) ctx )->lp ;
600+ double *cost = (( CountContext* ) ctx )->cost ;
601+ // int *feat = ((CountContext*)ctx)->feat;
602+ int *nbOv = (( CountContext* ) ctx )->nbOv ;
603+ double *inactiveCost = (( CountContext* ) ctx )->inactiveCost ;
604+ if ( lp2->isInConflict ( lp ) )
605+ {
606+ #ifdef _DEBUG_FULL_
607+ std::cout << " count overlap : " << lp->id << " <->" << lp2->id << std::endl;
608+ #endif
609+ ( *nbOv ) ++;
610+ *cost += inactiveCost[lp->probFeat ] + lp->getCost ();
611+
612+ }
613+
614+ return true ;
615+ }
616+
617+
618+ bool LabelPosition::removeOverlapCallback ( LabelPosition *lp, void *ctx )
619+ {
620+ LabelPosition *lp2 = ( LabelPosition * ) ctx;
621+
622+ if ( lp2->isInConflict ( lp ) )
623+ {
624+ // std::cout << " hit !" << std::endl;
625+ lp->nbOverlap --;
626+ lp2->nbOverlap --;
627+ }
628+
629+ return true ;
630+ }
631+
632+
606633} // end namespace
607634
0 commit comments