Skip to content
Permalink
Browse files

Got rid of StraightLabelPosition class in favour of using only LabelP…

…osition class.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11177 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 25, 2009
1 parent 5a4ef13 commit 3ddaa119f462d1603ab146919f01f4a42fb81248
@@ -60,7 +60,7 @@ namespace pal

////////

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

@@ -118,7 +118,7 @@ namespace pal
}


void CostCalculator::setCandidateCostFromPolygon( StraightLabelPosition* lp, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
void CostCalculator::setCandidateCostFromPolygon( LabelPosition* lp, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
{

double amin[2];
@@ -188,7 +188,7 @@ namespace pal
{
int arrangement = feat->feature->getLayer()->getArrangement();
if ( arrangement == P_FREE || arrangement == P_HORIZ )
setPolygonCandidatesCost( stop, (StraightLabelPosition**) feat->lPos, max_p, obstacles, bbx, bby );
setPolygonCandidatesCost( stop, (LabelPosition**) feat->lPos, max_p, obstacles, bbx, bby );
}

return max_p;
@@ -198,7 +198,7 @@ namespace pal

//////////

PolygonCostCalculator::PolygonCostCalculator( StraightLabelPosition *lp ) : lp( lp )
PolygonCostCalculator::PolygonCostCalculator( LabelPosition *lp ) : lp( lp )
{
int i;
double hyp = max( lp->feature->xmax - lp->feature->xmin, lp->feature->ymax - lp->feature->ymin );
@@ -6,18 +6,17 @@
namespace pal
{
class Feats;
class StraightLabelPosition;

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

static void setPolygonCandidatesCost( int nblp, StraightLabelPosition **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( StraightLabelPosition* lp, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
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] );
@@ -32,7 +31,7 @@ namespace pal
*/
class PolygonCostCalculator
{
StraightLabelPosition *lp;
LabelPosition *lp;
double px, py;
double dist[8];
double rpx[8];
@@ -42,7 +41,7 @@ namespace pal
void updatePoint( PointSet *pset );
double updateLinePoly( PointSet *pset );
public:
PolygonCostCalculator( StraightLabelPosition *lp );
PolygonCostCalculator( LabelPosition *lp );

void update( PointSet *pset );

@@ -166,11 +166,11 @@ namespace pal
double offset = label_x / 4;

// at the center
( *lPos )[0] = new StraightLabelPosition( id, lx, ly, label_x, label_y, alpha, cost, this );
( *lPos )[0] = new LabelPosition( id, lx, ly, label_x, label_y, alpha, cost, this );
// shifted to the sides - with higher cost
cost = 0.0021;
( *lPos )[1] = new StraightLabelPosition( id, lx+offset, ly, label_x, label_y, alpha, cost, this );
( *lPos )[2] = new StraightLabelPosition( id, lx-offset, ly, label_x, label_y, alpha, cost, this );
( *lPos )[1] = new LabelPosition( id, lx+offset, ly, label_x, label_y, alpha, cost, this );
( *lPos )[2] = new LabelPosition( id, lx-offset, ly, label_x, label_y, alpha, cost, this );
return nbp;
}

@@ -317,7 +317,7 @@ namespace pal
else
cost = 0.0001 + 0.0020 * double( icost ) / double( nbp - 1 );

( *lPos )[i] = new StraightLabelPosition( i, lx, ly, xrm, yrm, 0, cost, this );
( *lPos )[i] = new LabelPosition( i, lx, ly, xrm, yrm, 0, cost, this );

icost += inc;

@@ -489,15 +489,15 @@ namespace pal
reversed = ( alpha >= M_PI/2 || alpha < -M_PI/2 );

if ( (!reversed && (flags & FLAG_ABOVE_LINE)) || (reversed && (flags & FLAG_BELOW_LINE)) )
positions->push_back( new StraightLabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // 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 StraightLabelPosition( 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 StraightLabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
positions->push_back( new LabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
}
else if (layer->arrangement == P_HORIZ)
{
positions->push_back( new StraightLabelPosition(i, bx - xrm/2, by - yrm/2, xrm, yrm, 0, cost, this) ); // Line
positions->push_back( new LabelPosition(i, bx - xrm/2, by - yrm/2, xrm, yrm, 0, cost, this) ); // Line
//positions->push_back( new LabelPosition(i, bx -yrm/2, by - yrm*sin(beta)/2, xrm, yrm, alpha, cost, this, line)); // Line
}
else
@@ -533,7 +533,7 @@ namespace pal
}


StraightLabelPosition* Feature::curvedPlacementAtOffset( PointSet* path_positions, double* path_distances, int orientation, int index, double distance )
LabelPosition* Feature::curvedPlacementAtOffset( PointSet* path_positions, double* path_distances, int orientation, int index, double distance )
{
// Check that the given distance is on the given index and find the correct index and distance if not
while (distance < 0 && index > 1)
@@ -582,8 +582,8 @@ namespace pal
return NULL;
}

StraightLabelPosition* slp = NULL;
StraightLabelPosition* slp_tmp = NULL;
LabelPosition* slp = NULL;
LabelPosition* slp_tmp = NULL;
// current_placement = placement_result()
double xBase = old_x + dx*distance/segment_length;
double yBase = old_y + dy*distance/segment_length;
@@ -690,7 +690,7 @@ namespace pal
}

std::cerr << "adding part: " << render_x << " " << render_y << std::endl;
StraightLabelPosition* tmp = new StraightLabelPosition(0, render_x /*- xBase*/, render_y /*- yBase*/, ci.width, string_height, -render_angle, 0.0001, this);
LabelPosition* tmp = new LabelPosition(0, render_x /*- xBase*/, render_y /*- yBase*/, ci.width, string_height, -render_angle, 0.0001, this);
tmp->setPartId( orientation > 0 ? i : labelInfo->char_num-i-1 );
if (slp == NULL)
slp = tmp;
@@ -752,7 +752,7 @@ namespace pal
// TODO: generate more labels

// generate curved label
StraightLabelPosition* slp = curvedPlacementAtOffset(mapShape, path_distances, 0, 1, 0.0);
LabelPosition* slp = curvedPlacementAtOffset(mapShape, path_distances, 0, 1, 0.0);

if (!slp)
return 0;
@@ -972,7 +972,7 @@ namespace pal
if ( isPointInPolygon( mapShape->nbPoints, mapShape->x, mapShape->y, rx, ry ) )
{
// cost is set to minimal value, evaluated later
positions->push_back( new StraightLabelPosition( id++, rx - dlx, ry - dly , xrm, yrm, alpha, 0.0001, this ) ); // Polygon
positions->push_back( new LabelPosition( id++, rx - dlx, ry - dly , xrm, yrm, alpha, 0.0001, this ) ); // Polygon
}
}
}
@@ -73,7 +73,7 @@ namespace pal
CharacterInfo* char_info;
};

class StraightLabelPosition;
class LabelPosition;

/**
* \brief Main class to handle feature
@@ -132,7 +132,7 @@ namespace pal
*/
int setPositionForLine( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );

StraightLabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
LabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
int orientation, int index, double distance );

