58 fnIsCanceled =
nullptr;
59 fnIsCanceledContext =
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 );
127 const GEOSPreparedGeometry *mapBoundary =
nullptr;
139 double amin[2], amax[2];
155 QList< LabelPosition * > lPos;
164 context->
fFeats->append( ft );
188 double amin[2], amax[2];
193 context->
obstacles->Insert( amin, amax, ft_ptr );
207 RTree<LabelPosition *, double, 2, double> *cdtsIndex = (
reinterpret_cast< FilterContext *
>( ctx ) )->cdtsIndex;
213 double amin[2], amax[2];
217 pruneContext.
obstacle = featurePart;
218 pruneContext.
pal = pal;
227 RTree<FeaturePart *, double, 2, double> *obstacles =
new RTree<FeaturePart *, double, 2, double>();
229 std::unique_ptr< Problem > prob = qgis::make_unique< Problem >();
243 bbx[0] = bbx[3] = amin[0] = prob->bbox[0] = extent.
xMinimum();
244 bby[0] = bby[1] = amin[1] = prob->bbox[1] = extent.
yMinimum();
245 bbx[1] = bbx[2] = amax[0] = prob->bbox[2] = extent.
xMaximum();
246 bby[2] = bby[3] = amax[1] = prob->bbox[3] = extent.
yMaximum();
250 QLinkedList<Feats *> *fFeats =
new QLinkedList<Feats *>;
269 int previousFeatureCount = 0;
270 int previousObstacleCount = 0;
272 QStringList layersWithFeaturesInBBox;
275 Q_FOREACH (
Layer *layer, mLayers )
296 context.
layer = layer;
303 if ( context.
fFeats->size() - previousFeatureCount > 0 || obstacleContext.
obstacleCount > previousObstacleCount )
305 layersWithFeaturesInBBox << layer->
name();
307 previousFeatureCount = context.
fFeats->size();
312 prob->nbLabelledLayers = layersWithFeaturesInBBox.size();
313 prob->labelledLayersName = layersWithFeaturesInBBox;
315 if ( fFeats->isEmpty() )
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];
328 Feats *feat =
nullptr;
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 );
353 for ( i = 0; i < prob->nbft; i++ )
355 feat = fFeats->takeFirst();
357 prob->featStartId[i] = idlp;
358 prob->inactiveCost[i] = std::pow( 2, 10 - 10 * feat->
priority );
365 case GEOS_LINESTRING:
377 while ( feat->
lPos.count() > max_p )
380 feat->
lPos.last()->removeFromIndex( prob->candidates );
381 delete feat->
lPos.takeLast();
385 prob->featNbLp[i] = feat->
lPos.count();
386 prob->nblp += feat->
lPos.count();
389 for ( j = 0; j < feat->
lPos.count(); j++, idlp++ )
391 lp = feat->
lPos.at( j );
395 fFeats->append( feat );
400 while ( !fFeats->isEmpty() )
404 Q_FOREACH (
Feats *feat, *fFeats )
406 qDeleteAll( feat->
lPos );
410 qDeleteAll( *fFeats );
416 feat = fFeats->takeFirst();
417 while ( !feat->
lPos.isEmpty() )
419 lp = feat->
lPos.takeFirst();
425 prob->addCandidatePosition( lp );
443 prob->all_nblp = prob->nblp;
444 prob->nbOverlap = nbOverlaps;
451 fnIsCanceled = fnCanceled;
452 fnIsCanceledContext = context;
457 return extract( extent, mapBoundary );
463 return QList<LabelPosition *>();
469 if ( searchMethod ==
FALP )
471 else if ( searchMethod ==
CHAIN )
478 return QList<LabelPosition *>();
488 this->point_p = point_p;
494 this->line_p = line_p;
500 this->poly_p = poly_p;
504 void Pal::setMinIt(
int min_it )
510 void Pal::setMaxIt(
int max_it )
516 void Pal::setPopmusicR(
int r )
522 void Pal::setEjChainDeg(
int degree )
524 this->ejChainDeg = degree;
527 void Pal::setTenure(
int tenure )
529 this->tenure = tenure;
532 void Pal::setCandListSize(
double fact )
534 this->candListSize = fact;
539 this->showPartial = show;
582 searchMethod = method;
591 searchMethod = method;
595 searchMethod = method;
604 searchMethod = method;
613 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.
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
PointSet * getHoleOf()
Returns NULL if this isn't a hole. Otherwise returns pointer to parent pointset.
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
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
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.
int getNumSelfObstacles() const
Get number of holes (inner rings) - they are considered as obstacles.
void setShowPartial(bool show)
Set flag show partial label.
const GEOSPreparedGeometry * mapBoundary
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
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()
get maximum # candidates to generate for polygon features
void chain_search()
Test with very-large scale neighborhood.
bool(* FnIsCanceled)(void *ctx)
bool getShowPartial()
Get flag show partial label.
void joinConnectedFeatures()
Join connected features with the same label text.
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
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.
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 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...
void registerCancelationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
int getNumOverlaps() const
GEOSGeometry * exportToGeos(double precision=0) const
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
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)
Get hole (inner ring) - considered as obstacle.
QString name() const
Returns the layer's name.
bool active() const
Returns whether the layer is currently active.
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()
get maximum # candidates to generate for line features