Skip to content
Permalink
Browse files

First round of refactoring:

Made pal::Feature and pal::LabelPosition less friendly: prefer access to internal variables through access functions.
Removed some dead functions, moved some functions, less code duplication.
Shouldn't affect functionality in any way.


git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11044 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 11, 2009
1 parent 97ac08c commit 5cfe4877fcc39ed585df5e14f28c4d8d80d0854c
@@ -869,7 +869,7 @@ namespace pal
}
}

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

for ( i = rnbp;i < nbp;i++ )
{
@@ -944,10 +944,7 @@ namespace pal
y = NULL;
for ( i = 0;i < nbSelfObs;i++ )
{
delete[] selfObs[i]->x;
delete[] selfObs[i]->y;
selfObs[i]->x = NULL;
selfObs[i]->y = NULL;
selfObs[i]->deleteCoords();
}
}
}
@@ -60,19 +60,6 @@ namespace pal
class Feature : public PointSet
{

friend class Pal;
friend class Layer;
friend class Problem;
friend class LabelPosition;

friend bool extractFeatCallback( Feature *ft_ptr, void *ctx );
friend bool pruneLabelPositionCallback( LabelPosition *lp, void *ctx );
friend bool obstacleCallback( PointSet *feat, void *ctx );
//friend void setCost (int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4]);
friend void releaseAllInIndex( RTree<PointSet*, double, 2, double, 8, 4>* );
friend bool releaseCallback( PointSet *pset, void *ctx );
friend bool filteringCallback( PointSet*, void* );

protected:
//int id; /* feature no id into layer */
double label_x;
@@ -96,6 +83,7 @@ namespace pal

SimpleMutex *accessMutex;

public:
/**
* \brief generate candidates for point feature
* Generate candidates for point features
@@ -244,6 +232,23 @@ namespace pal

void fetchCoordinates();
void releaseCoordinates();



PalGeometry* getUserGeometry() { return userGeom; }

void setLabelSize(double x, double y) { label_x = x; label_y = y; }
double getLabelWidth() const { return label_x; }
double getLabelHeight() const { return label_y; }

int getNumParts() const { return nPart; }

void setLabelDistance(double dist) { distlabel = dist; }
double getLabelDistance() const { return distlabel; }

int getNumSelfObstacles() const { return nbSelfObs; }
PointSet* getSelfObstacle(int i) { return selfObs[i]; }

};

} // end namespace pal
@@ -213,37 +213,50 @@ namespace pal
return cost;
}

Feature * LabelPosition::getFeature()
{
return feature;
}

bool xGrow( void *l, void *r )
void LabelPosition::validateCost()
{
return (( LabelPosition* ) l )->x[0] > (( LabelPosition* ) r )->x[0];
if ( cost >= 1 )
{
std::cout << " Warning: lp->cost == " << cost << " (from feat: " << feature->getUID() << "/" << getLayerName() << ")" << std::endl;
cost -= int ( cost ); // label cost up to 1
}
}

bool yGrow( void *l, void *r )
Feature * LabelPosition::getFeature()
{
return (( LabelPosition* ) l )->y[0] > (( LabelPosition* ) r )->y[0];
return feature;
}

bool xShrink( void *l, void *r )
void LabelPosition::getBoundingBox(double amin[2], double amax[2]) const
{
return (( LabelPosition* ) l )->x[0] < (( LabelPosition* ) r )->x[0];
amin[0] = DBL_MAX;
amax[0] = -DBL_MAX;
amin[1] = DBL_MAX;
amax[1] = -DBL_MAX;
for ( int c = 0;c < 4;c++ )
{
if ( x[c] < amin[0] )
amin[0] = x[c];
if ( x[c] > amax[0] )
amax[0] = x[c];
if ( y[c] < amin[1] )
amin[1] = y[c];
if ( y[c] > amax[1] )
amax[1] = y[c];
}
}

bool yShrink( void *l, void *r )
char* LabelPosition::getLayerName() const
{
return (( LabelPosition* ) l )->y[0] < (( LabelPosition* ) r )->y[0];
return feature->getLayer()->name;
}

bool costShrink( void *l, void *r )
bool LabelPosition::costShrink( void *l, void *r )
{
return (( LabelPosition* ) l )->cost < (( LabelPosition* ) r )->cost;
}

bool costGrow( void *l, void *r )
bool LabelPosition::costGrow( void *l, void *r )
{
return (( LabelPosition* ) l )->cost > (( LabelPosition* ) r )->cost;
}
@@ -269,31 +282,31 @@ namespace pal
//#warning retourner les coord projeté ou pas ?
//feature->layer->pal->proj->getLatLong(this->x[0], this->y[0], &x, &y);

return new Label( this->x, this->y, alpha, feature->uid, feature->layer->name, feature->userGeom );
return new Label( this->x, this->y, alpha, feature->getUID(), feature->getLayer()->getName(), feature->getUserGeometry() );
}


bool obstacleCallback( PointSet *feat, void *ctx )
bool LabelPosition::obstacleCallback( PointSet *feat, void *ctx )
{
LabelPosition::PolygonCostCalculator *pCost = ( LabelPosition::PolygonCostCalculator* ) ctx;

LabelPosition *lp = pCost->getLabel();
if (( feat == lp->feature ) || ( feat->holeOf && feat->holeOf != lp->feature ) )
if (( feat == lp->feature ) || ( feat->getHoleOf() && feat->getHoleOf() != lp->feature ) )
{
return true;
}

// if the feature is not a hole we have to fetch corrdinates
// otherwise holes coordinates are still in memory (feature->selfObs)
if ( feat->holeOf == NULL )
if ( feat->getHoleOf() == NULL )
{
(( Feature* ) feat )->fetchCoordinates();
}

pCost->update( feat );


if ( feat->holeOf == NULL )
if ( feat->getHoleOf() == NULL )
{
(( Feature* ) feat )->releaseCoordinates();
}
@@ -332,10 +345,7 @@ namespace pal
amax[0] = amin[0] + 2 * dist;
amax[1] = amin[1] + 2 * dist;
} else {*/
amin[0] = feature->xmin;
amin[1] = feature->ymin;
amax[0] = feature->xmax;
amax[1] = feature->ymax;
feature->getBoundingBox(amin, amax);
//}

//std::cout << amin[0] << " " << amin[1] << " " << amax[0] << " " << amax[1] << std::endl;
@@ -351,24 +361,7 @@ namespace pal
{
double amin[2];
double amax[2];
int c;

amin[0] = DBL_MAX;
amax[0] = -DBL_MAX;
amin[1] = DBL_MAX;
amax[1] = -DBL_MAX;
for ( c = 0;c < 4;c++ )
{
if ( x[c] < amin[0] )
amin[0] = x[c];
if ( x[c] > amax[0] )
amax[0] = x[c];
if ( y[c] < amin[1] )
amin[1] = y[c];
if ( y[c] > amax[1] )
amax[1] = y[c];
}

getBoundingBox(amin, amax);
index->Remove( amin, amax, this );
}

@@ -377,24 +370,7 @@ namespace pal
{
double amin[2];
double amax[2];
int c;

amin[0] = DBL_MAX;
amax[0] = -DBL_MAX;
amin[1] = DBL_MAX;
amax[1] = -DBL_MAX;
for ( c = 0;c < 4;c++ )
{
if ( x[c] < amin[0] )
amin[0] = x[c];
if ( x[c] > amax[0] )
amax[0] = x[c];
if ( y[c] < amin[1] )
amin[1] = y[c];
if ( y[c] > amax[1] )
amax[1] = y[c];
}

getBoundingBox(amin, amax);
index->Insert( amin, amax, this );
}

@@ -603,5 +579,56 @@ namespace pal
//return (a+b+c+d);
return ( a*b*c*d );
}

