62 mLayers.remove( key );
73 qDeleteAll( mLayers );
85 Q_ASSERT( !mLayers.contains( provider ) );
87 Layer *layer =
new Layer( provider, layerName, arrangement, defaultPriority, active, toLabel,
this, displayAll );
88 mLayers.insert( provider, layer );
101 const GEOSPreparedGeometry *mapBoundary =
nullptr;
113 double amin[2], amax[2];
138 context->
fFeats->append( ft );
144 if ( unplacedPosition )
164 double amin[2], amax[2];
169 context->
obstacles->Insert( amin, amax, ft_ptr );
183 RTree<LabelPosition *, double, 2, double> *cdtsIndex = (
reinterpret_cast< FilterContext *
>( ctx ) )->cdtsIndex;
189 double amin[2], amax[2];
193 pruneContext.
obstacle = featurePart;
194 pruneContext.
pal = pal;
203 RTree<FeaturePart *, double, 2, double> obstacles;
204 std::unique_ptr< Problem > prob = qgis::make_unique< Problem >();
218 bbx[0] = bbx[3] = amin[0] = prob->bbox[0] = extent.
xMinimum();
219 bby[0] = bby[1] = amin[1] = prob->bbox[1] = extent.
yMinimum();
220 bbx[1] = bbx[2] = amax[0] = prob->bbox[2] = extent.
xMaximum();
221 bby[2] = bby[3] = amax[1] = prob->bbox[3] = extent.
yMaximum();
225 QLinkedList<Feats *> fFeats;
245 int previousFeatureCount = 0;
246 int previousObstacleCount = 0;
248 QStringList layersWithFeaturesInBBox;
251 const auto constMLayers = mLayers;
252 for (
Layer *layer : constMLayers )
261 if ( !layer->active() )
265 if ( layer->mergeConnectedLines() )
266 layer->joinConnectedFeatures();
268 layer->chopFeaturesAtRepeatDistance();
270 layer->mMutex.lock();
273 context.
layer = layer;
278 layer->mMutex.unlock();
280 if ( context.
fFeats->size() - previousFeatureCount > 0 || obstacleContext.
obstacleCount > previousObstacleCount )
282 layersWithFeaturesInBBox << layer->name();
284 previousFeatureCount = context.
fFeats->size();
289 prob->nbLabelledLayers = layersWithFeaturesInBBox.size();
290 prob->labelledLayersName = layersWithFeaturesInBBox;
292 prob->nbft = fFeats.size();
294 prob->featNbLp =
new int [prob->nbft];
295 prob->featStartId =
new int [prob->nbft];
296 prob->inactiveCost =
new double[prob->nbft];
299 if ( !fFeats.isEmpty() )
301 Feats *feat =
nullptr;
304 amin[0] = amin[1] = std::numeric_limits<double>::lowest();
305 amax[0] = amax[1] = std::numeric_limits<double>::max();
308 filterCtx.
pal =
this;
309 obstacles.Search( amin, amax,
filteringCallback, static_cast< void * >( &filterCtx ) );
313 for (
Feats *feat : qgis::as_const( fFeats ) )
315 qDeleteAll( feat->
lPos );
319 qDeleteAll( fFeats );
324 for ( i = 0; i < prob->nbft; i++ )
326 feat = fFeats.takeFirst();
328 prob->featStartId[i] = idlp;
329 prob->inactiveCost[i] = std::pow( 2, 10 - 10 * feat->
priority );
336 case GEOS_LINESTRING:
348 while ( feat->
lPos.count() > max_p )
351 feat->
lPos.constLast()->removeFromIndex( prob->candidates );
352 delete feat->
lPos.takeLast();
356 prob->featNbLp[i] = feat->
lPos.count();
357 prob->nblp += feat->
lPos.count();
360 for ( j = 0; j < feat->
lPos.count(); j++, idlp++ )
362 lp = feat->
lPos.at( j );
366 fFeats.append( feat );
371 while ( !fFeats.isEmpty() )
375 for (
Feats *feat : qgis::as_const( fFeats ) )
377 qDeleteAll( feat->
lPos );
381 qDeleteAll( fFeats );
385 feat = fFeats.takeFirst();
386 while ( !feat->
lPos.isEmpty() )
388 lp = feat->
lPos.takeFirst();
394 prob->addCandidatePosition( lp );
407 prob->all_nblp = prob->nblp;
408 prob->nbOverlap = nbOverlaps;
416 fnIsCanceled = fnCanceled;
417 fnIsCanceledContext = context;
422 return extract( extent, mapBoundary );
428 return QList<LabelPosition *>();
438 return QList<LabelPosition *>();
448 this->point_p = point_p;
454 this->line_p = line_p;
460 this->poly_p = poly_p;
464 void Pal::setMinIt(
int min_it )
470 void Pal::setMaxIt(
int max_it )
476 void Pal::setPopmusicR(
int r )
482 void Pal::setEjChainDeg(
int degree )
484 this->ejChainDeg = degree;
487 void Pal::setTenure(
int tenure )
489 this->tenure = tenure;
492 void Pal::setCandListSize(
double fact )
494 this->candListSize = fact;
499 this->showPartial = show;
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.
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
A geometry is the spatial representation of a feature.
int getNumSelfObstacles() const
Gets number of holes (inner rings) - they are considered as obstacles.
int maximumPointLabelCandidates() const
Returns the maximum number of point label candidates to generate for features in this layer...
void setShowPartial(bool show)
Set flag show partial label.
const GEOSPreparedGeometry * mapBoundary
int getPointP()
Returns the number of candidates to generate for point features.
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)
std::unique_ptr< LabelPosition > createCandidatePointOnSurface(PointSet *mapShape)
Creates a single candidate using the "point on sruface" algorithm.
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.
Layer * layer()
Returns the layer that feature belongs to.
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.
QList< LabelPosition * > lPos
For usage in problem solving algorithm.
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).
QList< LabelPosition * > createCandidates(const GEOSPreparedGeometry *mapBoundary, PointSet *mapShape, RTree< LabelPosition *, double, 2, double > *candidates)
Generic method to generate label candidates for the feature.
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...
int maximumPolygonLabelCandidates() const
Returns the maximum number of polygon label candidates to generate for features in this layer...
void setPolyP(int poly_p)
set maximum # candidates to generate for polygon features Higher the value is, longer Pal::labeller w...
int maximumLineLabelCandidates() const
Returns the maximum number of line label candidates to generate for features in this layer...
int getNumOverlaps() const
RTree< FeaturePart *, double, 2, double > * obstacles
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).
QList< LabelPosition * > solveProblem(Problem *prob, bool displayAll, QList< pal::LabelPosition *> *unlabeled=nullptr)
Solves the labeling problem, selecting the best candidate locations for all labels and returns a list...
QList< LabelPosition * > getSolution(bool returnInactive, QList< LabelPosition *> *unlabeled=nullptr)
Solves the labeling problem, selecting the best candidate locations for all labels and returns a list...
bool extractFeatCallback(FeaturePart *ft_ptr, void *ctx)
void setProblemIds(int probFid, int lpId)
Set problem feature ID and assigned label candidate ID.
Thrown when trying to access an empty data set.
QList< LabelPosition * > * positionsWithNoCandidates
int getLineP()
Returns the number of candidates to generate for line features.