1 /***************************************************************************
2                          qgsmesh3dgeometry_p.h
3                          -------------------------
4     begin                : january 2020
5     copyright            : (C) 2020 by Vincent Cloarec
6     email                : vcloarec at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef QGSMESHGEOMETRY_P_H
19 #define QGSMESHGEOMETRY_P_H
20 
21 #include <Qt3DExtras/qt3dextras_global.h>
22 #include <Qt3DRender/qgeometry.h>
23 #include <QVector3D>
24 
25 #include <Qt3DRender/QBufferDataGenerator>
26 
27 #include <qgsvector3d.h>
28 
29 #include "qgsmaplayerref.h"
30 #include "qgsmesh3dsymbol.h"
31 #include "qgstriangularmesh.h"
32 
33 ///@cond PRIVATE
34 
35 //
36 //  W A R N I N G
37 //  -------------
38 //
39 // This file is not part of the QGIS API.  It exists purely as an
40 // implementation detail.  This header file may change from version to
41 // version without notice, or even be removed.
42 //
43 
44 #define SIP_NO_FILE
45 
46 namespace Qt3DRender
47 {
48   class QAttribute;
49   class QBuffer;
50 }
51 
52 class QgsMeshLayer;
53 
54 /**
55  * Creates attributes and vertex/index buffers for a mesh layer
56  */
57 class QgsMesh3dGeometry: public  Qt3DRender::QGeometry
58 {
59   protected:
60     //! Constructor
61     explicit QgsMesh3dGeometry( const QgsTriangularMesh &triangularMesh,
62                                 const QgsVector3D &origin,
63                                 const QgsMesh3DSymbol *symbol,
64                                 QNode *parent );
65     virtual ~QgsMesh3dGeometry() = default;
66     void prepareVerticesPositionAttribute( Qt3DRender::QBuffer *buffer, int count, int stride, int offset );
67     void prepareVerticesNormalAttribute( Qt3DRender::QBuffer *buffer, int count, int stride, int offset );
68     void prepareIndexesAttribute( Qt3DRender::QBuffer *buffer, int count );
69 
70     QgsVector3D mOrigin;
71     float mVertScale;
72     QgsTriangularMesh mTriangulaMesh;
73 
74 };
75 
76 /**
77  * Creates attributes and vertex/index buffers for a mesh layer that renders the dataset
78  */
79 class QgsMeshDataset3dGeometry: public  QgsMesh3dGeometry
80 {
81   public:
82     //! Constructs a mesh layer geometry from triangular mesh.
83     explicit QgsMeshDataset3dGeometry( const QgsTriangularMesh &triangularMesh,
84                                        QgsMeshLayer *layer,
85                                        const QgsDateTimeRange &timeRange,
86                                        const QgsVector3D &origin,
87                                        const QgsMesh3DSymbol *symbol,
88                                        QNode *parent );
89 
90   private:
91     void init();
92 
93     //! Returns the number of active faces
94     int extractDataset( QVector<double> &verticaleMagnitude, QVector<double> &scalarMagnitude, QgsMeshDataBlock &verticalActiveFaceFlagValues );
95     void prepareVerticesDatasetAttribute( Qt3DRender::QBuffer *buffer, int count, int stride, int offset );
96 
97     bool mIsVerticalMagnitudeRelative;
98     int mVerticalGroupDatasetIndex;
99     QgsDateTimeRange mTimeRange;
100     QgsMapLayerRef mLayerRef;
101 
102     QgsMeshLayer *meshLayer() const;
103 
104 };
105 
106 /**
107  * Creates attributes and vertex/index buffers for a mesh layer that renders terrain
108  */
109 class QgsMeshTerrain3dGeometry: public  QgsMesh3dGeometry
110 {
111   public:
112     //! Constructs a mesh layer geometry from triangular mesh.
113     explicit QgsMeshTerrain3dGeometry( const QgsTriangularMesh &triangularMesh,
114                                        const QgsVector3D &origin,
115                                        const QgsMesh3DSymbol *symbol,
116                                        QNode *parent );
117   private:
118     void init();
119 };
120 
121 
122 ///@endcond
123 
124 #endif // QGSMESHGEOMETRY_P_H
125