Skip to content

Commit 4786e54

Browse files
author
wonder
committed
pal: created StraightLabelPosition derived from LabelPosition.
Return LabelPosition array instead of Label array. git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11126 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent dc046b5 commit 4786e54

File tree

12 files changed

+160
-125
lines changed

12 files changed

+160
-125
lines changed

src/core/pal/costcalculator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace pal
6060

6161
////////
6262

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

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

120120

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

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

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

199199
//////////
200200

201-
PolygonCostCalculator::PolygonCostCalculator( LabelPosition *lp ) : lp( lp )
201+
PolygonCostCalculator::PolygonCostCalculator( StraightLabelPosition *lp ) : lp( lp )
202202
{
203203
int i;
204204
double hyp = max( lp->feature->xmax - lp->feature->xmin, lp->feature->ymax - lp->feature->ymin );

src/core/pal/costcalculator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
namespace pal
77
{
88
class Feats;
9+
class StraightLabelPosition;
910

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

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

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

2122
/** sort candidates by costs, skip the worse ones, evaluate polygon candidates */
2223
static int finalizeCandidatesCosts( Feats* feat, int max_p, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
@@ -31,7 +32,7 @@ namespace pal
3132
*/
3233
class PolygonCostCalculator
3334
{
34-
LabelPosition *lp;
35+
StraightLabelPosition *lp;
3536
double px, py;
3637
double dist[8];
3738
double rpx[8];
@@ -41,7 +42,7 @@ namespace pal
4142
void updatePoint( PointSet *pset );
4243
double updateLinePoly( PointSet *pset );
4344
public:
44-
PolygonCostCalculator( LabelPosition *lp );
45+
PolygonCostCalculator( StraightLabelPosition *lp );
4546

4647
void update( PointSet *pset );
4748

src/core/pal/feature.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ namespace pal
165165
double offset = label_x / 4;
166166

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

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

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

321321
icost += inc;
322322

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

490490
if ( (!reversed && (flags & FLAG_ABOVE_LINE)) || (reversed && (flags & FLAG_BELOW_LINE)) )
491-
positions->push_back( new LabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // Line
491+
positions->push_back( new StraightLabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // Line
492492
if ( (!reversed && (flags & FLAG_BELOW_LINE)) || (reversed && (flags & FLAG_ABOVE_LINE)) )
493-
positions->push_back( new LabelPosition( i, bx - cos( beta ) * ( distlabel + yrm ) , by - sin( beta ) * ( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
493+
positions->push_back( new StraightLabelPosition( i, bx - cos( beta ) * ( distlabel + yrm ) , by - sin( beta ) * ( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
494494
if ( flags & FLAG_ON_LINE )
495-
positions->push_back( new LabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
495+
positions->push_back( new StraightLabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
496496
}
497497
else if (layer->arrangement == P_HORIZ)
498498
{
499-
positions->push_back( new LabelPosition(i, bx - xrm/2, by - yrm/2, xrm, yrm, 0, cost, this) ); // Line
499+
positions->push_back( new StraightLabelPosition(i, bx - xrm/2, by - yrm/2, xrm, yrm, 0, cost, this) ); // Line
500500
//positions->push_back( new LabelPosition(i, bx -yrm/2, by - yrm*sin(beta)/2, xrm, yrm, alpha, cost, this, line)); // Line
501501
}
502502
else
@@ -735,7 +735,7 @@ namespace pal
735735
if ( isPointInPolygon( mapShape->nbPoints, mapShape->x, mapShape->y, rx, ry ) )
736736
{
737737
// cost is set to minimal value, evaluated later
738-
positions->push_back( new LabelPosition( id++, rx - dlx, ry - dly , xrm, yrm, alpha, 0.0001, this ) ); // Polygon
738+
positions->push_back( new StraightLabelPosition( id++, rx - dlx, ry - dly , xrm, yrm, alpha, 0.0001, this ) ); // Polygon
739739
}
740740
}
741741
}

src/core/pal/labelposition.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@
5555

5656
namespace pal
5757
{
58-
59-
LabelPosition::LabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, Feature *feature ) : id( id ), cost( cost ), /*workingCost (0),*/ alpha( alpha ), feature( feature ), nbOverlap( 0 ), w( w ), h( h )
58+
LabelPosition::LabelPosition( int id, double cost, Feature *feature )
59+
: id( id ), cost( cost ), feature( feature ), nbOverlap( 0 )
6060
{
61+
}
6162

63+
StraightLabelPosition::StraightLabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, Feature *feature )
64+
: LabelPosition( id, cost, feature ), alpha( alpha ), w( w ), h( h )
65+
{
6266

6367
// alpha take his value bw 0 and 2*pi rad
6468
while ( this->alpha > 2*M_PI )
@@ -119,7 +123,7 @@ namespace pal
119123
}
120124
}
121125

122-
bool LabelPosition::isIn( double *bbox )
126+
bool StraightLabelPosition::isIn( double *bbox )
123127
{
124128
int i;
125129

@@ -134,7 +138,7 @@ namespace pal
134138

135139
}
136140

137-
void LabelPosition::print()
141+
void StraightLabelPosition::print()
138142
{
139143
std::cout << feature->getLayer()->getName() << "/" << feature->getUID() << "/" << id;
140144
std::cout << " cost: " << cost;
@@ -146,8 +150,11 @@ namespace pal
146150
std::cout << std::endl;
147151
}
148152

149-
bool LabelPosition::isInConflict( LabelPosition *ls )
153+
bool StraightLabelPosition::isInConflict( LabelPosition *lp )
150154
{
155+
// TODO: more types of labelposition
156+
StraightLabelPosition* ls = (StraightLabelPosition*) lp;
157+
151158
int i, i2, j;
152159
int d1, d2;
153160

@@ -194,17 +201,17 @@ namespace pal
194201
return id;
195202
}
196203

197-
double LabelPosition::getX() const
204+
double StraightLabelPosition::getX( int i ) const
198205
{
199-
return x[0];
206+
return (i >= 0 && i < 4 ? x[i] : -1);
200207
}
201208

202-
double LabelPosition::getY() const
209+
double StraightLabelPosition::getY( int i ) const
203210
{
204-
return y[0];
211+
return (i >= 0 && i < 4 ? y[i] : -1);
205212
}
206213

207-
double LabelPosition::getAlpha() const
214+
double StraightLabelPosition::getAlpha() const
208215
{
209216
return alpha;
210217
}
@@ -228,7 +235,7 @@ namespace pal
228235
return feature;
229236
}
230237

231-
void LabelPosition::getBoundingBox(double amin[2], double amax[2]) const
238+
void StraightLabelPosition::getBoundingBox(double amin[2], double amax[2]) const
232239
{
233240
amin[0] = DBL_MAX;
234241
amax[0] = -DBL_MAX;
@@ -263,12 +270,6 @@ namespace pal
263270
}
264271

265272

266-
Label *LabelPosition::toLabel( bool active )
267-
{
268-
return new Label( this->x, this->y, alpha, feature->getUID(), feature->getLayer()->getName(), feature->getUserGeometry() );
269-
}
270-
271-
272273
bool LabelPosition::polygonObstacleCallback( PointSet *feat, void *ctx )
273274
{
274275
PolygonCostCalculator *pCost = ( PolygonCostCalculator* ) ctx;
@@ -385,7 +386,7 @@ namespace pal
385386

386387

387388

388-
double LabelPosition::getDistanceToPoint( double xp, double yp )
389+
double StraightLabelPosition::getDistanceToPoint( double xp, double yp )
389390
{
390391
int i;
391392
int j;
@@ -436,7 +437,7 @@ namespace pal
436437
}
437438

438439

439-
bool LabelPosition::isBorderCrossingLine( PointSet* feat )
440+
bool StraightLabelPosition::isBorderCrossingLine( PointSet* feat )
440441
{
441442
double ca, cb;
442443
for ( int i = 0;i < 4;i++ )
@@ -462,7 +463,7 @@ namespace pal
462463
return false;
463464
}
464465

465-
int LabelPosition::getNumPointsInPolygon( int npol, double *xp, double *yp )
466+
int StraightLabelPosition::getNumPointsInPolygon( int npol, double *xp, double *yp )
466467
{
467468
int a, k, count = 0;
468469
double px, py;

0 commit comments

Comments
 (0)