42 #define M_PI 3.1415926535897931159979634685 58 , reversed( isReversed )
60 , quadrant( quadrant )
62 , mHasObstacleConflict( false )
70 while ( this->alpha > 2*
M_PI )
71 this->alpha -= 2 *
M_PI;
73 while ( this->alpha < 0 )
74 this->alpha += 2 *
M_PI;
76 double beta = this->alpha + (
M_PI / 2 );
78 double dx1, dx2, dy1, dy2;
82 dx1 = cos( this->alpha ) *
w;
83 dy1 = sin( this->alpha ) *
w;
85 dx2 = cos( beta ) *
h;
86 dy2 = sin( beta ) *
h;
94 x[2] = x1 + dx1 + dx2;
95 y[2] = y1 + dy1 + dy2;
102 this->alpha >
M_PI / 2 && this->alpha <= 3*
M_PI / 2 )
104 bool uprightLabel =
false;
144 if ( this->alpha <
M_PI )
155 for (
int i = 0; i <
nbPoints; ++i )
185 mHasObstacleConflict = other.mHasObstacleConflict;
192 for ( i = 0; i < 4; i++ )
194 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
195 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
209 for ( i = 0; i < 4; i++ )
211 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
212 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
224 for (
int i = 0; i < 4; i++ )
226 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
227 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
259 bool result = ( GEOSPreparedIntersects_r( geosctxt,
preparedGeom(), lp->
mGeos ) == 1 );
262 catch ( GEOSException &e )
289 int LabelPosition::partCount()
const 299 for (
int i = 0; i < 4; i++ )
318 return ( i >= 0 && i < 4 ?
x[i] : -1 );
323 return ( i >= 0 && i < 4 ?
y[i] : -1 );
335 mCost -= int ( mCost );
357 for (
int c = 0; c < 4; c++ )
359 if (
x[c] < amin[0] )
361 if (
x[c] > amax[0] )
363 if (
y[c] < amin[1] )
365 if (
y[c] > amax[1] )
372 mHasObstacleConflict = conflicts;
387 pCost->
update( obstacle );
397 index->Remove( amin, amax,
this );
405 index->Insert( amin, amax,
this );
445 int *nbOv = context->
nbOv;
501 catch ( GEOSException &e )
515 if ( !polygon->
mGeos )
531 catch ( GEOSException &e )
543 double totalCost = polygonIntersectionCostForParts( polygon );
545 return ceil( totalCost / n );
553 if ( !polygon->
mGeos )
564 catch ( GEOSException &e )
579 double LabelPosition::polygonIntersectionCostForParts(
PointSet *polygon )
const 584 if ( !polygon->
mGeos )
599 for (
int i = 0; i < 4; ++i )
604 for (
int a = 0; a < 2; ++a )
608 px = (
x[i] +
x[( i+1 ) %4] ) / 2.0;
609 py = (
y[i] +
y[( i+1 ) %4] ) / 2.0;
613 px = (
x[0] +
x[2] ) / 2.0;
614 py = (
y[0] +
y[2] ) / 2.0;
621 catch ( GEOSException &e )
627 cost = 12.0 * cost / 13.0;
631 cost +=
nextPart->polygonIntersectionCostForParts( polygon );
bool isInConflict(LabelPosition *ls)
Check whether or not this overlap with another labelPosition.
UpsideDownLabels upsidedownLabels() const
Returns how upside down labels are handled within the layer.
PointSet * getHoleOf()
Returns NULL if this isn't a hole.
bool isIntersect(double *bbox)
Is the labelposition intersect the bounding-box ?
bool isInConflictMultiPart(LabelPosition *lp)
void offsetPosition(double xOffset, double yOffset)
Shift the label by specified offset.
double cost() const
Returns the candidate label position's geographical cost.
void createGeosGeom() const
static bool countFullOverlapCallback(LabelPosition *lp, void *ctx)
FeaturePart * getFeaturePart()
return the feature corresponding to this labelposition
static bool removeOverlapCallback(LabelPosition *lp, void *ctx)
QString tr(const char *sourceText, const char *disambiguation, int n)
LabelPosition * getLabel()
void update(pal::PointSet *pset)
bool isInside(double *bbox)
Is the labelposition inside the bounding-box ?
QgsPalLayerSettings::Placement arrangement() const
Returns the layer's arrangement policy.
const GEOSPreparedGeometry * preparedGeom() const
static void addObstacleCostPenalty(LabelPosition *lp, pal::FeaturePart *obstacle)
Increase candidate's cost according to its collision with passed feature.
bool hasSameLabelFeatureAs(FeaturePart *part) const
Tests whether this feature part belongs to the same QgsLabelFeature as another feature part...
void getBoundingBox(double amin[2], double amax[2]) const
Return bounding box - amin: xmin,ymin - amax: xmax,ymax.
LabelPosition(int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, bool isReversed=false, Quadrant quadrant=QuadrantOver)
create a new LabelPosition
double getDistanceToPoint(double xp, double yp) const
Get distance from this label to a point.
double getY(int i=0) const
get the down-left y coordinate
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
Layer * layer()
Returns the layer that feature belongs to.
void insertIntoIndex(RTree< LabelPosition *, double, 2, double > *index)
int polygonIntersectionCost(PointSet *polygon) const
Returns cost of position intersection with polygon (testing area of intersection and center)...
void validateCost()
Make sure the cost is less than 1.
bool crossesLine(PointSet *line) const
Returns true if this label crosses the specified line.
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
double getX(int i=0) const
get the down-left x coordinate
void removeFromIndex(RTree< LabelPosition *, double, 2, double > *index)
Main class to handle feature.
static bool pruneCallback(LabelPosition *candidatePosition, void *ctx)
Check whether the candidate in ctx overlap with obstacle feat.
bool containsPoint(double x, double y) const
Tests whether point set contains a specified point.
double getAlpha() const
get alpha
bool intersectsWithPolygon(PointSet *polygon) const
Returns true if if any intersection between polygon and position exists.
bool crossesBoundary(PointSet *polygon) const
Returns true if this label crosses the boundary of the specified polygon.
void setConflictsWithObstacle(bool conflicts)
Sets whether the position is marked as conflicting with an obstacle feature.
static bool countOverlapCallback(LabelPosition *lp, void *ctx)
static bool polygonObstacleCallback(pal::FeaturePart *obstacle, void *ctx)
bool isIn(double *bbox)
Is the labelposition in the bounding-box ? (intersect or inside????)
LabelPosition is a candidate feature label position.
Quadrant
Position of label candidate relative to feature.
bool isInConflictSinglePart(LabelPosition *lp)
int getId() const
return id
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...
Data structure to compute polygon's candidates costs.
LabelPosition::Quadrant quadrant