Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[pal] Don't reuse spatial index for two different purposes
This forces many removals/additions to the existing index, which
we can avoid by just using a seperate index in the first place
  • Loading branch information
nyalldawson committed Dec 15, 2019
1 parent 1929c53 commit 2e3b57a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/core/pal/pal.cpp
Expand Up @@ -86,6 +86,7 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
{
// to store obstacles
PalRtree< FeaturePart > obstacles;
PalRtree< LabelPosition > allCandidatesFirstRound;
std::vector< FeaturePart * > allObstacleParts;
std::unique_ptr< Problem > prob = qgis::make_unique< Problem >();

Expand Down Expand Up @@ -185,7 +186,7 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
{
for ( std::unique_ptr< LabelPosition > &candidate : candidates )
{
candidate->insertIntoIndex( prob->allCandidatesIndex() );
candidate->insertIntoIndex( allCandidatesFirstRound );
}

std::sort( candidates.begin(), candidates.end(), CostCalculator::candidateSortGrow );
Expand Down Expand Up @@ -255,7 +256,7 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
if ( isCanceled() )
break; // do not continue searching

prob->allCandidatesIndex().intersects( obstaclePart->boundingBox(), [obstaclePart, this]( const LabelPosition * candidatePosition ) -> bool
allCandidatesFirstRound.intersects( obstaclePart->boundingBox(), [obstaclePart, this]( const LabelPosition * candidatePosition ) -> bool
{
// test whether we should ignore this obstacle for the candidate. We do this if:
// 1. it's not a hole, and the obstacle belongs to the same label feature as the candidate (e.g.,
Expand Down Expand Up @@ -322,7 +323,6 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
{
if ( candidate->hasHardObstacleConflict() )
{
candidate->removeFromIndex( prob->mAllCandidatesIndex );
return true;
}
return false;
Expand All @@ -332,7 +332,6 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
{
// we've ended up removing ALL candidates for this label. Oh well, that's allowed. We just need to
// make sure we move this last candidate to the unplaced labels list
feat->candidates.front()->removeFromIndex( prob->mAllCandidatesIndex );
prob->positionsWithNoCandidates()->emplace_back( std::move( feat->candidates.front() ) );
feat->candidates.clear();
}
Expand All @@ -342,7 +341,6 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
// only keep the 'max_p' best candidates
while ( feat->candidates.size() > max_p )
{
feat->candidates.back()->removeFromIndex( prob->mAllCandidatesIndex );
feat->candidates.pop_back();
}

Expand All @@ -356,7 +354,7 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
// add all candidates into a rtree (to speed up conflicts searching)
for ( std::size_t j = 0; j < feat->candidates.size(); j++, idlp++ )
{
//lp->insertIntoIndex(prob->candidates);
feat->candidates[ j ]->insertIntoIndex( prob->allCandidatesIndex() );
feat->candidates[ j ]->setProblemIds( static_cast< int >( i ), idlp );
}
features.emplace_back( std::move( feat ) );
Expand Down Expand Up @@ -387,7 +385,7 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom

// lookup for overlapping candidate
lp->getBoundingBox( amin, amax );
prob->mAllCandidatesIndex.intersects( QgsRectangle( amin[0], amin[1], amax[0], amax[1] ), [&lp]( const LabelPosition * lp2 )->bool
prob->allCandidatesIndex().intersects( QgsRectangle( amin[0], amin[1], amax[0], amax[1] ), [&lp]( const LabelPosition * lp2 )->bool
{
if ( lp->isInConflict( lp2 ) )
{
Expand Down

0 comments on commit 2e3b57a

Please sign in to comment.