QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
18 #include <QElapsedTimer>
41 , mLayerAttributes( layer->attributes() )
59 mZOffset = elevationProps->zOffset();
60 mZScale = elevationProps->zScale();
80 if ( !mClippingRegions.empty() )
82 bool needsPainterClipPath =
false;
84 if ( needsPainterClipPath )
88 if ( mRenderer->type() == QLatin1String(
"extent" ) )
91 mRenderer->startRender( context );
93 mRenderer->stopRender( context );
110 mBlockRenderUpdates =
true;
111 mElapsedTimer.start();
114 mRenderer->startRender( context );
125 QSet< QString > rendererAttributes = mRenderer->usedAttributes( context );
128 for (
const QString &attribute : std::as_const( rendererAttributes ) )
130 if ( mAttributes.
indexOf( attribute ) >= 0 )
133 const int layerIndex = mLayerAttributes.
indexOf( attribute );
134 if ( layerIndex < 0 )
136 QgsMessageLog::logMessage( QObject::tr(
"Required attribute %1 not found in layer" ).arg( attribute ), QObject::tr(
"Point Cloud" ) );
140 mAttributes.
push_back( mLayerAttributes.
at( layerIndex ) );
166 QgsDebugMsg( QStringLiteral(
"Could not transform node extent to map CRS" ) );
167 rootNodeExtentMapCoords = rootNodeExtentLayerCoords;
172 rootNodeExtentMapCoords = rootNodeExtentLayerCoords;
175 const double rootErrorInMapCoordinates = rootNodeExtentMapCoords.
width() / pc->
span();
178 if ( ( rootErrorInMapCoordinates < 0.0 ) || ( mapUnitsPerPixel < 0.0 ) || ( maximumError < 0.0 ) )
180 QgsDebugMsg( QStringLiteral(
"invalid screen error" ) );
184 double rootErrorPixels = rootErrorInMapCoordinates / mapUnitsPerPixel;
185 const QVector<IndexedPointCloudNode> nodes = traverseTree( pc, context.
renderContext(), pc->
root(), maximumError, rootErrorPixels );
192 bool canceled =
false;
194 switch ( mRenderer->drawOrder2d() )
199 nodesDrawn += renderNodesSorted( nodes, pc, context, request, canceled, mRenderer->drawOrder2d() );
206 case QgsPointCloudIndex::AccessType::Local:
208 nodesDrawn += renderNodesSync( nodes, pc, context, request, canceled );
211 case QgsPointCloudIndex::AccessType::Remote:
213 nodesDrawn += renderNodesAsync( nodes, pc, context, request, canceled );
221 QgsDebugMsgLevel( QStringLiteral(
"totals: %1 nodes | %2 points | %3ms" ).arg( nodesDrawn )
223 .arg( t.elapsed() ), 2 );
228 mRenderer->stopRender( context );
245 std::unique_ptr<QgsPointCloudBlock> block( pc->
nodeData( n, request ) );
258 mRenderer->renderBlock( block.get(), context );
284 QVector<QgsPointCloudBlockRequest *> blockRequests;
289 for (
int i = 0; i < nodes.size(); ++i )
294 blockRequests.append( blockRequest );
296 [
this, &canceled, &nodesDrawn, &loop, &blockRequests, &context, nStr, blockRequest ]()
298 blockRequests.removeOne( blockRequest );
301 if ( blockRequests.isEmpty() )
304 std::unique_ptr<QgsPointCloudBlock> block( blockRequest->
block() );
306 blockRequest->deleteLater();
316 QgsDebugMsg( QStringLiteral(
"Unable to load node %1, error: %2" ).arg( nStr, blockRequest->
errorStr() ) );
327 mRenderer->renderBlock( block.get(), context );
352 delete blockRequest->
block();
353 blockRequest->deleteLater();
370 QByteArray allByteArrays;
372 QVector<QPair<int, double>> allPairs;
382 std::unique_ptr<QgsPointCloudBlock> block( pc->
nodeData( n, request ) );
390 if ( blockCount == 0 )
392 blockScale = block->scale();
393 blockOffset = block->offset();
398 offsetDifference = blockOffset - block->offset();
401 const char *ptr = block->data();
409 for (
int i = 0; i < block->pointCount(); ++i )
411 allByteArrays.append( ptr + i * recordSize, recordSize );
414 if ( offsetDifference.
x() != 0 )
416 qint32 ix = *
reinterpret_cast< const qint32 *
>( ptr + i * recordSize + context.
xOffset() );
417 ix -= std::lround( offsetDifference.
x() / context.
scale().
x() );
418 const char *xPtr =
reinterpret_cast< const char *
>( &ix );
419 allByteArrays.replace( pointCount * recordSize + context.
xOffset(), 4, QByteArray( xPtr, 4 ) );
421 if ( offsetDifference.
y() != 0 )
423 qint32 iy = *
reinterpret_cast< const qint32 *
>( ptr + i * recordSize + context.
yOffset() );
424 iy -= std::lround( offsetDifference.
y() / context.
scale().
y() );
425 const char *yPtr =
reinterpret_cast< const char *
>( &iy );
426 allByteArrays.replace( pointCount * recordSize + context.
yOffset(), 4, QByteArray( yPtr, 4 ) );
429 qint32 iz = *
reinterpret_cast< const qint32 *
>( ptr + i * recordSize + context.
zOffset() );
430 if ( offsetDifference.
z() != 0 )
432 iz -= std::lround( offsetDifference.
z() / context.
scale().
z() );
433 const char *zPtr =
reinterpret_cast< const char *
>( &iz );
434 allByteArrays.replace( pointCount * recordSize + context.
zOffset(), 4, QByteArray( zPtr, 4 ) );
436 allPairs.append( qMakePair( pointCount,
double( iz ) + block->offset().z() ) );
443 if ( pointCount == 0 )
449 std::sort( allPairs.begin(), allPairs.end(), []( QPair<int, double> a, QPair<int, double> b ) { return a.second < b.second; } );
452 std::sort( allPairs.begin(), allPairs.end(), []( QPair<int, double> a, QPair<int, double> b ) { return a.second > b.second; } );
459 QByteArray sortedByteArray;
460 sortedByteArray.reserve( allPairs.size() );
461 for ( QPair<int, double> pair : allPairs )
462 sortedByteArray.append( allByteArrays.mid( pair.first * recordSize, recordSize ) );
473 context.
setScale( bigBlock->scale() );
477 mRenderer->renderBlock( bigBlock.get(), context );
489 return mRenderer ? mRenderer->type() != QLatin1String(
"extent" ) :
false;
494 mRenderTimeHint = time;
497 QVector<IndexedPointCloudNode> QgsPointCloudLayerRenderer::traverseTree(
const QgsPointCloudIndex *pc,
500 double maxErrorPixels,
501 double nodeErrorPixels )
503 QVector<IndexedPointCloudNode> nodes;
521 double childrenErrorPixels = nodeErrorPixels / 2.0;
522 if ( childrenErrorPixels < maxErrorPixels )
525 const QList<IndexedPointCloudNode> children = pc->
nodeChildren( n );
528 nodes += traverseTree( pc, context, nn, maxErrorPixels, childrenErrorPixels );
bool intersects(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle intersects with other rectangle.
static QList< QgsMapClippingRegion > collectClippingRegionsForLayer(const QgsRenderContext &context, const QgsMapLayer *layer)
Collects the list of map clipping regions from a context which apply to a map layer.
QgsRectangle nodeMapExtent(const IndexedPointCloudNode &node) const
Returns the extent of a node in map coordinates.
bool render() override
Do the rendering (based on data stored in the class).
QgsVector3D offset() const
Returns offset.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
QgsPointCloudBlock * block()
Returns the requested block.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
double mapUnitsPerPixel() const
Returns the current map units per pixel.
virtual QgsPointCloudBlock * nodeData(const IndexedPointCloudNode &n, const QgsPointCloudRequest &request)=0
Returns node data block.
bool overlaps(const QgsRange< T > &other) const
Returns true if this range overlaps another range.
#define QgsDebugMsgLevel(str, level)
double y() const
Returns Y coordinate.
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
Represents a map layer supporting display of point clouds.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
void canceled()
Internal routines can connect to this signal if they use event loop.
virtual QList< IndexedPointCloudNode > nodeChildren(const IndexedPointCloudNode &n) const
Returns all children of node.
const QgsPointCloudAttribute & at(int index) const
Returns the attribute at the specified index.
A renderer for 2d visualisation of point clouds which shows the dataset's extents using a fill symbol...
void setScale(const QgsVector3D &scale)
Sets the scale of the layer's int32 coordinates compared to CRS coords.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
Contains information about the context of a rendering operation.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
virtual QgsPointCloudRenderer * clone() const =0
Create a deep copy of this renderer.
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
Base class for storing raw data from point cloud nodes.
QgsPointCloudRenderer * renderer()
Returns the 2D renderer for the point cloud.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
virtual bool isValid() const =0
Returns whether index is loaded and valid.
@ TopToBottom
Draw points with larger Z values first.
A rectangle specified with double values.
virtual AccessType accessType() const =0
Returns the access type of the data If the access type is Remote, data will be fetched from an HTTP s...
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Point cloud data request.
int xOffset() const
Returns the offset for the x value in a point record.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
QgsPointCloudDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Represents a indexed point cloud node in octree.
Custom exception class for Coordinate Reference System related exceptions.
T lower() const
Returns the lower bound of the range.
virtual QgsGeometry polygonBounds() const
Returns the polygon bounds of the layer.
QVector< QgsPointCloudAttribute > attributes() const
Returns all attributes.
Encapsulates the render context for a 2D point cloud rendering operation.
double z() const
Returns Z coordinate.
@ BottomToTop
Draw points with larger Z values last.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets the attributes associated with the rendered block.
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, QgsMapLayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
T upper() const
Returns the upper bound of the range.
Collection of point cloud attributes.
~QgsPointCloudLayerRenderer()
QgsPointCloudLayerRenderer(QgsPointCloudLayer *layer, QgsRenderContext &context)
Ctor.
int yOffset() const
Returns the offset for the y value in a point record.
QgsVector3D offset() const
Returns the offset of the layer's int32 coordinates compared to CRS coords.
QgsVector3D scale() const
Returns scale.
QString errorStr()
Returns the error message string of the request.
int zOffset() const
Returns the offset for the y value in a point record.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
PointCloudDrawOrder
Pointcloud rendering order for 2d views.
IndexedPointCloudNode root()
Returns root node of the index.
Attribute for point cloud data pair of name and size in bytes.
Scoped object for saving and restoring a QPainter object's state.
QgsFeedback * feedback() const
Returns the feedback object used to cancel rendering.
bool isInfinite() const
Returns true if the range consists of all possible values.
int indexOf(const QString &name) const
Returns the index of the attribute with the specified name.
void setLayerRenderingTimeHint(int time) override
Sets approximate render time (in ms) for the layer to render.
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
virtual QgsPointCloudBlockRequest * asyncNodeData(const IndexedPointCloudNode &n, const QgsPointCloudRequest &request)=0
Returns a handle responsible for loading a node data block.
QgsRange which stores a range of double values.
@ Default
Draw points in the order they are stored.
Base class for handling loading QgsPointCloudBlock asynchronously.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
QgsVector3D scale() const
Returns the scale of the layer's int32 coordinates compared to CRS coords.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Set attributes filter in the request.
Represents packaged data bounds.
int pointRecordSize() const
Returns the size of a single point record.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
void setOffset(const QgsVector3D &offset)
Sets the offset of the layer's int32 coordinates compared to CRS coords.
void finished()
Emitted when the request processing has finished.
int span() const
Returns the number of points in one direction in a single node.
long pointsRendered() const
Returns the total number of points rendered.
Represents a indexed point clouds data in octree.
QString toString() const
Encode node to string.
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
static constexpr int MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE
Maximum time (in ms) to allow display of a previously cached preview image while rendering layers,...
QPainter * painter()
Returns the destination QPainter for the render operation.
void push_back(const QgsPointCloudAttribute &attribute)
Adds extra attribute.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
double x() const
Returns X coordinate.
QgsDoubleRange nodeZRange(const IndexedPointCloudNode &node) const
Returns the z range of a node.
virtual QgsPointCloudIndex * index() const
Returns the point cloud index associated with the provider.