Skip to content
Permalink
Browse files

remove layer and elevation properties

  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 4, 2021
1 parent ef9d272 commit 8ec26000b4a02cd6f06224380c61bc19e45c8f2e
@@ -201,11 +201,6 @@ and generate a proper subclass.
Renders a ``block`` of point cloud data using the specified render ``context``.
%End

QVector<QMap<QString, QVariant>> identify( QgsPointCloudLayer *layer, QgsRenderContext context, const QgsGeometry &geometry );
%Docstring
Returns the list of points of the point cloud layer ``layer`` and an extent defined by
a geometry in the 2D plane ``geometry`` and a range for z values ``extentZRange``
%End

virtual bool willRenderPoint( const QMap<QString, QVariant> &pointAttributes );
%Docstring
@@ -183,8 +183,7 @@ QVariant QgsPointCloudDataProvider::metadataClassStatistic( const QString &, con
}

QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
QgsPointCloudLayer *layer,
float maximumError,
float maxErrorPixels,
float rootErrorPixels,
QgsGeometry extentGeometry,
const QgsDoubleRange extentZRange )
@@ -194,17 +193,15 @@ QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
QgsPointCloudIndex *index = this->index();
const IndexedPointCloudNode root = index->root();


QgsPointCloudLayerElevationProperties *properties = dynamic_cast<QgsPointCloudLayerElevationProperties *>( layer->elevationProperties() );
QgsRenderContext renderContext;

QVector<IndexedPointCloudNode> nodes = traverseTree( index, root, maximumError, rootErrorPixels, extentGeometry, extentZRange );
QVector<IndexedPointCloudNode> nodes = traverseTree( index, root, maxErrorPixels, rootErrorPixels, extentGeometry, extentZRange );

QgsPointCloudAttributeCollection attributeCollection = index->attributes();
QgsPointCloudRequest request;
request.setAttributes( attributeCollection );

QgsPointCloudRenderContext context( renderContext, index->scale(), index->offset(), properties->zScale(), properties->zOffset() );
QgsPointCloudRenderContext context( renderContext, index->scale(), index->offset(), 1.0, 0.0 );
int pointCount = 0;

for ( const IndexedPointCloudNode &n : nodes )
@@ -79,10 +79,16 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider

/**
* Returns the list of points of the point cloud layer \a layer according to a zoom level
* defined by \a maximumError and \a rootErrorPixels, and an extent defined by a geometry
* defined by \a maxErrorPixels and \a rootErrorPixels, and an extent defined by a geometry
* in the 2D plane \a geometry and a range for z values \a extentZRange
*
* \a maxErrorPixels : maximum accepted error factor in pixels
* \a rootErrorPixels : the root node error factor in pixels
*
* \note this function does not handle elevation properties and you need to change it yourself
* after returning from the function
*/
QVector<QMap<QString, QVariant>> identify( QgsPointCloudLayer *layer, float maximumError, float rootErrorPixels, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange ) SIP_SKIP;
QVector<QMap<QString, QVariant>> identify( float maxErrorPixels, float rootErrorPixels, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange ) SIP_SKIP;

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

QgsPointCloudIndex *index = layer->dataProvider()->index();
const IndexedPointCloudNode root = index->root();
QgsPointCloudLayerElevationProperties *properties = dynamic_cast<QgsPointCloudLayerElevationProperties *>( layer->elevationProperties() );
QgsPointCloudRenderContext context( renderContext, index->scale(), index->offset(), properties->zScale(), properties->zOffset() );

const float maximumError = context.renderContext().convertToPainterUnits( maximumScreenError(), maximumScreenErrorUnit() );// in pixels
const float maxErrorPixels = renderContext.convertToPainterUnits( maximumScreenError(), maximumScreenErrorUnit() );// in pixels

const QgsRectangle rootNodeExtentLayerCoords = index->nodeMapExtent( root );
QgsRectangle rootNodeExtentMapCoords;
QgsRectangle rootNodeExtentMapCoords = index->nodeMapExtent( root );
try
{
rootNodeExtentMapCoords = context.renderContext().coordinateTransform().transformBoundingBox( rootNodeExtentLayerCoords );
rootNodeExtentMapCoords = renderContext.coordinateTransform().transformBoundingBox( index->nodeMapExtent( root ) );
}
catch ( QgsCsException & )
{
QgsDebugMsg( QStringLiteral( "Could not transform node extent to map CRS" ) );
rootNodeExtentMapCoords = rootNodeExtentLayerCoords;
}
//

const float rootErrorInMapCoordinates = rootNodeExtentMapCoords.width() / index->span(); // in map coords

