Skip to content
Permalink
Browse files

make the loading then rendering steps done on a group basis

  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Apr 8, 2021
1 parent f65c7d2 commit 006e32020e42289359955b3a3722893114dfd50b
@@ -238,64 +238,71 @@ int QgsPointCloudLayerRenderer::renderNodesAsync( const QVector<IndexedPointClou
QElapsedTimer downloadTimer;
downloadTimer.start();

// Async loading of nodes
QVector<QgsPointCloudBlockRequest *> blockRequests( nodes.size(), nullptr );
QVector<bool> finishedLoadingBlock( nodes.size(), false );
QEventLoop loop;
// Note: All capture by reference warnings here shouldn't be an issue since we have an event loop, so locals won't be deallocated
for ( int i = 0; i < nodes.size(); ++i )
int groupSize = 4;
for ( int groupIndex = 0; groupIndex < nodes.size(); groupIndex += groupSize )
{
const IndexedPointCloudNode &n = nodes[i];
QgsPointCloudBlockRequest *blockRequest = pc->asyncNodeData( n, request );
blockRequests[ i ] = blockRequest;
QObject::connect( blockRequest, &QgsPointCloudBlockRequest::finished, [ &, i, blockRequest ]()
// Async loading of nodes
QVector<QgsPointCloudBlockRequest *> blockRequests( std::min( nodes.size() - groupIndex, groupSize ), nullptr );
QVector<bool> finishedLoadingBlock( std::min( nodes.size() - groupIndex, groupSize ), false );
QEventLoop loop;

// Note: All capture by reference warnings here shouldn't be an issue since we have an event loop, so locals won't be deallocated
for ( int i = 0; i < blockRequests.size(); ++i )
{
if ( !blockRequest->block() )
int nodeIndex = groupIndex + i;
const IndexedPointCloudNode &n = nodes[nodeIndex];
QgsPointCloudBlockRequest *blockRequest = pc->asyncNodeData( n, request );
blockRequests[ i ] = blockRequest;
QObject::connect( blockRequest, &QgsPointCloudBlockRequest::finished, [ &, i, blockRequest ]()
{
QgsDebugMsg( QStringLiteral( "Unable to load node %1, error: %2" ).arg( n.toString(), blockRequest->errorStr() ) );
}
finishedLoadingBlock[ i ] = true;
// If all blocks are loaded, exit the event loop
if ( !finishedLoadingBlock.contains( false ) ) loop.exit();
} );
}
// Wait for all point cloud nodes to finish loading
loop.exec();
if ( !blockRequest->block() )
{
QgsDebugMsg( QStringLiteral( "Unable to load node %1, error: %2" ).arg( n.toString(), blockRequest->errorStr() ) );
}
finishedLoadingBlock[ i ] = true;
// If all blocks are loaded, exit the event loop
if ( !finishedLoadingBlock.contains( false ) ) loop.exit();
} );
}
// Wait for all point cloud nodes to finish loading
loop.exec();

QgsDebugMsg( QStringLiteral( "Downloaded in : %1ms" ).arg( downloadTimer.elapsed() ) );
QgsDebugMsg( QStringLiteral( "Downloaded in : %1ms" ).arg( downloadTimer.elapsed() ) );

// Render all the point cloud blocks sequentially
for ( int i = 0; i < nodes.size(); ++i )
{
if ( context.renderContext().renderingStopped() )
// Render all the point cloud blocks sequentially
for ( int i = 0; i < blockRequests.size(); ++i )
{
QgsDebugMsgLevel( "canceled", 2 );
canceled = true;
break;
}
if ( context.renderContext().renderingStopped() )
{
QgsDebugMsgLevel( "canceled", 2 );
canceled = true;
break;
}

if ( !blockRequests[ i ]->block() )
continue;
if ( !blockRequests[ i ]->block() )
continue;

context.setAttributes( blockRequests[ i ]->block()->attributes() );
context.setAttributes( blockRequests[ i ]->block()->attributes() );

mRenderer->renderBlock( blockRequests[ i ]->block(), context );
++nodesDrawn;
mRenderer->renderBlock( blockRequests[ i ]->block(), context );
++nodesDrawn;

// as soon as first block is rendered, we can start showing layer updates.
// but if we are blocking render updates (so that a previously cached image is being shown), we wait
// at most e.g. 3 seconds before we start forcing progressive updates.
if ( !mBlockRenderUpdates || mElapsedTimer.elapsed() > MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE )
// as soon as first block is rendered, we can start showing layer updates.
// but if we are blocking render updates (so that a previously cached image is being shown), we wait
// at most e.g. 3 seconds before we start forcing progressive updates.
if ( !mBlockRenderUpdates || mElapsedTimer.elapsed() > MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE )
{
mReadyToCompose = true;
}
}

for ( int i = 0; i < blockRequests.size(); ++i )
{
mReadyToCompose = true;
if ( blockRequests[ i ] )
blockRequests[ i ]->deleteLater();
}
}

for ( int i = 0; i < nodes.size(); ++i )
{
if ( blockRequests[ i ] )
blockRequests[ i ]->deleteLater();
}
return nodesDrawn;
}

@@ -98,7 +98,7 @@ QgsPointCloudBlock *QgsRemoteEptPointCloudIndex::nodeData( const IndexedPointClo

if ( !blockRequest->block() )
{
QgsDebugMsg( QStringLiteral( "Error downloading node %1 data, error : %2 " ).arg( n.toString(), blockRequest->errorStr() ) );
QgsDebugMsg( QStringLiteral( "Error downloading node %1 data, error : %2 " ).arg( n.toString(), blockRequest->errorStr() ) );
}

return blockRequest->block();

0 comments on commit 006e320

Please sign in to comment.