Skip to content

Commit 5cfe487

Browse files
author
wonder
committedJul 11, 2009
First round of refactoring:
Made pal::Feature and pal::LabelPosition less friendly: prefer access to internal variables through access functions. Removed some dead functions, moved some functions, less code duplication. Shouldn't affect functionality in any way. git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11044 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

11 files changed

+295
-572
lines changed

11 files changed

+295
-572
lines changed
 

‎src/core/pal/feature.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ namespace pal
869869
}
870870
}
871871

872-
sort(( void** )( *lPos ), nbp, costGrow );
872+
sort(( void** )( *lPos ), nbp, LabelPosition::costGrow );
873873

874874
for ( i = rnbp;i < nbp;i++ )
875875
{
@@ -944,10 +944,7 @@ namespace pal
944944
y = NULL;
945945
for ( i = 0;i < nbSelfObs;i++ )
946946
{
947-
delete[] selfObs[i]->x;
948-
delete[] selfObs[i]->y;
949-
selfObs[i]->x = NULL;
950-
selfObs[i]->y = NULL;
947+
selfObs[i]->deleteCoords();
951948
}
952949
}
953950
}

‎src/core/pal/feature.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ namespace pal
6060
class Feature : public PointSet
6161
{
6262

63-
friend class Pal;
64-
friend class Layer;
65-
friend class Problem;
66-
friend class LabelPosition;
67-
68-
friend bool extractFeatCallback( Feature *ft_ptr, void *ctx );
69-
friend bool pruneLabelPositionCallback( LabelPosition *lp, void *ctx );
70-
friend bool obstacleCallback( PointSet *feat, void *ctx );
71-
//friend void setCost (int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4]);
72-
friend void releaseAllInIndex( RTree<PointSet*, double, 2, double, 8, 4>* );
73-
friend bool releaseCallback( PointSet *pset, void *ctx );
74-
friend bool filteringCallback( PointSet*, void* );
75-
7663
protected:
7764
//int id; /* feature no id into layer */
7865
double label_x;
@@ -96,6 +83,7 @@ namespace pal
9683

9784
SimpleMutex *accessMutex;
9885

86+
public:
9987
/**
10088
* \brief generate candidates for point feature
10189
* Generate candidates for point features
@@ -244,6 +232,23 @@ namespace pal
244232

245233
void fetchCoordinates();
246234
void releaseCoordinates();
235+
236+
237+
238+
PalGeometry* getUserGeometry() { return userGeom; }
239+
240+
void setLabelSize(double x, double y) { label_x = x; label_y = y; }
241+
double getLabelWidth() const { return label_x; }
242+
double getLabelHeight() const { return label_y; }
243+
244+
int getNumParts() const { return nPart; }
245+
246+
void setLabelDistance(double dist) { distlabel = dist; }
247+
double getLabelDistance() const { return distlabel; }
248+
249+
int getNumSelfObstacles() const { return nbSelfObs; }
250+
PointSet* getSelfObstacle(int i) { return selfObs[i]; }
251+
247252
};
248253

249254
} // end namespace pal

‎src/core/pal/labelposition.cpp

Lines changed: 87 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -213,37 +213,50 @@ namespace pal
213213
return cost;
214214
}
215215

216-
Feature * LabelPosition::getFeature()
217-
{
218-
return feature;
219-
}
220-
221-
bool xGrow( void *l, void *r )
216+
void LabelPosition::validateCost()
222217
{
223-
return (( LabelPosition* ) l )->x[0] > (( LabelPosition* ) r )->x[0];
218+
if ( cost >= 1 )
219+
{
220+
std::cout << " Warning: lp->cost == " << cost << " (from feat: " << feature->getUID() << "/" << getLayerName() << ")" << std::endl;
221+
cost -= int ( cost ); // label cost up to 1
222+
}
224223
}
225224

226-
bool yGrow( void *l, void *r )
225+
Feature * LabelPosition::getFeature()
227226
{
228-
return (( LabelPosition* ) l )->y[0] > (( LabelPosition* ) r )->y[0];
227+
return feature;
229228
}
230229

231-
bool xShrink( void *l, void *r )
230+
void LabelPosition::getBoundingBox(double amin[2], double amax[2]) const
232231
{
233-
return (( LabelPosition* ) l )->x[0] < (( LabelPosition* ) r )->x[0];
232+
amin[0] = DBL_MAX;
233+
amax[0] = -DBL_MAX;
234+
amin[1] = DBL_MAX;
235+
amax[1] = -DBL_MAX;
236+
for ( int c = 0;c < 4;c++ )
237+
{
238+
if ( x[c] < amin[0] )
239+
amin[0] = x[c];
240+
if ( x[c] > amax[0] )
241+
amax[0] = x[c];
242+
if ( y[c] < amin[1] )
243+
amin[1] = y[c];
244+
if ( y[c] > amax[1] )
245+
amax[1] = y[c];
246+
}
234247
}
235248

236-
bool yShrink( void *l, void *r )
249+
char* LabelPosition::getLayerName() const
237250
{
238-
return (( LabelPosition* ) l )->y[0] < (( LabelPosition* ) r )->y[0];
251+
return feature->getLayer()->name;
239252
}
240253

241-
bool costShrink( void *l, void *r )
254+
bool LabelPosition::costShrink( void *l, void *r )
242255
{
243256
return (( LabelPosition* ) l )->cost < (( LabelPosition* ) r )->cost;
244257
}
245258

246-
bool costGrow( void *l, void *r )
259+
bool LabelPosition::costGrow( void *l, void *r )
247260
{
248261
return (( LabelPosition* ) l )->cost > (( LabelPosition* ) r )->cost;
249262
}
@@ -269,31 +282,31 @@ namespace pal
269282
//#warning retourner les coord projeté ou pas ?
270283
//feature->layer->pal->proj->getLatLong(this->x[0], this->y[0], &x, &y);
271284

272-
return new Label( this->x, this->y, alpha, feature->uid, feature->layer->name, feature->userGeom );
285+
return new Label( this->x, this->y, alpha, feature->getUID(), feature->getLayer()->getName(), feature->getUserGeometry() );
273286
}
274287

275288

276-
bool obstacleCallback( PointSet *feat, void *ctx )
289+
bool LabelPosition::obstacleCallback( PointSet *feat, void *ctx )
277290
{
278291
LabelPosition::PolygonCostCalculator *pCost = ( LabelPosition::PolygonCostCalculator* ) ctx;
279292

280293
LabelPosition *lp = pCost->getLabel();
281-
if (( feat == lp->feature ) || ( feat->holeOf && feat->holeOf != lp->feature ) )
294+
if (( feat == lp->feature ) || ( feat->getHoleOf() && feat->getHoleOf() != lp->feature ) )
282295
{
283296
return true;
284297
}
285298

286299
// if the feature is not a hole we have to fetch corrdinates
287300
// otherwise holes coordinates are still in memory (feature->selfObs)
288-
if ( feat->holeOf == NULL )
301+
if ( feat->getHoleOf() == NULL )
289302
{
290303
(( Feature* ) feat )->fetchCoordinates();
291304
}
292305

293306
pCost->update( feat );
294307

295308

296-
if ( feat->holeOf == NULL )
309+
if ( feat->getHoleOf() == NULL )
297310
{
298311
(( Feature* ) feat )->releaseCoordinates();
299312
}
@@ -332,10 +345,7 @@ namespace pal
332345
amax[0] = amin[0] + 2 * dist;
333346
amax[1] = amin[1] + 2 * dist;
334347
} else {*/
335-
amin[0] = feature->xmin;
336-
amin[1] = feature->ymin;
337-
amax[0] = feature->xmax;
338-
amax[1] = feature->ymax;
348+
feature->getBoundingBox(amin, amax);
339349
//}
340350

341351
//std::cout << amin[0] << " " << amin[1] << " " << amax[0] << " " << amax[1] << std::endl;
@@ -351,24 +361,7 @@ namespace pal
351361
{
352362
double amin[2];
353363
double amax[2];
354-
int c;
355-
356-
amin[0] = DBL_MAX;
357-
amax[0] = -DBL_MAX;
358-
amin[1] = DBL_MAX;
359-
amax[1] = -DBL_MAX;
360-
for ( c = 0;c < 4;c++ )
361-
{
362-
if ( x[c] < amin[0] )
363-
amin[0] = x[c];
364-
if ( x[c] > amax[0] )
365-
amax[0] = x[c];
366-
if ( y[c] < amin[1] )
367-
amin[1] = y[c];
368-
if ( y[c] > amax[1] )
369-
amax[1] = y[c];
370-
}
371-
364+
getBoundingBox(amin, amax);
372365
index->Remove( amin, amax, this );
373366
}
374367

@@ -377,24 +370,7 @@ namespace pal
377370
{
378371
double amin[2];
379372
double amax[2];
380-
int c;
381-
382-
amin[0] = DBL_MAX;
383-
amax[0] = -DBL_MAX;
384-
amin[1] = DBL_MAX;
385-
amax[1] = -DBL_MAX;
386-
for ( c = 0;c < 4;c++ )
387-
{
388-
if ( x[c] < amin[0] )
389-
amin[0] = x[c];
390-
if ( x[c] > amax[0] )
391-
amax[0] = x[c];
392-
if ( y[c] < amin[1] )
393-
amin[1] = y[c];
394-
if ( y[c] > amax[1] )
395-
amax[1] = y[c];
396-
}
397-
373+
getBoundingBox(amin, amax);
398374
index->Insert( amin, amax, this );
399375
}
400376

@@ -603,5 +579,56 @@ namespace pal
603579
//return (a+b+c+d);
604580
return ( a*b*c*d );
605581
}
582+
583+
//////////
584+
585+
bool LabelPosition::countOverlapCallback( LabelPosition *lp, void *ctx )
586+
{
587+
LabelPosition *lp2 = ( LabelPosition* ) ctx;
588+
589+
if ( lp2->isInConflict( lp ) )
590+
{
591+
lp2->nbOverlap++;
592+
}
593+
594+
return true;
595+
}
596+
597+
bool LabelPosition::countFullOverlapCallback( LabelPosition *lp, void *ctx )
598+
{
599+
LabelPosition *lp2 = (( CountContext* ) ctx )->lp;
600+
double *cost = (( CountContext* ) ctx )->cost;
601+
//int *feat = ((CountContext*)ctx)->feat;
602+
int *nbOv = (( CountContext* ) ctx )->nbOv;
603+
double *inactiveCost = (( CountContext* ) ctx )->inactiveCost;
604+
if ( lp2->isInConflict( lp ) )
605+
{
606+
#ifdef _DEBUG_FULL_
607+
std::cout << "count overlap : " << lp->id << "<->" << lp2->id << std::endl;
608+
#endif
609+
( *nbOv ) ++;
610+
*cost += inactiveCost[lp->probFeat] + lp->getCost();
611+
612+
}
613+
614+
return true;
615+
}
616+
617+
618+
bool LabelPosition::removeOverlapCallback( LabelPosition *lp, void *ctx )
619+
{
620+
LabelPosition *lp2 = ( LabelPosition * ) ctx;
621+
622+
if ( lp2->isInConflict( lp ) )
623+
{
624+
//std::cout << " hit !" << std::endl;
625+
lp->nbOverlap--;
626+
lp2->nbOverlap--;
627+
}
628+
629+
return true;
630+
}
631+
632+
606633
} // end namespace
607634

