Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
only access layer in QgsPointCloudLayerRenderer constructor
skip intersection calculation
handle potential QgsCsException
  • Loading branch information
uclaros authored and wonder-sk committed Apr 13, 2023
1 parent 72d732f commit 966c6b4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
16 changes: 12 additions & 4 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -958,16 +958,24 @@ void QgsPointCloudLayer::loadIndexesForRenderContext( QgsRenderContext &renderer
{
if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::ContainSubIndexes )
{
const QgsRectangle renderExtent = rendererContext.coordinateTransform().transformBoundingBox( rendererContext.mapExtent(), Qgis::TransformDirection::Reverse );
QVector<QgsPointCloudSubIndex> subIndex = mDataProvider->subIndexes();
QgsRectangle renderExtent;
try
{
renderExtent = rendererContext.coordinateTransform().transformBoundingBox( rendererContext.mapExtent(), Qgis::TransformDirection::Reverse );
}
catch ( QgsCsException & )
{
QgsDebugMsg( QStringLiteral( "Transformation of extent failed!" ) );
}

const QVector<QgsPointCloudSubIndex> subIndex = mDataProvider->subIndexes();
for ( int i = 0; i < subIndex.size(); ++i )
{
// no need to load as it's there
if ( subIndex.at( i ).index )
continue;

const QgsRectangle intersection = subIndex.at( i ).extent.intersect( renderExtent );
if ( !intersection.isEmpty() &&
if ( subIndex.at( i ).extent.intersects( renderExtent ) &&
renderExtent.width() < subIndex.at( i ).extent.width() )
{
mDataProvider->loadIndex( i );
Expand Down
30 changes: 18 additions & 12 deletions src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Expand Up @@ -38,6 +38,7 @@ QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *laye
: QgsMapLayerRenderer( layer->id(), &context )
, mLayer( layer )
, mLayerAttributes( layer->attributes() )
, mSubIndexes( layer && layer->dataProvider() ? layer->dataProvider()->subIndexes() : QVector<QgsPointCloudSubIndex>() )
, mFeedback( new QgsFeedback )
{
// TODO: we must not keep pointer to mLayer (it's dangerous) - we must copy anything we need for rendering
Expand Down Expand Up @@ -95,11 +96,9 @@ bool QgsPointCloudLayerRenderer::render()
return true;
}

const bool hasMultipleIndexes = mLayer->dataProvider()->capabilities() & QgsPointCloudDataProvider::ContainSubIndexes;

// TODO cache!?
QgsPointCloudIndex *pc = mLayer->dataProvider()->index();
if ( !hasMultipleIndexes &&
if ( mSubIndexes.isEmpty() &&
( !pc || !pc->isValid() ) )
{
mReadyToCompose = true;
Expand Down Expand Up @@ -144,32 +143,39 @@ bool QgsPointCloudLayerRenderer::render()
mAttributes.push_back( mLayerAttributes.at( layerIndex ) );
}

const QgsRectangle renderExtent = renderContext()->coordinateTransform().transformBoundingBox( renderContext()->mapExtent(), Qgis::TransformDirection::Reverse );
QgsRectangle renderExtent;
try
{
renderExtent = renderContext()->coordinateTransform().transformBoundingBox( renderContext()->mapExtent(), Qgis::TransformDirection::Reverse );
}
catch ( QgsCsException & )
{
QgsDebugMsg( QStringLiteral( "Transformation of extent failed!" ) );
}

bool canceled = false;
if ( !hasMultipleIndexes )
if ( mSubIndexes.isEmpty() )
{
canceled = !renderIndex( pc );
}
else
{
const auto subLayers = mLayer->dataProvider()->subIndexes();
for ( const auto &sl : subLayers )
for ( const auto &si : mSubIndexes )
{
if ( canceled )
break;

QgsPointCloudIndex *pc = sl.index.get();
QgsPointCloudIndex *pc = si.index.get();

const auto commonExtent = renderExtent.intersect( sl.extent );
if ( commonExtent.isEmpty() )
if ( !renderExtent.intersects( si.extent ) )
continue;

if ( !pc || !pc->isValid() || renderExtent.width() > sl.extent.width() )
if ( !pc || !pc->isValid() || renderExtent.width() > si.extent.width() )
{
// when dealing with virtual point clouds, we want to render the individual extents when zoomed out
// and only use the selected renderer when zoomed in
mSubExtentsRenderer->startRender( context );
mSubExtentsRenderer->renderExtent( sl.geometry, context );
mSubExtentsRenderer->renderExtent( si.geometry, context );
mSubExtentsRenderer->stopRender( context );
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/core/pointcloud/qgspointcloudlayerrenderer.h
Expand Up @@ -42,6 +42,7 @@ class QgsRenderContext;
class QgsPointCloudLayer;
class QgsPointCloudRenderer;
class QgsPointCloudRenderContext;
class QgsPointCloudSubIndex;

#define SIP_NO_FILE

Expand Down Expand Up @@ -90,6 +91,7 @@ class CORE_EXPORT QgsPointCloudLayerRenderer: public QgsMapLayerRenderer
QgsPointCloudAttributeCollection mAttributes;
QgsGeometry mCloudExtent;
QList< QgsMapClippingRegion > mClippingRegions;
const QVector< QgsPointCloudSubIndex > mSubIndexes;

int mRenderTimeHint = 0;
bool mBlockRenderUpdates = false;
Expand Down

0 comments on commit 966c6b4

Please sign in to comment.