/**
@@ -55,13 +55,8 @@

namespace pal
{
LabelPosition::LabelPosition( int id, double cost, Feature *feature )
: id( id ), cost( cost ), feature( feature ), nbOverlap( 0 )
{
}

StraightLabelPosition::StraightLabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, Feature *feature )
: LabelPosition( id, cost, feature ), alpha( alpha ), w( w ), h( h ), nextPart(NULL), partId(-1)
LabelPosition::LabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, Feature *feature )
: id( id ), cost( cost ), feature( feature ), nbOverlap( 0 ), alpha( alpha ), w( w ), h( h ), nextPart(NULL), partId(-1)
{

// alpha take his value bw 0 and 2*pi rad
@@ -123,7 +118,7 @@ namespace pal
}
}

bool StraightLabelPosition::isIn( double *bbox )
bool LabelPosition::isIn( double *bbox )
{
int i;

@@ -141,7 +136,7 @@ namespace pal

}

void StraightLabelPosition::print()
void LabelPosition::print()
{
std::cout << feature->getLayer()->getName() << "/" << feature->getUID() << "/" << id;
std::cout << " cost: " << cost;
@@ -153,15 +148,12 @@ namespace pal
std::cout << std::endl;
}

bool StraightLabelPosition::isInConflict( LabelPosition *lp )
bool LabelPosition::isInConflict( LabelPosition *lp )
{
// TODO: more types of labelposition
StraightLabelPosition* ls = (StraightLabelPosition*) lp;

int i, i2, j;
int d1, d2;

if ( this->probFeat == ls->probFeat ) // bugfix #1
if ( this->probFeat == lp->probFeat ) // bugfix #1
return false; // always overlaping itself !

double cp1, cp2;
@@ -176,14 +168,14 @@ namespace pal
//std::cout << "new seg..." << std::endl;
for ( j = 0;j < 4;j++ )
{
cp1 = cross_product( x[i], y[i], x[i2], y[i2], ls->x[j], ls->y[j] );
cp1 = cross_product( x[i], y[i], x[i2], y[i2], lp->x[j], lp->y[j] );
if ( cp1 > 0 )
{
d1 = 1;
//std::cout << " cp1: " << cp1 << std::endl;
}
cp2 = cross_product( ls->x[i], ls->y[i],
ls->x[i2], ls->y[i2],
cp2 = cross_product( lp->x[i], lp->y[i],
lp->x[i2], lp->y[i2],
x[j], y[j] );

if ( cp2 > 0 )
@@ -195,9 +187,9 @@ namespace pal

if ( d1 == -1 || d2 == -1 ) // disjoint
{
if ( ls->getNextPart() )
if ( lp->getNextPart() )
{
if ( isInConflict(ls->getNextPart()) )
if ( isInConflict(lp->getNextPart()) )
return true;
}

@@ -215,17 +207,17 @@ namespace pal
return id;
}

double StraightLabelPosition::getX( int i ) const
double LabelPosition::getX( int i ) const
{
return (i >= 0 && i < 4 ? x[i] : -1);
}

double StraightLabelPosition::getY( int i ) const
double LabelPosition::getY( int i ) const
{
return (i >= 0 && i < 4 ? y[i] : -1);
}

double StraightLabelPosition::getAlpha() const
double LabelPosition::getAlpha() const
{
return alpha;
}
@@ -249,7 +241,7 @@ namespace pal
return feature;
}

void StraightLabelPosition::getBoundingBox(double amin[2], double amax[2]) const
void LabelPosition::getBoundingBox(double amin[2], double amax[2]) const
{
if (nextPart)
{
@@ -410,7 +402,7 @@ namespace pal



double StraightLabelPosition::getDistanceToPoint( double xp, double yp )
double LabelPosition::getDistanceToPoint( double xp, double yp )
{
int i;
int j;
@@ -464,7 +456,7 @@ namespace pal
}


bool StraightLabelPosition::isBorderCrossingLine( PointSet* feat )
bool LabelPosition::isBorderCrossingLine( PointSet* feat )
{
double ca, cb;
for ( int i = 0;i < 4;i++ )
@@ -494,7 +486,7 @@ namespace pal
return false;
}

int StraightLabelPosition::getNumPointsInPolygon( int npol, double *xp, double *yp )
int LabelPosition::getNumPointsInPolygon( int npol, double *xp, double *yp )
{
int a, k, count = 0;
double px, py;

0 comments on commit 3ddaa11

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