25
25
26
26
using namespace pal ;
27
27
28
- bool CostCalculator::candidateSortGrow ( const LabelPosition * c1, const LabelPosition * c2 )
28
+ bool CostCalculator::candidateSortGrow ( const std::unique_ptr< LabelPosition > & c1, const std::unique_ptr< LabelPosition > & c2 )
29
29
{
30
30
return c1->cost () < c2->cost ();
31
31
}
32
32
33
- bool CostCalculator::candidateSortShrink ( const LabelPosition * c1, const LabelPosition * c2 )
33
+ bool CostCalculator::candidateSortShrink ( const std::unique_ptr< LabelPosition > & c1, const std::unique_ptr< LabelPosition > & c2 )
34
34
{
35
35
return c1->cost () > c2->cost ();
36
36
}
@@ -93,31 +93,21 @@ void CostCalculator::addObstacleCostPenalty( LabelPosition *lp, FeaturePart *obs
93
93
lp->setCost ( lp->cost () + obstacleCost );
94
94
}
95
95
96
- void CostCalculator::setPolygonCandidatesCost ( int nblp, QList< LabelPosition * > &lPos, RTree<FeaturePart *, double , 2 , double > *obstacles, double bbx[4 ], double bby[4 ] )
96
+ void CostCalculator::setPolygonCandidatesCost ( std:: size_t nblp, std::vector< std::unique_ptr< LabelPosition > > &lPos, RTree<FeaturePart *, double , 2 , double > *obstacles, double bbx[4 ], double bby[4 ] )
97
97
{
98
98
double normalizer;
99
99
// compute raw cost
100
- for ( int i = 0 ; i < nblp; ++i )
101
- setCandidateCostFromPolygon ( lPos. at ( i ), obstacles, bbx, bby );
100
+ for ( std:: size_t i = 0 ; i < nblp; ++i )
101
+ setCandidateCostFromPolygon ( lPos[ i ]. get ( ), obstacles, bbx, bby );
102
102
103
103
// lPos with big values came first (value = min distance from label to Polygon's Perimeter)
104
104
// IMPORTANT - only want to sort first nblp positions. The rest have not had the cost
105
105
// calculated so will have nonsense values
106
- QList< LabelPosition * > toSort;
107
- toSort.reserve ( nblp );
108
- for ( int i = 0 ; i < nblp; ++i )
109
- {
110
- toSort << lPos.at ( i );
111
- }
112
- std::sort ( toSort.begin (), toSort.end (), candidateSortShrink );
113
- for ( int i = 0 ; i < nblp; ++i )
114
- {
115
- lPos[i] = toSort.at ( i );
116
- }
106
+ std::sort ( lPos.begin (), lPos.begin () + nblp, candidateSortShrink );
117
107
118
108
// define the value's range
119
- double cost_max = lPos.at ( 0 )->cost ();
120
- double cost_min = lPos.at ( nblp - 1 )->cost ();
109
+ double cost_max = lPos.front ( )->cost ();
110
+ double cost_min = lPos.back ( )->cost ();
121
111
122
112
cost_max -= cost_min;
123
113
@@ -132,17 +122,18 @@ void CostCalculator::setPolygonCandidatesCost( int nblp, QList< LabelPosition *
132
122
133
123
// adjust cost => the best is 0.0001, the worst is 0.0021
134
124
// others are set proportionally between best and worst
135
- for ( int i = 0 ; i < nblp; ++i )
125
+ for ( std:: size_t i = 0 ; i < nblp; ++i )
136
126
{
127
+ LabelPosition *pos = lPos[ i ].get ();
137
128
// if (cost_max - cost_min < EPSILON)
138
129
if ( cost_max > EPSILON )
139
130
{
140
- lPos. at ( i ) ->setCost ( 0.0021 - ( lPos. at ( i ) ->cost () - cost_min ) * normalizer );
131
+ pos ->setCost ( 0.0021 - ( pos ->cost () - cost_min ) * normalizer );
141
132
}
142
133
else
143
134
{
144
- // lPos[i] ->cost = 0.0001 + (lPos[i] ->cost - cost_min) * normalizer;
145
- lPos. at ( i ) ->setCost ( 0.0001 );
135
+ // pos ->cost = 0.0001 + (pos ->cost - cost_min) * normalizer;
136
+ pos ->setCost ( 0.0001 );
146
137
}
147
138
}
148
139
}
@@ -174,31 +165,30 @@ void CostCalculator::setCandidateCostFromPolygon( LabelPosition *lp, RTree <Feat
174
165
delete pCost;
175
166
}
176
167
177
- int CostCalculator::finalizeCandidatesCosts ( Feats *feat, int max_p, RTree <FeaturePart *, double , 2 , double > *obstacles, double bbx[4 ], double bby[4 ] )
168
+ std:: size_t CostCalculator::finalizeCandidatesCosts ( Feats *feat, std:: size_t max_p, RTree <FeaturePart *, double , 2 , double > *obstacles, double bbx[4 ], double bby[4 ] )
178
169
{
179
170
// If candidates list is smaller than expected
180
- if ( max_p > feat->candidates .count () )
181
- max_p = feat->candidates .count ();
171
+ if ( max_p > feat->candidates .size () )
172
+ max_p = feat->candidates .size ();
182
173
//
183
174
// sort candidates list, best label to worst
184
175
std::sort ( feat->candidates .begin (), feat->candidates .end (), candidateSortGrow );
185
176
186
177
// try to exclude all conflitual labels (good ones have cost < 1 by pruning)
187
178
double discrim = 0.0 ;
188
- int stop;
179
+ std:: size_t stop = 0 ;
189
180
do
190
181
{
191
182
discrim += 1.0 ;
192
- for ( stop = 0 ; stop < feat->candidates .count () && feat->candidates . at ( stop ) ->cost () < discrim; stop++ )
183
+ for ( stop = 0 ; stop < feat->candidates .size () && feat->candidates [ stop ] ->cost () < discrim; stop++ )
193
184
;
194
185
}
195
- while ( stop == 0 && discrim < feat->candidates .last ()->cost () + 2.0 );
186
+ while ( stop == 0 && discrim < feat->candidates .back ()->cost () + 2.0 );
196
187
197
188
if ( discrim > 1.5 )
198
189
{
199
- int k;
200
- for ( k = 0 ; k < stop; k++ )
201
- feat->candidates .at ( k )->setCost ( 0.0021 );
190
+ for ( std::size_t k = 0 ; k < stop; k++ )
191
+ feat->candidates [ k ]->setCost ( 0.0021 );
202
192
}
203
193
204
194
if ( max_p > stop )
0 commit comments