Skip to content

Commit 307b1b9

Browse files
committedOct 22, 2015
[pal] Fix regression in placement for free/horizontal polygon labels
1 parent 0559939 commit 307b1b9

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed
 

‎src/core/pal/costcalculator.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,35 @@ namespace pal
9595

9696
////////
9797

98-
void CostCalculator::setPolygonCandidatesCost( int nblp, QList< LabelPosition* >& lPos, int max_p, RTree<FeaturePart*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
98+
void CostCalculator::setPolygonCandidatesCost( int nblp, QList< LabelPosition* >& lPos, RTree<FeaturePart*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
9999
{
100-
int i;
101-
102100
double normalizer;
103101
// compute raw cost
104102
#ifdef _DEBUG_
105103
std::cout << "LabelPosition for feat: " << lPos[0]->feature->uid << std::endl;
106104
#endif
107105

108-
for ( i = 0; i < nblp; i++ )
109-
setCandidateCostFromPolygon( lPos[i], obstacles, bbx, bby );
106+
for ( int i = 0; i < nblp; ++i )
107+
setCandidateCostFromPolygon( lPos.at( i ), obstacles, bbx, bby );
110108

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

114123

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

119128
cost_max -= cost_min;
120129

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

130139
// adjust cost => the best is 0.0001, the worst is 0.0021
131140
// others are set proportionally between best and worst
132-
for ( i = 0; i < max_p; i++ )
141+
for ( int i = 0; i < nblp; ++i )
133142
{
134143
#ifdef _DEBUG_
135144
std::cout << " lpos[" << i << "] = " << lPos[i]->cost;
136145
#endif
137146
//if (cost_max - cost_min < EPSILON)
138147
if ( cost_max > EPSILON )
139148
{
140-
lPos[i]->mCost = 0.0021 - ( lPos.at( i )->cost() - cost_min ) * normalizer;
149+
lPos.at( i )->setCost( 0.0021 - ( lPos.at( i )->cost() - cost_min ) * normalizer );
141150
}
142151
else
143152
{
144153
//lPos[i]->cost = 0.0001 + (lPos[i]->cost - cost_min) * normalizer;
145-
lPos[i]->mCost = 0.0001;
154+
lPos.at( i )->setCost( 0.0001 );
146155
}
147156

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

226235
// add size penalty (small lines/polygons get higher cost)

‎src/core/pal/costcalculator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace pal
2828
/** Increase candidate's cost according to its collision with passed feature */
2929
static void addObstacleCostPenalty( LabelPosition* lp, pal::FeaturePart *obstacle );
3030

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.