Skip to content
Permalink
Browse files

More responsive cancelation of point cloud render jobs (#40615)

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 42b33db3bcbee1ea1e241a37233188dae32dad61
@@ -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 )
@@ -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 );
@@ -159,6 +169,9 @@ class _3D_NO_EXPORT QgsPointCloud3DRenderContext : public Qgs3DRenderContext
QgsPointCloudCategoryList mFilteredOutCategories;
double mZValueScale = 1.0;
double mZValueFixedOffset = 0;

std::function< bool() > mIsCanceledCallback;

};


@@ -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() );

@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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...
@@ -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...
@@ -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...

0 comments on commit 42b33db

Please sign in to comment.
You can’t perform that action at this time.