Skip to content
Permalink
Browse files

[pal] Fix regression in placement for free/horizontal polygon labels

  • Loading branch information
nyalldawson committed Oct 22, 2015
1 parent 0559939 commit 307b1b92a38a64aaf62ddaf59d01f4aabeffc8db
Showing with 21 additions and 12 deletions.
  1. +20 −11 src/core/pal/costcalculator.cpp
  2. +1 −1 src/core/pal/costcalculator.h
@@ -95,26 +95,35 @@ namespace pal

////////

void CostCalculator::setPolygonCandidatesCost( int nblp, QList< LabelPosition* >& lPos, int max_p, RTree<FeaturePart*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
void CostCalculator::setPolygonCandidatesCost( int nblp, QList< LabelPosition* >& lPos, RTree<FeaturePart*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
{
int i;

double normalizer;
// compute raw cost
#ifdef _DEBUG_
std::cout << "LabelPosition for feat: " << lPos[0]->feature->uid << std::endl;
#endif

for ( i = 0; i < nblp; i++ )
setCandidateCostFromPolygon( lPos[i], obstacles, bbx, bby );
for ( int i = 0; i < nblp; ++i )
setCandidateCostFromPolygon( lPos.at( i ), obstacles, bbx, bby );

// lPos with big values came first (value = min distance from label to Polygon's Perimeter)
qSort( lPos.begin(), lPos.end(), candidateSortShrink );
// IMPORTANT - only want to sort first nblp positions. The rest have not had the cost
// calculated so will have nonsense values
QList< LabelPosition* > toSort;
for ( int i = 0; i < nblp; ++i )
{
toSort << lPos.at( i );
}
qSort( toSort.begin(), toSort.end(), candidateSortShrink );
for ( int i = 0; i < nblp; ++i )
{
lPos[i] = toSort.at( i );
}


// define the value's range
double cost_max = lPos.at( 0 )->cost();
double cost_min = lPos.at( max_p - 1 )->cost();
double cost_min = lPos.at( nblp - 1 )->cost();

cost_max -= cost_min;

@@ -129,20 +138,20 @@ namespace pal

// adjust cost => the best is 0.0001, the worst is 0.0021
// others are set proportionally between best and worst
for ( i = 0; i < max_p; i++ )
for ( int i = 0; i < nblp; ++i )
{
#ifdef _DEBUG_
std::cout << " lpos[" << i << "] = " << lPos[i]->cost;
#endif
//if (cost_max - cost_min < EPSILON)
if ( cost_max > EPSILON )
{
lPos[i]->mCost = 0.0021 - ( lPos.at( i )->cost() - cost_min ) * normalizer;
lPos.at( i )->setCost( 0.0021 - ( lPos.at( i )->cost() - cost_min ) * normalizer );
}
else
{
//lPos[i]->cost = 0.0001 + (lPos[i]->cost - cost_min) * normalizer;
lPos[i]->mCost = 0.0001;
lPos.at( i )->setCost( 0.0001 );
}

#ifdef _DEBUG_
@@ -220,7 +229,7 @@ namespace pal
{
int arrangement = feat->feature->layer()->arrangement();
if ( arrangement == P_FREE || arrangement == P_HORIZ )
setPolygonCandidatesCost( stop, feat->lPos, max_p, obstacles, bbx, bby );
setPolygonCandidatesCost( stop, feat->lPos, obstacles, bbx, bby );
}

// add size penalty (small lines/polygons get higher cost)
@@ -28,7 +28,7 @@ namespace pal
/** Increase candidate's cost according to its collision with passed feature */
static void addObstacleCostPenalty( LabelPosition* lp, pal::FeaturePart *obstacle );

static void setPolygonCandidatesCost( int nblp, QList< LabelPosition* >& lPos, int max_p, RTree<pal::FeaturePart*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
static void setPolygonCandidatesCost( int nblp, QList< LabelPosition* >& lPos, RTree<pal::FeaturePart*, double, 2, double> *obstacles, double bbx[4], double bby[4] );

/** Set cost to the smallest distance between lPos's centroid and a polygon stored in geoetry field */
static void setCandidateCostFromPolygon( LabelPosition* lp, RTree<pal::FeaturePart *, double, 2, double> *obstacles, double bbx[4], double bby[4] );

0 comments on commit 307b1b9

Please sign in to comment.
You can’t perform that action at this time.