@@ -95,26 +95,35 @@ namespace pal
95
95
96
96
// //////
97
97
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 ] )
99
99
{
100
- int i;
101
-
102
100
double normalizer;
103
101
// compute raw cost
104
102
#ifdef _DEBUG_
105
103
std::cout << " LabelPosition for feat: " << lPos[0 ]->feature ->uid << std::endl;
106
104
#endif
107
105
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 );
110
108
111
109
// 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
+ }
113
122
114
123
115
124
// define the value's range
116
125
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 ();
118
127
119
128
cost_max -= cost_min;
120
129
@@ -129,20 +138,20 @@ namespace pal
129
138
130
139
// adjust cost => the best is 0.0001, the worst is 0.0021
131
140
// others are set proportionally between best and worst
132
- for ( i = 0 ; i < max_p; i++ )
141
+ for ( int i = 0 ; i < nblp; ++i )
133
142
{
134
143
#ifdef _DEBUG_
135
144
std::cout << " lpos[" << i << " ] = " << lPos[i]->cost ;
136
145
#endif
137
146
// if (cost_max - cost_min < EPSILON)
138
147
if ( cost_max > EPSILON )
139
148
{
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 ) ;
141
150
}
142
151
else
143
152
{
144
153
// lPos[i]->cost = 0.0001 + (lPos[i]->cost - cost_min) * normalizer;
145
- lPos[i]-> mCost = 0.0001 ;
154
+ lPos. at ( i )-> setCost ( 0.0001 ) ;
146
155
}
147
156
148
157
#ifdef _DEBUG_
@@ -220,7 +229,7 @@ namespace pal
220
229
{
221
230
int arrangement = feat->feature ->layer ()->arrangement ();
222
231
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 );
224
233
}
225
234
226
235
// add size penalty (small lines/polygons get higher cost)
0 commit comments