Skip to content

Commit

Permalink
More responsive cancelation of point cloud render jobs (#40615)
Browse files Browse the repository at this point in the history
Don't wait till whole node has been rendered before checking for
cancelation, rather check during rendering of a node
  • Loading branch information
nyalldawson committed Dec 16, 2020
1 parent 56fe4fa commit 42b33db
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/3d/qgspointcloudlayer3drenderer.cpp
Expand Up @@ -35,7 +35,11 @@ QgsPointCloud3DRenderContext::QgsPointCloud3DRenderContext( const Qgs3DMapSettin
, mZValueScale( zValueScale )
, mZValueFixedOffset( zValueFixedOffset )
{

auto callback = []()->bool
{
return false;
};
mIsCanceledCallback = callback;
}

void QgsPointCloud3DRenderContext::setAttributes( const QgsPointCloudAttributeCollection &attributes )
Expand Down
13 changes: 13 additions & 0 deletions src/3d/qgspointcloudlayer3drenderer.h
Expand Up @@ -150,6 +150,16 @@ class _3D_NO_EXPORT QgsPointCloud3DRenderContext : public Qgs3DRenderContext
*/
double zValueFixedOffset() const { return mZValueFixedOffset; }

/**
* Sets the function to call to test if the rendering is canceled.
*/
void setIsCanceledCallback( const std::function< bool() > &callback ) { mIsCanceledCallback = callback; }

/**
* Returns TRUE if the rendering is canceled.
*/
bool isCanceled() const { return mIsCanceledCallback(); }

private:
#ifdef SIP_RUN
QgsPointCloudRenderContext( const QgsPointCloudRenderContext &rh );
Expand All @@ -159,6 +169,9 @@ class _3D_NO_EXPORT QgsPointCloud3DRenderContext : public Qgs3DRenderContext
QgsPointCloudCategoryList mFilteredOutCategories;
double mZValueScale = 1.0;
double mZValueFixedOffset = 0;

std::function< bool() > mIsCanceledCallback;

};


Expand Down
2 changes: 2 additions & 0 deletions src/3d/qgspointcloudlayerchunkloader_p.cpp
Expand Up @@ -52,6 +52,8 @@ QgsPointCloudLayerChunkLoader::QgsPointCloudLayerChunkLoader( const QgsPointClou
, mFactory( factory )
, mContext( factory->mMap, std::move( symbol ), zValueScale, zValueOffset )
{
mContext.setIsCanceledCallback( [this] { return mCanceled; } );

QgsPointCloudIndex *pc = mFactory->mPointCloudIndex;
mContext.setAttributes( pc->attributes() );

Expand Down
12 changes: 12 additions & 0 deletions src/3d/symbols/qgspointcloud3dsymbol_p.cpp
Expand Up @@ -265,6 +265,9 @@ void QgsSingleColorPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *p

for ( int i = 0; i < count; ++i )
{
if ( context.isCanceled() )
break;

qint32 ix = *( qint32 * )( ptr + i * recordSize + 0 );
qint32 iy = *( qint32 * )( ptr + i * recordSize + 4 );
qint32 iz = *( qint32 * )( ptr + i * recordSize + 8 );
Expand Down Expand Up @@ -367,6 +370,9 @@ void QgsColorRampPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc,

for ( int i = 0; i < count; ++i )
{
if ( context.isCanceled() )
break;

qint32 ix = *( qint32 * )( ptr + i * recordSize + xOffset );
qint32 iy = *( qint32 * )( ptr + i * recordSize + yOffset );
qint32 iz = *( qint32 * )( ptr + i * recordSize + zOffset );
Expand Down Expand Up @@ -471,6 +477,9 @@ void QgsRGBPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const
int ib = 0;
for ( int i = 0; i < count; ++i )
{
if ( context.isCanceled() )
break;

qint32 ix = *( qint32 * )( ptr + i * recordSize + 0 );
qint32 iy = *( qint32 * )( ptr + i * recordSize + 4 );
qint32 iz = *( qint32 * )( ptr + i * recordSize + 8 );
Expand Down Expand Up @@ -607,6 +616,9 @@ void QgsClassificationPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex
QSet<int> filteredOutValues = context.getFilteredOutValues();
for ( int i = 0; i < count; ++i )
{
if ( context.isCanceled() )
break;

qint32 ix = *( qint32 * )( ptr + i * recordSize + xOffset );
qint32 iy = *( qint32 * )( ptr + i * recordSize + yOffset );
qint32 iz = *( qint32 * )( ptr + i * recordSize + zOffset );
Expand Down
5 changes: 5 additions & 0 deletions src/core/pointcloud/qgspointcloudattributebyramprenderer.cpp
Expand Up @@ -81,6 +81,11 @@ void QgsPointCloudAttributeByRampRenderer::renderBlock( const QgsPointCloudBlock
int alpha = 0;
for ( int i = 0; i < count; ++i )
{
if ( context.renderContext().renderingStopped() )
{
break;
}

if ( considerZ )
{
// z value filtering is cheapest, if we're doing it...
Expand Down
5 changes: 5 additions & 0 deletions src/core/pointcloud/qgspointcloudclassifiedrenderer.cpp
Expand Up @@ -93,6 +93,11 @@ void QgsPointCloudClassifiedRenderer::renderBlock( const QgsPointCloudBlock *blo

for ( int i = 0; i < count; ++i )
{
if ( context.renderContext().renderingStopped() )
{
break;
}

if ( considerZ )
{
// z value filtering is cheapest, if we're doing it...
Expand Down
5 changes: 5 additions & 0 deletions src/core/pointcloud/qgspointcloudrgbrenderer.cpp
Expand Up @@ -96,6 +96,11 @@ void QgsPointCloudRgbRenderer::renderBlock( const QgsPointCloudBlock *block, Qgs
const bool reproject = ct.isValid();
for ( int i = 0; i < count; ++i )
{
if ( context.renderContext().renderingStopped() )
{
break;
}

if ( considerZ )
{
// z value filtering is cheapest, if we're doing it...
Expand Down

0 comments on commit 42b33db

Please sign in to comment.