51 else if ( dist < distlabel )
100 for (
int i = 0; i < nblp; ++i )
106 QList< LabelPosition * > toSort;
107 toSort.reserve( nblp );
108 for (
int i = 0; i < nblp; ++i )
110 toSort << lPos.at( i );
113 for (
int i = 0; i < nblp; ++i )
115 lPos[i] = toSort.at( i );
119 double cost_max = lPos.at( 0 )->cost();
120 double cost_min = lPos.at( nblp - 1 )->cost();
122 cost_max -= cost_min;
126 normalizer = 0.0020 / cost_max;
135 for (
int i = 0; i < nblp; ++i )
140 lPos.at( i )->setCost( 0.0021 - ( lPos.at( i )->cost() - cost_min ) * normalizer );
145 lPos.at( i )->setCost( 0.0001 );
180 if ( max_p > feat->
lPos.count() )
181 max_p = feat->
lPos.count();
187 double discrim = 0.0;
192 for ( stop = 0; stop < feat->
lPos.count() && feat->
lPos.at( stop )->cost() < discrim; stop++ )
195 while ( stop == 0 && discrim < feat->lPos.last()->cost() + 2.0 );
200 for ( k = 0; k < stop; k++ )
201 feat->
lPos.at( k )->setCost( 0.0021 );
224 px = ( lp->
x[0] + lp->
x[2] ) / 2.0;
225 py = ( lp->
y[0] + lp->
y[2] ) / 2.0;
double obstacleFactor() const
Returns the feature's obstacle factor, which represents the penalty incurred for a label to overlap t...
static bool candidateSortGrow(const LabelPosition *c1, const LabelPosition *c2)
Sorts label candidates in ascending order of cost.
bool intersectsWithPolygon(PointSet *polygon) const
Returns true if any intersection between polygon and position exists.
void setCost(double newCost)
Sets the candidate label position's geographical cost.
double getLabelDistance() const
LabelPosition * getLabel()
QgsPalLayerSettings::ObstacleType obstacleType() const
Returns the obstacle type, which controls how features within the layer act as obstacles for labels...
Arranges candidates following the curvature of a line feature. Applies to line layers only...
void update(pal::PointSet *pset)
static void addObstacleCostPenalty(LabelPosition *lp, pal::FeaturePart *obstacle)
Increase candidate's cost according to its collision with passed feature.
double cost() const
Returns the candidate label position's geographical cost.
void addSizePenalty(int nbp, QList< LabelPosition *> &lPos, double bbx[4], double bby[4])
PolygonCostCalculator(LabelPosition *lp)
void getBoundingBox(double min[2], double max[2]) const
Layer * layer()
Returns the layer that feature belongs to.
QgsPalLayerSettings::Placement arrangement() const
Returns the layer's arrangement policy.
static int finalizeCandidatesCosts(Feats *feat, int max_p, RTree< pal::FeaturePart *, double, 2, double > *obstacles, double bbx[4], double bby[4])
Sort candidates by costs, skip the worse ones, evaluate polygon candidates.
QList< LabelPosition * > lPos
For usage in problem solving algorithm.
Main class to handle feature.
int polygonIntersectionCost(PointSet *polygon) const
Returns cost of position intersection with polygon (testing area of intersection and center)...
static void setPolygonCandidatesCost(int nblp, QList< LabelPosition * > &lPos, RTree< pal::FeaturePart *, double, 2, double > *obstacles, double bbx[4], double bby[4])
void setConflictsWithObstacle(bool conflicts)
Sets whether the position is marked as conflicting with an obstacle feature.
static bool polygonObstacleCallback(pal::FeaturePart *obstacle, void *ctx)
static void setCandidateCostFromPolygon(LabelPosition *lp, RTree< pal::FeaturePart *, 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...
LabelPosition is a candidate feature label position.
bool crossesBoundary(PointSet *polygon) const
Returns true if this label crosses the boundary of the specified polygon.
static bool candidateSortShrink(const LabelPosition *c1, const LabelPosition *c2)
Sorts label candidates in descending order of cost.
Data structure to compute polygon's candidates costs.
double minDistanceToPoint(double px, double py, double *rx=nullptr, double *ry=nullptr) const
Returns the squared minimum distance between the point set geometry and the point (px...
bool crossesLine(PointSet *line) const
Returns true if this label crosses the specified line.
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
double getDistanceToPoint(double xp, double yp) const
Get distance from this label to a point. If point lies inside, returns negative number.