QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
68  // outputs
69  PointData outNormal;
70 };
71 
72 class QgsSingleColorPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
73 {
74  public:
75  QgsSingleColorPointCloud3DSymbolHandler();
76 
77  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
78  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
79  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
80 
81  private:
82  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
83 };
84 
85 class QgsColorRampPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
86 {
87  public:
88  QgsColorRampPointCloud3DSymbolHandler();
89 
90  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
91  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
92  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
93 
94  private:
95  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
96 };
97 
98 class QgsRGBPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
99 {
100  public:
101  QgsRGBPointCloud3DSymbolHandler();
102 
103  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
104  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
105  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
106 
107  private:
108  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
109 };
110 
111 class QgsClassificationPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
112 {
113  public:
114  QgsClassificationPointCloud3DSymbolHandler();
115 
116  bool prepare( const QgsPointCloud3DRenderContext &context ) override;
117  void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
118  void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
119 
120  private:
121  Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
122 };
123 
124 
125 class QgsPointCloud3DGeometry: public Qt3DRender::QGeometry
126 {
127  public:
128  QgsPointCloud3DGeometry( Qt3DCore::QNode *parent, unsigned int byteStride );
129 
130  protected:
131  virtual void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) = 0;
132 
133  Qt3DRender::QAttribute *mPositionAttribute = nullptr;
134  Qt3DRender::QAttribute *mParameterAttribute = nullptr;
135  Qt3DRender::QAttribute *mColorAttribute = nullptr;
136  Qt3DRender::QBuffer *mVertexBuffer = nullptr;
137  int mVertexCount = 0;
138 
139  unsigned int mByteStride = 16;
140 };
141 
142 class QgsSingleColorPointCloud3DGeometry : public QgsPointCloud3DGeometry
143 {
144  public:
145  QgsSingleColorPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
146 
147  private:
148  void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
149 };
150 
151 class QgsColorRampPointCloud3DGeometry : public QgsPointCloud3DGeometry
152 {
153  public:
154  QgsColorRampPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
155 
156  private:
157  void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
158 };
159 
160 class QgsRGBPointCloud3DGeometry : public QgsPointCloud3DGeometry
161 {
162  public:
163  QgsRGBPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
164  private:
165  void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
166 };
167 
168 
170 
171 #endif // QGSPOINTCLOUD3DSYMBOL_P_H
Represents a indexed point cloud node in octree.
Encapsulates the render context for a 3D point cloud rendering operation.
Represents a indexed point clouds data in octree.