‎src/core/pal/labelposition.h

Lines changed: 40 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,15 @@ namespace pal
5454
class LabelPosition
5555
{
5656

57-
friend bool extractFeatCallback( Feature *ft_ptr, void*ctx );
58-
friend bool xGrow( void *l, void *r );
59-
friend bool yGrow( void *l, void *r );
60-
friend bool xShrink( void *l, void *r );
61-
friend bool yShrink( void *l, void *r );
62-
friend bool costShrink( void *l, void *r );
63-
friend bool costGrow( void *l, void *r );
6457
friend bool pruneLabelPositionCallback( LabelPosition *lp, void *ctx );
65-
//friend void setCost (int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4]);
66-
friend bool countOverlapCallback( LabelPosition *lp, void *ctx );
67-
friend bool countFullOverlapCallback( LabelPosition *lp, void *ctx );
68-
friend bool removeOverlapCallback( LabelPosition *lp, void *ctx );
69-
friend bool falpCallback1( LabelPosition *lp, void * ctx );
70-
friend bool falpCallback2( LabelPosition *lp, void * ctx );
71-
friend bool subPartCallback( LabelPosition *lp, void *ctx );
72-
friend bool chainCallback( LabelPosition *lp, void *context );
73-
friend void ignoreLabel( LabelPosition*, PriorityQueue*, RTree<LabelPosition*, double, 2, double, 8, 4>* );
74-
friend bool obstacleCallback( PointSet *feat, void *ctx );
75-
76-
friend bool updateCandidatesCost( LabelPosition *lp, void *context );
77-
friend bool nokCallback( LabelPosition*, void* );
78-
58+
friend double dist_pointToLabel( double, double, LabelPosition* );
7959
friend class Pal;
80-
friend class Problem;
8160
friend class Feature;
82-
friend double dist_pointToLabel( double, double, LabelPosition* );
61+
8362
private:
84-
//LabelPosition **overlaped;
85-
//int nbOverlap;
8663

8764
int id;
8865
double cost;
89-
//double workingCost;
9066
double x[4], y[4];
9167

9268
double alpha;
@@ -100,9 +76,6 @@ namespace pal
10076
double w;
10177
double h;
10278

103-
//LabelPosition (int id, double x1, double y1, double w, double h, double cost, Feature *feature);
104-
//LabelPosition (int id, int nbPart, double *x, double *y, double *alpha,
105-
10679
public:
10780
/**
10881
* \brief create a new LabelPosition
@@ -160,11 +133,6 @@ namespace pal
160133
*/
161134
int getId();
162135

163-
/** \brief return the feature id which the labelposition is
164-
* \return feature id
165-
*/
166-
//int getFeatureId();
167-
168136

169137
/** \brief return the feature corresponding to this labelposition
170138
* \return the feature
@@ -185,6 +153,16 @@ namespace pal
185153
double getWidth() { return w; }
186154
double getHeight() { return h; }
187155

156+
double getNumOverlaps() const { return nbOverlap; }
157+
void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
158+
159+
int getProblemFeatureId() const { return probFeat; }
160+
/** set problem feature ID. called from pal.cpp during extraction */
161+
void setProblemFeatureId( int probFid ) { probFeat = probFid; }
162+
163+
/** return pointer to layer's name. used for stats */
164+
char* getLayerName() const;
165+
188166
/**
189167
* \brief get alpha
190168
* \return alpha to rotate text (in rad)
@@ -196,6 +174,12 @@ namespace pal
196174
*/
197175
double getCost();
198176

177+
/** Make sure the cost is less than 1 */
178+
void validateCost();
179+
180+
/** return bounding box - amin: xmin,ymin - amax: xmax,ymax */
181+
void getBoundingBox(double amin[2], double amax[2]) const;
182+
199183
/**
200184
* \brief get a final lable from this
201185
* \return a new Label() object
@@ -238,57 +222,33 @@ namespace pal
238222
};
239223

240224

225+
// for sorting
226+
static bool costShrink( void *l, void *r );
227+
static bool costGrow( void *l, void *r );
241228

242-
};
243-
244-
/**
245-
* \brief LabelPosition cmp
246-
*
247-
* \return true if l.id < r.id
248-
* \see Util::sort()
249-
*/
250-
bool idGrow( void *l, void *r );
251-
/**
252-
* \brief LabelPosition cmp
253-
*
254-
* \return true if l.id < r.id
255-
* \see sort
256-
*/
257-
bool xGrow( void *l, void *r );
258-
/**
259-
* \brief LabelPosition cmp
260-
*
261-
* \return true if l.id > r.id
262-
* \see sort
263-
*/
264-
bool yGrow( void *l, void *r );
265-
/**
266-
* \brief LabelPosition cmp
267-
*
268-
* \return true if l.id < r.id
269-
* \see sort
270-
*/
271-
bool xShrink( void *l, void *r );
272-
/**
273-
* \brief LabelPosition cmp
274-
*
275-
* \return true if l.id < r.id
276-
* \see sort
277-
*/
278-
bool yShrink( void *l, void *r );
279-
/**
280-
* \brief LabelPosition cmp
281-
*
282-
* \return true if l.id < r.id
283-
* \see sort
284-
*/
285-
//bool nboGrow (void *l, void *r);
229+
// for counting number of overlaps
230+
typedef struct
231+
{
232+
LabelPosition *lp;
233+
int *nbOv;
234+
double *cost;
235+
double *inactiveCost;
236+
//int *feat;
237+
} CountContext;
238+
239+
/*
240+
* count overlap, ctx = p_lp
241+
*/
242+
static bool countOverlapCallback( LabelPosition *lp, void *ctx );
286243

244+
static bool countFullOverlapCallback( LabelPosition *lp, void *ctx );
287245

288-
bool costShrink( void *l, void *r );
289-
bool costGrow( void *l, void *r );
246+
static bool removeOverlapCallback( LabelPosition *lp, void *ctx );
290247

248+
// for polygon cost calculation
249+
static bool obstacleCallback( PointSet *feat, void *ctx );
291250

251+
};
292252
} // end namespac
293253

