30 #define _CRT_SECURE_NO_DEPRECATE
46 #define M_PI 3.1415926535897931159979634685
63 , reversed( isReversed )
65 , quadrant( quadrant )
67 , mHasObstacleConflict( false )
75 while ( this->alpha > 2*
M_PI )
76 this->alpha -= 2 *
M_PI;
78 while ( this->alpha < 0 )
79 this->alpha += 2 *
M_PI;
81 double beta = this->alpha + (
M_PI / 2 );
83 double dx1, dx2, dy1, dy2;
87 dx1 = cos( this->alpha ) *
w;
88 dy1 = sin( this->alpha ) *
w;
90 dx2 = cos( beta ) *
h;
91 dy2 = sin( beta ) *
h;
99 x[2] = x1 + dx1 + dx2;
100 y[2] = y1 + dy1 + dy2;
107 this->alpha >
M_PI / 2 && this->alpha <= 3*
M_PI / 2 )
109 bool uprightLabel =
false;
149 if ( this->alpha <
M_PI )
160 for (
int i = 0; i <
nbPoints; ++i )
190 mHasObstacleConflict = other.mHasObstacleConflict;
197 for ( i = 0; i < 4; i++ )
199 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
200 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
215 for ( i = 0; i < 4; i++ )
217 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
218 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
230 for (
int i = 0; i < 4; i++ )
232 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
233 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
247 std::cout <<
" cost: " << mCost;
248 std::cout <<
" alpha" <<
alpha << std::endl;
249 std::cout <<
x[0] <<
", " <<
y[0] << std::endl;
250 std::cout <<
x[1] <<
", " <<
y[1] << std::endl;
251 std::cout <<
x[2] <<
", " <<
y[2] << std::endl;
252 std::cout <<
x[3] <<
", " <<
y[3] << std::endl;
253 std::cout << std::endl;
278 bool result = ( GEOSPreparedIntersects_r( geosctxt,
preparedGeom(), lp->
mGeos ) == 1 );
281 catch ( GEOSException &e )
308 int LabelPosition::partCount()
const
318 for (
int i = 0; i < 4; i++ )
337 return ( i >= 0 && i < 4 ?
x[i] : -1 );
342 return ( i >= 0 && i < 4 ?
y[i] : -1 );
355 mCost -= int ( mCost );
378 for (
int c = 0; c < 4; c++ )
380 if (
x[c] < amin[0] )
382 if (
x[c] > amax[0] )
384 if (
y[c] < amin[1] )
386 if (
y[c] > amax[1] )
393 mHasObstacleConflict = conflicts;
418 pCost->
update( obstacle );
429 index->Remove( amin, amax,
this );
438 index->Insert( amin, amax,
this );
479 double *inactiveCost = ((
CountContext* ) ctx )->inactiveCost;
483 std::cout <<
"count overlap : " << lp->
id <<
"<->" << lp2->
id << std::endl;
540 catch ( GEOSException &e )
554 if ( !polygon->
mGeos )
570 catch ( GEOSException &e )
582 double totalCost = polygonIntersectionCostForParts( polygon );
584 return ceil( totalCost / n );
587 double LabelPosition::polygonIntersectionCostForParts(
PointSet *polygon )
const
592 if ( !polygon->
mGeos )
605 GEOSGeometry* intersectionGeom = GEOSIntersection_r( geosctxt,
mGeos, polygon->
mGeos );
606 if ( intersectionGeom )
608 double positionArea = 0;
609 if ( GEOSArea_r( geosctxt,
mGeos, &positionArea ) == 1 )
611 double intersectionArea = 0;
612 if ( GEOSArea_r( geosctxt, intersectionGeom, &intersectionArea ) == 1 )
614 double portionCovered = intersectionArea / positionArea;
615 cost += portionCovered * 8.0;
618 GEOSGeom_destroy_r( geosctxt, intersectionGeom );
621 catch ( GEOSException &e )
628 cost +=
nextPart->polygonIntersectionCostForParts( polygon );
UpsideDownLabels upsidedownLabels() const
Returns how upside down labels are handled within the layer.
FeaturePart * getFeaturePart()
return the feature corresponding to this labelposition
double getDistanceToPoint(double xp, double yp) const
Get distance from this label to a point.
PointSet * getHoleOf()
Returns NULL if this isn't a hole.
static bool polygonObstacleCallback(pal::FeaturePart *obstacle, void *ctx)
void validateCost()
Make sure the cost is less than 1.
static bool removeOverlapCallback(LabelPosition *lp, void *ctx)
Arrangement arrangement() const
Returns the layer's arrangement policy.
static bool countOverlapCallback(LabelPosition *lp, void *ctx)
void offsetPosition(double xOffset, double yOffset)
Shift the label by specified offset.
double cost() const
Returns the candidate label position's geographical cost.
int polygonIntersectionCost(PointSet *polygon) const
Returns cost of position intersection with polygon (testing area of intersection and center)...
static bool costGrow(void *l, void *r)
bool crossesLine(PointSet *line) const
Returns true if this label crosses the specified line.
bool isInConflictMultiPart(LabelPosition *lp)
QString tr(const char *sourceText, const char *disambiguation, int n)
void createGeosGeom() const
bool isIn(double *bbox)
Is the labelposition in the bounding-box ? (intersect or inside????)
bool isInConflict(LabelPosition *ls)
Check whether or not this overlap with another labelPosition.
int getId() const
return id
void getBoundingBox(double amin[2], double amax[2]) const
Return bounding box - amin: xmin,ymin - amax: xmax,ymax.
bool isIntersect(double *bbox)
Is the labelposition intersect the bounding-box ?
double getY(int i=0) const
get the down-left y coordinate
double getAlpha() const
get alpha
Layer * layer()
Returns the layer that feature belongs to.
bool isInConflictSinglePart(LabelPosition *lp)
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)
void removeFromIndex(RTree< LabelPosition *, double, 2, double > *index)
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
static bool countFullOverlapCallback(LabelPosition *lp, void *ctx)
void insertIntoIndex(RTree< LabelPosition *, double, 2, double > *index)
Main class to handle feature.
bool containsPoint(double x, double y) const
Tests whether point set contains a specified point.
static void addObstacleCostPenalty(LabelPosition *lp, pal::FeaturePart *obstacle)
Increase candidate's cost according to its collision with passed feature.
static bool pruneCallback(LabelPosition *lp, void *ctx)
Check whether the candidate in ctx overlap with obstacle feat.
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
void update(pal::PointSet *pset)
void setConflictsWithObstacle(bool conflicts)
Sets whether the position is marked as conflicting with an obstacle feature.
LabelPosition is a candidate feature label position.
Quadrant
Position of label candidate relative to feature.
double getX(int i=0) const
get the down-left x coordinate
double minDistanceToPoint(double px, double py, double *rx=0, double *ry=0) const
Returns the squared minimum distance between the point set geometry and the point (px...
bool crossesBoundary(PointSet *polygon) const
Returns true if this label crosses the boundary of the specified polygon.
const GEOSPreparedGeometry * preparedGeom() const
LabelPosition * getLabel()
Data structure to compute polygon's candidates costs.
bool isInside(double *bbox)
Is the labelposition inside the bounding-box ?
static bool costShrink(void *l, void *r)
LabelPosition::Quadrant quadrant