summaryrefslogtreecommitdiffstats
path: root/tests/kinectsurface
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-09-27 07:43:40 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-09-27 07:46:51 +0300
commitb776b6d3aa287b973c9346736badc6181e50cbc7 (patch)
tree67812fbc8dee1977c6fb34c1274d1f1af8aa9cd0 /tests/kinectsurface
parent9d0495cae3181f2caf52235df9a4fb81b48789c1 (diff)
Kinect demo update
+ added compile-time option to use scatter instead of surface Change-Id: I1b5edbdc4e3057a6e7a236476e0bc3d83bf533eb Change-Id: I1b5edbdc4e3057a6e7a236476e0bc3d83bf533eb Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'tests/kinectsurface')
-rw-r--r--tests/kinectsurface/main.cpp11
-rw-r--r--tests/kinectsurface/surfacedata.cpp74
-rw-r--r--tests/kinectsurface/surfacedata.h20
3 files changed, 104 insertions, 1 deletions
diff --git a/tests/kinectsurface/main.cpp b/tests/kinectsurface/main.cpp
index b9469c8b..fc969ace 100644
--- a/tests/kinectsurface/main.cpp
+++ b/tests/kinectsurface/main.cpp
@@ -37,7 +37,12 @@ int main(int argc, char **argv)
QHBoxLayout *hLayout = new QHBoxLayout(widget);
QVBoxLayout *vLayout = new QVBoxLayout();
+#ifdef USE_SCATTER
+ Q3DScatter *surface = new Q3DScatter();
+#else
Q3DSurface *surface = new Q3DSurface();
+#endif
+
QSize screenSize = surface->screen()->size();
QWidget *container = QWidget::createWindowContainer(surface);
@@ -71,6 +76,7 @@ int main(int argc, char **argv)
distanceSlider->setValue(50);
distanceSlider->setMaximum(200);
+#ifndef USE_SCATTER
QLinearGradient gradientOne(0, 0, 200, 1);
gradientOne.setColorAt(0.0, Qt::black);
gradientOne.setColorAt(0.33, Qt::blue);
@@ -101,6 +107,7 @@ int main(int argc, char **argv)
gradientTwoButton->setIcon(QIcon(pm));
gradientTwoButton->setIconSize(QSize(200, 24));
gradientTwoButton->setToolTip(QStringLiteral("Colors: Highlight Foreground"));
+#endif
QTextEdit *status = new QTextEdit(QStringLiteral("<b>Ready</b><br>"), widget);
status->setReadOnly(true);
@@ -111,9 +118,11 @@ int main(int argc, char **argv)
vLayout->addWidget(resolutionBox);
vLayout->addWidget(new QLabel(QStringLiteral("Adjust far distance")));
vLayout->addWidget(distanceSlider);
+#ifndef USE_SCATTER
vLayout->addWidget(new QLabel(QStringLiteral("Change color scheme")));
vLayout->addWidget(gradientOneButton);
vLayout->addWidget(gradientTwoButton);
+#endif
vLayout->addWidget(status, 1, Qt::AlignBottom);
widget->show();
@@ -125,10 +134,12 @@ int main(int argc, char **argv)
QObject::connect(distanceSlider, &QSlider::valueChanged, datagen, &SurfaceData::setDistance);
QObject::connect(resolutionBox, SIGNAL(activated(int)), datagen, SLOT(setResolution(int)));
QObject::connect(status, &QTextEdit::textChanged, datagen, &SurfaceData::scrollDown);
+#ifndef USE_SCATTER
QObject::connect(gradientOneButton, &QPushButton::clicked, datagen,
&SurfaceData::useGradientOne);
QObject::connect(gradientTwoButton, &QPushButton::clicked, datagen,
&SurfaceData::useGradientTwo);
+#endif
datagen->setDistance(distanceSlider->value());
diff --git a/tests/kinectsurface/surfacedata.cpp b/tests/kinectsurface/surfacedata.cpp
index 1b19d136..e80d1cac 100644
--- a/tests/kinectsurface/surfacedata.cpp
+++ b/tests/kinectsurface/surfacedata.cpp
@@ -20,15 +20,40 @@
#include "surfacedata.h"
#include "QKinectWrapper.h"
+#ifdef USE_SCATTER
+#include <QtDataVisualization/QScatterDataProxy>
+#else
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
+#endif
#include <QtDataVisualization/Q3DValueAxis>
#include <QScrollBar>
#include <QSize>
+#include <QImage>
#include <QDebug>
QT_DATAVISUALIZATION_USE_NAMESPACE
+#ifdef USE_SCATTER
+SurfaceData::SurfaceData(Q3DScatter *surface, QTextEdit *statusArea) :
+ m_surface(surface),
+ m_statusArea(statusArea),
+ m_resize(true),
+ m_resolution(QSize(80, 60))
+{
+ // Initialize scatter
+ m_surface->setTheme(QDataVis::ThemeStoneMoss);
+ m_surface->setGridVisible(false);
+ m_surface->setObjectType(QDataVis::Dots, false);
+ m_surface->setSelectionMode(QDataVis::ModeNone);
+ m_surface->setShadowQuality(QDataVis::ShadowSoftLow);
+ m_surface->setCameraPosition(0.0, 85.0, 110);
+ m_surface->axisY()->setMax(255);
+ m_surface->axisX()->setMin(-m_resolution.width() / 2);
+ m_surface->axisX()->setMax(m_resolution.width() / 2);
+ m_surface->axisZ()->setMin(-m_resolution.height() / 2);
+ m_surface->axisZ()->setMax(m_resolution.height() / 2);
+#else
SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
m_surface(surface),
m_statusArea(statusArea),
@@ -49,6 +74,7 @@ SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
m_surface->setGridVisible(false);
m_surface->setSmoothSurfaceEnabled(false);
m_surface->setActiveDataProxy(new QHeightMapSurfaceDataProxy());
+#endif
// Hide scroll bar
m_statusArea->verticalScrollBar()->setVisible(false);
@@ -69,7 +95,11 @@ void SurfaceData::updateData()
QImage depthMap = m_kinect.getDepth();
if (m_resize) // Resize for better performance
depthMap = depthMap.scaled(m_resolution);
+#ifdef USE_SCATTER
+ setData(depthMap);
+#else
static_cast<QHeightMapSurfaceDataProxy *>(m_surface->activeDataProxy())->setHeightMap(depthMap);
+#endif
}
void SurfaceData::updateStatus(QKinect::KinectStatus status)
@@ -142,6 +172,15 @@ void SurfaceData::setResolution(int selection)
break;
}
};
+#ifdef USE_SCATTER
+ m_resize = true;
+ m_resolution /= 4;
+ m_surface->axisX()->setMin(-m_resolution.width() / 2);
+ m_surface->axisX()->setMax(m_resolution.width() / 2);
+ m_surface->axisZ()->setMin(-m_resolution.height() / 2);
+ m_surface->axisZ()->setMax(m_resolution.height() / 2);
+#endif
+
m_statusArea->append(QString(QStringLiteral("<b>Resolution:</b> %1 x %2")).arg(
m_resolution.width()).arg(m_resolution.height()));
if (m_kinect.isStopped())
@@ -154,6 +193,7 @@ void SurfaceData::scrollDown()
scrollbar->setValue(scrollbar->maximum());
}
+#ifndef USE_SCATTER
void SurfaceData::useGradientOne()
{
m_surface->setTheme(QDataVis::ThemeIsabelle);
@@ -176,3 +216,37 @@ void SurfaceData::useGradientTwo()
m_surface->setGradient(gradient);
m_statusArea->append(QStringLiteral("<b>Colors:</b> Highlight foreground"));
}
+#else
+void SurfaceData::setData(const QImage &image)
+{
+ QImage heightImage = image;
+
+ uchar *bits = heightImage.bits();
+
+ int imageHeight = heightImage.height();
+ int imageWidth = heightImage.width();
+ int bitCount = imageWidth * 4 * (imageHeight - 1);
+ int widthBits = imageWidth * 4;
+
+ QScatterDataArray *dataArray = new QScatterDataArray;
+ dataArray->resize(imageHeight * imageWidth);
+ QScatterDataItem *ptrToDataArray = &dataArray->first();
+
+ int limitsX = imageWidth / 2;
+ int limitsZ = imageHeight / 2;
+ qreal height = 0;
+
+ for (int i = -limitsZ; i < limitsZ; i++, bitCount -= widthBits) {
+ for (int j = -limitsX; j < limitsX; j++) {
+ height = qreal(bits[bitCount + ((j + limitsX) * 4)]);
+ if (height > 0) {
+ ptrToDataArray->setPosition(QVector3D(qreal(j), height, qreal(i)));
+ ptrToDataArray++;
+ }
+ }
+ }
+
+ static_cast<QScatterDataProxy *>(m_surface->activeDataProxy())->resetArray(dataArray);
+}
+
+#endif
diff --git a/tests/kinectsurface/surfacedata.h b/tests/kinectsurface/surfacedata.h
index 24b92fad..9a89dd13 100644
--- a/tests/kinectsurface/surfacedata.h
+++ b/tests/kinectsurface/surfacedata.h
@@ -19,8 +19,14 @@
#ifndef SURFACEDATA_H
#define SURFACEDATA_H
+//#define USE_SCATTER
+
#include "QKinectWrapper.h"
-#include <QtDataVisualization/q3dsurface.h>
+#ifdef USE_SCATTER
+#include <QtDataVisualization/Q3DScatter>
+#else
+#include <QtDataVisualization/Q3DSurface>
+#endif
#include <QTextEdit>
using namespace QtDataVisualization;
@@ -30,7 +36,11 @@ class SurfaceData : public QObject
Q_OBJECT
public:
+#ifdef USE_SCATTER
+ explicit SurfaceData(Q3DScatter *surface, QTextEdit *statusLabel);
+#else
explicit SurfaceData(Q3DSurface *surface, QTextEdit *statusLabel);
+#endif
~SurfaceData();
void start();
@@ -41,14 +51,22 @@ public:
void setDistance(int distance);
void scrollDown();
+#ifndef USE_SCATTER
void useGradientOne();
void useGradientTwo();
+#else
+ void setData(const QImage &image);
+#endif
public slots:
void setResolution(int selection);
private:
+#ifdef USE_SCATTER
+ Q3DScatter *m_surface;
+#else
Q3DSurface *m_surface;
+#endif
QTextEdit *m_statusArea;
bool m_resize;
QSize m_resolution;