Skip to content

Commit

Permalink
remove render context from the provider code
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 4, 2021
1 parent 16a8ef5 commit 93e13e1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 87 deletions.
112 changes: 85 additions & 27 deletions src/core/pointcloud/qgspointclouddataprovider.cpp
Expand Up @@ -19,8 +19,6 @@
#include "qgspointclouddataprovider.h"
#include "qgspointcloudindex.h"
#include "qgsgeometry.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudlayerelevationproperties.h"
#include "qgspointcloudrequest.h"
#include "qgsgeometryengine.h"
#include <mutex>
Expand Down Expand Up @@ -183,33 +181,93 @@ QVariant QgsPointCloudDataProvider::metadataClassStatistic( const QString &, con
return QVariant();
}

static void _pointXY( QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y )
/**
* Retrieves the x & y values for the point at index \a i.
*/
static void _pointXY( const char *ptr, int i, int pointRecordSize, int xOffset, int yOffset, QgsVector3D indexScale, QgsVector3D indexOffset, double &x, double &y )
{
const qint32 ix = *reinterpret_cast< const qint32 * >( ptr + i * context.pointRecordSize() + context.xOffset() );
const qint32 iy = *reinterpret_cast< const qint32 * >( ptr + i * context.pointRecordSize() + context.yOffset() );
x = context.offset().x() + context.scale().x() * ix;
y = context.offset().y() + context.scale().y() * iy;
const qint32 ix = *reinterpret_cast< const qint32 * >( ptr + i * pointRecordSize + xOffset );
const qint32 iy = *reinterpret_cast< const qint32 * >( ptr + i * pointRecordSize + yOffset );
x = indexOffset.x() + indexScale.x() * ix;
y = indexOffset.y() + indexScale.y() * iy;
}

/**
* Retrieves the z value for the point at index \a i.
*/
static double _pointZ( QgsPointCloudRenderContext &context, const char *ptr, int i )
* Retrieves the z value for the point at index \a i.
*/
static double _pointZ( const char *ptr, int i, int pointRecordSize, int zOffset, QgsVector3D indexScale, QgsVector3D indexOffset )
{
const qint32 iz = *reinterpret_cast<const qint32 * >( ptr + i * context.pointRecordSize() + context.zOffset() );
return context.offset().z() + context.scale().z() * iz;
const qint32 iz = *reinterpret_cast<const qint32 * >( ptr + i * pointRecordSize + zOffset );
return indexOffset.z() + indexScale.z() * iz;
}