double mapUnitsPerPixel = context.renderContext().mapToPixel().mapUnitsPerPixel();
if ( ( rootErrorInMapCoordinates < 0.0 ) || ( mapUnitsPerPixel < 0.0 ) || ( maximumError < 0.0 ) )
double mapUnitsPerPixel = renderContext.mapToPixel().mapUnitsPerPixel();
if ( ( rootErrorInMapCoordinates < 0.0 ) || ( mapUnitsPerPixel < 0.0 ) || ( maxErrorPixels < 0.0 ) )
{
QgsDebugMsg( QStringLiteral( "invalid screen error" ) );
return selectedPoints;
@@ -236,22 +233,22 @@ QVector<QMap<QString, QVariant>> QgsPointCloudRenderer::identify( QgsPointCloudL
double y = geometry.asPoint().y();
if ( pointSymbol() == QgsPointCloudRenderer::PointSymbol::Square )
{
QgsPointXY deviceCoords = context.renderContext().mapToPixel().transform( QgsPointXY( x, y ) );
QgsPointXY deviceCoords = renderContext.mapToPixel().transform( QgsPointXY( x, y ) );
QgsPointXY point1( deviceCoords.x() - 2 * pointSize(), deviceCoords.y() - 2 * pointSize() );
QgsPointXY point2( deviceCoords.x() + 2 * pointSize(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsRectangle pointRect( point1MapCoords, point2MapCoords );
selectionGeometry = QgsGeometry::fromRect( pointRect );
}
else if ( pointSymbol() == QgsPointCloudRenderer::PointSymbol::Circle )
{
QgsPoint centerMapCoords( x, y );
QgsPointXY deviceCoords = context.renderContext().mapToPixel().transform( centerMapCoords );
QgsPointXY deviceCoords = renderContext.mapToPixel().transform( centerMapCoords );
QgsPoint point1( deviceCoords.x(), deviceCoords.y() - 2 * pointSize() );
QgsPoint point2( deviceCoords.x(), deviceCoords.y() + 2 * pointSize() );
QgsPointXY point1MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = context.renderContext().mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
QgsCircle circle = QgsCircle::from2Points( QgsPoint( point1MapCoords ), QgsPoint( point2MapCoords ) );
// TODO: make this faster?
QgsPolygon *polygon = circle.toPolygon( 5 );
@@ -260,15 +257,9 @@ QVector<QMap<QString, QVariant>> QgsPointCloudRenderer::identify( QgsPointCloudL
}
}

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

for ( QMap<QString, QVariant> point : points )
{
if ( this->willRenderPoint( point ) )
selectedPoints.push_back( point );
}

return selectedPoints;
QVector<QMap<QString, QVariant>> points = layer->dataProvider()->identify( maxErrorPixels, rootErrorPixels, selectionGeometry, QgsDoubleRange() );
points.erase( std::remove_if( points.begin(), points.end(), [this]( const QMap<QString, QVariant> &point ) { return !this->willRenderPoint( point ); } ), points.end() );
return points;
}


@@ -342,7 +342,7 @@ class CORE_EXPORT QgsPointCloudRenderer
* Returns the list of points of the point cloud layer \a layer and an extent defined by
* a geometry in the 2D plane \a geometry and a range for z values \a extentZRange
*/
QVector<QMap<QString, QVariant>> identify( QgsPointCloudLayer *layer, QgsRenderContext context, const QgsGeometry &geometry );
QVector<QMap<QString, QVariant>> identify( QgsPointCloudLayer *layer, QgsRenderContext context, const QgsGeometry &geometry ) SIP_SKIP;

/**
* Checks whether the point holding \a pointAttributes attributes will be rendered
@@ -53,6 +53,7 @@
#include "qgspointcloudlayer.h"
#include "qgspointcloudrenderer.h"
#include "qgspointcloudlayerrenderer.h"
#include "qgspointcloudlayerelevationproperties.h"

#include <QMouseEvent>
#include <QCursor>
@@ -519,8 +520,11 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::Iden
QgsRenderContext context = QgsRenderContext::fromMapSettings( mCanvas->mapSettings() );
QVector<QMap<QString, QVariant>> points = renderer->identify( layer, context, transformedGeometry );
int id = 0;
QgsPointCloudLayerElevationProperties *elevationProps = dynamic_cast<QgsPointCloudLayerElevationProperties *>( layer->elevationProperties() );
for ( QMap<QString, QVariant> pt : points )
{
// Apply elevation properties
pt["Z"] = pt["Z"].toReal() * elevationProps->zScale() + elevationProps->zOffset();
// TODO: replace this conversion with something better
QMap<QString, QString> ptStr;
for ( QString key : pt.keys() )

0 comments on commit 8ec2600

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