Skip to content
Permalink
Browse files

Add returned point clouds limit

  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 4, 2021
1 parent 87280a9 commit 6a0e0188aea66d5ba69863fa1037259366b9628c
@@ -206,8 +206,8 @@ struct MapIndexedPointCloudNode
typedef QVector<QMap<QString, QVariant>> result_type;

MapIndexedPointCloudNode( QgsPointCloudRequest &request, QgsPointCloudRenderContext &context,
QgsGeometry &extentGeometry, const QgsDoubleRange &zRange, QgsPointCloudIndex *index )
: mRequest( request ), mContext( context ), mExtentGeometry( extentGeometry ), mZRange( zRange ), mIndex( index )
QgsGeometry &extentGeometry, const QgsDoubleRange &zRange, QgsPointCloudIndex *index, int pointsLimit )
: mRequest( request ), mContext( context ), mExtentGeometry( extentGeometry ), mZRange( zRange ), mIndex( index ), mPointsLimit( pointsLimit )
{

}
@@ -217,7 +217,7 @@ struct MapIndexedPointCloudNode
QVector<QMap<QString, QVariant>> acceptedPoints;
std::unique_ptr<QgsPointCloudBlock> block( mIndex->nodeData( n, mRequest ) );

if ( !block )
if ( !block || pointsCount == mPointsLimit )
return acceptedPoints;

const char *ptr = block->data();
@@ -231,12 +231,13 @@ struct MapIndexedPointCloudNode
z = _pointZ( mContext, ptr, i );
QgsPointXY pointXY( x, y );

if ( mExtentGeometry.contains( &pointXY ) && mZRange.contains( z ) )
if ( pointsCount < mPointsLimit && mExtentGeometry.contains( &pointXY ) && mZRange.contains( z ) )
{
QMap<QString, QVariant> pointAttr = mContext.attributeMap( ptr, i * recordSize, blockAttributes );
pointAttr[ QStringLiteral( "X" ) ] = x;
pointAttr[ QStringLiteral( "Y" ) ] = y;
pointAttr[ QStringLiteral( "Z" ) ] = z;
pointsCount++;
acceptedPoints.push_back( pointAttr );
}
}
@@ -248,12 +249,14 @@ struct MapIndexedPointCloudNode
QgsGeometry &mExtentGeometry;
const QgsDoubleRange &mZRange;
QgsPointCloudIndex *mIndex = nullptr;
int mPointsLimit;
int pointsCount = 0;
};

QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
float maxErrorInMapCoords,
QgsGeometry extentGeometry,
const QgsDoubleRange extentZRange )
const QgsDoubleRange extentZRange, int pointsLimit )
{
QVector<QMap<QString, QVariant>> acceptedPoints;

@@ -283,7 +286,7 @@ QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
QgsPointCloudRenderContext context( renderContext, index->scale(), index->offset(), 1.0, 0.0 );

acceptedPoints = QtConcurrent::blockingMappedReduced( nodes,
MapIndexedPointCloudNode( request, context, extentGeometry, extentZRange, index ),
MapIndexedPointCloudNode( request, context, extentGeometry, extentZRange, index, pointsLimit ),
qgis::overload<const QVector<QMap<QString, QVariant>>&>::of( &QVector<QMap<QString, QVariant>>::append ),
QtConcurrent::UnorderedReduce );

@@ -80,14 +80,15 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
/**
* Returns the list of points of the point cloud according to a zoom level
* defined by \a maxErrorInMapCoords, an extent \a geometry in the 2D plane
* and a range \a extentZRange for z values
* and a range \a extentZRange for z values. The function will try to limit
* the number of points returned to \a pointsLimit points
*
* \a maxErrorPixels : maximum accepted error factor in pixels
*
* \note this function does not handle elevation properties and you need to
* change elevation coordinates yourself after returning from the function
*/
QVector<QMap<QString, QVariant>> identify( float maxErrorInMapCoords, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange ) SIP_SKIP;
QVector<QMap<QString, QVariant>> identify( float maxErrorInMapCoords, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange, int pointsLimit = 1000 ) SIP_SKIP;

/**
* Returns flags containing the supported capabilities for the data provider.
@@ -256,11 +256,11 @@ QVector<QMap<QString, QVariant>> QgsPointCloudRenderer::identify( QgsPointCloudL
}
}

QVector<QMap<QString, QVariant>> points = layer->dataProvider()->identify( maxErrorInMapCoordinates, selectionGeometry, QgsDoubleRange() );
selectedPoints = layer->dataProvider()->identify( maxErrorInMapCoordinates, selectionGeometry, QgsDoubleRange() );

points.erase( std::remove_if( points.begin(), points.end(), [this]( const QMap<QString, QVariant> &point ) { return !this->willRenderPoint( point ); } ), points.end() );
selectedPoints.erase( std::remove_if( selectedPoints.begin(), selectedPoints.end(), [this]( const QMap<QString, QVariant> &point ) { return !this->willRenderPoint( point ); } ), selectedPoints.end() );

return points;
return selectedPoints;
}


0 comments on commit 6a0e018

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