Skip to content

Commit e18dcbf

Browse files
committed
Merge pull request #640 from mhugent/labeling_performance
Labeling performance
2 parents eb6ca1e + 2bf0b2e commit e18dcbf

File tree

3 files changed

+14
-135
lines changed

3 files changed

+14
-135
lines changed

src/core/pal/costcalculator.cpp

Lines changed: 8 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -216,151 +216,31 @@ namespace pal
216216

217217
PolygonCostCalculator::PolygonCostCalculator( LabelPosition *lp ) : lp( lp )
218218
{
219-
int i;
220-
double hyp = max( lp->feature->xmax - lp->feature->xmin, lp->feature->ymax - lp->feature->ymin );
221-
hyp *= 10;
222-
223219
px = ( lp->x[0] + lp->x[2] ) / 2.0;
224220
py = ( lp->y[0] + lp->y[2] ) / 2.0;
225221

226-
/*
227-
3 2 1
228-
\ | /
229-
4 --x -- 0
230-
/ | \
231-
5 6 7
232-
*/
233-
234-
double alpha = lp->getAlpha();
235-
for ( i = 0; i < 8; i++, alpha += M_PI_4 )
236-
{
237-
dist[i] = DBL_MAX;
238-
ok[i] = false;
239-
rpx[i] = px + cos( alpha ) * hyp;
240-
rpy[i] = py + sin( alpha ) * hyp;
241-
}
222+
dist = DBL_MAX;
223+
ok = false;
242224
}
243225

244226
void PolygonCostCalculator::update( PointSet *pset )
245227
{
246-
if ( pset->type == GEOS_POINT )
228+
double rx, ry;
229+
pset->getDist( px, py, &rx, &ry );
230+
double d = dist_euc2d_sq( px, py, rx, ry );
231+
if ( d < dist )
247232
{
248-
updatePoint( pset );
249-
}
250-
else
251-
{
252-
double rx, ry;
253-
if ( pset->getDist( px, py, &rx, &ry ) < updateLinePoly( pset ) )
254-
{
255-
PointSet *point = new PointSet( ry, ry );
256-
update( point );
257-
delete point;
258-
}
259-
}
260-
}
261-
262-
void PolygonCostCalculator::updatePoint( PointSet *pset )
263-
{
264-
double beta = atan2( pset->y[0] - py, pset->x[0] - px ) - lp->getAlpha();
265-
266-
while ( beta < 0.0 )
267-
{
268-
beta += 2 * M_PI;
269-
}
270-
271-
int i = ( int ) floor( beta / M_PI_4 ) % 8;
272-
273-
for ( int j = 0; j < 2; j++, i = ( i + 1 ) % 8 )
274-
{
275-
double rx, ry;
276-
rx = px - rpy[i] + py;
277-
ry = py + rpx[i] - px;
278-
double ix, iy; // the point that we look for
279-
if ( computeLineIntersection( px, py, rpx[i], rpy[i], pset->x[0], pset->y[0], rx, ry, &ix, &iy ) )
280-
{
281-
double d = dist_euc2d_sq( px, py, ix, iy );
282-
if ( d < dist[i] )
283-
{
284-
dist[i] = d;
285-
ok[i] = true;
286-
}
287-
}
288-
else
289-
{
290-
std::cout << "this shouldn't occur!!!" << std::endl;
291-
}
233+
dist = d;
292234
}
293235
}
294236

295-
double PolygonCostCalculator::updateLinePoly( PointSet *pset )
296-
{
297-
int i, j, k;
298-
int nbP = ( pset->type == GEOS_POLYGON ? pset->nbPoints : pset->nbPoints - 1 );
299-
double min_dist = DBL_MAX;
300-
301-
for ( i = 0; i < nbP; i++ )
302-
{
303-
j = ( i + 1 ) % pset->nbPoints;
304-
305-
for ( k = 0; k < 8; k++ )
306-
{
307-
double ix, iy;
308-
if ( computeSegIntersection( px, py, rpx[k], rpy[k], pset->x[i], pset->y[i], pset->x[j], pset->y[j], &ix, &iy ) )
309-
{
310-
double d = dist_euc2d_sq( px, py, ix, iy );
311-
if ( d < dist[k] )
312-
{
313-
dist[k] = d;
314-
ok[k] = true;
315-
}
316-
if ( d < min_dist )
317-
{
318-
min_dist = d;
319-
}
320-
}
321-
}
322-
}
323-
return min_dist;
324-
}
325-
326237
LabelPosition* PolygonCostCalculator::getLabel()
327238
{
328239
return lp;
329240
}
330241

331242
double PolygonCostCalculator::getCost()
332243
{
333-
int i;
334-
335-
for ( i = 0; i < 8; i++ )
336-
{
337-
#if 0
338-
if ( i == 0 || i == 4 ) // horizontal directions
339-
dist[i] -= lp->w / 2;
340-
else if ( i == 2 || i == 6 ) // vertical directions
341-
dist[i] -= lp->h / 2;
342-
else // other directions
343-
dist[i] -= ( lp->w / 2 ) / cos( M_PI_4 );
344-
#endif
345-
346-
if ( !ok[i] || dist[i] < EPSILON )
347-
{
348-
dist[i] = EPSILON;
349-
}
350-
}
351-
352-
double a, b, c, d;
353-
354-
a = min( dist[0], dist[4] );
355-
b = min( dist[1], dist[5] );
356-
c = min( dist[2], dist[6] );
357-
d = min( dist[3], dist[7] );
358-
359-
#if 0
360-
if ( a != EPSILON || b != EPSILON || c != EPSILON || d != EPSILON )
361-
std::cout << "res " << ( a*b*c*d ) << " " << a << " " << b << " " << c << " " << d << std::endl;
362-
#endif
363-
return ( a*b*c*d );
244+
return ( 4 * dist );
364245
}
365-
366246
}

src/core/pal/costcalculator.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ namespace pal
4747
{
4848
LabelPosition *lp;
4949
double px, py;
50-
double dist[8];
51-
double rpx[8];
52-
double rpy[8];
53-
bool ok[8];
50+
double dist;
51+
bool ok;
5452

55-
void updatePoint( PointSet *pset );
56-
double updateLinePoly( PointSet *pset );
5753
public:
5854
PolygonCostCalculator( LabelPosition *lp );
5955

src/core/pal/feature.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,10 @@ namespace pal
11031103
j++;
11041104
}
11051105

1106-
dx = dy = min( yrm, xrm ) / 2;
1106+
//dx = dy = min( yrm, xrm ) / 2;
1107+
dx = xrm / 2.0;
1108+
dy = yrm / 2.0;
1109+
11071110

11081111
int num_try = 0;
11091112
int max_try = 10;

0 commit comments

Comments
 (0)