Skip to content
Permalink
Browse files

[pal] Various cleanups

Remove support for map scale, dpi and units from PAL. None of these features
were being used by QGIS (we use our own handling of these features) so the
PAL implementations were just bogging up the code. Also remove custom
min/max/abs implementations from pal and remove a bunch of unused methods.
  • Loading branch information
nyalldawson committed Jul 8, 2015
1 parent 0853ead commit bf61219e2e7921cdcd1989cbf5586e09796817fa
@@ -225,7 +225,7 @@ namespace pal
j = ( i + 1 ) % nbPoints;
if ( i == j )
break;
if ( vabs( x[i] - x[j] ) < 0.0000001 && vabs( y[i] - y[j] ) < 0.0000001 )
if ( qAbs( x[i] - x[j] ) < 0.0000001 && qAbs( y[i] - y[j] ) < 0.0000001 )
{
new_nbPoints--;
ok[i] = false;
@@ -319,10 +319,8 @@ namespace pal
}
}

int FeaturePart::setPositionOverPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle )
int FeaturePart::setPositionOverPoint( double x, double y, LabelPosition ***lPos, double angle )
{
Q_UNUSED( scale );
Q_UNUSED( delta_width );
int nbp = 1;
*lPos = new LabelPosition *[nbp];

@@ -396,30 +394,17 @@ namespace pal
return nbp;
}

int FeaturePart::setPositionForPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle )
int FeaturePart::setPositionForPoint( double x, double y, LabelPosition ***lPos, double angle )
{

#ifdef _DEBUG_
std::cout << "SetPosition (point) : " << layer->name << "/" << uid << std::endl;
#endif

int dpi = f->layer->pal->dpi;


double xrm;
double yrm;
double xrm = f->label_x;
double yrm = f->label_y;
double distlabel = f->distlabel;

xrm = unit_convert( f->label_x,
f->layer->label_unit,
f->layer->pal->map_unit,
dpi, scale, delta_width );

yrm = unit_convert( f->label_y,
f->layer->label_unit,
f->layer->pal->map_unit,
dpi, scale, delta_width );

int numberCandidates = f->layer->pal->point_p;

//std::cout << "Nbp : " << nbp << std::endl;
@@ -558,25 +543,16 @@ namespace pal
}

