mirror of https://github.com/qt/qtdatavis3d.git
Texture UVs for surface to follow data dimension
Change texture UVs to be generated according to data dimension. Also utilise this change on texturesurface example. Change-Id: Ideacfba409dc2e7cf579fb38d897e08c9f9a1b71 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
This commit is contained in:
parent
0e5b7fba37
commit
aab6b4f77d
|
|
@ -49,7 +49,8 @@ void TopographicSeries::setTopographyFile(const QString file, float width, float
|
|||
QSurfaceDataArray *dataArray = new QSurfaceDataArray;
|
||||
dataArray->reserve(imageHeight);
|
||||
for (int i = 0; i < imageHeight; i++) {
|
||||
int p = (imageHeight - 1 - i) * widthBits;
|
||||
int p = i * widthBits;
|
||||
float z = height - float(i) * stepZ;
|
||||
QSurfaceDataRow *newRow = new QSurfaceDataRow(imageWidth);
|
||||
for (int j = 0; j < imageWidth; j++) {
|
||||
uchar aa = bits[p + 0];
|
||||
|
|
@ -57,7 +58,7 @@ void TopographicSeries::setTopographyFile(const QString file, float width, float
|
|||
uchar gg = bits[p + 2];
|
||||
uint color = uint((gg << 16) + (rr << 8) + aa);
|
||||
float y = float(color) / packingFactor;
|
||||
(*newRow)[j].setPosition(QVector3D(float(j) * stepX, y, float(i) * stepZ));
|
||||
(*newRow)[j].setPosition(QVector3D(float(j) * stepX, y, z));
|
||||
p = p + 4;
|
||||
}
|
||||
*dataArray << newRow;
|
||||
|
|
|
|||
|
|
@ -307,15 +307,21 @@ void SurfaceObject::smoothUVs(const QSurfaceDataArray &dataArray,
|
|||
float zRangeNormalizer = dataArray.at(rows - 1)->at(0).z() - dataArray.at(0)->at(0).z();
|
||||
float xMin = dataArray.at(0)->at(0).x();
|
||||
float zMin = dataArray.at(0)->at(0).z();
|
||||
const bool zDescending = m_dataDimension.testFlag(SurfaceObject::ZDescending);
|
||||
const bool xDescending = m_dataDimension.testFlag(SurfaceObject::XDescending);
|
||||
|
||||
QVector<QVector2D> uvs;
|
||||
uvs.resize(m_rows * m_columns);
|
||||
int index = 0;
|
||||
for (int i = 0; i < m_rows; i++) {
|
||||
float y = (modelArray.at(i)->at(0).z() - zMin) / zRangeNormalizer;
|
||||
if (zDescending)
|
||||
y = 1.0f - y;
|
||||
const QSurfaceDataRow &p = *modelArray.at(i);
|
||||
for (int j = 0; j < m_columns; j++) {
|
||||
float x = (p.at(j).x() - xMin) / xRangeNormalizer;
|
||||
if (xDescending)
|
||||
x = 1.0f - x;
|
||||
uvs[index] = QVector2D(x, y);
|
||||
index++;
|
||||
}
|
||||
|
|
@ -601,6 +607,8 @@ void SurfaceObject::coarseUVs(const QSurfaceDataArray &dataArray,
|
|||
float zRangeNormalizer = dataArray.at(rows - 1)->at(0).z() - dataArray.at(0)->at(0).z();
|
||||
float xMin = dataArray.at(0)->at(0).x();
|
||||
float zMin = dataArray.at(0)->at(0).z();
|
||||
const bool zDescending = m_dataDimension.testFlag(SurfaceObject::ZDescending);
|
||||
const bool xDescending = m_dataDimension.testFlag(SurfaceObject::XDescending);
|
||||
|
||||
QVector<QVector2D> uvs;
|
||||
uvs.resize(m_rows * m_columns * 2);
|
||||
|
|
@ -608,9 +616,13 @@ void SurfaceObject::coarseUVs(const QSurfaceDataArray &dataArray,
|
|||
int colLimit = m_columns - 1;
|
||||
for (int i = 0; i < m_rows; i++) {
|
||||
float y = (modelArray.at(i)->at(0).z() - zMin) / zRangeNormalizer;
|
||||
if (zDescending)
|
||||
y = 1.0f - y;
|
||||
const QSurfaceDataRow &p = *modelArray.at(i);
|
||||
for (int j = 0; j < m_columns; j++) {
|
||||
float x = (p.at(j).x() - xMin) / xRangeNormalizer;
|
||||
if (xDescending)
|
||||
x = 1.0f - x;
|
||||
uvs[index] = QVector2D(x, y);
|
||||
index++;
|
||||
if (j > 0 && j < colLimit) {
|
||||
|
|
|
|||
|
|
@ -49,12 +49,13 @@ public:
|
|||
Undefined
|
||||
};
|
||||
|
||||
enum DataDimensions {
|
||||
enum DataDimension {
|
||||
BothAscending = 0,
|
||||
XDescending = 1,
|
||||
ZDescending = 2,
|
||||
BothDescending = XDescending | ZDescending
|
||||
};
|
||||
Q_DECLARE_FLAGS(DataDimensions, DataDimension)
|
||||
|
||||
public:
|
||||
SurfaceObject(Surface3DRenderer *renderer);
|
||||
|
|
@ -115,8 +116,8 @@ private:
|
|||
float m_maxY;
|
||||
GLuint m_uvTextureBuffer;
|
||||
bool m_returnTextureBuffer;
|
||||
int m_dataDimension;
|
||||
int m_oldDataDimension;
|
||||
SurfaceObject::DataDimensions m_dataDimension;
|
||||
SurfaceObject::DataDimensions m_oldDataDimension;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE_DATAVISUALIZATION
|
||||
|
|
|
|||
Loading…
Reference in New Issue