QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
22
23#include <QFutureWatcher>
24#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
25#include <Qt3DRender/QGeometry>
26#include <Qt3DRender/QBuffer>
27#else
28#include <Qt3DCore/QGeometry>
29#include <Qt3DCore/QBuffer>
30#endif
31#include <Qt3DRender/QMaterial>
32#include <QVector3D>
33
34#define SIP_NO_FILE
35
37class QgsAABB;
38
39class 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 void triangulate( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context, const QgsAABB &bbox );
51
52 float zMinimum() const { return mZMin; }
53 float zMaximum() const { return mZMax; }
54
56 struct PointData
57 {
58 QVector<QVector3D> positions; // Contains triplets of float x,y,z for each point
59 QVector<float> parameter;
60 QVector<float> pointSizes; // Contains point sizes, in case they are overridden for classification renderer
61 QVector<QVector3D> colors;
62 QByteArray triangles; // In case of points triangulation, contains index of point in the array positions
63 QByteArray normals; // In case of points triangulation, contains the normals of the solid surface on each vertex
64 };
65
66 protected:
67 float mZMin = std::numeric_limits<float>::max();
68 float mZMax = std::numeric_limits<float>::lowest();
69
70 void makeEntity( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context, const PointData &out, bool selected );
71
72#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
73 virtual Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) = 0;
74#else
75 virtual Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) = 0;
76#endif
77 std::unique_ptr<QgsPointCloudBlock> pointCloudBlock( QgsPointCloudIndex *pc, const IndexedPointCloudNode &node, const QgsPointCloudRequest &request, const QgsPointCloud3DRenderContext &context );
78
79 // outputs
80 PointData outNormal;
81
82 private:
84 std::vector<double> getVertices( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context, const QgsAABB &bbox );
85
87 void calculateNormals( const std::vector<size_t> &triangles );
88
97 void filterTriangles( const std::vector<size_t> &triangleIndexes, const QgsPointCloud3DRenderContext &context, const QgsAABB &bbox );
98};
99
100class QgsSingleColorPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
101{
102 public:
103 QgsSingleColorPointCloud3DSymbolHandler();
104
105 bool prepare( const QgsPointCloud3DRenderContext &context ) override;
106 void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
107 void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
108
109 private:
110#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
111 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
112#else
113 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
114#endif
115};
116
117class QgsColorRampPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
118{
119 public:
120 QgsColorRampPointCloud3DSymbolHandler();
121
122 bool prepare( const QgsPointCloud3DRenderContext &context ) override;
123 void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
124 void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
125
126 private:
127#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
128 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
129#else
130 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
131#endif
132};
133
134class QgsRGBPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
135{
136 public:
137 QgsRGBPointCloud3DSymbolHandler();
138
139 bool prepare( const QgsPointCloud3DRenderContext &context ) override;
140 void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
141 void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
142
143 private:
144#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
145 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
146#else
147 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
148#endif
149};
150
151class QgsClassificationPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
152{
153 public:
154 QgsClassificationPointCloud3DSymbolHandler();
155
156 bool prepare( const QgsPointCloud3DRenderContext &context ) override;
157 void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
158 void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
159
160 private:
161#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
162 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
163#else
164 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
165#endif
166};
167
168#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
169class QgsPointCloud3DGeometry: public Qt3DRender::QGeometry
170#else
171class QgsPointCloud3DGeometry: public Qt3DCore::QGeometry
172#endif
173{
174 Q_OBJECT
175
176 public:
177 QgsPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
178
179 protected:
180 virtual void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) = 0;
181
182#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
183 Qt3DRender::QAttribute *mPositionAttribute = nullptr;
184 Qt3DRender::QAttribute *mParameterAttribute = nullptr;
185 Qt3DRender::QAttribute *mPointSizeAttribute = nullptr;
186 Qt3DRender::QAttribute *mColorAttribute = nullptr;
187 Qt3DRender::QAttribute *mTriangleIndexAttribute = nullptr;
188 Qt3DRender::QAttribute *mNormalsAttribute = nullptr;
189 Qt3DRender::QBuffer *mVertexBuffer = nullptr;
190 Qt3DRender::QBuffer *mTriangleBuffer = nullptr;
191 Qt3DRender::QBuffer *mNormalsBuffer = nullptr;
192#else
193 Qt3DCore::QAttribute *mPositionAttribute = nullptr;
194 Qt3DCore::QAttribute *mParameterAttribute = nullptr;
195 Qt3DCore::QAttribute *mPointSizeAttribute = nullptr;
196 Qt3DCore::QAttribute *mColorAttribute = nullptr;
197 Qt3DCore::QAttribute *mTriangleIndexAttribute = nullptr;
198 Qt3DCore::QAttribute *mNormalsAttribute = nullptr;
199 Qt3DCore::QBuffer *mVertexBuffer = nullptr;
200 Qt3DCore::QBuffer *mTriangleBuffer = nullptr;
201 Qt3DCore::QBuffer *mNormalsBuffer = nullptr;
202#endif
203 int mVertexCount = 0;
204
205 unsigned int mByteStride = 16;
206};
207
208class QgsSingleColorPointCloud3DGeometry : public QgsPointCloud3DGeometry
209{
210 Q_OBJECT
211
212 public:
213 QgsSingleColorPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
214
215 private:
216 void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
217};
218
219class QgsColorRampPointCloud3DGeometry : public QgsPointCloud3DGeometry
220{
221 Q_OBJECT
222
223 public:
224 QgsColorRampPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
225
226 private:
227 void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
228};
229
230class QgsRGBPointCloud3DGeometry : public QgsPointCloud3DGeometry
231{
232 Q_OBJECT
233
234 public:
235 QgsRGBPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
236 private:
237 void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
238};
239
240class QgsClassificationPointCloud3DGeometry : public QgsPointCloud3DGeometry
241{
242 Q_OBJECT
243
244 public:
245 QgsClassificationPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
246
247 private:
248 void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
249};
251
252#endif // QGSPOINTCLOUD3DSYMBOL_P_H
Represents a indexed point cloud node in octree.
3
Definition: qgsaabb.h:33
Encapsulates the render context for a 3D point cloud rendering operation.
Represents a indexed point clouds data in octree.
Point cloud data request.