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 Q_FOREACH (
Layer *layer, mLayers )
291 context.
layer = layer;
298 if ( context.
fFeats->size() - previousFeatureCount > 0 || obstacleContext.
obstacleCount > previousObstacleCount )
300 layersWithFeaturesInBBox << layer->
name();
302 previousFeatureCount = context.
fFeats->size();
307 prob->nbLabelledLayers = layersWithFeaturesInBBox.size();
308 prob->labelledLayersName = layersWithFeaturesInBBox;
310 if ( fFeats->isEmpty() )
317 prob->nbft = fFeats->size();
319 prob->featNbLp =
new int [prob->nbft];
320 prob->featStartId =
new int [prob->nbft];
321 prob->inactiveCost =
new double[prob->nbft];
323 Feats *feat =
nullptr;
326 amin[0] = amin[1] = std::numeric_limits<double>::lowest();
327 amax[0] = amax[1] = std::numeric_limits<double>::max();
330 filterCtx.
pal =
this;
331 obstacles->Search( amin, amax,
filteringCallback, static_cast< void * >( &filterCtx ) );
335 Q_FOREACH (
Feats *feat, *fFeats )
337 qDeleteAll( feat->
lPos );
341 qDeleteAll( *fFeats );
348 for ( i = 0; i < prob->nbft; i++ )
350 feat = fFeats->takeFirst();
352 prob->featStartId[i] = idlp;
353 prob->inactiveCost[i] = std::pow( 2, 10 - 10 * feat->
priority );
360 case GEOS_LINESTRING:
372 while ( feat->
lPos.count() > max_p )
375 feat->
lPos.last()->removeFromIndex( prob->candidates );
376 delete feat->
lPos.takeLast();
380 prob->featNbLp[i] = feat->
lPos.count();
381 prob->nblp += feat->
lPos.count();
384 for ( j = 0; j < feat->
lPos.count(); j++, idlp++ )
386 lp = feat->
lPos.at( j );
390 fFeats->append( feat );
395 while ( !fFeats->isEmpty() )
399 Q_FOREACH (
Feats *feat, *fFeats )
401 qDeleteAll( feat->
lPos );
405 qDeleteAll( *fFeats );
411 feat = fFeats->takeFirst();
412 while ( !feat->
lPos.isEmpty() )
414 lp = feat->
lPos.takeFirst();
420 prob->addCandidatePosition( lp );
438 prob->all_nblp = prob->nblp;
439 prob->nbOverlap = nbOverlaps;
446 fnIsCanceled = fnCanceled;
447 fnIsCanceledContext = context;
452 return extract( extent, mapBoundary );
458 return QList<LabelPosition *>();
464 if ( searchMethod ==
FALP )
466 else if ( searchMethod ==
CHAIN )
473 return QList<LabelPosition *>();
483 this->point_p = point_p;
489 this->line_p = line_p;
495 this->poly_p = poly_p;
499 void Pal::setMinIt(
int min_it )
505 void Pal::setMaxIt(
int max_it )
511 void Pal::setPopmusicR(
int r )
517 void Pal::setEjChainDeg(
int degree )
519 this->ejChainDeg = degree;
522 void Pal::setTenure(
int tenure )
524 this->tenure = tenure;
527 void Pal::setCandListSize(
double fact )
529 this->candListSize = fact;
534 this->showPartial = show;
577 searchMethod = method;
586 searchMethod = method;
590 searchMethod = method;
599 searchMethod = method;
608 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 NULL if this isn't a hole. Otherwise returns pointer to parent pointset.
struct _featCbackCtx FeatCallBackCtx
bool active() const
Returns whether the layer is currently active.
SearchMethod getSearch()
Returns the search method in use.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
int getNumSelfObstacles() const
Gets number of holes (inner rings) - they are considered as obstacles.
A set of features which influence the labeling process.
RTree< LabelPosition *, double, 2, double > * candidates
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance *.
Is slower and best than TABU, worse and faster than TABU_CHAIN.
A geometry is the spatial representation of a feature.
void setShowPartial(bool show)
Set flag show partial label.
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.
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...
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
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.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double calculatePriority() const
Calculates the priority for the feature.
void joinConnectedFeatures()
Join connected features with the same label text.
bool isCanceled()
Check whether the job has been canceled.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
void getBoundingBox(double amin[2], double amax[2]) const
Returns bounding box - amin: xmin,ymin - amax: xmax,ymax.
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.
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.
void getBoundingBox(double min[2], double max[2]) const
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...
void registerCancelationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
RTree< FeaturePart *, double, 2, double > * obstacles
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
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.
QString name() const
Returns the layer's name.
int getNumOverlaps() const
RTree< FeaturePart *, double, 2, double > * obstacles
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.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
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.