// TODO work with squared distance by remonving call to sqrt or dist_euc2d
int FeaturePart::setPositionForLine( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width )
int FeaturePart::setPositionForLine( LabelPosition ***lPos, PointSet *mapShape )
{
#ifdef _DEBUG_
std::cout << "SetPosition (line) : " << layer->name << "/" << uid << std::endl;
#endif
int i;
int dpi = f->layer->pal->dpi;
double xrm, yrm;
double distlabel = f->distlabel;

xrm = unit_convert( f->label_x,
f->layer->label_unit,
f->layer->pal->map_unit,
dpi, scale, delta_width );

yrm = unit_convert( f->label_y,
f->layer->label_unit,
f->layer->pal->map_unit,
dpi, scale, delta_width );
double xrm = f->label_x;
double yrm = f->label_y;

double *d; // segments lengths distance bw pt[i] && pt[i+1]
double *ad; // absolute distance bw pt[0] and pt[i] along the line
@@ -639,7 +615,7 @@ namespace pal
{
//dist /= nbls;
l = 0;
dist = min( yrm, xrm );
dist = qMin( yrm, xrm );
}
else // line length < label with => centering label position
{
@@ -676,12 +652,11 @@ namespace pal
cost = ( 1 - cost ) / 100; // < 0.0001, 0.01 > (but 0.005 is already pretty much)

// penalize positions which are further from the line's midpoint
double costCenter = vabs( ll / 2 - ( l + xrm / 2 ) ) / ll; // <0, 0.5>
double costCenter = qAbs( ll / 2 - ( l + xrm / 2 ) ) / ll; // <0, 0.5>
cost += costCenter / 1000; // < 0, 0.0005 >

if (( vabs( ey - by ) < EPSILON ) && ( vabs( ex - bx ) < EPSILON ) )
if ( qgsDoubleNear( ey, by ) && qgsDoubleNear( ex, bx ) )
{
std::cout << "EPSILON " << EPSILON << std::endl;
std::cout << "b: " << bx << ";" << by << std::endl;
std::cout << "e: " << ex << ";" << ey << std::endl;
alpha = 0.0;
@@ -979,7 +954,7 @@ namespace pal
}

QLinkedList<LabelPosition*> positions;
double delta = max( f->labelInfo->label_height, total_distance / 10.0 );
double delta = qMax( f->labelInfo->label_height, total_distance / 10.0 );

unsigned long flags = f->layer->getArrangementFlags();
if ( flags == 0 )
@@ -1002,7 +977,7 @@ namespace pal
{
diff = fabs( tmp->getAlpha() - angle_last );
if ( diff > 2*M_PI ) diff -= 2 * M_PI;
diff = min( diff, 2 * M_PI - diff ); // difference 350 deg is actually just 10 deg...
diff = qMin( diff, 2 * M_PI - diff ); // difference 350 deg is actually just 10 deg...
angle_diff += diff;
}

@@ -1018,7 +993,7 @@ namespace pal

// penalize positions which are further from the line's midpoint
double labelCenter = ( i * delta ) + f->label_x / 2;
double costCenter = vabs( total_distance / 2 - labelCenter ) / total_distance; // <0, 0.5>
double costCenter = qAbs( total_distance / 2 - labelCenter ) / total_distance; // <0, 0.5>
cost += costCenter / 1000; // < 0, 0.0005 >
//std::cerr << "cost " << angle_diff << " vs " << costCenter << std::endl;
slp->setCost( cost );
@@ -1066,7 +1041,7 @@ namespace pal
*
*/

int FeaturePart::setPositionForPolygon( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width )
int FeaturePart::setPositionForPolygon( LabelPosition ***lPos, PointSet *mapShape )
{

#ifdef _DEBUG_
@@ -1076,18 +1051,8 @@ namespace pal
int i;
int j;

double xrm;
double yrm;

xrm = unit_convert( f->label_x,
f->layer->label_unit,
f->layer->pal->map_unit,
f->layer->pal->dpi, scale, delta_width );

yrm = unit_convert( f->label_y,
f->layer->label_unit,
f->layer->pal->map_unit,
f->layer->pal->dpi, scale, delta_width );
double xrm = f->label_x;
double yrm = f->label_y;

//print();

@@ -1317,7 +1282,7 @@ namespace pal
}
#endif

int FeaturePart::setPosition( double scale, LabelPosition ***lPos,
int FeaturePart::setPosition( LabelPosition ***lPos,
double bbox_min[2], double bbox_max[2],
PointSet *mapShape, RTree<LabelPosition*, double, 2, double> *candidates )
{
@@ -1330,7 +1295,6 @@ namespace pal
bbox[2] = bbox_max[0];
bbox[3] = bbox_max[1];

double delta = bbox_max[0] - bbox_min[0];
double angle = f->fixedRotation ? f->fixedAngle : 0.0;

if ( f->fixedPosition() )
@@ -1345,15 +1309,15 @@ namespace pal
{
case GEOS_POINT:
if ( f->layer->getArrangement() == P_POINT_OVER || f->fixedQuadrant() )
nbp = setPositionOverPoint( x[0], y[0], scale, lPos, delta, angle );
nbp = setPositionOverPoint( x[0], y[0], lPos, angle );
else
nbp = setPositionForPoint( x[0], y[0], scale, lPos, delta, angle );
nbp = setPositionForPoint( x[0], y[0], lPos, angle );
break;
case GEOS_LINESTRING:
if ( f->layer->getArrangement() == P_CURVED )
nbp = setPositionForLineCurved( lPos, mapShape );
else
nbp = setPositionForLine( scale, lPos, mapShape, delta );
nbp = setPositionForLine( lPos, mapShape );
break;

case GEOS_POLYGON:
@@ -1364,15 +1328,15 @@ namespace pal
double cx, cy;
mapShape->getCentroid( cx, cy, f->layer->getCentroidInside() );
if ( f->layer->getArrangement() == P_POINT_OVER )
nbp = setPositionOverPoint( cx, cy, scale, lPos, delta, angle );
nbp = setPositionOverPoint( cx, cy, lPos, angle );
else
nbp = setPositionForPoint( cx, cy, scale, lPos, delta, angle );
nbp = setPositionForPoint( cx, cy, lPos, angle );
break;
case P_LINE:
nbp = setPositionForLine( scale, lPos, mapShape, delta );
nbp = setPositionForLine( lPos, mapShape );
break;
default:
nbp = setPositionForPolygon( scale, lPos, mapShape, delta );
nbp = setPositionForPolygon( lPos, mapShape );
break;
}
}
@@ -1420,7 +1384,7 @@ namespace pal
double length;
if ( GEOSLength_r( ctxt, the_geom, &length ) != 1 )
return; // failed to calculate length
double bbox_length = max( bbx[2] - bbx[0], bby[2] - bby[0] );
double bbox_length = qMax( bbx[2] - bbx[0], bby[2] - bby[0] );
if ( length >= bbox_length / 4 )
return; // the line is longer than quarter of height or width - don't penalize it

@@ -198,29 +198,25 @@ namespace pal
* Generate candidates for point features
* \param x x coordinates of the point
* \param y y coordinates of the point
* \param scale map scale is 1:scale
* \param lPos pointer to an array of candidates, will be filled by generated candidates
* \param delta_width delta width
* \param angle orientation of the label
* \return the number of generated cadidates
*/
int setPositionForPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );
int setPositionForPoint( double x, double y, LabelPosition ***lPos, double angle );

/**
* generate one candidate over specified point
*/
int setPositionOverPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );
int setPositionOverPoint( double x, double y, LabelPosition ***lPos, double angle );

/**
* \brief generate candidates for line feature
* Generate candidates for line features
* \param scale map scale is 1:scale
* \param lPos pointer to an array of candidates, will be filled by generated candidates
* \param mapShape a pointer to the line
* \param delta_width delta width
* \return the number of generated cadidates
*/
int setPositionForLine( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );
int setPositionForLine( LabelPosition ***lPos, PointSet *mapShape );

LabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
int orientation, int index, double distance );
@@ -233,13 +229,11 @@ namespace pal
/**
* \brief generate candidates for point feature
* Generate candidates for point features
* \param scale map scale is 1:scale
* \param lPos pointer to an array of candidates, will be filled by generated candidates
* \param mapShape a pointer to the polygon
* \param delta_width delta width
* \return the number of generated cadidates
*/
int setPositionForPolygon( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );
int setPositionForPolygon( LabelPosition ***lPos, PointSet *mapShape );

