1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30//
31// W A R N I N G
32// -------------
33//
34// This file is not part of the QtDataVisualization API. It exists purely as an
35// implementation detail. This header file may change from version to
36// version without notice, or even be removed.
37//
38// We mean it.
39
40#ifndef SURFACEOBJECT_P_H
41#define SURFACEOBJECT_P_H
42
43#include "datavisualizationglobal_p.h"
44#include "abstractobjecthelper_p.h"
45#include "qsurfacedataproxy.h"
46
47#include <QtCore/QRect>
48
49QT_BEGIN_NAMESPACE_DATAVISUALIZATION
50
51class Surface3DRenderer;
52class AxisRenderCache;
53
54class SurfaceObject : public AbstractObjectHelper
55{
56public:
57 enum SurfaceType {
58 SurfaceSmooth,
59 SurfaceFlat,
60 Undefined
61 };
62
63 enum DataDimension {
64 BothAscending = 0,
65 XDescending = 1,
66 ZDescending = 2,
67 BothDescending = XDescending | ZDescending
68 };
69 Q_DECLARE_FLAGS(DataDimensions, DataDimension)
70
71public:
72 SurfaceObject(Surface3DRenderer *renderer);
73 virtual ~SurfaceObject();
74
75 void setUpData(const QSurfaceDataArray &dataArray, const QRect &space,
76 bool changeGeometry, bool polar, bool flipXZ = false);
77 void setUpSmoothData(const QSurfaceDataArray &dataArray, const QRect &space,
78 bool changeGeometry, bool polar, bool flipXZ = false);
79 void smoothUVs(const QSurfaceDataArray &dataArray, const QSurfaceDataArray &modelArray);
80 void coarseUVs(const QSurfaceDataArray &dataArray, const QSurfaceDataArray &modelArray);
81 void updateCoarseRow(const QSurfaceDataArray &dataArray, int rowIndex, bool polar);
82 void updateSmoothRow(const QSurfaceDataArray &dataArray, int startRow, bool polar);
83 void updateSmoothItem(const QSurfaceDataArray &dataArray, int row, int column, bool polar);
84 void updateCoarseItem(const QSurfaceDataArray &dataArray, int row, int column, bool polar);
85 void createSmoothIndices(int x, int y, int endX, int endY);
86 void createCoarseSubSection(int x, int y, int columns, int rows);
87 void createSmoothGridlineIndices(int x, int y, int endX, int endY);
88 void createCoarseGridlineIndices(int x, int y, int endX, int endY);
89 void uploadBuffers();
90 GLuint gridElementBuf();
91 GLuint uvBuf();
92 GLuint gridIndexCount();
93 QVector3D vertexAt(int column, int row);
94 void clear();
95 float minYValue() const { return m_minY; }
96 float maxYValue() const { return m_maxY; }
97 inline void activateSurfaceTexture(bool value) { m_returnTextureBuffer = value; }
98
99private:
100 void createCoarseIndices(GLint *indices, int &p, int row, int upperRow, int j);
101 void createNormals(int &p, int row, int upperRow, int j);
102 void createSmoothNormalBodyLine(int &totalIndex, int column);
103 void createSmoothNormalUpperLine(int &totalIndex);
104 QVector3D createSmoothNormalBodyLineItem(int x, int y);
105 QVector3D createSmoothNormalUpperLineItem(int x, int y);
106 QVector3D normal(const QVector3D &a, const QVector3D &b, const QVector3D &c);
107 void createBuffers(const QVector<QVector3D> &vertices, const QVector<QVector2D> &uvs,
108 const QVector<QVector3D> &normals, const GLint *indices);
109 void checkDirections(const QSurfaceDataArray &array);
110 inline void getNormalizedVertex(const QSurfaceDataItem &data, QVector3D &vertex, bool polar,
111 bool flipXZ);
112
113private:
114 SurfaceType m_surfaceType = Undefined;
115 int m_columns = 0;
116 int m_rows = 0;
117 GLuint m_gridElementbuffer;
118 GLuint m_gridIndexCount = 0;
119 QVector<QVector3D> m_vertices;
120 QVector<QVector3D> m_normals;
121 // Caches are not owned
122 AxisRenderCache &m_axisCacheX;
123 AxisRenderCache &m_axisCacheY;
124 AxisRenderCache &m_axisCacheZ;
125 Surface3DRenderer *m_renderer;
126 float m_minY;
127 float m_maxY;
128 GLuint m_uvTextureBuffer;
129 bool m_returnTextureBuffer = false;
130 SurfaceObject::DataDimensions m_dataDimension;
131 SurfaceObject::DataDimensions m_oldDataDimension = DataDimensions(-1);
132};
133
134QT_END_NAMESPACE_DATAVISUALIZATION
135
136#endif
137

source code of qtdatavis3d/src/datavisualization/utils/surfaceobject_p.h