QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgspointcloudlayer3drenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointcloudlayer3drenderer.h
3  --------------------------------------
4  Date : October 2020
5  Copyright : (C) 2020 by Peter Petrik
6  Email : zilolv dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSPOINTCLOUDLAYER3DRENDERER_H
17 #define QGSPOINTCLOUDLAYER3DRENDERER_H
18 
19 #include "qgis_3d.h"
20 #include "qgis_sip.h"
21 
22 #include "qgs3drendererregistry.h"
23 #include "qgsabstract3drenderer.h"
24 #include "qgsmaplayerref.h"
25 
26 #include <QObject>
27 
28 class QgsPointCloudLayer;
29 #include "qgspointcloud3dsymbol.h"
30 #include "qgsfeature3dhandler_p.h"
31 
32 #ifndef SIP_RUN
33 
42 class _3D_NO_EXPORT QgsPointCloud3DRenderContext : public Qgs3DRenderContext
43 {
44  public:
45 
55  QgsPointCloud3DRenderContext( const Qgs3DMapSettings &map, const QgsCoordinateTransform &coordinateTransform, std::unique_ptr< QgsPointCloud3DSymbol > symbol,
56  double zValueScale, double zValueFixedOffset );
57 
60 
63 
69  QgsPointCloudAttributeCollection attributes() const { return mAttributes; }
70 
76  void setAttributes( const QgsPointCloudAttributeCollection &attributes );
77 
83  QgsPointCloud3DSymbol *symbol() const { return mSymbol.get(); }
84 
90  void setSymbol( QgsPointCloud3DSymbol *symbol );
91 
96  void setFilteredOutCategories( const QgsPointCloudCategoryList &categories );
97 
102  QSet<int> getFilteredOutValues() const;
103 
108  template <typename T>
109  void getAttribute( const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value ) const
110  {
111  switch ( type )
112  {
114  value = *( data + offset );
115  return;
116 
118  value = *reinterpret_cast< const qint32 * >( data + offset );
119  return;
120 
122  value = *reinterpret_cast< const short * >( data + offset );
123  return;
124 
126  value = *reinterpret_cast< const unsigned short * >( data + offset );
127  return;
128 
130  value = *reinterpret_cast< const float * >( data + offset );
131  return;
132 
134  value = *reinterpret_cast< const double * >( data + offset );
135  return;
136  }
137  }
138 
144  double zValueScale() const { return mZValueScale; }
145 
151  double zValueFixedOffset() const { return mZValueFixedOffset; }
152 
156  void setIsCanceledCallback( const std::function< bool() > &callback ) { mIsCanceledCallback = callback; }
157 
161  bool isCanceled() const { return mIsCanceledCallback(); }
162 
166  void setCoordinateTransform( const QgsCoordinateTransform &coordinateTransform );
167 
171  QgsCoordinateTransform coordinateTransform() const { return mCoordinateTransform; }
172 
173  private:
174 #ifdef SIP_RUN
176 #endif
178  std::unique_ptr<QgsPointCloud3DSymbol> mSymbol;
179  QgsPointCloudCategoryList mFilteredOutCategories;
180  double mZValueScale = 1.0;
181  double mZValueFixedOffset = 0;
182  QgsCoordinateTransform mCoordinateTransform;
183 
184  std::function< bool() > mIsCanceledCallback;
185 
186 };
187 
188 
198 {
199  public:
201 
203  QgsAbstract3DRenderer *createRenderer( QDomElement &elem, const QgsReadWriteContext &context ) override SIP_FACTORY;
204 };
205 
206 #endif
207 
215 {
216  public:
218  explicit QgsPointCloudLayer3DRenderer();
219 
221  void setLayer( QgsPointCloudLayer *layer );
223  QgsPointCloudLayer *layer() const;
224 
225  QString type() const override;
226  QgsPointCloudLayer3DRenderer *clone() const override SIP_FACTORY;
227  Qt3DCore::QEntity *createEntity( const Qgs3DMapSettings &map ) const override SIP_SKIP;
228 
234  void setSymbol( QgsPointCloud3DSymbol *symbol SIP_TRANSFER );
236  const QgsPointCloud3DSymbol *symbol() const { return mSymbol.get(); }
237 
238  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
239  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
240  void resolveReferences( const QgsProject &project ) override;
241 
249  double maximumScreenError() const;
250 
258  void setMaximumScreenError( double error );
259 
265  bool showBoundingBoxes() const;
266 
272  void setShowBoundingBoxes( bool showBoundingBoxes );
273 
277  int pointRenderingBudget() const { return mPointBudget; };
278 
282  void setPointRenderingBudget( int budget );
283 
284  private:
285  QgsMapLayerRef mLayerRef;
286  std::unique_ptr< QgsPointCloud3DSymbol > mSymbol;
287  double mMaximumScreenError = 1.0;
288  bool mShowBoundingBoxes = false;
289  int mPointBudget = 1000000;
290 
291  private:
292 #ifdef SIP_RUN
295 #endif
296 };
297 
298 
299 #endif // QGSPOINTCLOUDLAYER3DRENDERER_H
Base metadata class for 3D renderers.
QString type() const
Returns unique identifier of the 3D renderer class.
virtual QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
Base class for all renderers that may to participate in 3D view.
Class for doing transforms between two map coordinate systems.
Encapsulates the render context for a 3D point cloud rendering operation.
void getAttribute(const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value) const
Retrieves the attribute value from data at the specified offset, where type indicates the original da...
double zValueScale() const
Returns any constant scaling factor which must be applied to z values taken from the point cloud inde...
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the rendered block.
QgsPointCloud3DRenderContext(const QgsPointCloud3DRenderContext &rh)=delete
QgsPointCloudRenderContext cannot be copied.
bool isCanceled() const
Returns true if the rendering is canceled.
void setIsCanceledCallback(const std::function< bool() > &callback)
Sets the function to call to test if the rendering is canceled.
QgsCoordinateTransform coordinateTransform() const
Returns the coordinate transform used to transform points from layer CRS to the map CRS.
QgsPointCloud3DSymbol * symbol() const
Returns the symbol used for rendering the point cloud.
double zValueFixedOffset() const
Returns any constant offset which must be applied to z values taken from the point cloud index.
QgsPointCloud3DRenderContext & operator=(const QgsPointCloud3DRenderContext &)=delete
QgsPointCloudRenderContext cannot be copied.
Collection of point cloud attributes.
DataType
Systems of unit measurement.
@ UShort
Unsigned short int 2 bytes.
Metadata for point cloud layer 3D renderer to allow creation of its instances from XML.
3D renderer that renders all points from a point cloud layer
const QgsPointCloud3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
int pointRenderingBudget() const
Returns the maximum number of points that will be rendered to the scene.
Represents a map layer supporting display of point clouds.
Encapsulates the render context for a 2D point cloud rendering operation.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
The class is used as a container of context for various read/write operations on other objects.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
QList< QgsPointCloudCategory > QgsPointCloudCategoryList