QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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<QVector3D> colors;
61 QByteArray triangles; // in case of points triangulation, contains index of point in the array positions
62 QByteArray normals; // in case of points triangulation, contains the normals of the solid surface on each vertex
63 };
64
65 protected:
66 float mZMin = std::numeric_limits<float>::max();
67 float mZMax = std::numeric_limits<float>::lowest();
68
69 void makeEntity( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context, const PointData &out, bool selected );
70
71#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
72 virtual Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) = 0;
73#else
74 virtual Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) = 0;
75#endif
76 QgsPointCloudBlock *pointCloudBlock( QgsPointCloudIndex *pc, const IndexedPointCloudNode &node, const QgsPointCloudRequest &request, const QgsPointCloud3DRenderContext &context );
77
78 // outputs
79 PointData outNormal;
80
81 private:
83 std::vector<double> getVertices( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context, const QgsAABB &bbox );
84
86 void calculateNormals( const std::vector<size_t> &triangles );
87
96 void filterTriangles( const std::vector<size_t> &triangleIndexes, const QgsPointCloud3DRenderContext &context, const QgsAABB &bbox );
97};
98
99class QgsSingleColorPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
100{
101 public:
102 QgsSingleColorPointCloud3DSymbolHandler();
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#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
110 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
111#else
112 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
113#endif
114};
115
116class QgsColorRampPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
117{
118 public:
119 QgsColorRampPointCloud3DSymbolHandler();
120
121 bool prepare( const QgsPointCloud3DRenderContext &context ) override;
122 void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
123 void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
124
125 private:
126#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
127 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
128#else
129 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
130#endif
131};
132
133class QgsRGBPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
134{
135 public:
136 QgsRGBPointCloud3DSymbolHandler();
137
138 bool prepare( const QgsPointCloud3DRenderContext &context ) override;
139 void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
140 void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
141
142 private:
143#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
144 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
145#else
146 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
147#endif
148};
149
150class QgsClassificationPointCloud3DSymbolHandler : public QgsPointCloud3DSymbolHandler
151{
152 public:
153 QgsClassificationPointCloud3DSymbolHandler();
154
155 bool prepare( const QgsPointCloud3DRenderContext &context ) override;
156 void processNode( QgsPointCloudIndex *pc, const IndexedPointCloudNode &n, const QgsPointCloud3DRenderContext &context ) override;
157 void finalize( Qt3DCore::QEntity *parent, const QgsPointCloud3DRenderContext &context ) override;
158
159 private:
160#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
161 Qt3DRender::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
162#else
163 Qt3DCore::QGeometry *makeGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride ) override;
164#endif
165};
166
167#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
168class QgsPointCloud3DGeometry: public Qt3DRender::QGeometry
169#else
170class QgsPointCloud3DGeometry: public Qt3DCore::QGeometry
171#endif
172{
173 Q_OBJECT
174
175 public:
176 QgsPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
177
178 protected:
179 virtual void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) = 0;
180
181#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
182 Qt3DRender::QAttribute *mPositionAttribute = nullptr;
183 Qt3DRender::QAttribute *mParameterAttribute = nullptr;
184 Qt3DRender::QAttribute *mColorAttribute = nullptr;
185 Qt3DRender::QAttribute *mTriangleIndexAttribute = nullptr;
186 Qt3DRender::QAttribute *mNormalsAttribute = nullptr;
187 Qt3DRender::QBuffer *mVertexBuffer = nullptr;
188 Qt3DRender::QBuffer *mTriangleBuffer = nullptr;
189 Qt3DRender::QBuffer *mNormalsBuffer = nullptr;
190#else
191 Qt3DCore::QAttribute *mPositionAttribute = nullptr;
192 Qt3DCore::QAttribute *mParameterAttribute = nullptr;
193 Qt3DCore::QAttribute *mColorAttribute = nullptr;
194 Qt3DCore::QAttribute *mTriangleIndexAttribute = nullptr;
195 Qt3DCore::QAttribute *mNormalsAttribute = nullptr;
196 Qt3DCore::QBuffer *mVertexBuffer = nullptr;
197 Qt3DCore::QBuffer *mTriangleBuffer = nullptr;
198 Qt3DCore::QBuffer *mNormalsBuffer = nullptr;
199#endif
200 int mVertexCount = 0;
201
202 unsigned int mByteStride = 16;
203};
204
205class QgsSingleColorPointCloud3DGeometry : public QgsPointCloud3DGeometry
206{
207 Q_OBJECT
208
209 public:
210 QgsSingleColorPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
211
212 private:
213 void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
214};
215
216class QgsColorRampPointCloud3DGeometry : public QgsPointCloud3DGeometry
217{
218 Q_OBJECT
219
220 public:
221 QgsColorRampPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
222
223 private:
224 void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
225};
226
227class QgsRGBPointCloud3DGeometry : public QgsPointCloud3DGeometry
228{
229 Q_OBJECT
230
231 public:
232 QgsRGBPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data, unsigned int byteStride );
233 private:
234 void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ) override;
235};
236
237
239
240#endif // QGSPOINTCLOUD3DSYMBOL_P_H
Represents a indexed point cloud node in octree.
3
Definition: qgsaabb.h:34
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.