From 51ad2b7e532296fde314e8157475b667b18ae82a Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Mon, 10 Feb 2014 10:26:30 +0200 Subject: Multiseries support for surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Multiseries support for item and row changes. Task-number: QTRD-2767 Change-Id: I5702989e7f59913481a2ca888e402effa22a4221 Reviewed-by: Tomi Korpipää Reviewed-by: Miikka Heikkinen --- tests/surfacetest/graphmodifier.cpp | 66 +++++++++++++++++++++++++++++++++++-- tests/surfacetest/graphmodifier.h | 1 + 2 files changed, 65 insertions(+), 2 deletions(-) (limited to 'tests/surfacetest') diff --git a/tests/surfacetest/graphmodifier.cpp b/tests/surfacetest/graphmodifier.cpp index c6247bb5..849a3070 100644 --- a/tests/surfacetest/graphmodifier.cpp +++ b/tests/surfacetest/graphmodifier.cpp @@ -122,9 +122,9 @@ void GraphModifier::fillSeries() QSurfaceDataRow *newRow3 = new QSurfaceDataRow(m_xCount); QSurfaceDataRow *newRow4 = new QSurfaceDataRow(m_xCount); + float z = float(i) - m_limitZ + 0.5f; for (int j = 0; j < m_xCount; j++) { float x = float(j) - m_limitX + 0.5f; - float z = float(i) - m_limitZ + 0.5f; float angle = (z * x) / float(full) * 1.57f; (*newRow1)[j].setPosition(QVector3D(x, qSin(angle), z)); angle *= 1.3f; @@ -701,10 +701,39 @@ void GraphModifier::changeRow() m_theSeries->dataProxy()->setRow(int(i), newRow); } else { +#ifdef MULTI_SERIES + static int changeRowSeries = 0; + qDebug() << "Generating new values to a row at random pos for series " << changeRowSeries; + + int row = rand() % m_zCount; + QSurfaceDataRow *newRow = createMultiRow(row, changeRowSeries); + m_multiseries[changeRowSeries]->dataProxy()->setRow(row, newRow); + + changeRowSeries++; + if (changeRowSeries > 3) + changeRowSeries = 0; +#else qDebug() << "Change row function active only for SqrtSin"; +#endif } } +QSurfaceDataRow *GraphModifier::createMultiRow(int row, int series) +{ + int full = m_limitX * m_limitZ; + float i = float(row); + QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + float z = float(i) - m_limitZ + 0.5f; + for (int j = 0; j < m_xCount; j++) { + float x = float(j) - m_limitX + 0.5f; + float angle = (z * x) / float(full) * 1.57f; + float y = qSin(angle * float(qPow(1.3f, series))) + 0.2f + 1.1f *series; + (*newRow)[j].setPosition(QVector3D(x, y, z)); + } + + return newRow; +} + void GraphModifier::changeRows() { if (m_activeSample == GraphModifier::SqrtSin) { @@ -734,7 +763,24 @@ void GraphModifier::changeRows() m_theSeries->dataProxy()->setRows(int(start), dataArray); } else { +#ifdef MULTI_SERIES + static int changeRowSeries = 0; + qDebug() << "Generating new values for 3 rows at random pos for series " << changeRowSeries; + + int row = rand() % (m_zCount - 3); + QSurfaceDataArray dataArray; + for (int i = 0; i < 3; i++) { + QSurfaceDataRow *newRow = createMultiRow(row + i, changeRowSeries); + dataArray.append(newRow); + } + m_multiseries[changeRowSeries]->dataProxy()->setRows(row, dataArray); + + changeRowSeries++; + if (changeRowSeries > 3) + changeRowSeries = 0; +#else qDebug() << "Change row function active only for SqrtSin"; +#endif } } @@ -759,7 +805,23 @@ void GraphModifier::changeItem() m_theSeries->dataProxy()->setItem(int(i), int(j), newItem); } else { - qDebug() << "Change row function active only for SqrtSin"; +#ifdef MULTI_SERIES + static int changeItemSeries = 0; + int full = m_limitX * m_limitZ; + float i = float(rand() % m_zCount); + float j = float(rand() % m_xCount); + float x = float(j) - m_limitX + 0.5f; + float z = float(i) - m_limitZ + 0.5f; + float angle = (z * x) / float(full) * 1.57f; + float y = qSin(angle * float(qPow(1.3f, changeItemSeries))) + 0.2f + 1.1f *changeItemSeries; + QSurfaceDataItem newItem(QVector3D(x, y, z)); + m_multiseries[changeItemSeries]->dataProxy()->setItem(int(i), int(j), newItem); + changeItemSeries++; + if (changeItemSeries > 3) + changeItemSeries = 0; +#else + qDebug() << "Change item function active only for SqrtSin"; +#endif } } diff --git a/tests/surfacetest/graphmodifier.h b/tests/surfacetest/graphmodifier.h index 308db1f0..699bb9bf 100644 --- a/tests/surfacetest/graphmodifier.h +++ b/tests/surfacetest/graphmodifier.h @@ -119,6 +119,7 @@ private: void fillSeries(); void resetArrayAndSliders(QSurfaceDataArray *array, float minZ, float maxZ, float minX, float maxX); + QSurfaceDataRow *createMultiRow(int row, int series); Q3DSurface *m_graph; QSurface3DSeries *m_multiseries[4]; -- cgit v1.2.3