34 #define _CRT_SECURE_NO_DEPRECATE
51 #define M_PI 3.1415926535897931159979634685
68 , reversed( isReversed )
70 , quadrant( quadrant )
74 while ( this->alpha > 2*
M_PI )
75 this->alpha -= 2 *
M_PI;
77 while ( this->alpha < 0 )
78 this->alpha += 2 *
M_PI;
80 double beta = this->alpha + (
M_PI / 2 );
82 double dx1, dx2, dy1, dy2;
86 dx1 = cos( this->alpha ) *
w;
87 dy1 = sin( this->alpha ) *
w;
89 dx2 = cos( beta ) *
h;
90 dy2 = sin( beta ) *
h;
98 x[2] = x1 + dx1 + dx2;
99 y[2] = y1 + dy1 + dy2;
106 this->alpha >
M_PI / 2 && this->alpha <= 3*
M_PI / 2 )
108 bool uprightLabel =
false;
148 if ( this->alpha <
M_PI )
168 memcpy(
x, other.
x,
sizeof(
double )*4 );
169 memcpy(
y, other.
y,
sizeof(
double )*4 );
188 for ( i = 0; i < 4; i++ )
190 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
191 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
206 for ( i = 0; i < 4; i++ )
208 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
209 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
221 for (
int i = 0; i < 4; i++ )
223 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
224 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
238 std::cout <<
" cost: " <<
cost;
239 std::cout <<
" alpha" <<
alpha << std::endl;
240 std::cout <<
x[0] <<
", " <<
y[0] << std::endl;
241 std::cout <<
x[1] <<
", " <<
y[1] << std::endl;
242 std::cout <<
x[2] <<
", " <<
y[2] << std::endl;
243 std::cout <<
x[3] <<
", " <<
y[3] << std::endl;
244 std::cout << std::endl;
266 for ( i = 0; i < 4; i++ )
272 for ( j = 0; j < 4; j++ )
280 lp->
x[i2], lp->
y[i2],
289 if ( d1 == -1 || d2 == -1 )
317 for (
int i = 0; i < 4; i++ )
335 return ( i >= 0 && i < 4 ?
x[i] : -1 );
340 return ( i >= 0 && i < 4 ?
y[i] : -1 );
381 for (
int c = 0; c < 4; c++ )
383 if (
x[c] < amin[0] )
385 if (
x[c] > amax[0] )
387 if (
y[c] < amin[1] )
389 if (
y[c] > amax[1] )
431 index->Remove( amin, amax,
this );
440 index->Insert( amin, amax,
this );
481 double *inactiveCost = ((
CountContext* ) ctx )->inactiveCost;
485 std::cout <<
"count overlap : " << lp->
id <<
"<->" << lp2->
id << std::endl;
520 double dist_min = DBL_MAX;
523 for ( i = 0; i < 4; i++ )
526 mx[i] = (
x[i] +
x[j] ) / 2.0;
527 my[i] = (
y[i] +
y[j] ) / 2.0;
533 if (
vabs( dist ) <
vabs( dist_min ) )
537 if (
vabs( dist ) <
vabs( dist_min ) )
544 if (
vabs( dist ) <
vabs( dist_min ) )
548 if (
vabs( dist ) <
vabs( dist_min ) )
552 for ( i = 0; i < 4; i++ )
555 if (
vabs( dist ) <
vabs( dist_min ) )
569 for (
int i = 0; i < 4; i++ )
574 feat->
x[j], feat->
y[j] );
576 feat->
x[j+1], feat->
y[j+1] );
578 if (( ca < 0 && cb > 0 ) || ( ca > 0 && cb < 0 ) )
583 x[( i+1 ) %4],
y[( i+1 ) %4] );
584 if (( ca < 0 && cb > 0 ) || ( ca > 0 && cb < 0 ) )
602 for ( k = 0; k < 4; k++ )
607 for ( a = 0; a < 2; a++ )
611 px = (
x[k] +
x[( k+1 ) %4] ) / 2.0;
612 py = (
y[k] +
y[( k+1 ) %4] ) / 2.0;
616 px = (
x[0] +
x[2] ) / 2.0;
617 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, Quadrant quadrant=QuadrantOver)
create a new LabelPosition
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
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)
LabelPosition::Quadrant quadrant