Skip to content

Commit

Permalink
semi-automatic indentation update
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12177 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 18, 2009
1 parent 4a4d05a commit b9c6857
Show file tree
Hide file tree
Showing 61 changed files with 13,794 additions and 13,349 deletions.
94 changes: 47 additions & 47 deletions src/core/pal/costcalculator.cpp
Expand Up @@ -18,7 +18,7 @@
namespace pal
{

void CostCalculator::addObstacleCostPenalty(LabelPosition* lp, PointSet* feat)
void CostCalculator::addObstacleCostPenalty( LabelPosition* lp, PointSet* feat )
{
int n = 0;
double dist;
Expand Down Expand Up @@ -69,7 +69,7 @@ namespace pal
std::cout << "LabelPosition for feat: " << lPos[0]->feature->uid << std::endl;
#endif

for ( i = 0;i < nblp;i++ )
for ( i = 0; i < nblp; i++ )
setCandidateCostFromPolygon( lPos[i], obstacles, bbx, bby );

// lPos with big values came fisrts (value = min distance from label to Polygon's Perimeter)
Expand All @@ -94,7 +94,7 @@ namespace pal

// adjust cost => the best is 0.0001, the worst is 0.0021
// others are set proportionally between best and worst
for ( i = 0;i < max_p;i++ )
for ( i = 0; i < max_p; i++ )
{
#ifdef _DEBUG_
std::cout << " lpos[" << i << "] = " << lPos[i]->cost;
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace pal

delete extent;

lp->feature->getBoundingBox(amin, amax);
lp->feature->getBoundingBox( amin, amax );

obstacles->Search( amin, amax, LabelPosition::polygonObstacleCallback, pCost );

Expand All @@ -146,53 +146,53 @@ namespace pal
}


int CostCalculator::finalizeCandidatesCosts( Feats* feat, int max_p, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
{
// If candidates list is smaller than expected
if ( max_p > feat->nblp )
max_p = feat->nblp;
//
// sort candidates list, best label to worst
sort(( void** ) feat->lPos, feat->nblp, LabelPosition::costGrow );

// try to exclude all conflitual labels (good ones have cost < 1 by pruning)
double discrim = 0.0;
int stop;
do
{
discrim += 1.0;
for ( stop = 0;stop < feat->nblp && feat->lPos[stop]->getCost() < discrim;stop++ );
}
while ( stop == 0 && discrim < feat->lPos[feat->nblp-1]->getCost() + 2.0 );
int CostCalculator::finalizeCandidatesCosts( Feats* feat, int max_p, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
{
// If candidates list is smaller than expected
if ( max_p > feat->nblp )
max_p = feat->nblp;
//
// sort candidates list, best label to worst
sort(( void** ) feat->lPos, feat->nblp, LabelPosition::costGrow );

// try to exclude all conflitual labels (good ones have cost < 1 by pruning)
double discrim = 0.0;
int stop;
do
{
discrim += 1.0;
for ( stop = 0; stop < feat->nblp && feat->lPos[stop]->getCost() < discrim; stop++ );
}
while ( stop == 0 && discrim < feat->lPos[feat->nblp-1]->getCost() + 2.0 );

if ( discrim > 1.5 )
{
int k;
for ( k = 0;k < stop;k++ )
feat->lPos[k]->setCost( 0.0021 );
}
if ( discrim > 1.5 )
{
int k;
for ( k = 0; k < stop; k++ )
feat->lPos[k]->setCost( 0.0021 );
}

if ( max_p > stop )
max_p = stop;
if ( max_p > stop )
max_p = stop;

#ifdef _DEBUG_FULL_
std::cout << "Nblabel kept for feat " << feat->feature->uid << "/" << feat->feature->layer->name << ": " << max_p << "/" << feat->nblp << std::endl;
std::cout << "Nblabel kept for feat " << feat->feature->uid << "/" << feat->feature->layer->name << ": " << max_p << "/" << feat->nblp << std::endl;
#endif

// Sets costs for candidates of polygon
// Sets costs for candidates of polygon

if ( feat->feature->getGeosType() == GEOS_POLYGON )
{
int arrangement = feat->feature->getLayer()->getArrangement();
if ( arrangement == P_FREE || arrangement == P_HORIZ )
setPolygonCandidatesCost( stop, (LabelPosition**) feat->lPos, max_p, obstacles, bbx, bby );
}
if ( feat->feature->getGeosType() == GEOS_POLYGON )
{
int arrangement = feat->feature->getLayer()->getArrangement();
if ( arrangement == P_FREE || arrangement == P_HORIZ )
setPolygonCandidatesCost( stop, ( LabelPosition** ) feat->lPos, max_p, obstacles, bbx, bby );
}

// add size penalty (small lines/polygons get higher cost)
feat->feature->addSizePenalty(max_p, feat->lPos, bbx, bby);
// add size penalty (small lines/polygons get higher cost)
feat->feature->addSizePenalty( max_p, feat->lPos, bbx, bby );

return max_p;
}
return max_p;
}



Expand All @@ -216,7 +216,7 @@ namespace pal
*/

double alpha = lp->getAlpha();
for ( i = 0;i < 8;i++, alpha += M_PI / 4 )
for ( i = 0; i < 8; i++, alpha += M_PI / 4 )
{
dist[i] = DBL_MAX;
ok[i] = false;
Expand Down Expand Up @@ -256,7 +256,7 @@ namespace pal

int i = ( int )( beta / a45 );

for ( int j = 0;j < 2;j++, i = ( i + 1 ) % 8 )
for ( int j = 0; j < 2; j++, i = ( i + 1 ) % 8 )
{
double rx, ry;
rx = px - rpy[i] + py;
Expand Down Expand Up @@ -284,11 +284,11 @@ namespace pal
int nbP = ( pset->type == GEOS_POLYGON ? pset->nbPoints : pset->nbPoints - 1 );
double min_dist = DBL_MAX;

for ( i = 0;i < nbP;i++ )
for ( i = 0; i < nbP; i++ )
{
j = ( i + 1 ) % pset->nbPoints;

for ( k = 0;k < 8;k++ )
for ( k = 0; k < 8; k++ )
{
double ix, iy;
if ( computeSegIntersection( px, py, rpx[k], rpy[k], pset->x[i], pset->y[i], pset->x[j], pset->y[j], &ix, &iy ) )
Expand Down Expand Up @@ -318,7 +318,7 @@ namespace pal
{
int i;

for ( i = 0;i < 8;i++ )
for ( i = 0; i < 8; i++ )
{
/*
if ( i == 0 || i == 4 ) // horizontal directions
Expand Down
16 changes: 8 additions & 8 deletions src/core/pal/costcalculator.h
Expand Up @@ -9,17 +9,17 @@ namespace pal

class CostCalculator
{
public:
/** increase candidate's cost according to its collision with passed feature */
static void addObstacleCostPenalty(LabelPosition* lp, PointSet* feat);
public:
/** increase candidate's cost according to its collision with passed feature */
static void addObstacleCostPenalty( LabelPosition* lp, PointSet* feat );

static void setPolygonCandidatesCost( int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
static void setPolygonCandidatesCost( int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );

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

/** sort candidates by costs, skip the worse ones, evaluate polygon candidates */
static int finalizeCandidatesCosts( Feats* feat, int max_p, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
/** sort candidates by costs, skip the worse ones, evaluate polygon candidates */
static int finalizeCandidatesCosts( Feats* feat, int max_p, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
};

/**
Expand Down
44 changes: 22 additions & 22 deletions src/core/pal/feature.cpp
Expand Up @@ -84,7 +84,7 @@ namespace pal
extractCoords( geom );

holeOf = NULL;
for ( int i = 0;i < nbHoles;i++ )
for ( int i = 0; i < nbHoles; i++ )
{
holes[i]->holeOf = this;
}
Expand All @@ -97,7 +97,7 @@ namespace pal

if ( holes )
{
for ( int i = 0; i < nbHoles;i++ )
for ( int i = 0; i < nbHoles; i++ )
delete holes[i];
delete [] holes;
holes = NULL;
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace pal
nbHoles = GEOSGetNumInteriorRings( geom );
holes = new PointSet*[nbHoles];

for ( i = 0;i < nbHoles;i++ )
for ( i = 0; i < nbHoles; i++ )
{
holes[i] = new PointSet();
holes[i]->holeOf = NULL;
Expand All @@ -145,7 +145,7 @@ namespace pal

coordSeq = GEOSGeom_getCoordSeq( interior );

for ( j = 0;j < holes[i]->nbPoints;j++ )
for ( j = 0; j < holes[i]->nbPoints; j++ )
{
GEOSCoordSeq_getX( coordSeq, j, &holes[i]->x[j] );
GEOSCoordSeq_getY( coordSeq, j, &holes[i]->y[j] );
Expand Down Expand Up @@ -182,7 +182,7 @@ namespace pal
x = new double[nbPoints];
y = new double[nbPoints];

for ( i = 0;i < nbPoints;i++ )
for ( i = 0; i < nbPoints; i++ )
{
GEOSCoordSeq_getX( coordSeq, i, &x[i] );
GEOSCoordSeq_getY( coordSeq, i, &y[i] );
Expand All @@ -202,7 +202,7 @@ namespace pal
bool *ok = new bool[new_nbPoints];
int i, j;

for ( i = 0;i < nbPoints;i++ )
for ( i = 0; i < nbPoints; i++ )
{
ok[i] = true;
j = ( i + 1 ) % nbPoints;
Expand All @@ -219,7 +219,7 @@ namespace pal
{
double *new_x = new double[new_nbPoints];
double *new_y = new double[new_nbPoints];
for ( i = 0, j = 0;i < nbPoints;i++ )
for ( i = 0, j = 0; i < nbPoints; i++ )
{
if ( ok[i] )
{
Expand Down Expand Up @@ -359,7 +359,7 @@ namespace pal

*lPos = new LabelPosition *[nbp];

for ( i = 0, alpha = M_PI / 4;i < nbp;i++, alpha += beta )
for ( i = 0, alpha = M_PI / 4; i < nbp; i++, alpha += beta )
{
lx = x;
ly = y;
Expand Down Expand Up @@ -508,7 +508,7 @@ namespace pal
ad = new double[nbPoints];

ll = 0.0; // line length
for ( i = 0;i < line->nbPoints - 1;i++ )
for ( i = 0; i < line->nbPoints - 1; i++ )
{
if ( i == 0 )
ad[i] = 0;
Expand Down Expand Up @@ -601,7 +601,7 @@ namespace pal
if (( !reversed && ( flags & FLAG_ABOVE_LINE ) ) || ( reversed && ( flags & FLAG_BELOW_LINE ) ) )
positions->push_back( new LabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // Line
if (( !reversed && ( flags & FLAG_BELOW_LINE ) ) || ( reversed && ( flags & FLAG_ABOVE_LINE ) ) )
positions->push_back( new LabelPosition( i, bx - cos( beta ) * ( distlabel + yrm ) , by - sin( beta ) * ( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
positions->push_back( new LabelPosition( i, bx - cos( beta ) *( distlabel + yrm ) , by - sin( beta ) *( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
if ( flags & FLAG_ON_LINE )
positions->push_back( new LabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
}
Expand Down Expand Up @@ -1041,11 +1041,11 @@ namespace pal
int max_try = 10;
do
{
for ( bbid = 0;bbid < j;bbid++ )
for ( bbid = 0; bbid < j; bbid++ )
{
CHullBox *box = boxes[bbid];

if (( box->length * box->width ) > ( xmax - xmin ) * ( ymax - ymin ) *5 )
if (( box->length * box->width ) > ( xmax - xmin ) *( ymax - ymin ) *5 )
{
std::cout << "Very Large BBOX (should never occurs : bug-report please)" << std::endl;
std::cout << " Box size: " << box->length << "/" << box->width << std::endl;
Expand All @@ -1058,7 +1058,7 @@ namespace pal

#ifdef _DEBUG_FULL_
std::cout << "New BBox : " << bbid << std::endl;
for ( i = 0;i < 4;i++ )
for ( i = 0; i < 4; i++ )
{
std::cout << box->x[i] << "\t" << box->y[i] << std::endl;
}
Expand Down Expand Up @@ -1136,9 +1136,9 @@ namespace pal
px0 -= ceil( px0 / dx ) * dx;
py0 -= ceil( py0 / dy ) * dy;

for ( px = px0;px <= box->width;px += dx )
for ( px = px0; px <= box->width; px += dx )
{
for ( py = py0;py <= box->length;py += dy )
for ( py = py0; py <= box->length; py += dy )
{

rx = cos( box->alpha ) * px + cos( box->alpha - M_PI / 2 ) * py;
Expand Down Expand Up @@ -1170,12 +1170,12 @@ namespace pal
nbp = positions->size();

( *lPos ) = new LabelPosition*[nbp];
for ( i = 0;i < nbp;i++ )
for ( i = 0; i < nbp; i++ )
{
( *lPos )[i] = positions->pop_front();
}

for ( bbid = 0;bbid < j;bbid++ )
for ( bbid = 0; bbid < j; bbid++ )
{
delete boxes[bbid];
}
Expand Down Expand Up @@ -1203,13 +1203,13 @@ namespace pal
std::cout << "Type: " << type << std::endl;
if ( x && y )
{
for ( i = 0;i < nbPoints;i++ )
for ( i = 0; i < nbPoints; i++ )
std::cout << x[i] << ", " << y[i] << std::endl;
std::cout << "Obstacle: " << nbHoles << std::endl;
for ( i = 0;i < nbHoles;i++ )
for ( i = 0; i < nbHoles; i++ )
{
std::cout << " obs " << i << std::endl;
for ( j = 0;j < holes[i]->nbPoints;j++ )
for ( j = 0; j < holes[i]->nbPoints; j++ )
{
std::cout << holes[i]->x[j] << ";" << holes[i]->y[j] << std::endl;
}
Expand Down Expand Up @@ -1281,7 +1281,7 @@ namespace pal
int rnbp = nbp;

// purge candidates that are outside the bbox
for ( i = 0;i < nbp;i++ )
for ( i = 0; i < nbp; i++ )
{
if ( !( *lPos )[i]->isIn( bbox ) )
{
Expand All @@ -1296,7 +1296,7 @@ namespace pal

sort(( void** )( *lPos ), nbp, LabelPosition::costGrow );

for ( i = rnbp;i < nbp;i++ )
for ( i = rnbp; i < nbp; i++ )
{
delete( *lPos )[i];
}
Expand Down

0 comments on commit b9c6857

Please sign in to comment.