294254
#endif

‎src/core/pal/layer.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,9 @@ bool Layer::registerFeature( const char *geom_id, PalGeometry *userGeom, double
371371

372372
double bmin[2];
373373
double bmax[2];
374-
bmin[0] = ft->xmin;
375-
bmin[1] = ft->ymin;
374+
ft->getBoundingBox(bmin, bmax);
376375

377-
bmax[0] = ft->xmax;
378-
bmax[1] = ft->ymax;
379-
380-
ft->label_x = label_x;
381-
ft->label_y = label_y;
376+
ft->setLabelSize(label_x, label_y);
382377

383378
features->push_back( ft );
384379

@@ -442,12 +437,12 @@ void Layer::setFeatureDistlabel( const char * geom_id, double distlabel )
442437
{
443438
// log
444439
Feature *feat = it->item;
445-
int nb = feat->nPart;
440+
int nb = feat->getNumParts();
446441

447442
for ( i = 0;i < nb;i++ )
448443
{
449444
feat = it->item;
450-
feat->distlabel = distlabel;
445+
feat->setLabelDistance(distlabel);
451446
it = it->next;
452447
}
453448
}
@@ -468,7 +463,7 @@ double Layer::getFeatureDistlabel( const char *geom_id )
468463

469464
int ret = -1;
470465
if ( it )
471-
ret = it->item->distlabel;
466+
ret = it->item->getLabelDistance();
472467
else
473468
{
474469
modMutex->unlock();
@@ -496,13 +491,12 @@ void Layer::setFeatureLabelSize( const char * geom_id, double label_x, double la
496491
if ( it )
497492
{
498493
Feature *feat = it->item;
499-
int nb = feat->nPart;
494+
int nb = feat->getNumParts();
500495

501496
for ( i = 0;i < nb;i++ )
502497
{
503498
feat = it->item;
504-
feat->label_x = label_x;
505-
feat->label_y = label_y;
499+
feat->setLabelSize(label_x, label_y);
506500
it = it->next;
507501
}
508502
}
@@ -523,7 +517,7 @@ double Layer::getFeatureLabelHeight( const char *geom_id )
523517
double ret = -1;
524518

525519
if ( it )
526-
ret = it->item->label_y;
520+
ret = it->item->getLabelHeight();
527521
else
528522
{
529523
modMutex->unlock();
@@ -542,7 +536,7 @@ double Layer::getFeatureLabelWidth( const char *geom_id )
542536
double ret = -1;
543537

544538
if ( it )
545-
ret = it->item->label_x;
539+
ret = it->item->getLabelWidth();
546540
else
547541
{
548542
modMutex->unlock();

‎src/core/pal/pal.cpp

Lines changed: 32 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,7 @@ namespace pal
244244
// all feature which are obstacle will be inserted into obstacles
245245
if ( context->layer->obstacle )
246246
{
247-
min[0] = ft_ptr->xmin;
248-
min[1] = ft_ptr->ymin;
249-
max[0] = ft_ptr->xmax;
250-
max[1] = ft_ptr->ymax;
247+
ft_ptr->getBoundingBox(min, max);
251248
context->obstacles->Insert( min, max, ft_ptr );
252249

253250
ft_ptr->fetchCoordinates();
@@ -258,20 +255,17 @@ namespace pal
258255
if ( context->layer->toLabel && context->layer->isScaleValid( context->scale ) )
259256
{
260257
// is the feature well defined ? // TODO Check epsilon
261-
if ( ft_ptr->label_x > 0.0000001 && ft_ptr->label_y > 0.0000001 )
258+
if ( ft_ptr->getLabelWidth() > 0.0000001 && ft_ptr->getLabelHeight() > 0.0000001 )
262259
{
263260

264261
int i;
265262
// Hole of the feature are obstacles
266-
for ( i = 0;i < ft_ptr->nbSelfObs;i++ )
263+
for ( i = 0;i < ft_ptr->getNumSelfObstacles();i++ )
267264
{
268-
min[0] = ft_ptr->selfObs[i]->xmin;
269-
min[1] = ft_ptr->selfObs[i]->ymin;
270-
max[0] = ft_ptr->selfObs[i]->xmax;
271-
max[1] = ft_ptr->selfObs[i]->ymax;
272-
context->obstacles->Insert( min, max, ft_ptr->selfObs[i] );
265+
ft_ptr->getSelfObstacle(i)->getBoundingBox(min, max);
266+
context->obstacles->Insert( min, max, ft_ptr->getSelfObstacle(i) );
273267

274-
if ( !ft_ptr->selfObs[i]->holeOf )
268+
if ( !ft_ptr->getSelfObstacle(i)->getHoleOf() )
275269
{
276270
std::cout << "ERROR: SHOULD HAVE A PARENT!!!!!" << std::endl;
277271
}
@@ -283,8 +277,8 @@ namespace pal
283277
QTime t;
284278
t.start();
285279

286-
if (( ft_ptr->type == GEOS_LINESTRING )
287-
|| ft_ptr->type == GEOS_POLYGON )
280+
if (( ft_ptr->getGeosType() == GEOS_LINESTRING )
281+
|| ft_ptr->getGeosType() == GEOS_POLYGON )
288282
{
289283

290284
double bbx[4], bby[4];
@@ -312,7 +306,7 @@ namespace pal
312306
else
313307
{
314308
// feature isn't completly in the math
315-
if ( ft_ptr->type == GEOS_LINESTRING )
309+
if ( ft_ptr->getGeosType() == GEOS_LINESTRING )
316310
PointSet::reduceLine( shape, shapes, bbx, bby );
317311
else
318312
{
@@ -462,7 +456,7 @@ namespace pal
462456
double scale = (( PruneCtx* ) ctx )->scale;
463457
Pal* pal = (( PruneCtx* ) ctx )->pal;
464458

465-
if (( feat == lp->feature ) || ( feat->holeOf && feat->holeOf != lp->feature ) )
459+
if (( feat == lp->feature ) || ( feat->getHoleOf() && feat->getHoleOf() != lp->feature ) )
466460
{
467461
return true;
468462
}
@@ -479,15 +473,15 @@ namespace pal
479473

480474
double dist;
481475

482-
double distlabel = lp->feature->distlabel;
476+
double distlabel = lp->feature->getLabelDistance();
483477
/*unit_convert( double( lp->feature->distlabel ),
484478
pal::PIXEL,
485479
pal->map_unit,
486480
pal->dpi, scale, 1 );*/
487481

488482

489483

490-
switch ( feat->type )
484+
switch ( feat->getGeosType() )
491485
{
492486
//case geos::geom::GEOS_POINT:
493487
case GEOS_POINT:
@@ -515,7 +509,7 @@ namespace pal
515509
// Is one of label's boarder cross the line ?
516510
for ( i = 0;i < 4;i++ )
517511
{
518-
for ( j = 0;j < feat->nbPoints - 1;j++ )
512+
for ( j = 0;j < feat->getNumPoints() - 1;j++ )
519513
{
520514
ca = cross_product( lp->x[i], lp->y[i], lp->x[( i+1 ) %4], lp->y[( i+1 ) %4],
521515
feat->x[j], feat->y[j] );
@@ -543,7 +537,7 @@ namespace pal
543537
#ifdef _DEBUG_FULL
544538
std::cout << " POLY" << std::endl;
545539
#endif
546-
n = nbLabelPointInPolygon( feat->nbPoints, feat->x, feat->y, lp->x, lp->y );
540+
n = nbLabelPointInPolygon( feat->getNumPoints(), feat->x, feat->y, lp->x, lp->y );
547541

548542
//n<1?n=0:n=1;
549543
break;
@@ -560,7 +554,7 @@ namespace pal
560554

561555
bool releaseCallback( PointSet *pset, void *ctx )
562556
{
563-
if ( pset->holeOf == NULL )
557+
if ( pset->getHoleOf() == NULL )
564558
{
565559
(( Feature* ) pset )->releaseCoordinates();
566560
}
@@ -605,21 +599,17 @@ namespace pal
605599
double scale = (( FilterContext* ) ctx )->scale;
606600
Pal* pal = (( FilterContext* )ctx )->pal;
607601

608-
if ( pset->holeOf == NULL )
602+
if ( pset->getHoleOf() == NULL )
609603
{
610604
(( Feature* ) pset )->fetchCoordinates();
611605
}
612606
else
613607
{
614-
(( Feature* ) pset->holeOf )->fetchCoordinates();
608+
(( Feature* ) pset->getHoleOf() )->fetchCoordinates();
615609
}
616610

617611
double amin[2], amax[2];
618-
619-
amin[0] = pset->xmin;
620-
amin[1] = pset->ymin;
621-
amax[0] = pset->xmax;
622-
amax[1] = pset->ymax;
612+
pset->getBoundingBox(amin, amax);
623613

624614
PruneCtx pruneContext;
625615

@@ -628,13 +618,13 @@ namespace pal
628618
pruneContext.pal = pal;
629619
cdtsIndex->Search( amin, amax, pruneLabelPositionCallback, ( void* ) &pruneContext );
630620

631-
if ( pset->holeOf == NULL )
621+
if ( pset->getHoleOf() == NULL )
632622
{
633623
(( Feature* ) pset )->releaseCoordinates();
634624
}
635625
else
636626
{
637-
(( Feature* ) pset->holeOf )->releaseCoordinates();
627+
(( Feature* ) pset->getHoleOf() )->releaseCoordinates();
638628
}
639629

640630
return true;
@@ -825,7 +815,7 @@ namespace pal
825815
prob->featStartId[i] = idlp;
826816
prob->inactiveCost[i] = pow( 2, 10 - 10 * feat->priority );
827817

828-
switch ( feat->feature->type )
818+
switch ( feat->feature->getGeosType() )
829819
{
830820
case GEOS_POINT:
831821
max_p = point_p;
@@ -843,17 +833,17 @@ namespace pal
843833
max_p = feat->nblp;
844834
//
845835
// sort candidates list, best label to worst
846-
sort(( void** ) feat->lPos, feat->nblp, costGrow );
836+
sort(( void** ) feat->lPos, feat->nblp, LabelPosition::costGrow );
847837

848838
// try to exclude all conflitual labels (good ones have cost < 1 by pruning)
849839
double discrim = 0.0;
850840
int stop;
851841
do
852842
{
853843
discrim += 1.0;
854-
for ( stop = 0;stop < feat->nblp && feat->lPos[stop]->cost < discrim;stop++ );
844+
for ( stop = 0;stop < feat->nblp && feat->lPos[stop]->getCost() < discrim;stop++ );
855845
}
856-
while ( stop == 0 && discrim < feat->lPos[feat->nblp-1]->cost + 2.0 );
846+
while ( stop == 0 && discrim < feat->lPos[feat->nblp-1]->getCost() + 2.0 );
857847

858848
if ( discrim > 1.5 )
859849
{
@@ -870,7 +860,7 @@ namespace pal
870860
#endif
871861

872862
// Sets costs for candidates of polygon
873-
if ( feat->feature->type == GEOS_POLYGON && ( feat->feature->layer->arrangement == P_FREE || feat->feature->layer->arrangement == P_HORIZ ) )
863+
if ( feat->feature->getGeosType() == GEOS_POLYGON && ( feat->feature->getLayer()->arrangement == P_FREE || feat->feature->getLayer()->arrangement == P_HORIZ ) )
874864
LabelPosition::setCost( stop, feat->lPos, max_p, obstacles, bbx, bby );
875865

876866
#ifdef _DEBUG_FULL_
@@ -895,7 +885,7 @@ namespace pal
895885
lp = feat->lPos[j];
896886
//lp->insertIntoIndex(prob->candidates);
897887
lp->id = idlp;
898-
lp->probFeat = i; // bugfix #1 (maxence 10/23/2008)
888+
lp->setProblemFeatureId( i ); // bugfix #1 (maxence 10/23/2008)
899889
}
900890
fFeats->push_back( feat );
901891
}
@@ -922,37 +912,20 @@ namespace pal
922912
for ( i = 0;i < feat->nblp;i++, idlp++ ) // foreach label candidate
923913
{
924914
lp = feat->lPos[i];
925-
lp->nbOverlap = 0;
915+
lp->resetNumOverlaps();
926916

927-
if ( lp->cost >= 1 )
928-
{
929-
std::cout << " Warning: lp->cost == " << lp->cost << " (from feat: " << lp->feature->uid << "/" << lp->feature->layer->name << ")" << std::endl;
930-
lp->cost -= int ( lp->cost ); // label cost up to 1
931-
}
917+
// make sure that candidate's cost is less than 1
918+
lp->validateCost();
932919

933920
prob->labelpositions[idlp] = lp;
934921
//prob->feat[idlp] = j;
935922

923+
lp->getBoundingBox(amin, amax);
936924

937-
amin[0] = DBL_MAX;
938-
amax[0] = -DBL_MAX;
939-
amin[1] = DBL_MAX;
940-
amax[1] = -DBL_MAX;
941-
for ( c = 0;c < 4;c++ )
942-
{
943-
if ( lp->x[c] < amin[0] )
944-
amin[0] = lp->x[c];
945-
if ( lp->x[c] > amax[0] )
946-
amax[0] = lp->x[c];
947-
if ( lp->y[c] < amin[1] )
948-
amin[1] = lp->y[c];
949-
if ( lp->y[c] > amax[1] )
950-
amax[1] = lp->y[c];
951-
}
952925
// lookup for overlapping candidate
953-
prob->candidates->Search( amin, amax, countOverlapCallback, ( void* ) lp );
926+
prob->candidates->Search( amin, amax, LabelPosition::countOverlapCallback, ( void* ) lp );
954927

955-
nbOverlaps += lp->nbOverlap;
928+
nbOverlaps += lp->getNumOverlaps();
956929
#ifdef _DEBUG_FULL_
957930
std::cout << "Nb overlap for " << idlp << "/" << prob->nblp - 1 << " : " << lp->nbOverlap << std::endl;
958931
#endif

‎src/core/pal/pointset.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,14 @@ namespace pal
17471747
py = cy / (3*A);
17481748
}
17491749

1750+
void PointSet::deleteCoords()
1751+
{
1752+
delete[] x;
1753+
delete[] y;
1754+
x = NULL;
1755+
y = NULL;
1756+
}
1757+
17501758
} // end namespace
17511759

17521760
#endif

‎src/core/pal/pointset.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,11 @@ namespace pal
9393
class PointSet
9494
{
9595
friend class Feature;
96-
friend class Pal;
97-
friend class Layer;
9896
friend class LabelPosition;
99-
friend class PolygonCostCalculator;
100-
friend class Problem;
10197
friend bool pruneLabelPositionCallback( LabelPosition *lp, void *ctx );
102-
//friend Feat *splitButterflyPolygon (Feat *f, int pt_a, int pt_b, double cx, double cy);
103-
friend bool obstacleCallback( PointSet *feat, void *ctx );
104-
friend bool extractFeatCallback( Feature*, void* );
10598
friend void extractXYCoord( Feat *f );
106-
friend LinkedList<Feat*> * splitGeom( GEOSGeometry *the_geom, const char *geom_id, bool check_valid );
107-
friend void releaseAllInIndex( RTree<PointSet*, double, 2, double> *obstacles );
108-
friend bool releaseCallback( PointSet *pset, void *ctx );
109-
friend bool filteringCallback( PointSet*, void* );
110-
/*protected*/
111-
public:
99+
100+
protected:
112101
int nbPoints;
113102
double *x;
114103
double *y; // points order is counterclockwise
@@ -128,13 +117,12 @@ namespace pal
128117

129118
PointSet( PointSet &ps );
130119

131-
132-
//public:
133120
double xmin;
134121
double xmax;
135122
double ymin;
136123
double ymax;
137124

125+
public:
138126
PointSet();
139127
PointSet( int nbPoints, double *x, double *y );
140128
~PointSet();
@@ -196,7 +184,21 @@ namespace pal
196184
void getCentroid( double &px, double &py );
197185

198186

187+
/** delete x and y coordinate arrays */
188+
void deleteCoords();
189+
190+
int getGeosType() const { return type; }
191+
192+
void getBoundingBox(double min[2], double max[2]) const
193+
{
194+
min[0] = xmin; min[1] = ymin;
195+
max[0] = xmax; max[1] = ymax;
196+
}
197+
198+
/** returns NULL if this isn't a hole. Otherwise returns pointer to parent pointset. */
199+
PointSet* getHoleOf() { return holeOf; }
199200

201+
int getNumPoints() const { return nbPoints; }
200202

201203
/*
202204
* Iterate on line by real step of dl on x,y points

‎src/core/pal/problem.cpp

Lines changed: 82 additions & 277 deletions
Large diffs are not rendered by default.

‎src/core/pal/util.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -185,38 +185,6 @@ namespace pal
185185

186186

187187

188-
bool countOverlapCallback( LabelPosition *lp, void *ctx )
189-
{
190-
LabelPosition *lp2 = ( LabelPosition* ) ctx;
191-
192-
if ( lp2->isInConflict( lp ) )
193-
{
194-
lp2->nbOverlap++;
195-
}
196-
197-
return true;
198-
}
199-
200-
bool countFullOverlapCallback( LabelPosition *lp, void *ctx )
201-
{
202-
LabelPosition *lp2 = (( CountContext* ) ctx )->lp;
203-
double *cost = (( CountContext* ) ctx )->cost;
204-
//int *feat = ((CountContext*)ctx)->feat;
205-
int *nbOv = (( CountContext* ) ctx )->nbOv;
206-
double *inactiveCost = (( CountContext* ) ctx )->inactiveCost;
207-
if ( lp2->isInConflict( lp ) )
208-
{
209-
#ifdef _DEBUG_FULL_
210-
std::cout << "count overlap : " << lp->id << "<->" << lp2->id << std::endl;
211-
#endif
212-
( *nbOv ) ++;
213-
*cost += inactiveCost[lp->probFeat] + lp->cost;
214-
215-
}
216-
217-
return true;
218-
}
219-
220188

221189
//inline bool ptrGeomEq (const geos::geom::Geometry *l, const geos::geom::Geometry *r){
222190
inline bool ptrGeomEq( const GEOSGeometry *l, const GEOSGeometry *r )

‎src/core/pal/util.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,22 +298,6 @@ namespace pal
298298
const double* const prob, int *cx, int *cy, double *p );
299299

300300

301-
typedef struct
302-
{
303-
LabelPosition *lp;
304-
int *nbOv;
305-
double *cost;
306-
double *inactiveCost;
307-
//int *feat;
308-
} CountContext;
309-
310-
/*
311-
* count overlap, ctx = p_lp
312-
*/
313-
bool countOverlapCallback( LabelPosition *lp, void *ctx );
314-
315-
bool countFullOverlapCallback( LabelPosition *lp, void *ctx );
316-
317301
} // namespace
318302

319303
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.