/**
* Retrieves all the attributes of a point
*/
QMap<QString, QVariant> _attributeMap( const char *data, std::size_t recordOffset, const QgsPointCloudAttributeCollection &attributeCollection )
{
QMap<QString, QVariant> map;
for ( QgsPointCloudAttribute attr : attributeCollection.attributes() )
{
QString attributeName = attr.name();
int attributeOffset;
attributeCollection.find( attributeName, attributeOffset );
switch ( attr.type() )
{
case QgsPointCloudAttribute::Char:
{
const char value = *( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Int32:
{
const qint32 value = *reinterpret_cast< const qint32 * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Short:
{
const short value = *reinterpret_cast< const short * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::UShort:
{
const unsigned short value = *reinterpret_cast< const unsigned short * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Float:
{
const float value = *reinterpret_cast< const float * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Double:
{
const double value = *reinterpret_cast< const double * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;
}
}
return map;
}

struct MapIndexedPointCloudNode
{
typedef QVector<QMap<QString, QVariant>> result_type;

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

}
: mRequest( request ), mIndexScale( indexScale ), mIndexOffset( indexOffset ), mExtentGeometry( extentGeometry ), mZRange( zRange ), mIndex( index ), mPointsLimit( pointsLimit )
{ }

QVector<QMap<QString, QVariant>> operator()( const IndexedPointCloudNode &n )
{
Expand All @@ -222,19 +280,22 @@ struct MapIndexedPointCloudNode
const char *ptr = block->data();
QgsPointCloudAttributeCollection blockAttributes = block->attributes();
const std::size_t recordSize = blockAttributes.pointRecordSize();
mContext.setAttributes( block->attributes() );
int xOffset, yOffset, zOffset;
blockAttributes.find( QStringLiteral( "X" ), xOffset );
blockAttributes.find( QStringLiteral( "Y" ), yOffset );
blockAttributes.find( QStringLiteral( "Z" ), zOffset );
std::unique_ptr< QgsGeometryEngine > extentEngine( QgsGeometry::createGeometryEngine( mExtentGeometry.constGet() ) );
extentEngine->prepareGeometry();
for ( int i = 0; i < block->pointCount(); ++i )
{
double x, y, z;
_pointXY( mContext, ptr, i, x, y );
z = _pointZ( mContext, ptr, i );
_pointXY( ptr, i, recordSize, xOffset, yOffset, mIndexScale, mIndexOffset, x, y );
z = _pointZ( ptr, i, recordSize, zOffset, mIndexScale, mIndexOffset );
QgsPoint pointXY( x, y );

if ( pointsCount < mPointsLimit && extentEngine->contains( &pointXY ) && mZRange.contains( z ) )
{
QMap<QString, QVariant> pointAttr = mContext.attributeMap( ptr, i * recordSize, blockAttributes );
QMap<QString, QVariant> pointAttr = _attributeMap( ptr, i * recordSize, blockAttributes );
pointAttr[ QStringLiteral( "X" ) ] = x;
pointAttr[ QStringLiteral( "Y" ) ] = y;
pointAttr[ QStringLiteral( "Z" ) ] = z;
Expand All @@ -246,7 +307,8 @@ struct MapIndexedPointCloudNode
};

QgsPointCloudRequest &mRequest;
QgsPointCloudRenderContext &mContext;
QgsVector3D mIndexScale;
QgsVector3D mIndexOffset;
QgsGeometry &mExtentGeometry;
const QgsDoubleRange &mZRange;
QgsPointCloudIndex *mIndex = nullptr;
Expand All @@ -264,8 +326,6 @@ QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
QgsPointCloudIndex *index = this->index();
const IndexedPointCloudNode root = index->root();

QgsRenderContext renderContext;

QgsRectangle rootNodeExtentMapCoords = index->nodeMapExtent( root );
// TODO? reproject the root node extent
// try
Expand All @@ -284,10 +344,8 @@ QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
QgsPointCloudRequest request;
request.setAttributes( attributeCollection );

QgsPointCloudRenderContext context( renderContext, index->scale(), index->offset(), 1.0, 0.0 );

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

Expand Down
3 changes: 0 additions & 3 deletions src/core/pointcloud/qgspointclouddataprovider.h
Expand Up @@ -22,11 +22,8 @@
#include "qgsdataprovider.h"
#include "qgspointcloudattribute.h"
#include "qgsstatisticalsummary.h"
#include "qgspointcloudrenderer.h"
#include "qgsidentifycontext.h"
#include <memory>

class QgsPointCloudLayer;
class IndexedPointCloudNode;
class QgsPointCloudIndex;
class QgsPointCloudRenderer;
Expand Down
57 changes: 0 additions & 57 deletions src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -190,63 +190,6 @@ class CORE_EXPORT QgsPointCloudRenderContext
return;
}
}

//! Returns a map containing the attributes of a certain point from the point cloud
QMap<QString, QVariant> attributeMap( const char *data, std::size_t recordOffset, const QgsPointCloudAttributeCollection &attributeCollection )
{
QMap<QString, QVariant> map;
for ( QgsPointCloudAttribute attr : attributeCollection.attributes() )
{
QString attributeName = attr.name();
int attributeOffset;
attributeCollection.find( attributeName, attributeOffset );
switch ( attr.type() )
{
case QgsPointCloudAttribute::Char:
{
const char value = *( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Int32:
{
const qint32 value = *reinterpret_cast< const qint32 * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Short:
{
const short value = *reinterpret_cast< const short * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::UShort:
{
const unsigned short value = *reinterpret_cast< const unsigned short * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Float:
{
const float value = *reinterpret_cast< const float * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;

case QgsPointCloudAttribute::Double:
{
const double value = *reinterpret_cast< const double * >( data + recordOffset + attributeOffset );
map[ attributeName ] = value;
}
break;
}
}
return map;
}
#endif

private:
Expand Down

0 comments on commit 93e13e1

Please sign in to comment.