QGIS API Documentation  3.23.0-Master (eb871beae0)
qgspointcloud3dsymbol_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointcloud3dsymbol_p.h
3  ------------------------------
4  Date : December 2020
5  Copyright : (C) 2020 by Nedjima Belgacem
6  Email : belgacem dot nedjima 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 QGSPOINTCLOUD3DSYMBOL_P_H
17 #define QGSPOINTCLOUD3DSYMBOL_P_H
18 
20 
21 #include "qgspointcloud3dsymbol.h"
22 
23 #include "qgschunkloader_p.h"
24 #include "qgsfeature3dhandler_p.h"
25 #include "qgschunkedentity_p.h"
26 
28 
29 #include <QFutureWatcher>
30 #include <Qt3DRender/QGeometry>
31 #include <Qt3DRender/QBuffer>
32 #include <Qt3DRender/QMaterial>
33 #include <QVector3D>
34 
35 #define SIP_NO_FILE
36 
38 
39 class QgsPointCloud3DSymbolHandler // : public QgsFeature3DHandler
40 {
41  public:
42  QgsPointCloud3DSymbolHandler();
43 
44  virtual ~QgsPointCloud3DSymbolHandler() = default;
45 
46  virtual bool prepare( const QgsPointCloud3DRenderContext &context ) = 0;// override;
47  virtual void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) = 0; // override;
48  virtual void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) = 0;// override;
49 
50  float zMinimum() const { return mZMin; }
51  float zMaximum() const { return mZMax; }
52 
54  struct PointData
55  {
56  QVector<QVector3D> positions; // contains triplets of float x,y,z for each point
57  QVector<float> parameter;
58  QVector<QVector3D> colors;
59  };
60 
61  protected:
62  float mZMin = std::numeric_limits<float>::max();
63  float mZMax = std::numeric_limits<float>::lowest();
64 
65  void makeEntity( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context, PointData &out, bool selected );
66  virtual Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) = 0;
67  QgsPointCloudBlock *pointCloudBlock( QgsPointCloudIndex *pc, const IndexedPointCloudNode &node, const QgsPointCloudRequest &request, const QgsPointCloud3DRenderContext &context );
68 
69  // outputs
70  PointData outNormal;
71 };
72 
73 class QgsSingleColorPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
74 {
75  public:
76  QgsSingleColorPointCloud3DSymbolHandler();
77 
78  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
79  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
80  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
81 
82  private:
83  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
84 };
85 
86 class QgsColorRampPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
87 {
88  public:
89  QgsColorRampPointCloud3DSymbolHandler();
90 
91  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
92  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
93  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
94 
95  private:
96  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
97 };
98 
99 class QgsRGBPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
100 {
101  public:
102  QgsRGBPointCloud3DSymbolHandler();
103 
104  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
105  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
106  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
107 
108  private:
109  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
110 };
111 
112 class QgsClassificationPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
113 {
114  public:
115  QgsClassificationPointCloud3DSymbolHandler();
116 
117  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
118  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
119  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
120 
121  private:
122  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
123 };
124 
125 
126 class QgsPointCloud3DGeometry: public Qt3DRender::QGeometry
127 {
128  public:
129  QgsPointCloud3DGeometry( Qt3DCore::QNode *parent, unsigned int byteStride );
130 
131  protected:
132  virtual void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) = 0;
133 
134  Qt3DRender::QAttribute *mPositionAttribute = nullptr;
135  Qt3DRender::QAttribute *mParameterAttribute = nullptr;
136  Qt3DRender::QAttribute *mColorAttribute = nullptr;
137  Qt3DRender::QBuffer *mVertexBuffer = nullptr;
138  int mVertexCount = 0;
139 
140  unsigned int mByteStride = 16;
141 };
142 
143 class QgsSingleColorPointCloud3DGeometry : public QgsPointCloud3DGeometry
144 {
145  public:
146  QgsSingleColorPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
147 
148  private:
149  void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
150 };
151 
152 class QgsColorRampPointCloud3DGeometry : public QgsPointCloud3DGeometry
153 {
154  public:
155  QgsColorRampPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
156 
157  private:
158  void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
159 };
160 
161 class QgsRGBPointCloud3DGeometry : public QgsPointCloud3DGeometry
162 {
163  public:
164  QgsRGBPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
165  private:
166  void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
167 };
168 
169 
171 
172 #endif // QGSPOINTCLOUD3DSYMBOL_P_H
Represents a indexed point cloud node in octree.
Encapsulates the render context for a 3D point cloud rendering operation.
Base class for storing raw data from point cloud nodes.
Represents a indexed point clouds data in octree.
Point cloud data request.