Skip to content

Commit

Permalink
Calculate point cloud attributes to fetch based on renderer's needs
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 12, 2020
1 parent 1feccd1 commit 4e38237
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Expand Up @@ -126,15 +126,6 @@ QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *laye

mRenderer.reset( mLayer->renderer()->clone() );

mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) );
mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Y" ), QgsPointCloudAttribute::Int32 ) );

int offset;
const QgsPointCloudAttribute *renderAttribute = mLayer->attributes().find( mConfig.attribute(), offset );
if ( !renderAttribute )
return;

mAttributes.push_back( *renderAttribute );
mScale = mLayer->dataProvider()->index()->scale();
mOffset = mLayer->dataProvider()->index()->offset();
}
Expand All @@ -149,6 +140,27 @@ bool QgsPointCloudLayerRenderer::render()
QgsPointCloudRenderContext context( *renderContext(), mScale, mOffset );


mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) );
mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Y" ), QgsPointCloudAttribute::Int32 ) );

// collect attributes required by renderer
const QSet< QString > rendererAttributes = mRenderer->usedAttributes( context );
for ( const QString &attribute : rendererAttributes )
{
if ( mAttributes.indexOf( attribute ) >= 0 )
continue; // don't re-add attributes we are already going to fetch

const int layerIndex = mLayer->attributes().indexOf( attribute );
if ( layerIndex < 0 )
{
QgsMessageLog::logMessage( QObject::tr( "Required attribute %1 not found in layer" ).arg( attribute ), QObject::tr( "Point Cloud" ) );
continue;
}

mAttributes.push_back( mLayer->attributes().at( layerIndex ) );
}


// Set up the render configuration options
QPainter *painter = context.renderContext().painter();

Expand Down

0 comments on commit 4e38237

Please sign in to comment.