Skip to content
Permalink
Browse files

Add classified renderer filtering behaviour

  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 4, 2021
1 parent 9ee8ec8 commit 2d274af355e39cd58d2487ca252ad460aeb2fea0
@@ -125,6 +125,8 @@ Constructor for QgsPointCloudClassifiedRenderer.

virtual void renderBlock( const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context );

virtual bool willRenderPoint( const QMap<QString, QString> &pointAttributes );

virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const;

virtual QSet< QString > usedAttributes( const QgsPointCloudRenderContext &context ) const;
@@ -199,6 +199,13 @@ and generate a proper subclass.
virtual void renderBlock( const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context ) = 0;
%Docstring
Renders a ``block`` of point cloud data using the specified render ``context``.
%End

virtual bool willRenderPoint( const QMap<QString, QString> &pointAttributes );
%Docstring
Checks whether the point holding ``pointAttributes`` attributes will be rendered
By default if not overriden in the subclass renderer will return true
( the renderer is responsible for the filtering behaviour )
%End

static QgsPointCloudRenderer *load( QDomElement &element, const QgsReadWriteContext &context ) /Factory/;
@@ -134,6 +134,22 @@ void QgsPointCloudClassifiedRenderer::renderBlock( const QgsPointCloudBlock *blo
context.incrementPointsRendered( rendered );
}

bool QgsPointCloudClassifiedRenderer::willRenderPoint( const QMap<QString, QString> &pointAttributes )
{
if ( !pointAttributes.contains( mAttribute ) )
return false;
QString attributeString = pointAttributes[ mAttribute ];
bool parsedCorrectly;
int attributeInt = attributeString.toInt( &parsedCorrectly );
if ( !parsedCorrectly )
return false;
for ( const QgsPointCloudCategory &category : qgis::as_const( mCategories ) )
{
if ( category.value() == attributeInt )
return category.renderState();
}
return false;
}

QgsPointCloudRenderer *QgsPointCloudClassifiedRenderer::create( QDomElement &element, const QgsReadWriteContext &context )
{
@@ -128,6 +128,7 @@ class CORE_EXPORT QgsPointCloudClassifiedRenderer : public QgsPointCloudRenderer
QString type() const override;
QgsPointCloudRenderer *clone() const override;
void renderBlock( const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context ) override;
bool willRenderPoint( const QMap<QString, QString> &pointAttributes ) override;
QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
QSet< QString > usedAttributes( const QgsPointCloudRenderContext &context ) const override;
QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) override SIP_FACTORY;
@@ -283,7 +283,8 @@ QVector<QMap<QString, QString>> QgsPointCloudLayerRenderer::identify( const QgsG
pointAttr[ attributeName ] = QString::number( val );
}

acceptedPoints.push_back( pointAttr );
if ( mRenderer->willRenderPoint( pointAttr ) )
acceptedPoints.push_back( pointAttr );
}
}
}
@@ -333,36 +334,5 @@ QVector<IndexedPointCloudNode> QgsPointCloudLayerRenderer::traverseTree( const Q
return nodes;
}

//QVector<IndexedPointCloudNode> QgsPointCloudLayerRenderer::traverseTree( const QgsPointCloudIndex *pc,
// const QgsRenderContext &context,
// IndexedPointCloudNode n,
// float maxErrorPixels,
// float nodeErrorPixels,
// const QgsGeometry &geom )
//{
// QVector<IndexedPointCloudNode> nodes;

// if ( !geom.intersects( pc->nodeMapExtent( n ) ) )
// return nodes;

// if ( !context.zRange().isInfinite() && !context.zRange().overlaps( pc->nodeZRange( n ) ) )
// return nodes;

// nodes.append( n );

// float childrenErrorPixels = nodeErrorPixels / 2.0f;
// if ( childrenErrorPixels < maxErrorPixels )
// return nodes;

// const QList<IndexedPointCloudNode> children = pc->nodeChildren( n );
// for ( const IndexedPointCloudNode &nn : children )
// {
// if ( geom.intersects( pc->nodeMapExtent( nn ) ) )
// nodes += traverseTree( pc, context, nn, maxErrorPixels, childrenErrorPixels, geom );
// }

// return nodes;
//}

QgsPointCloudLayerRenderer::~QgsPointCloudLayerRenderer() = default;

@@ -280,6 +280,17 @@ class CORE_EXPORT QgsPointCloudRenderer
*/
virtual void renderBlock( const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context ) = 0;

/**
* Checks whether the point holding \a pointAttributes attributes will be rendered
* By default if not overriden in the subclass renderer will return true
* ( the renderer is responsible for the filtering behaviour )
*/
virtual bool willRenderPoint( const QMap<QString, QString> &pointAttributes )
{
Q_UNUSED( pointAttributes );
return true;
}

/**
* Creates a renderer from an XML \a element.
*

0 comments on commit 2d274af

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