Skip to content

Commit

Permalink
Fix categories filtering performance
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Dec 7, 2020
1 parent e1776df commit 752c42c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 11 deletions.
7 changes: 7 additions & 0 deletions python/3d/auto_generated/symbols/qgspointcloud3dsymbol.sip.in
Expand Up @@ -449,6 +449,13 @@ Returns the list of categories of the classification
%Docstring
Sets the list of categories of the classification

.. seealso:: :py:func:`categoriesList`
%End

QgsPointCloudCategoryList getFilteredOutCategories() const;
%Docstring
Gets the list of categories of the classification that should not be rendered

.. seealso:: :py:func:`categoriesList`
%End

Expand Down
15 changes: 15 additions & 0 deletions src/3d/qgspointcloudlayer3drenderer.cpp
Expand Up @@ -45,6 +45,21 @@ void QgsPointCloud3DRenderContext::setSymbol( QgsPointCloud3DSymbol *symbol )
mSymbol.reset( symbol );
}

void QgsPointCloud3DRenderContext::setFilteredOutCategories( const QgsPointCloudCategoryList &categories )
{
mFilteredOutCategories = categories;
}

bool QgsPointCloud3DRenderContext::isFilteredOut( int value ) const
{
for ( QgsPointCloudCategory category : mFilteredOutCategories )
{
if ( category.value() == value )
return true;
}
return false;
}

QgsPointCloudLayer3DRendererMetadata::QgsPointCloudLayer3DRendererMetadata()
: Qgs3DRendererAbstractMetadata( QStringLiteral( "pointcloud" ) )
{
Expand Down
13 changes: 13 additions & 0 deletions src/3d/qgspointcloudlayer3drenderer.h
Expand Up @@ -80,6 +80,18 @@ class _3D_NO_EXPORT QgsPointCloud3DRenderContext : public Qgs3DRenderContext
*/
void setSymbol( QgsPointCloud3DSymbol *symbol );

/**
* Sets the list of categories of the classification that won't be rendered
* \see isFilteredOut()
*/
void setFilteredOutCategories( const QgsPointCloudCategoryList &categories );

/**
* Checks whether \a value shouldn't be rendered and is filtered out
* \see setFilteredOutCategories()
*/
bool isFilteredOut( int value ) const;

/**
* Retrieves the attribute \a value from \a data at the specified \a offset, where
* \a type indicates the original data type for the attribute.
Expand Down Expand Up @@ -121,6 +133,7 @@ class _3D_NO_EXPORT QgsPointCloud3DRenderContext : public Qgs3DRenderContext
#endif
QgsPointCloudAttributeCollection mAttributes;
std::unique_ptr<QgsPointCloud3DSymbol> mSymbol;
QgsPointCloudCategoryList mFilteredOutCategories;
};


Expand Down
4 changes: 4 additions & 0 deletions src/3d/qgspointcloudlayerchunkloader_p.cpp
Expand Up @@ -68,7 +68,11 @@ QgsPointCloudLayerChunkLoader::QgsPointCloudLayerChunkLoader( const QgsPointClou
else if ( symbol->symbolType() == QLatin1String( "rgb" ) )
mHandler.reset( new QgsRGBPointCloud3DSymbolHandler() );
else if ( symbol->symbolType() == QLatin1String( "classification" ) )
{
mHandler.reset( new QgsClassificationPointCloud3DSymbolHandler() );
QgsClassificationPointCloud3DSymbol *classificationSymbol = dynamic_cast<QgsClassificationPointCloud3DSymbol *>( symbol );
mContext.setFilteredOutCategories( classificationSymbol->getFilteredOutCategories() );
}

//
// this will be run in a background thread
Expand Down
2 changes: 0 additions & 2 deletions src/3d/shaders/pointcloud.frag
Expand Up @@ -83,8 +83,6 @@ vec4 exactColorRamp()
if ( abs( parameter - value ) < 0.01 )
return vec4( color, 1.0f );
}
// discard has a big performance hit because of the shader code taking different execution paths in the same warp
discard;
return vec4(0.0, 0.0, 0.0, 0.0f);
}

Expand Down
11 changes: 11 additions & 0 deletions src/3d/symbols/qgspointcloud3dsymbol.cpp
Expand Up @@ -455,6 +455,17 @@ void QgsClassificationPointCloud3DSymbol::setCategoriesList( const QgsPointCloud
mCategoriesList = categories;
}

QgsPointCloudCategoryList QgsClassificationPointCloud3DSymbol::getFilteredOutCategories() const
{
QgsPointCloudCategoryList filteredOut;
for ( QgsPointCloudCategory category : mCategoriesList )
{
if ( !category.renderState() )
filteredOut.push_back( category );
}
return filteredOut;
}

QgsColorRampShader QgsClassificationPointCloud3DSymbol::colorRampShader() const
{
QgsColorRampShader colorRampShader;
Expand Down
6 changes: 6 additions & 0 deletions src/3d/symbols/qgspointcloud3dsymbol.h
Expand Up @@ -406,6 +406,12 @@ class _3D_EXPORT QgsClassificationPointCloud3DSymbol : public QgsPointCloud3DSym
*/
void setCategoriesList( const QgsPointCloudCategoryList &categories );

/**
* Gets the list of categories of the classification that should not be rendered
* \see categoriesList() setCategoriesList()
*/
QgsPointCloudCategoryList getFilteredOutCategories() const;

unsigned int byteStride() override { return 4 * sizeof( float ); }
void fillMaterial( Qt3DRender::QMaterial *material ) override SIP_SKIP;

Expand Down
18 changes: 9 additions & 9 deletions src/3d/symbols/qgspointcloud3dsymbol_p.cpp
Expand Up @@ -608,20 +608,20 @@ void QgsClassificationPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex
QVector3D point( x, y, z );

QgsVector3D p = context.map().mapToWorldCoordinates( point );
outNormal.positions.push_back( QVector3D( p.x(), p.y(), p.z() ) );

float iParam = 0.0f;
if ( attrIsX )
outNormal.parameter.push_back( x );
iParam = x;
else if ( attrIsY )
outNormal.parameter.push_back( y );
iParam = y;
else if ( attrIsZ )
outNormal.parameter.push_back( z );
iParam = z;
else
{
float iParam = 0.0f;
context.getAttribute( ptr, i * recordSize + attributeOffset, attributeType, iParam );
outNormal.parameter.push_back( iParam );
}

if ( context.isFilteredOut( ( int ) iParam ) )
continue;
outNormal.positions.push_back( QVector3D( p.x(), p.y(), p.z() ) );
outNormal.parameter.push_back( iParam );
}
}

Expand Down

0 comments on commit 752c42c

Please sign in to comment.