1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the QtDataVisualization API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13
14#ifndef SURFACEOBJECT_P_H
15#define SURFACEOBJECT_P_H
16
17#include "abstractobjecthelper_p.h"
18#include "qsurfacedataproxy.h"
19
20#include <QtCore/QRect>
21#include <QtGui/QColor>
22
23QT_BEGIN_NAMESPACE
24
25class Surface3DRenderer;
26class AxisRenderCache;
27
28class SurfaceObject : public AbstractObjectHelper
29{
30public:
31 enum SurfaceType {
32 SurfaceSmooth,
33 SurfaceFlat,
34 Undefined
35 };
36
37 enum DataDimension {
38 BothAscending = 0,
39 XDescending = 1,
40 ZDescending = 2,
41 BothDescending = XDescending | ZDescending
42 };
43 Q_DECLARE_FLAGS(DataDimensions, DataDimension)
44
45public:
46 SurfaceObject(Surface3DRenderer *renderer);
47 virtual ~SurfaceObject();
48
49 void setUpData(const QSurfaceDataArray &dataArray, const QRect &space,
50 bool changeGeometry, bool polar, bool flipXZ = false);
51 void setUpSmoothData(const QSurfaceDataArray &dataArray, const QRect &space,
52 bool changeGeometry, bool polar, bool flipXZ = false);
53 void smoothUVs(const QSurfaceDataArray &dataArray, const QSurfaceDataArray &modelArray);
54 void coarseUVs(const QSurfaceDataArray &dataArray, const QSurfaceDataArray &modelArray);
55 void updateCoarseRow(const QSurfaceDataArray &dataArray, int rowIndex, bool polar);
56 void updateSmoothRow(const QSurfaceDataArray &dataArray, int startRow, bool polar);
57 void updateSmoothItem(const QSurfaceDataArray &dataArray, int row, int column, bool polar);
58 void updateCoarseItem(const QSurfaceDataArray &dataArray, int row, int column, bool polar);
59 void createSmoothIndices(int x, int y, int endX, int endY);
60 void createCoarseSubSection(int x, int y, int columns, int rows);
61 void createSmoothGridlineIndices(int x, int y, int endX, int endY);
62 void createCoarseGridlineIndices(int x, int y, int endX, int endY);
63 void uploadBuffers();
64 GLuint gridElementBuf();
65 GLuint uvBuf() override;
66 GLuint gridIndexCount();
67 QVector3D vertexAt(int column, int row);
68 void clear();
69 float minYValue() const { return m_minY; }
70 float maxYValue() const { return m_maxY; }
71 inline void activateSurfaceTexture(bool value) { m_returnTextureBuffer = value; }
72 inline void setLineColor(const QColor &color) { m_wireframeColor = color; }
73 inline const QColor &wireframeColor() const { return m_wireframeColor; }
74
75private:
76 void createCoarseIndices(GLint *indices, int &p, int row, int upperRow, int j);
77 void createNormals(int &p, int row, int upperRow, int j);
78 void createSmoothNormalBodyLine(int &totalIndex, int column);
79 void createSmoothNormalUpperLine(int &totalIndex);
80 QVector3D createSmoothNormalBodyLineItem(int x, int y);
81 QVector3D createSmoothNormalUpperLineItem(int x, int y);
82 QVector3D normal(const QVector3D &a, const QVector3D &b, const QVector3D &c);
83 void createBuffers(const QList<QVector3D> &vertices, const QList<QVector2D> &uvs,
84 const QList<QVector3D> &normals, const GLint *indices);
85 void checkDirections(const QSurfaceDataArray &array);
86 inline void getNormalizedVertex(const QSurfaceDataItem &data, QVector3D &vertex, bool polar,
87 bool flipXZ);
88
89private:
90 SurfaceType m_surfaceType = Undefined;
91 int m_columns = 0;
92 int m_rows = 0;
93 GLuint m_gridElementbuffer;
94 GLuint m_gridIndexCount = 0;
95 QList<QVector3D> m_vertices;
96 QList<QVector3D> m_normals;
97 // Caches are not owned
98 AxisRenderCache &m_axisCacheX;
99 AxisRenderCache &m_axisCacheY;
100 AxisRenderCache &m_axisCacheZ;
101 Surface3DRenderer *m_renderer;
102 float m_minY;
103 float m_maxY;
104 GLuint m_uvTextureBuffer;
105 bool m_returnTextureBuffer = false;
106 SurfaceObject::DataDimensions m_dataDimension;
107 SurfaceObject::DataDimensions m_oldDataDimension = DataDimensions(-1);
108 QColor m_wireframeColor;
109};
110
111QT_END_NAMESPACE
112
113#endif
114

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