Skip to content

Commit

Permalink
More pal simplifications and variable renames
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 28, 2019
1 parent dc435ef commit 3cbb3a0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
39 changes: 7 additions & 32 deletions src/core/pal/feature.cpp
Expand Up @@ -1618,8 +1618,7 @@ int FeaturePart::createCandidatesForPolygon( QList< LabelPosition *> &lPos, Poin
return nbp;
}

QList<LabelPosition *> FeaturePart::createCandidates( const GEOSPreparedGeometry *mapBoundary,
PointSet *mapShape, RTree<LabelPosition *, double, 2, double> *candidates )
QList<LabelPosition *> FeaturePart::createCandidates()
{
QList<LabelPosition *> lPos;
double angle = mLF->hasFixedAngle() ? mLF->fixedAngle() : 0.0;
Expand All @@ -1642,9 +1641,9 @@ QList<LabelPosition *> FeaturePart::createCandidates( const GEOSPreparedGeometry
break;
case GEOS_LINESTRING:
if ( mLF->layer()->isCurved() )
createCurvedCandidatesAlongLine( lPos, mapShape, true );
createCurvedCandidatesAlongLine( lPos, this, true );
else
createCandidatesAlongLine( lPos, mapShape, true );
createCandidatesAlongLine( lPos, this, true );
break;

case GEOS_POLYGON:
Expand All @@ -1653,49 +1652,25 @@ QList<LabelPosition *> FeaturePart::createCandidates( const GEOSPreparedGeometry
case QgsPalLayerSettings::AroundPoint:
case QgsPalLayerSettings::OverPoint:
double cx, cy;
mapShape->getCentroid( cx, cy, mLF->layer()->centroidInside() );
getCentroid( cx, cy, mLF->layer()->centroidInside() );
if ( mLF->layer()->arrangement() == QgsPalLayerSettings::OverPoint )
createCandidatesOverPoint( cx, cy, lPos, angle );
else
createCandidatesAroundPoint( cx, cy, lPos, angle );
break;
case QgsPalLayerSettings::Line:
createCandidatesAlongLine( lPos, mapShape );
createCandidatesAlongLine( lPos, this );
break;
case QgsPalLayerSettings::PerimeterCurved:
createCurvedCandidatesAlongLine( lPos, mapShape );
createCurvedCandidatesAlongLine( lPos, this );
break;
default:
createCandidatesForPolygon( lPos, mapShape );
createCandidatesForPolygon( lPos, this );
break;
}
}
}

// purge candidates that are outside the bbox

QMutableListIterator< LabelPosition *> i( lPos );
while ( i.hasNext() )
{
LabelPosition *pos = i.next();
bool outside = false;

if ( mLF->layer()->pal->getShowPartial() )
outside = !pos->intersects( mapBoundary );
else
outside = !pos->within( mapBoundary );
if ( outside )
{
i.remove();
delete pos;
}
else // this one is OK
{
pos->insertIntoIndex( candidates );
}
}

std::sort( lPos.begin(), lPos.end(), CostCalculator::candidateSortGrow );
return lPos;
}

Expand Down
8 changes: 2 additions & 6 deletions src/core/pal/feature.h
Expand Up @@ -128,13 +128,9 @@ namespace pal
QgsFeatureId featureId() const;

/**
* Generic method to generate label candidates for the feature.
* \param mapBoundary map boundary geometry
* \param mapShape generate candidates for this spatial entity
* \param candidates index for candidates
* \returns a list of generated candidates positions
* Generates a list of candidate positions for labels for this feature.
*/
QList<LabelPosition *> createCandidates( const GEOSPreparedGeometry *mapBoundary, PointSet *mapShape, RTree<LabelPosition *, double, 2, double> *candidates );
QList<LabelPosition *> createCandidates();

/**
* Generate candidates for point feature, located around a specified point.
Expand Down
50 changes: 39 additions & 11 deletions src/core/pal/pal.cpp
Expand Up @@ -99,6 +99,7 @@ typedef struct _featCbackCtx
RTree<LabelPosition *, double, 2, double> *candidates;
QList<LabelPosition *> *positionsWithNoCandidates;
const GEOSPreparedGeometry *mapBoundary = nullptr;
Pal *pal = nullptr;
} FeatCallBackCtx;


Expand All @@ -108,39 +109,65 @@ typedef struct _featCbackCtx
*
* Extract a specific shape from indexes
*/
bool extractFeatCallback( FeaturePart *ft_ptr, void *ctx )
bool extractFeatCallback( FeaturePart *featurePart, void *ctx )
{
double amin[2], amax[2];
FeatCallBackCtx *context = reinterpret_cast< FeatCallBackCtx * >( ctx );

// Holes of the feature are obstacles
for ( int i = 0; i < ft_ptr->getNumSelfObstacles(); i++ )
for ( int i = 0; i < featurePart->getNumSelfObstacles(); i++ )
{
ft_ptr->getSelfObstacle( i )->getBoundingBox( amin, amax );
context->obstacles->Insert( amin, amax, ft_ptr->getSelfObstacle( i ) );
featurePart->getSelfObstacle( i )->getBoundingBox( amin, amax );
context->obstacles->Insert( amin, amax, featurePart->getSelfObstacle( i ) );

if ( !ft_ptr->getSelfObstacle( i )->getHoleOf() )
if ( !featurePart->getSelfObstacle( i )->getHoleOf() )
{
//ERROR: SHOULD HAVE A PARENT!!!!!
}
}

// generate candidates for the feature part
const QList< LabelPosition * > lPos = ft_ptr->createCandidates( context->mapBoundary, ft_ptr, context->candidates );
if ( !lPos.empty() )
QList< LabelPosition * > candidates = featurePart->createCandidates();

// purge candidates that are outside the bbox

QMutableListIterator< LabelPosition *> i( candidates );
while ( i.hasNext() )
{
LabelPosition *pos = i.next();
bool outside = false;

if ( context->pal->getShowPartial() )
outside = !pos->intersects( context->mapBoundary );
else
outside = !pos->within( context->mapBoundary );
if ( outside )
{
i.remove();
delete pos;
}
else // this one is OK
{
pos->insertIntoIndex( context->candidates );
}
}

if ( !candidates.empty() )
{
std::sort( candidates.begin(), candidates.end(), CostCalculator::candidateSortGrow );

// valid features are added to fFeats
Feats *ft = new Feats();
ft->feature = ft_ptr;
ft->feature = featurePart;
ft->shape = nullptr;
ft->candidates = lPos;
ft->priority = ft_ptr->calculatePriority();
ft->candidates = candidates;
ft->priority = featurePart->calculatePriority();
context->fFeats->append( ft );
}
else
{
// features with no candidates are recorded in the unlabeled feature list
std::unique_ptr< LabelPosition > unplacedPosition = ft_ptr->createCandidatePointOnSurface( ft_ptr );
std::unique_ptr< LabelPosition > unplacedPosition = featurePart->createCandidatePointOnSurface( featurePart );
if ( unplacedPosition )
context->positionsWithNoCandidates->append( unplacedPosition.release() );
}
Expand Down Expand Up @@ -235,6 +262,7 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
context.candidates = prob->candidates;
context.positionsWithNoCandidates = prob->positionsWithNoCandidates();
context.mapBoundary = mapBoundaryPrepared.get();
context.pal = this;

ObstacleCallBackCtx obstacleContext;
obstacleContext.obstacles = &obstacles;
Expand Down

0 comments on commit 3cbb3a0

Please sign in to comment.