QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgspointcloudrenderer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspointcloudrenderer.h
3 --------------------
4 begin : October 2020
5 copyright : (C) 2020 by Peter Petrik
6 email : zilolv at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSPOINTCLOUDRENDERER_H
19#define QGSPOINTCLOUDRENDERER_H
20
21#include "qgsrendercontext.h"
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
25#include "qgsvector3d.h"
27#include "qgselevationmap.h"
28
33class QgsElevationMap;
34
44{
45 public:
46
59 QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset,
60 double zValueScale, double zValueFixedOffset, QgsFeedback *feedback = nullptr );
61
64
67
71 QgsRenderContext &renderContext() { return mRenderContext; }
72
77 const QgsRenderContext &renderContext() const { return mRenderContext; } SIP_SKIP
78
82 QgsVector3D scale() const { return mScale; }
83
88 void setScale( const QgsVector3D &scale ) { mScale = scale; }
89
93 QgsVector3D offset() const { return mOffset; }
94
99 void setOffset( const QgsVector3D &offset ) { mOffset = offset; }
100
104 long pointsRendered() const;
105
112 void incrementPointsRendered( long count );
113
119 QgsPointCloudAttributeCollection attributes() const { return mAttributes; }
120
126 void setAttributes( const QgsPointCloudAttributeCollection &attributes );
127
131 int pointRecordSize() const { return mPointRecordSize; }
132
139 int xOffset() const { return mXOffset; }
140
147 int yOffset() const { return mYOffset; }
148
155 int zOffset() const { return mZOffset; }
156
162 double zValueScale() const { return mZValueScale; }
163
169 double zValueFixedOffset() const { return mZValueFixedOffset; }
170
176 QgsFeedback *feedback() const { return mFeedback; }
177
178#ifndef SIP_RUN // intentionally left out from SIP to avoid API breaks in future when we move elevation post-processing elsewhere
179
186 void setElevationMap( QgsElevationMap *elevationMap SIP_TRANSFER );
187
193 QgsElevationMap *elevationMap() { return mElevationMap.get(); }
194#endif
195
196#ifndef SIP_RUN
197
202 template <typename T>
203 static void getAttribute( const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value )
204 {
205 switch ( type )
206 {
208 value = *reinterpret_cast< const unsigned char * >( data + offset );
209 return;
211 value = *( data + offset );
212 return;
213
215 value = *reinterpret_cast< const quint32 * >( data + offset );
216 return;
218 value = *reinterpret_cast< const qint32 * >( data + offset );
219 return;
220
222 value = *reinterpret_cast< const quint64 * >( data + offset );
223 return;
225 value = *reinterpret_cast< const qint64 * >( data + offset );
226 return;
227
229 value = *reinterpret_cast< const short * >( data + offset );
230 return;
231
233 value = *reinterpret_cast< const unsigned short * >( data + offset );
234 return;
235
237 value = *reinterpret_cast< const float * >( data + offset );
238 return;
239
241 value = *reinterpret_cast< const double * >( data + offset );
242 return;
243 }
244 }
245#endif
246
247 private:
248#ifdef SIP_RUN
250#endif
251
252 QgsRenderContext &mRenderContext;
253 QgsVector3D mScale;
254 QgsVector3D mOffset;
255 long mPointsRendered = 0;
257 int mPointRecordSize = 0;
258 int mXOffset = 0;
259 int mYOffset = 0;
260 int mZOffset = 0;
261 double mZValueScale = 1.0;
262 double mZValueFixedOffset = 0;
263 std::unique_ptr<QgsElevationMap> mElevationMap;
264
265 QgsFeedback *mFeedback = nullptr;
266};
267
268#ifndef SIP_RUN
269
280{
281 public:
282
284
288 virtual QSet< QString > usedAttributes() const = 0;
289
295 virtual bool prepareBlock( const QgsPointCloudBlock *block ) = 0;
296
304 virtual QColor pointColor( const QgsPointCloudBlock *block, int i, double z ) = 0;
305
306};
307
308#endif
309
310
319class CORE_EXPORT QgsPointCloudRenderer
320{
321
322#ifdef SIP_RUN
324
325 const QString type = sipCpp->type();
326
327 if ( type == QLatin1String( "rgb" ) )
328 sipType = sipType_QgsPointCloudRgbRenderer;
329 else if ( type == QLatin1String( "ramp" ) )
330 sipType = sipType_QgsPointCloudAttributeByRampRenderer;
331 else if ( type == QLatin1String( "classified" ) )
332 sipType = sipType_QgsPointCloudClassifiedRenderer;
333 else if ( type == QLatin1String( "extent" ) )
334 sipType = sipType_QgsPointCloudExtentRenderer;
335 else
336 sipType = 0;
337 SIP_END
338#endif
339
340 public:
341
346
347 virtual ~QgsPointCloudRenderer() = default;
348
352 virtual QString type() const = 0;
353
359
362
365
369 virtual void renderBlock( const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context ) = 0;
370
380 QVector<QVariantMap> identify( QgsPointCloudLayer *layer, const QgsRenderContext &context, const QgsGeometry &geometry, double toleranceForPointIdentification = 0 ) SIP_SKIP;
381
387 virtual bool willRenderPoint( const QMap<QString, QVariant> &pointAttributes )
388 {
389 Q_UNUSED( pointAttributes );
390 return true;
391 }
392
400 static QgsPointCloudRenderer *load( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
401
406 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
407
415 virtual QSet< QString > usedAttributes( const QgsPointCloudRenderContext &context ) const;
416
423 virtual std::unique_ptr< QgsPreparedPointCloudRendererData > prepare() SIP_SKIP;
424
434 virtual void startRender( QgsPointCloudRenderContext &context );
435
446 virtual void stopRender( QgsPointCloudRenderContext &context );
447
453 virtual bool legendItemChecked( const QString &key );
454
460 virtual void checkLegendItem( const QString &key, bool state = true );
461
468 void setPointSize( double size ) { mPointSize = size; }
469
479 double pointSize() const { return mPointSize; }
480
488 void setPointSizeUnit( const QgsUnitTypes::RenderUnit units ) { mPointSizeUnit = units; }
489
496 QgsUnitTypes::RenderUnit pointSizeUnit() const { return mPointSizeUnit; }
497
504 void setPointSizeMapUnitScale( const QgsMapUnitScale &scale ) { mPointSizeMapUnitScale = scale; }
505
512 const QgsMapUnitScale &pointSizeMapUnitScale() const { return mPointSizeMapUnitScale; }
513
520 Qgis::PointCloudDrawOrder drawOrder2d() const;
521
528 void setDrawOrder2d( Qgis::PointCloudDrawOrder order );
529
535 Qgis::PointCloudSymbol pointSymbol() const;
536
542 void setPointSymbol( Qgis::PointCloudSymbol symbol );
543
554 double maximumScreenError() const;
555
566 void setMaximumScreenError( double error );
567
574 QgsUnitTypes::RenderUnit maximumScreenErrorUnit() const;
575
582 void setMaximumScreenErrorUnit( QgsUnitTypes::RenderUnit unit );
583
587 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY;
588
592 virtual QStringList legendRuleKeys() const;
593
599 bool eyeDomeLightingEnabled() const { return mEyeDomeLightingEnabled; }
600
606 void setEyeDomeLightingEnabled( bool enabled ) { mEyeDomeLightingEnabled = enabled; }
607
613 double eyeDomeLightingStrength() const { return mEyeDomeLightingStrength; }
614
620 void setEyeDomeLightingStrength( double strength ) { mEyeDomeLightingStrength = strength; }
621
627 double eyeDomeLightingDistance() const { return mEyeDomeLightingDistance; }
628
634 void setEyeDomeLightingDistance( double distance ) { mEyeDomeLightingDistance = distance; }
635
641 QgsUnitTypes::RenderUnit eyeDomeLightingDistanceUnit() const { return mEyeDomeLightingDistanceUnit; }
642
648 void setEyeDomeLightingDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mEyeDomeLightingDistanceUnit = unit; }
649
650 protected:
651
655 static void pointXY( QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y )
656 {
657 // be wary when copying this code!! In the renderer we explicitly request x/y/z as qint32 values, but in other
658 // situations these may be floats or doubles!
659 const qint32 ix = *reinterpret_cast< const qint32 * >( ptr + i * context.pointRecordSize() + context.xOffset() );
660 const qint32 iy = *reinterpret_cast< const qint32 * >( ptr + i * context.pointRecordSize() + context.yOffset() );
661 x = context.offset().x() + context.scale().x() * ix;
662 y = context.offset().y() + context.scale().y() * iy;
663 }
664
668 static double pointZ( QgsPointCloudRenderContext &context, const char *ptr, int i )
669 {
670 // be wary when copying this code!! In the renderer we explicitly request x/y/z as qint32 values, but in other
671 // situations these may be floats or doubles!
672 const qint32 iz = *reinterpret_cast<const qint32 * >( ptr + i * context.pointRecordSize() + context.zOffset() );
673 return ( context.offset().z() + context.scale().z() * iz ) * context.zValueScale() + context.zValueFixedOffset();
674 }
675
679 void drawPoint( double x, double y, const QColor &color, QgsPointCloudRenderContext &context ) const
680 {
681 const QPointF originalXY( x, y );
682 context.renderContext().mapToPixel().transformInPlace( x, y );
683 QPainter *painter = context.renderContext().painter();
684 switch ( mPointSymbol )
685 {
687 painter->fillRect( QRectF( x - mPainterPenWidth * 0.5,
688 y - mPainterPenWidth * 0.5,
689 mPainterPenWidth, mPainterPenWidth ), color );
690 break;
691
693 painter->setBrush( QBrush( color ) );
694 painter->setPen( Qt::NoPen );
695 painter->drawEllipse( QRectF( x - mPainterPenWidth * 0.5,
696 y - mPainterPenWidth * 0.5,
697 mPainterPenWidth, mPainterPenWidth ) );
698 break;
699 };
700 }
701
702#ifndef SIP_RUN // intentionally left out from SIP to avoid API breaks in future when we move elevation post-processing elsewhere
703
708 void drawPointToElevationMap( double x, double y, double z, QgsPointCloudRenderContext &context ) const;
709#endif
710
714 void copyCommonProperties( QgsPointCloudRenderer *destination ) const;
715
722 void restoreCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );
723
730 void saveCommonProperties( QDomElement &element, const QgsReadWriteContext &context ) const;
731
732 private:
733#ifdef SIP_RUN
735#endif
736
737#ifdef QGISDEBUG
739 QThread *mThread = nullptr;
740#endif
741
742 double mMaximumScreenError = 0.3;
744
745 double mPointSize = 1;
747 QgsMapUnitScale mPointSizeMapUnitScale;
748
750 int mPainterPenWidth = 1;
752
753 bool mEyeDomeLightingEnabled = false;
754 double mEyeDomeLightingStrength = 1000.0;
755 double mEyeDomeLightingDistance = 0.5;
756 QgsUnitTypes::RenderUnit mEyeDomeLightingDistanceUnit = QgsUnitTypes::RenderMillimeters;
757};
758
759#endif // QGSPOINTCLOUDRENDERER_H
PointCloudSymbol
Rendering symbols for point cloud points.
Definition: qgis.h:2058
@ Circle
Renders points as circles.
@ Square
Renders points as squares.
PointCloudDrawOrder
Pointcloud rendering order for 2d views.
Definition: qgis.h:2070
@ Default
Draw points in the order they are stored.
Stores digital elevation model in a raster image which may get updated as a part of map layer renderi...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Layer tree node points to a map layer.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
Struct for storing maximum and minimum scales for measurements in map units.
Collection of point cloud attributes.
DataType
Systems of unit measurement.
@ UShort
Unsigned short int 2 bytes.
@ UChar
Unsigned char 1 byte.
@ UInt32
Unsigned int32 4 bytes.
@ UInt64
Unsigned int64 8 bytes.
Base class for storing raw data from point cloud nodes.
Represents a map layer supporting display of point clouds.
Encapsulates the render context for a 2D point cloud rendering operation.
int yOffset() const
Returns the offset for the y value in a point record.
double zValueFixedOffset() const
Returns any constant offset which must be applied to z values taken from the point cloud index.
QgsVector3D offset() const
Returns the offset of the layer's int32 coordinates compared to CRS coords.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
static void getAttribute(const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value)
Retrieves the attribute value from data at the specified offset, where type indicates the original da...
void setOffset(const QgsVector3D &offset)
Sets the offset of the layer's int32 coordinates compared to CRS coords.
void setScale(const QgsVector3D &scale)
Sets the scale of the layer's int32 coordinates compared to CRS coords.
int pointRecordSize() const
Returns the size of a single point record.
int xOffset() const
Returns the offset for the x value in a point record.
const QgsRenderContext & renderContext() const
Returns a reference to the context's render context.
QgsPointCloudRenderContext & operator=(const QgsPointCloudRenderContext &)=delete
QgsPointCloudRenderContext cannot be copied.
QgsPointCloudRenderContext(const QgsPointCloudRenderContext &rh)=delete
QgsPointCloudRenderContext cannot be copied.
QgsElevationMap * elevationMap()
Returns elevation map.
double zValueScale() const
Returns any constant scaling factor which must be applied to z values taken from the point cloud inde...
QgsVector3D scale() const
Returns the scale of the layer's int32 coordinates compared to CRS coords.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the rendered block.
int zOffset() const
Returns the offset for the y value in a point record.
QgsFeedback * feedback() const
Returns the feedback object used to cancel rendering.
Abstract base class for 2d point cloud renderers.
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Saves the renderer configuration to an XML element.
virtual void renderBlock(const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context)=0
Renders a block of point cloud data using the specified render context.
void setPointSizeUnit(const QgsUnitTypes::RenderUnit units)
Sets the units used for the point size.
void setEyeDomeLightingEnabled(bool enabled)
Sets whether eye dome lighting effect will be used.
QgsPointCloudRenderer & operator=(const QgsPointCloudRenderer &other)=delete
QgsPointCloudRenderer cannot be copied – use clone() instead.
const QgsMapUnitScale & pointSizeMapUnitScale() const
Returns the map unit scale used for the point size.
void setPointSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the point size.
QgsPointCloudRenderer()=default
Constructor for QgsPointCloudRenderer.
QgsUnitTypes::RenderUnit eyeDomeLightingDistanceUnit() const
Returns unit for the eye dome lighting distance.
virtual QString type() const =0
Returns the identifier of the renderer type.
QgsPointCloudRenderer(const QgsPointCloudRenderer &other)=delete
QgsPointCloudRenderer cannot be copied – use clone() instead.
virtual QgsPointCloudRenderer * clone() const =0
Create a deep copy of this renderer.
QgsUnitTypes::RenderUnit pointSizeUnit() const
Returns the units used for the point size.
void setEyeDomeLightingDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets unit for the eye dome lighting distance.
void setEyeDomeLightingDistance(double distance)
Sets the eye dome lighting distance.
virtual ~QgsPointCloudRenderer()=default
void drawPoint(double x, double y, const QColor &color, QgsPointCloudRenderContext &context) const
Draws a point using a color at the specified x and y (in map coordinates).
void setEyeDomeLightingStrength(double strength)
Sets the eye dome lighting strength value.
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting effect will be used.
double eyeDomeLightingStrength() const
Returns the eye dome lighting strength value.
double pointSize() const
Returns the point size.
double eyeDomeLightingDistance() const
Returns the eye dome lighting distance.
static double pointZ(QgsPointCloudRenderContext &context, const char *ptr, int i)
Retrieves the z value for the point at index i.
static void pointXY(QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y)
Retrieves the x and y coordinate for the point at index i.
Base class for 2d point cloud renderer prepared data containers.
virtual QColor pointColor(const QgsPointCloudBlock *block, int i, double z)=0
An optimised method of retrieving the color of a point from a point cloud block.
virtual bool prepareBlock(const QgsPointCloudBlock *block)=0
Prepares the renderer for using the specified block.
virtual QSet< QString > usedAttributes() const =0
Returns the set of attributes used by the prepared point cloud renderer.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:203