//////////

bool LabelPosition::countOverlapCallback( LabelPosition *lp, void *ctx )
{
LabelPosition *lp2 = ( LabelPosition* ) ctx;

if ( lp2->isInConflict( lp ) )
{
lp2->nbOverlap++;
}

return true;
}

bool LabelPosition::countFullOverlapCallback( LabelPosition *lp, void *ctx )
{
LabelPosition *lp2 = (( CountContext* ) ctx )->lp;
double *cost = (( CountContext* ) ctx )->cost;
//int *feat = ((CountContext*)ctx)->feat;
int *nbOv = (( CountContext* ) ctx )->nbOv;
double *inactiveCost = (( CountContext* ) ctx )->inactiveCost;
if ( lp2->isInConflict( lp ) )
{
#ifdef _DEBUG_FULL_
std::cout << "count overlap : " << lp->id << "<->" << lp2->id << std::endl;
#endif
( *nbOv ) ++;
*cost += inactiveCost[lp->probFeat] + lp->getCost();

}

return true;
}


bool LabelPosition::removeOverlapCallback( LabelPosition *lp, void *ctx )
{
LabelPosition *lp2 = ( LabelPosition * ) ctx;

if ( lp2->isInConflict( lp ) )
{
//std::cout << " hit !" << std::endl;
lp->nbOverlap--;
lp2->nbOverlap--;
}

return true;
}


} // end namespace

0 comments on commit 5cfe487

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