53 fnIsCanceled =
nullptr;
54 fnIsCanceledContext =
nullptr;
84 mLayers.remove( key );
95 qDeleteAll( mLayers );
107 Q_ASSERT( !mLayers.contains( provider ) );
109 Layer *layer =
new Layer( provider, layerName, arrangement, defaultPriority, active, toLabel,
this, displayAll );
110 mLayers.insert( provider, layer );
122 const GEOSPreparedGeometry *mapBoundary =
nullptr;
134 double amin[2], amax[2];
150 QList< LabelPosition * > lPos;
159 context->
fFeats->append( ft );
183 double amin[2], amax[2];
188 context->
obstacles->Insert( amin, amax, ft_ptr );
202 RTree<LabelPosition *, double, 2, double> *cdtsIndex = (
reinterpret_cast< FilterContext *
>( ctx ) )->cdtsIndex;
208 double amin[2], amax[2];
212 pruneContext.
obstacle = featurePart;
213 pruneContext.
pal = pal;
222 RTree<FeaturePart *, double, 2, double> *obstacles =
new RTree<FeaturePart *, double, 2, double>();
224 std::unique_ptr< Problem > prob = qgis::make_unique< Problem >();
238 bbx[0] = bbx[3] = amin[0] = prob->bbox[0] = extent.
xMinimum();
239 bby[0] = bby[1] = amin[1] = prob->bbox[1] = extent.
yMinimum();
240 bbx[1] = bbx[2] = amax[0] = prob->bbox[2] = extent.
xMaximum();
241 bby[2] = bby[3] = amax[1] = prob->bbox[3] = extent.
yMaximum();
245 QLinkedList<Feats *> *fFeats =
new QLinkedList<Feats *>;
264 int previousFeatureCount = 0;
265 int previousObstacleCount = 0;
267 QStringList layersWithFeaturesInBBox;
270 const auto constMLayers = mLayers;
271 for (
Layer *layer : constMLayers )
280 if ( !layer->active() )
284 if ( layer->mergeConnectedLines() )
285 layer->joinConnectedFeatures();
287 layer->chopFeaturesAtRepeatDistance();
289 layer->mMutex.lock();
292 context.
layer = layer;
297 layer->mMutex.unlock();
299 if ( context.
fFeats->size() - previousFeatureCount > 0 || obstacleContext.
obstacleCount > previousObstacleCount )
301 layersWithFeaturesInBBox << layer->name();
303 previousFeatureCount = context.
fFeats->size();
308 prob->nbLabelledLayers = layersWithFeaturesInBBox.size();
309 prob->labelledLayersName = layersWithFeaturesInBBox;
311 if ( fFeats->isEmpty() )
318 prob->nbft = fFeats->size();
320 prob->featNbLp =
new int [prob->nbft];
321 prob->featStartId =
new int [prob->nbft];
322 prob->inactiveCost =
new double[prob->nbft];
324 Feats *feat =
nullptr;
327 amin[0] = amin[1] = std::numeric_limits<double>::lowest();
328 amax[0] = amax[1] = std::numeric_limits<double>::max();
331 filterCtx.
pal =
this;
332 obstacles->Search( amin, amax,
filteringCallback, static_cast< void * >( &filterCtx ) );
336 const auto constFFeats = *fFeats;
337 for (
Feats *feat : constFFeats )
339 qDeleteAll( feat->
lPos );
343 qDeleteAll( *fFeats );
350 for ( i = 0; i < prob->nbft; i++ )
352 feat = fFeats->takeFirst();
354 prob->featStartId[i] = idlp;
355 prob->inactiveCost[i] = std::pow( 2, 10 - 10 * feat->
priority );
362 case GEOS_LINESTRING:
374 while ( feat->
lPos.count() > max_p )
377 feat->
lPos.last()->removeFromIndex( prob->candidates );
378 delete feat->
lPos.takeLast();
382 prob->featNbLp[i] = feat->
lPos.count();
383 prob->nblp += feat->
lPos.count();
386 for ( j = 0; j < feat->
lPos.count(); j++, idlp++ )
388 lp = feat->
lPos.at( j );
392 fFeats->append( feat );
397 while ( !fFeats->isEmpty() )
401 const auto constFFeats = *fFeats;
402 for (
Feats *feat : constFFeats )
404 qDeleteAll( feat->
lPos );
408 qDeleteAll( *fFeats );
414 feat = fFeats->takeFirst();
415 while ( !feat->
lPos.isEmpty() )
417 lp = feat->
lPos.takeFirst();
423 prob->addCandidatePosition( lp );
441 prob->all_nblp = prob->nblp;
442 prob->nbOverlap = nbOverlaps;
449 fnIsCanceled = fnCanceled;
450 fnIsCanceledContext = context;
455 return extract( extent, mapBoundary );
461 return QList<LabelPosition *>();
467 if ( searchMethod ==
FALP )
469 else if ( searchMethod ==
CHAIN )
476 return QList<LabelPosition *>();
486 this->point_p = point_p;
492 this->line_p = line_p;
498 this->poly_p = poly_p;
502 void Pal::setMinIt(
int min_it )
508 void Pal::setMaxIt(
int max_it )
514 void Pal::setPopmusicR(
int r )
520 void Pal::setEjChainDeg(
int degree )
522 this->ejChainDeg = degree;
525 void Pal::setTenure(
int tenure )
527 this->tenure = tenure;
530 void Pal::setCandListSize(
double fact )
532 this->candListSize = fact;
537 this->showPartial = show;
580 searchMethod = method;
589 searchMethod = method;
593 searchMethod = method;
602 searchMethod = method;
611 searchMethod = method;
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
A rectangle specified with double values.
PointSet * getHoleOf()
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
struct _featCbackCtx FeatCallBackCtx
void getBoundingBox(double amin[2], double amax[2]) const
Returns bounding box - amin: xmin,ymin - amax: xmax,ymax.
SearchMethod getSearch()
Returns the search method in use.
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
void registerCancellationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
A set of features which influence the labeling process.
RTree< LabelPosition *, double, 2, double > * candidates
Is slower and best than TABU, worse and faster than TABU_CHAIN.
A geometry is the spatial representation of a feature.
int getNumSelfObstacles() const
Gets number of holes (inner rings) - they are considered as obstacles.
void setShowPartial(bool show)
Set flag show partial label.
const GEOSPreparedGeometry * mapBoundary
int getPointP()
Returns the number of candidates to generate for point features.
Is a little bit better than CHAIN but slower.
static GEOSContextHandle_t getGEOSHandler()
void removeLayer(Layer *layer)
remove a layer
std::unique_ptr< Problem > extractProblem(const QgsRectangle &extent, const QgsGeometry &mapBoundary)
Extracts the labeling problem for the specified map extent - only features within this extent will be...
RTree< FeaturePart *, double, 2, double, 8, 4 > * mFeatureIndex
int getPolyP()
Returns the number of candidates to generate for polygon features.
void chain_search()
Test with very-large scale neighborhood.
bool(* FnIsCanceled)(void *ctx)
bool getShowPartial()
Returns whether partial labels should be allowed.
void getBoundingBox(double min[2], double max[2]) const
bool isCanceled()
Check whether the job has been canceled.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
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...
int createCandidates(QList< LabelPosition *> &lPos, const GEOSPreparedGeometry *mapBoundary, PointSet *mapShape, RTree< LabelPosition *, double, 2, double > *candidates)
Generic method to generate label candidates for the feature.
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.
QList< LabelPosition * > lPos
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.
QLinkedList< Feats * > * fFeats
Pal()
Create an new pal instance.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Placement
Placement modes which determine how label candidates are generated for a feature. ...
RTree< LabelPosition *, double, 2, double > * cdtsIndex
static bool countOverlapCallback(LabelPosition *lp, void *ctx)
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0)
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
void setPolyP(int poly_p)
set maximum # candidates to generate for polygon features Higher the value is, longer Pal::labeller w...
int getNumOverlaps() const
RTree< FeaturePart *, double, 2, double > * obstacles
QList< LabelPosition * > solveProblem(Problem *prob, bool displayAll)
FeaturePart * getSelfObstacle(int i)
Gets hole (inner ring) - considered as obstacle.
bool filteringCallback(FeaturePart *featurePart, void *ctx)
LabelPosition is a candidate feature label position.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
RTree< FeaturePart *, double, 2, double > * obstacles
Representation of a labeling problem.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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.
Thrown when trying to access an empty data set.
void setSearch(SearchMethod method)
Select the search method to use.
QList< LabelPosition * > getSolution(bool returnInactive)
int getLineP()
Returns the number of candidates to generate for line features.