/**
* \brief return the feature
@@ -262,15 +256,14 @@ namespace pal
/**
* \brief generic method to generate candidates
* This method will call either setPositionFromPoint(), setPositionFromLine or setPositionFromPolygon
* \param scale the map scale is 1:scale
* \param lPos pointer to candidates array in which candidates will be put
* \param bbox_min min values of the map extent
* \param bbox_max max values of the map extent
* \param mapShape generate candidates for this spatial entites
* \param candidates index for candidates
* \return the number of candidates in *lPos
*/
int setPosition( double scale, LabelPosition ***lPos, double bbox_min[2], double bbox_max[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>*candidates );
int setPosition( LabelPosition ***lPos, double bbox_min[2], double bbox_max[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>*candidates );

/**
* \brief get the unique id of the feature
@@ -30,6 +30,7 @@
#include "geomfunction.h"
#include "feature.h"
#include "util.h"
#include "qgis.h"

namespace pal
{
@@ -261,13 +262,13 @@ namespace pal
toDist = distance[0];

distance[1] = dist_euc2d( cx, cy, xs1, ys1 );// j2
toDist = max( toDist, distance[1] );
toDist = qMax( toDist, distance[1] );

distance[2] = dist_euc2d( cx, cy, x3, y3 );// k
toDist = max( toDist, distance[2] );
toDist = qMax( toDist, distance[2] );

distance[3] = dist_euc2d( cx, cy, xs2, ys2 ); // l2
toDist = max( toDist, distance[3] );
toDist = qMax( toDist, distance[3] );

for ( i = 0; i < 4; i++ )
{
@@ -409,14 +410,14 @@ namespace pal

// find the lowest x value from the lowest y
ref = 1;
while ( ref < n && vabs( y[id[cHull[ref]]] - y[id[cHull[0]]] ) < EPSILON ) ref++;
while ( ref < n && qgsDoubleNear( y[id[cHull[ref]]], y[id[cHull[0]]] ) ) ref++;

heapsort( cHull, id, x, ref );

// the first point is now for sure in the hull as well as the ref one
for ( i = ref; i < n; i++ )
{
if ( vabs( y[id[cHull[i]]] - y[id[cHull[0]]] ) < EPSILON )
if ( qgsDoubleNear( y[id[cHull[i]]], y[id[cHull[0]]] ) )
tan[i] = FLT_MAX;
else
tan[i] = ( x[id[cHull[0]]] - x[id[cHull[i]]] ) / ( y[id[cHull[i]]] - y[id[cHull[0]]] );
@@ -444,7 +445,7 @@ namespace pal
result = cross_product( x[id[stack[second]]], y[id[stack[second]]],
x[id[stack[top]]], y[id[stack[top]]], x[id[cHull[i]]], y[id[cHull[i]]] );
// Coolineaire !! garder le plus éloigné
if ( vabs( result ) < EPSILON )
if ( qgsDoubleNear( result, 0.0 ) )
{
if ( dist_euc2d_sq( x[id[stack[second]]], y[id[stack[second]]], x[id[cHull[i]]], y[id[cHull[i]]] )
> dist_euc2d_sq( x[id[stack[second]]], y[id[stack[second]]], x[id[stack[top]]], y[id[stack[top]]] ) )
@@ -522,37 +522,37 @@ namespace pal
my[i] = ( y[i] + y[j] ) / 2.0;
}

if ( vabs( cross_product( mx[0], my[0], mx[2], my[2], xp, yp ) / h ) < w / 2 )
if ( qAbs( cross_product( mx[0], my[0], mx[2], my[2], xp, yp ) / h ) < w / 2 )
{
dist = cross_product( x[1], y[1], x[0], y[0], xp, yp ) / w;
if ( vabs( dist ) < vabs( dist_min ) )
if ( qAbs( dist ) < qAbs( dist_min ) )
dist_min = dist;

dist = cross_product( x[3], y[3], x[2], y[2], xp, yp ) / w;
if ( vabs( dist ) < vabs( dist_min ) )
if ( qAbs( dist ) < qAbs( dist_min ) )
dist_min = dist;
}

if ( vabs( cross_product( mx[1], my[1], mx[3], my[3], xp, yp ) / w ) < h / 2 )
if ( qAbs( cross_product( mx[1], my[1], mx[3], my[3], xp, yp ) / w ) < h / 2 )
{
dist = cross_product( x[2], y[2], x[1], y[1], xp, yp ) / h;
if ( vabs( dist ) < vabs( dist_min ) )
if ( qAbs( dist ) < qAbs( dist_min ) )
dist_min = dist;

dist = cross_product( x[0], y[0], x[3], y[3], xp, yp ) / h;
if ( vabs( dist ) < vabs( dist_min ) )
if ( qAbs( dist ) < qAbs( dist_min ) )
dist_min = dist;
}

for ( i = 0; i < 4; i++ )
{
dist = dist_euc2d( x[i], y[i], xp, yp );
if ( vabs( dist ) < vabs( dist_min ) )
if ( qAbs( dist ) < qAbs( dist_min ) )
dist_min = dist;
}

if ( nextPart && dist_min > 0 )
return min( dist_min, nextPart->getDistanceToPoint( xp, yp ) );
return qMin( dist_min, nextPart->getDistanceToPoint( xp, yp ) );

return dist_min;
}
@@ -216,7 +216,6 @@ namespace pal

typedef struct
{
double scale;
Pal* pal;
PointSet *obstacle;
} PruneCtx;

0 comments on commit bf61219

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