summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-09-27 08:50:03 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-09-27 08:52:53 +0300
commit1628d6a96629ccb99c57f14131e5188ae2488347 (patch)
tree4be9693e11230b528f77615b3e2f6b07e142b68d /tests
parentf2a5c09144f17f3240ae6a7e7b48237f1b234d9b (diff)
Kinect demo update
+ added compile-time option for using bars Change-Id: Icdab902c7969326cc09974c3e45e40e33a9144f9 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/kinectsurface/main.cpp10
-rw-r--r--tests/kinectsurface/surfacedata.cpp52
-rw-r--r--tests/kinectsurface/surfacedata.h19
3 files changed, 63 insertions, 18 deletions
diff --git a/tests/kinectsurface/main.cpp b/tests/kinectsurface/main.cpp
index fc969ace..bc82a38e 100644
--- a/tests/kinectsurface/main.cpp
+++ b/tests/kinectsurface/main.cpp
@@ -37,8 +37,10 @@ int main(int argc, char **argv)
QHBoxLayout *hLayout = new QHBoxLayout(widget);
QVBoxLayout *vLayout = new QVBoxLayout();
-#ifdef USE_SCATTER
+#if defined(USE_SCATTER)
Q3DScatter *surface = new Q3DScatter();
+#elif defined(USE_BARS)
+ Q3DBars *surface = new Q3DBars();
#else
Q3DSurface *surface = new Q3DSurface();
#endif
@@ -76,7 +78,7 @@ int main(int argc, char **argv)
distanceSlider->setValue(50);
distanceSlider->setMaximum(200);
-#ifndef USE_SCATTER
+#if !defined(USE_SCATTER) && !defined(USE_BARS)
QLinearGradient gradientOne(0, 0, 200, 1);
gradientOne.setColorAt(0.0, Qt::black);
gradientOne.setColorAt(0.33, Qt::blue);
@@ -118,7 +120,7 @@ int main(int argc, char **argv)
vLayout->addWidget(resolutionBox);
vLayout->addWidget(new QLabel(QStringLiteral("Adjust far distance")));
vLayout->addWidget(distanceSlider);
-#ifndef USE_SCATTER
+#if !defined(USE_SCATTER) && !defined(USE_BARS)
vLayout->addWidget(new QLabel(QStringLiteral("Change color scheme")));
vLayout->addWidget(gradientOneButton);
vLayout->addWidget(gradientTwoButton);
@@ -134,7 +136,7 @@ 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
+#if !defined(USE_SCATTER) && !defined(USE_BARS)
QObject::connect(gradientOneButton, &QPushButton::clicked, datagen,
&SurfaceData::useGradientOne);
QObject::connect(gradientTwoButton, &QPushButton::clicked, datagen,
diff --git a/tests/kinectsurface/surfacedata.cpp b/tests/kinectsurface/surfacedata.cpp
index e80d1cac..06d73ec1 100644
--- a/tests/kinectsurface/surfacedata.cpp
+++ b/tests/kinectsurface/surfacedata.cpp
@@ -20,8 +20,10 @@
#include "surfacedata.h"
#include "QKinectWrapper.h"
-#ifdef USE_SCATTER
+#if defined(USE_SCATTER)
#include <QtDataVisualization/QScatterDataProxy>
+#elif defined(USE_BARS)
+#include <QtDataVisualization/QBarDataProxy>
#else
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
#endif
@@ -34,7 +36,7 @@
QT_DATAVISUALIZATION_USE_NAMESPACE
-#ifdef USE_SCATTER
+#if defined(USE_SCATTER)
SurfaceData::SurfaceData(Q3DScatter *surface, QTextEdit *statusArea) :
m_surface(surface),
m_statusArea(statusArea),
@@ -43,9 +45,7 @@ SurfaceData::SurfaceData(Q3DScatter *surface, QTextEdit *statusArea) :
{
// 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);
@@ -53,6 +53,23 @@ SurfaceData::SurfaceData(Q3DScatter *surface, QTextEdit *statusArea) :
m_surface->axisX()->setMax(m_resolution.width() / 2);
m_surface->axisZ()->setMin(-m_resolution.height() / 2);
m_surface->axisZ()->setMax(m_resolution.height() / 2);
+#elif defined(USE_BARS)
+SurfaceData::SurfaceData(Q3DBars *surface, QTextEdit *statusArea) :
+ m_surface(surface),
+ m_statusArea(statusArea),
+ m_resize(true),
+ m_resolution(QSize(80, 60))
+{
+ // Initialize scatter
+ m_surface->setTheme(QDataVis::ThemeQt);
+ m_surface->setBarType(QDataVis::Bars, true);
+#if 1
+ m_surface->setShadowQuality(QDataVis::ShadowLow);
+#else
+ m_surface->setBarSpacing(QSizeF(0.0, 0.0));
+#endif
+ m_surface->setCameraPosition(0.0, 75.0);
+ m_surface->valueAxis()->setMax(255);
#else
SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
m_surface(surface),
@@ -71,11 +88,14 @@ SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
m_surface->axisY()->setMax(255);
m_surface->setSurfaceGridEnabled(false);
m_surface->setBackgroundVisible(false);
- m_surface->setGridVisible(false);
m_surface->setSmoothSurfaceEnabled(false);
m_surface->setActiveDataProxy(new QHeightMapSurfaceDataProxy());
#endif
+ // Common initializers
+ m_surface->setSelectionMode(QDataVis::ModeNone);
+ m_surface->setGridVisible(false);
+
// Hide scroll bar
m_statusArea->verticalScrollBar()->setVisible(false);
@@ -95,7 +115,7 @@ void SurfaceData::updateData()
QImage depthMap = m_kinect.getDepth();
if (m_resize) // Resize for better performance
depthMap = depthMap.scaled(m_resolution);
-#ifdef USE_SCATTER
+#if defined(USE_SCATTER) || defined(USE_BARS)
setData(depthMap);
#else
static_cast<QHeightMapSurfaceDataProxy *>(m_surface->activeDataProxy())->setHeightMap(depthMap);
@@ -172,13 +192,16 @@ void SurfaceData::setResolution(int selection)
break;
}
};
-#ifdef USE_SCATTER
+#if defined(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);
+#elif defined(USE_BARS)
+ m_resize = true;
+ m_resolution /= 4;
#endif
m_statusArea->append(QString(QStringLiteral("<b>Resolution:</b> %1 x %2")).arg(
@@ -193,7 +216,7 @@ void SurfaceData::scrollDown()
scrollbar->setValue(scrollbar->maximum());
}
-#ifndef USE_SCATTER
+#if !defined(USE_SCATTER) && !defined(USE_BARS)
void SurfaceData::useGradientOne()
{
m_surface->setTheme(QDataVis::ThemeIsabelle);
@@ -228,6 +251,7 @@ void SurfaceData::setData(const QImage &image)
int bitCount = imageWidth * 4 * (imageHeight - 1);
int widthBits = imageWidth * 4;
+#if defined(USE_SCATTER)
QScatterDataArray *dataArray = new QScatterDataArray;
dataArray->resize(imageHeight * imageWidth);
QScatterDataItem *ptrToDataArray = &dataArray->first();
@@ -247,6 +271,18 @@ void SurfaceData::setData(const QImage &image)
}
static_cast<QScatterDataProxy *>(m_surface->activeDataProxy())->resetArray(dataArray);
+#elif defined(USE_BARS)
+ QBarDataArray *dataArray = new QBarDataArray;
+ dataArray->reserve(imageHeight);
+ for (int i = imageHeight; i > 0; i--, bitCount -= widthBits) {
+ QBarDataRow *newRow = new QBarDataRow(imageWidth);
+ for (int j = 0; j < imageWidth; j++)
+ (*newRow)[j] = qreal(bits[bitCount + (j * 4)]);
+ *dataArray << newRow;
+ }
+
+ static_cast<QBarDataProxy *>(m_surface->activeDataProxy())->resetArray(dataArray);
+#endif
}
#endif
diff --git a/tests/kinectsurface/surfacedata.h b/tests/kinectsurface/surfacedata.h
index 9a89dd13..707bf3c8 100644
--- a/tests/kinectsurface/surfacedata.h
+++ b/tests/kinectsurface/surfacedata.h
@@ -20,10 +20,13 @@
#define SURFACEDATA_H
//#define USE_SCATTER
+//#define USE_BARS
#include "QKinectWrapper.h"
-#ifdef USE_SCATTER
+#if defined(USE_SCATTER)
#include <QtDataVisualization/Q3DScatter>
+#elif defined(USE_BARS)
+#include <QtDataVisualization/Q3DBars>
#else
#include <QtDataVisualization/Q3DSurface>
#endif
@@ -36,8 +39,10 @@ class SurfaceData : public QObject
Q_OBJECT
public:
-#ifdef USE_SCATTER
+#if defined(USE_SCATTER)
explicit SurfaceData(Q3DScatter *surface, QTextEdit *statusLabel);
+#elif defined(USE_BARS)
+ explicit SurfaceData(Q3DBars *surface, QTextEdit *statusLabel);
#else
explicit SurfaceData(Q3DSurface *surface, QTextEdit *statusLabel);
#endif
@@ -51,19 +56,21 @@ public:
void setDistance(int distance);
void scrollDown();
-#ifndef USE_SCATTER
+#if defined(USE_SCATTER) || defined(USE_BARS)
+ void setData(const QImage &image);
+#else
void useGradientOne();
void useGradientTwo();
-#else
- void setData(const QImage &image);
#endif
public slots:
void setResolution(int selection);
private:
-#ifdef USE_SCATTER
+#if defined(USE_SCATTER)
Q3DScatter *m_surface;
+#elif defined(USE_BARS)
+ Q3DBars *m_surface;
#else
Q3DSurface *m_surface;
#endif