summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-08-22 16:40:52 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-08-25 08:17:45 +0300
commitf9bb71fd11cce59d74e78202a1117c8abb3a2e44 (patch)
tree3fcc832dfece19f6158b8b56e395a6c289e26bbe /src
parentae411d84b9eac08c217bdda3aa5fbc6f39d03d85 (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')
-rw-r--r--src/datavisualization/data/qcustom3dvolume.cpp83
-rw-r--r--src/datavisualization/data/qcustom3dvolume.h2
-rw-r--r--src/datavisualization/engine/shaders/texture3dslice.frag4
3 files changed, 84 insertions, 5 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;
diff --git a/src/datavisualization/data/qcustom3dvolume.h b/src/datavisualization/data/qcustom3dvolume.h
index 498922e8..00733d17 100644
--- a/src/datavisualization/data/qcustom3dvolume.h
+++ b/src/datavisualization/data/qcustom3dvolume.h
@@ -80,6 +80,8 @@ public:
void setTextureFormat(QImage::Format format);
QImage::Format textureFormat() const;
+ QImage renderSlice(Qt::Axis axis, int index);
+
signals:
void textureWidthChanged(int value);
void textureHeightChanged(int value);
diff --git a/src/datavisualization/engine/shaders/texture3dslice.frag b/src/datavisualization/engine/shaders/texture3dslice.frag
index 409ab41d..8870b26d 100644
--- a/src/datavisualization/engine/shaders/texture3dslice.frag
+++ b/src/datavisualization/engine/shaders/texture3dslice.frag
@@ -33,8 +33,8 @@ void main() {
if (rayDir.z < 0)
boxBounds.z = -1.0;
highp vec3 t = (boxBounds - rayStart) * invRayDir;
- tFar = max(t.x, t.y);
- tFar = max(tFar, t.z);
+ tFar = min(t.x, t.y);
+ tFar = min(tFar, t.z);
}
highp vec3 xPoint = vec3(volumeSliceIndices.x, 0, 0);