58 fnIsCancelled =
nullptr;
59 fnIsCancelledContext =
nullptr;
89 mLayers.remove( key );
100 qDeleteAll( mLayers );
112 Q_ASSERT( !mLayers.contains( provider ) );
114 Layer* layer =
new Layer( provider, layerName, arrangement, defaultPriority, active, toLabel,
this, displayAll );
115 mLayers.insert( provider, layer );
140 double amin[2], amax[2];
189 double amin[2], amax[2];
194 context->
obstacles->Insert( amin, amax, ft_ptr );
208 RTree<LabelPosition*, double, 2, double> *cdtsIndex = (
reinterpret_cast< FilterContext*
>( ctx ) )->cdtsIndex;
214 double amin[2], amax[2];
218 pruneContext.
obstacle = featurePart;
219 pruneContext.
pal = pal;
225 Problem* Pal::extract(
double lambda_min,
double phi_min,
double lambda_max,
double phi_max )
228 RTree<FeaturePart*, double, 2, double> *obstacles =
new RTree<FeaturePart*, double, 2, double>();
244 bbx[0] = bbx[3] = amin[0] = prob->bbox[0] = lambda_min;
245 bby[0] = bby[1] = amin[1] = prob->bbox[1] = phi_min;
246 bbx[1] = bbx[2] = amax[0] = prob->bbox[2] = lambda_max;
247 bby[2] = bby[3] = amax[1] = prob->bbox[3] = phi_max;
268 int previousFeatureCount = 0;
269 int previousObstacleCount = 0;
274 Q_FOREACH (
Layer* layer, mLayers )
295 context.
layer = layer;
302 if ( context.
fFeats->
size() - previousFeatureCount > 0 || obstacleContext.
obstacleCount > previousObstacleCount )
304 layersWithFeaturesInBBox << layer->
name();
306 previousFeatureCount = context.
fFeats->
size();
311 prob->nbLabelledLayers = layersWithFeaturesInBBox.
size();
312 prob->labelledLayersName = layersWithFeaturesInBBox;
322 prob->nbft = fFeats->
size();
324 prob->featNbLp =
new int [prob->nbft];
325 prob->featStartId =
new int [prob->nbft];
326 prob->inactiveCost =
new double[prob->nbft];
331 amin[0] = amin[1] = -DBL_MAX;
332 amax[0] = amax[1] = DBL_MAX;
335 filterCtx.
pal =
this;
336 obstacles->Search( amin, amax,
filteringCallback, static_cast< void* >( &filterCtx ) );
340 Q_FOREACH (
Feats* feat, *fFeats )
342 qDeleteAll( feat->
lPos );
346 qDeleteAll( *fFeats );
354 for ( i = 0; i < prob->nbft; i++ )
358 prob->featStartId[i] = idlp;
359 prob->inactiveCost[i] = pow( 2, 10 - 10 * feat->
priority );
366 case GEOS_LINESTRING:
378 while ( feat->
lPos.count() > max_p )
381 feat->
lPos.last()->removeFromIndex( prob->candidates );
382 delete feat->
lPos.takeLast();
386 prob->featNbLp[i] = feat->
lPos.count();
387 prob->nblp += feat->
lPos.count();
390 for ( j = 0; j < feat->
lPos.count(); j++, idlp++ )
392 lp = feat->
lPos.at( j );
405 Q_FOREACH (
Feats* feat, *fFeats )
407 qDeleteAll( feat->
lPos );
411 qDeleteAll( *fFeats );
419 while ( !feat->
lPos.isEmpty() )
421 lp = feat->
lPos.takeFirst();
427 prob->addCandidatePosition( lp );
445 prob->all_nblp = prob->nblp;
446 prob->nbOverlap = nbOverlaps;
466 if ( !( prob = extract( bbox[0], bbox[1], bbox[2], bbox[3] ) ) )
477 prob->displayAll = displayAll;
480 if ( searchMethod ==
FALP )
482 else if ( searchMethod ==
CHAIN )
508 fnIsCancelled = fnCancelled;
509 fnIsCancelledContext = context;
514 return extract( bbox[0], bbox[1], bbox[2], bbox[3] );
526 if ( searchMethod ==
FALP )
528 else if ( searchMethod ==
CHAIN )
545 this->point_p = point_p;
551 this->line_p = line_p;
557 this->poly_p = poly_p;
561 void Pal::setMinIt(
int min_it )
567 void Pal::setMaxIt(
int max_it )
573 void Pal::setPopmusicR(
int r )
579 void Pal::setEjChainDeg(
int degree )
581 this->ejChainDeg = degree;
584 void Pal::setTenure(
int tenure )
586 this->tenure = tenure;
589 void Pal::setCandListSize(
double fact )
591 this->candListSize = fact;
596 this->showPartial = show;
639 searchMethod = method;
648 searchMethod = method;
652 searchMethod = method;
661 searchMethod = method;
670 searchMethod = method;
int createCandidates(QList< LabelPosition *> &lPos, double bboxMin[2], double bboxMax[2], PointSet *mapShape, RTree< LabelPosition *, double, 2, double > *candidates)
Generic method to generate label candidates for the feature.
struct _obstaclebackCtx ObstacleCallBackCtx
Layer * addLayer(QgsAbstractLabelProvider *provider, const QString &layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll=false)
add a new layer
struct _filterContext FilterContext
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
PointSet * getHoleOf()
Returns NULL if this isn't a hole.
struct _featCbackCtx FeatCallBackCtx
void getBoundingBox(double amin[2], double amax[2]) const
Return bounding box - amin: xmin,ymin - amax: xmax,ymax.
SearchMethod getSearch()
get the search method in use
void registerCancellationCallback(FnIsCancelled fnCancelled, void *context)
Register a function that returns whether this job has been cancelled - PAL calls it during the comput...
A set of features which influence the labelling process.
Main Pal labelling class.
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance.
bool isCancelled()
Check whether the job has been cancelled.
is slower and best than TABU, worse and faster than TABU_CHAIN
int getNumSelfObstacles() const
Get number of holes (inner rings) - they are considered as obstacles.
void setShowPartial(bool show)
Set flag show partial label.
int getPointP()
get # candidates to generate for point features
is a little bit better than CHAIN but slower
void removeLayer(Layer *layer)
remove a layer
bool(* FnIsCancelled)(void *ctx)
int getPolyP()
get maximum # candidates to generate for polygon features
RTree< FeaturePart *, double, 2, double > * obstacles
void chain_search()
Test with very-large scale neighborhood.
QList< LabelPosition * > * getSolution(bool returnInactive)
bool getShowPartial()
Get flag show partial label.
void joinConnectedFeatures()
Join connected features with the same label text.
QLinkedList< Feats * > * fFeats
void getBoundingBox(double min[2], double max[2]) const
RTree< LabelPosition *, double, 2, double > * cdtsIndex
double calculatePriority() const
Calculates the priority for the feature.
void setPointP(int point_p)
set # candidates to generate for points features Higher the value is, longer Pal::labeller will spend...
void setLineP(int line_p)
set maximum # candidates to generate for lines features Higher the value is, longer Pal::labeller wil...
static int finalizeCandidatesCosts(Feats *feat, int max_p, RTree< pal::FeaturePart *, double, 2, double > *obstacles, double bbx[4], double bby[4])
Sort candidates by costs, skip the worse ones, evaluate polygon candidates.
void validateCost()
Make sure the cost is less than 1.
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
For usage in problem solving algorithm.
void popmusic()
popmusic framework
bool extractObstaclesCallback(FeaturePart *ft_ptr, void *ctx)
Main class to handle feature.
The QgsAbstractLabelProvider class is an interface class.
static bool pruneCallback(LabelPosition *candidatePosition, void *ctx)
Check whether the candidate in ctx overlap with obstacle feat.
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
Pal()
Create an new pal instance.
RTree< LabelPosition *, double, 2, double > * candidates
QList< LabelPosition * > * labeller(double bbox[4], PalStat **stats, bool displayAll)
the labeling machine Will extract all active layers
Placement
Placement modes which determine how label candidates are generated for a feature. ...
static bool countOverlapCallback(LabelPosition *lp, void *ctx)
Problem * extractProblem(double bbox[4])
static GEOSContextHandle_t getGEOSHandler()
Return GEOS context handle.
void setPolyP(int poly_p)
set maximum # candidates to generate for polygon features Higher the value is, longer Pal::labeller w...
QList< LabelPosition * > * solveProblem(Problem *prob, bool displayAll)
int getNumOverlaps() const
RTree< FeaturePart *, double, 2, double, 8, 4 > * mFeatureIndex
FeaturePart * getSelfObstacle(int i)
Get hole (inner ring) - considered as obstacle.
QString name() const
Returns the layer's name.
Summary statistics of labelling problem.
bool active() const
Returns whether the layer is currently active.
bool filteringCallback(FeaturePart *featurePart, void *ctx)
LabelPosition is a candidate feature label position.
Representation of a labeling problem.
bool extractFeatCallback(FeaturePart *ft_ptr, void *ctx)
SearchMethod
Search method to use.
void setProblemIds(int probFid, int lpId)
Set problem feature ID and assigned label candidate ID.
is the worst but fastest method
RTree< FeaturePart *, double, 2, double > * obstacles
QList< LabelPosition * > lPos
Thrown when trying to access an empty dada set.
void setSearch(SearchMethod method)
Select the search method to use.
void append(const T &value)
int getLineP()
get maximum # candidates to generate for line features