34 #define _CRT_SECURE_NO_DEPRECATE 51 #define M_PI 3.1415926535897931159979634685 58 : id( id ), cost( cost ), feature( feature ), probFeat( 0 ), nbOverlap( 0 ), alpha( alpha ), w( w ), h( h ), nextPart( NULL ), partId( -1 ), reversed( isReversed ), upsideDown( false )
62 while ( this->alpha > 2*
M_PI )
63 this->alpha -= 2 *
M_PI;
65 while ( this->alpha < 0 )
66 this->alpha += 2 *
M_PI;
68 double beta = this->alpha + (
M_PI / 2 );
70 double dx1, dx2, dy1, dy2;
74 dx1 = cos( this->alpha ) *
w;
75 dy1 = sin( this->alpha ) *
w;
77 dx2 = cos( beta ) *
h;
78 dy2 = sin( beta ) *
h;
86 x[2] = x1 + dx1 + dx2;
87 y[2] = y1 + dy1 + dy2;
94 this->alpha >
M_PI / 2 && this->alpha <= 3*
M_PI / 2 )
96 bool uprightLabel =
false;
136 if ( this->alpha <
M_PI )
156 memcpy(
x, other.
x,
sizeof(
double )*4 );
157 memcpy(
y, other.
y,
sizeof(
double )*4 );
175 for ( i = 0; i < 4; i++ )
177 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
178 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
193 for ( i = 0; i < 4; i++ )
195 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
196 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
208 for (
int i = 0; i < 4; i++ )
210 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
211 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
225 std::cout <<
" cost: " <<
cost;
226 std::cout <<
" alpha" <<
alpha << std::endl;
227 std::cout <<
x[0] <<
", " <<
y[0] << std::endl;
228 std::cout <<
x[1] <<
", " <<
y[1] << std::endl;
229 std::cout <<
x[2] <<
", " <<
y[2] << std::endl;
230 std::cout <<
x[3] <<
", " <<
y[3] << std::endl;
231 std::cout << std::endl;
253 for ( i = 0; i < 4; i++ )
259 for ( j = 0; j < 4; j++ )
267 lp->
x[i2], lp->
y[i2],
276 if ( d1 == -1 || d2 == -1 )
304 for (
int i = 0; i < 4; i++ )
322 return ( i >= 0 && i < 4 ?
x[i] : -1 );
327 return ( i >= 0 && i < 4 ?
y[i] : -1 );
368 for (
int c = 0; c < 4; c++ )
370 if (
x[c] < amin[0] )
372 if (
x[c] > amax[0] )
374 if (
y[c] < amin[1] )
376 if (
y[c] > amax[1] )
418 index->Remove( amin, amax,
this );
427 index->Insert( amin, amax,
this );
468 double *inactiveCost = ((
CountContext* ) ctx )->inactiveCost;
472 std::cout <<
"count overlap : " << lp->
id <<
"<->" << lp2->
id << std::endl;
507 double dist_min = DBL_MAX;
510 for ( i = 0; i < 4; i++ )
513 mx[i] = (
x[i] +
x[j] ) / 2.0;
514 my[i] = (
y[i] +
y[j] ) / 2.0;
520 if (
vabs( dist ) <
vabs( dist_min ) )
524 if (
vabs( dist ) <
vabs( dist_min ) )
531 if (
vabs( dist ) <
vabs( dist_min ) )
535 if (
vabs( dist ) <
vabs( dist_min ) )
539 for ( i = 0; i < 4; i++ )
542 if (
vabs( dist ) <
vabs( dist_min ) )
556 for (
int i = 0; i < 4; i++ )
561 feat->
x[j], feat->
y[j] );
563 feat->
x[j+1], feat->
y[j+1] );
565 if (( ca < 0 && cb > 0 ) || ( ca > 0 && cb < 0 ) )
570 x[( i+1 ) %4],
y[( i+1 ) %4] );
571 if (( ca < 0 && cb > 0 ) || ( ca > 0 && cb < 0 ) )
589 for ( k = 0; k < 4; k++ )
594 for ( a = 0; a < 2; a++ )
598 px = (
x[k] +
x[( k+1 ) %4] ) / 2.0;
599 py = (
y[k] +
y[( k+1 ) %4] ) / 2.0;
603 px = (
x[0] +
x[2] ) / 2.0;
604 py = (
y[0] +
y[2] ) / 2.0;
FeaturePart * getFeaturePart()
return the feature corresponding to this labelposition
bool isBorderCrossingLine(PointSet *feat)
returns true if this label crosses the specified line
PointSet * getHoleOf()
returns NULL if this isn't a hole.
double getCost() const
get the position geographical cost
void validateCost()
Make sure the cost is less than 1.
static bool removeOverlapCallback(LabelPosition *lp, void *ctx)
static bool countOverlapCallback(LabelPosition *lp, void *ctx)
void offsetPosition(double xOffset, double yOffset)
shift the label by specified offset
static bool costGrow(void *l, void *r)
bool isInConflictMultiPart(LabelPosition *lp)
Layer * getLayer()
return the layer that feature belongs to
static void addObstacleCostPenalty(LabelPosition *lp, PointSet *feat)
increase candidate's cost according to its collision with passed feature
bool isIn(double *bbox)
Is the labelposition in the bounding-box ? (intersect or inside????)
bool isPointInPolygon(int npol, double *xp, double *yp, double x, double y)
bool isInConflict(LabelPosition *ls)
Check whether or not this overlap with another labelPosition.
int getId() const
return id
char * getLayerName() const
return pointer to layer's name.
UpsideDownLabels getUpsidedownLabels() const
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 ?
static bool polygonObstacleCallback(PointSet *feat, void *ctx)
double getY(int i=0) const
get the down-left y coordinate
double getAlpha() const
get alpha
double getDistanceToPoint(double xp, double yp)
get distance from this label to a point.
bool isInConflictSinglePart(LabelPosition *lp)
double dist_euc2d(double x1, double y1, double x2, double y2)
void update(PointSet *pset)
void removeFromIndex(RTree< LabelPosition *, double, 2, double > *index)
static bool countFullOverlapCallback(LabelPosition *lp, void *ctx)
void insertIntoIndex(RTree< LabelPosition *, double, 2, double > *index)
double cross_product(double x1, double y1, double x2, double y2, double x3, double y3)
const char * getUID()
get the unique id of the feature
Main class to handle feature.
Arrangement getArrangement()
get arrangement policy
static bool pruneCallback(LabelPosition *lp, void *ctx)
Check whether the candidate in ctx overlap with obstacle feat.
const char * getName()
get layer's name
LabelPosition(int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, bool isReversed=false)
create a new LabelPosition
LabelPositon is a candidate feature label position.
double getX(int i=0) const
get the down-left x coordinate
LabelPosition * getLabel()
Data structure to compute polygon's candidates costs.
bool isInside(double *bbox)
Is the labelposition inside the bounding-box ?
int getNumPointsInPolygon(int npol, double *xp, double *yp)
returns number of intersections with polygon (testing border and center)
static bool costShrink(void *l, void *r)