diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-05-06 12:02:02 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-05-08 08:37:22 +0300 |
commit | 7b6ae38253e946225f1df27b7c97661d1cc14cf2 (patch) | |
tree | 9c8fd90caedac81e796d0396e305aa98613ca4f8 /src | |
parent | 8ff45fe94c3f3f6916f8f673c3ce0b574a69cfdf (diff) |
Allow surface rows and cols be in ascending or descending XZ order
This allows adding rows that have smaller Z-value than the
previously added row instead of being forced to insert rows
into the beginning of the data array in these cases.
Task-number: QTRD-2428
Change-Id: I4dc6c5a48a55ca494a2372f917aa7447f61f336e
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/datavisualization/data/qsurfacedataproxy.cpp | 21 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3drenderer.cpp | 81 |
2 files changed, 66 insertions, 36 deletions
diff --git a/src/datavisualization/data/qsurfacedataproxy.cpp b/src/datavisualization/data/qsurfacedataproxy.cpp index 2e66bb5b..f8f2c900 100644 --- a/src/datavisualization/data/qsurfacedataproxy.cpp +++ b/src/datavisualization/data/qsurfacedataproxy.cpp @@ -28,8 +28,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION * \brief Base proxy class for Q3DSurface. * \since Qt Data Visualization 1.0 * - * QSurfaceDataProxy takes care of surface related data handling. The QSurfaceDataProxy handles the data - * in rows and for this it provides two auxiliary typedefs. QSurfaceDataArray is a QList for + * QSurfaceDataProxy takes care of surface related data handling. The QSurfaceDataProxy handles the + * data in rows and for this it provides two auxiliary typedefs. QSurfaceDataArray is a QList for * controlling the rows. For rows there is a QVector QSurfaceDataRow which contains QSurfaceDataItem * objects. See Q3DSurface documentation and basic sample code there how to feed the data for the * QSurfaceDataProxy. @@ -41,17 +41,18 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION * If you use QSurfaceDataRow pointers to directly modify data after adding the array to the proxy, * you must also emit proper signal to make the graph update. * - * To make a sensible surface, the X-value of each successive item in the same row must be greater than the - * previous item in that row, and the the Z-value of each successive item in a column must be greater than - * the previous item in that column. + * To make a sensible surface, the X-value of each successive item in all rows must be + * either ascending or descending throughout the row. + * Similarly, the Z-value of each successive item in all columns must be either ascending or + * descending throughout the column. * - * \note In the initial release, only surfaces with straight rows and columns are fully supported. Any row - * with items that do not have the exact same Z-value or any columns with items that do not have the exact - * same X-value may get clipped incorrectly if the whole surface doesn't fit to the visible X or Z axis - * ranges. + * \note Currently only surfaces with straight rows and columns are fully supported. Any row + * with items that do not have the exact same Z-value or any column with items that do not have + * the exact same X-value may get clipped incorrectly if the whole surface doesn't completely fit + * in the visible X or Z axis ranges. * * \note Surfaces with less than two rows or columns are not considered valid surfaces and will - * not get rendered. + * not be rendered. * * \sa {Qt Data Visualization Data Handling} */ diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 56219104..d3898476 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -581,71 +581,100 @@ QRect Surface3DRenderer::calculateSampleRect(const QSurfaceDataArray &array) { QRect sampleSpace; - int rowCount = array.size(); - int columnCount = array.at(0)->size(); - - int i; - bool found; - float axisMinX = m_axisCacheX.min(); - float axisMaxX = m_axisCacheX.max(); - float axisMinZ = m_axisCacheZ.min(); - float axisMaxZ = m_axisCacheZ.max(); - + const int rowCount = array.size(); + const int columnCount = array.at(0)->size(); + + const float axisMinX = m_axisCacheX.min(); + const float axisMaxX = m_axisCacheX.max(); + const float axisMinZ = m_axisCacheZ.min(); + const float axisMaxZ = m_axisCacheZ.max(); + + // We assume data is ordered sequentially in rows for X-value and in columns for Z-value. + // Determine if data is ascending or descending in each case. + const bool ascendingX = array.at(0)->at(0).x() < array.at(0)->at(columnCount - 1).x(); + const bool ascendingZ = array.at(0)->at(0).z() < array.at(rowCount - 1)->at(0).z(); + + const int minCol = ascendingX ? 0 : columnCount - 1; + const int maxCol = ascendingX ? columnCount - 1 : 0; + const int colStep = ascendingX ? 1 : -1; + const int minRow = ascendingZ ? 0 : rowCount - 1; + const int maxRow = ascendingZ ? rowCount - 1 : 0; + const int rowStep = ascendingZ ? 1 : -1; + + bool found = false; + int idx = 0; + int i = 0; // m_minVisibleColumnValue - for (i = 0, found = false; i < columnCount; i++) { - if (array.at(0)->at(i).x() >= axisMinX) { + for (i = 0, idx = minCol, found = false; i < columnCount; i++) { + if (array.at(0)->at(idx).x() >= axisMinX) { found = true; break; } + idx += colStep; } if (found) { - m_minVisibleColumnValue = array.at(0)->at(i).x(); - sampleSpace.setLeft(i); + m_minVisibleColumnValue = array.at(0)->at(idx).x(); + if (ascendingX) + sampleSpace.setLeft(idx); + else + sampleSpace.setRight(idx); } else { sampleSpace.setWidth(-1); // to indicate nothing needs to be shown return sampleSpace; } // m_maxVisibleColumnValue - for (i = columnCount - 1, found = false; i >= 0; i--) { - if (array.at(0)->at(i).x() <= axisMaxX) { + for (i = 0, idx = maxCol, found = false; i < columnCount; i++) { + if (array.at(0)->at(idx).x() <= axisMaxX) { found = true; break; } + idx -= colStep; } if (found) { - m_maxVisibleColumnValue = array.at(0)->at(i).x(); - sampleSpace.setRight(i); + m_maxVisibleColumnValue = array.at(0)->at(idx).x(); + if (ascendingX) + sampleSpace.setRight(idx); + else + sampleSpace.setLeft(idx); } else { sampleSpace.setWidth(-1); // to indicate nothing needs to be shown return sampleSpace; } // m_minVisibleRowValue - for (i = 0, found = false; i < rowCount; i++) { - if (array.at(i)->at(0).z() >= axisMinZ) { + for (i = 0, idx = minRow, found = false; i < rowCount; i++) { + if (array.at(idx)->at(0).z() >= axisMinZ) { found = true; break; } + idx += rowStep; } if (found) { - m_minVisibleRowValue = array.at(i)->at(0).z(); - sampleSpace.setTop(i); + m_minVisibleRowValue = array.at(idx)->at(0).z(); + if (ascendingZ) + sampleSpace.setTop(idx); + else + sampleSpace.setBottom(idx); } else { sampleSpace.setWidth(-1); // to indicate nothing needs to be shown return sampleSpace; } // m_maxVisibleRowValue - for (i = rowCount - 1, found = false; i >= 0; i--) { - if (array.at(i)->at(0).z() <= axisMaxZ) { + for (i = 0, idx = maxRow, found = false; i < rowCount; i++) { + if (array.at(idx)->at(0).z() <= axisMaxZ) { found = true; break; } + idx -= rowStep; } if (found) { - m_maxVisibleRowValue = array.at(i)->at(0).z(); - sampleSpace.setBottom(i); + m_maxVisibleRowValue = array.at(idx)->at(0).z(); + if (ascendingZ) + sampleSpace.setBottom(idx); + else + sampleSpace.setTop(idx); } else { sampleSpace.setWidth(-1); // to indicate nothing needs to be shown return sampleSpace; |