diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-08-22 16:40:52 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-08-25 08:17:45 +0300 |
commit | f9bb71fd11cce59d74e78202a1117c8abb3a2e44 (patch) | |
tree | 3fcc832dfece19f6158b8b56e395a6c289e26bbe /src/datavisualization/data/qcustom3dvolume.cpp | |
parent | ae411d84b9eac08c217bdda3aa5fbc6f39d03d85 (diff) |
Implement API function for rendering volume slice to an image.
Change-Id: Iea18967c3b525a8d4507a06e6541c85ed3abb470
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data/qcustom3dvolume.cpp')
-rw-r--r-- | src/datavisualization/data/qcustom3dvolume.cpp | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/src/datavisualization/data/qcustom3dvolume.cpp b/src/datavisualization/data/qcustom3dvolume.cpp index a7bbae9b..cab79ac0 100644 --- a/src/datavisualization/data/qcustom3dvolume.cpp +++ b/src/datavisualization/data/qcustom3dvolume.cpp @@ -577,6 +577,86 @@ QImage::Format QCustom3DVolume::textureFormat() const return dptrc()->m_textureFormat; } +/*! + * Renders the slice specified by \a index along \a axis into an image. + * The texture format of this object is used. + * + * \return the rendered image of the slice, or a null image if invalid index is specified. + * + * \sa textureFormat + */ +QImage QCustom3DVolume::renderSlice(Qt::Axis axis, int index) +{ + if (index < 0) + return QImage(); + + int x; + int y; + if (axis == Qt::XAxis) { + if (index >= textureWidth()) + return QImage(); + x = textureDepth(); + y = textureHeight(); + } else if (axis == Qt::YAxis) { + if (index >= textureHeight()) + return QImage(); + x = textureWidth(); + y = textureDepth(); + } else { + if (index >= textureDepth()) + return QImage(); + x = textureWidth(); + y = textureHeight(); + } + + int padding = 0; + int pixelWidth = 4; + if (textureFormat() == QImage::Format_Indexed8) { + padding = x % 4; + pixelWidth = 1; + } + QVector<uchar> data((x + padding) * y * pixelWidth); + int frameSize = textureDataWidth() * textureHeight(); + + int dataIndex = 0; + if (axis == Qt::XAxis) { + for (int i = 0; i < y; i++) { + const uchar *p = textureData()->constData() + + (index * pixelWidth) + (textureDataWidth() * i); + for (int j = 0; j < x; j++) { + data[dataIndex++] = *p; + for (int k = 1; k < pixelWidth; k++) + data[dataIndex++] = *(p + k); + p += frameSize; + } + } + } else if (axis == Qt::YAxis) { + for (int i = 0; i < y; i++) { + const uchar *p = textureData()->constData() + (index * textureDataWidth()) + + (frameSize * i); + for (int j = 0; j < (x * pixelWidth); j++) { + data[dataIndex++] = *p; + p++; + } + } + } else { + for (int i = 0; i < y; i++) { + const uchar *p = textureData()->constData() + (index * frameSize) + + (textureDataWidth() * i); + for (int j = 0; j < (x * pixelWidth); j++) { + data[dataIndex++] = *p; + p++; + } + } + } + + QImage image(data.constData(), x, y, x * pixelWidth, textureFormat()); + image.bits(); // Call bits() to detach the new image from local data + if (textureFormat() == QImage::Format_Indexed8) + image.setColorTable(colorTable()); + + return image; +} /*! * \internal @@ -637,9 +717,6 @@ QCustom3DVolumePrivate::QCustom3DVolumePrivate(QCustom3DVolume *q, const QVector if (m_textureDepth < 0) m_textureDepth = 0; - if (m_colorTable.size() != 256) - m_colorTable.clear(); - if (m_textureFormat != QImage::Format_Indexed8) m_textureFormat = QImage::Format_ARGB32; |