mirror of https://github.com/qt/qtdatavis3d.git
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>
This commit is contained in:
parent
9d0495cae3
commit
b776b6d3aa
|
|
@ -37,7 +37,12 @@ int main(int argc, char **argv)
|
||||||
QHBoxLayout *hLayout = new QHBoxLayout(widget);
|
QHBoxLayout *hLayout = new QHBoxLayout(widget);
|
||||||
QVBoxLayout *vLayout = new QVBoxLayout();
|
QVBoxLayout *vLayout = new QVBoxLayout();
|
||||||
|
|
||||||
|
#ifdef USE_SCATTER
|
||||||
|
Q3DScatter *surface = new Q3DScatter();
|
||||||
|
#else
|
||||||
Q3DSurface *surface = new Q3DSurface();
|
Q3DSurface *surface = new Q3DSurface();
|
||||||
|
#endif
|
||||||
|
|
||||||
QSize screenSize = surface->screen()->size();
|
QSize screenSize = surface->screen()->size();
|
||||||
|
|
||||||
QWidget *container = QWidget::createWindowContainer(surface);
|
QWidget *container = QWidget::createWindowContainer(surface);
|
||||||
|
|
@ -71,6 +76,7 @@ int main(int argc, char **argv)
|
||||||
distanceSlider->setValue(50);
|
distanceSlider->setValue(50);
|
||||||
distanceSlider->setMaximum(200);
|
distanceSlider->setMaximum(200);
|
||||||
|
|
||||||
|
#ifndef USE_SCATTER
|
||||||
QLinearGradient gradientOne(0, 0, 200, 1);
|
QLinearGradient gradientOne(0, 0, 200, 1);
|
||||||
gradientOne.setColorAt(0.0, Qt::black);
|
gradientOne.setColorAt(0.0, Qt::black);
|
||||||
gradientOne.setColorAt(0.33, Qt::blue);
|
gradientOne.setColorAt(0.33, Qt::blue);
|
||||||
|
|
@ -101,6 +107,7 @@ int main(int argc, char **argv)
|
||||||
gradientTwoButton->setIcon(QIcon(pm));
|
gradientTwoButton->setIcon(QIcon(pm));
|
||||||
gradientTwoButton->setIconSize(QSize(200, 24));
|
gradientTwoButton->setIconSize(QSize(200, 24));
|
||||||
gradientTwoButton->setToolTip(QStringLiteral("Colors: Highlight Foreground"));
|
gradientTwoButton->setToolTip(QStringLiteral("Colors: Highlight Foreground"));
|
||||||
|
#endif
|
||||||
|
|
||||||
QTextEdit *status = new QTextEdit(QStringLiteral("<b>Ready</b><br>"), widget);
|
QTextEdit *status = new QTextEdit(QStringLiteral("<b>Ready</b><br>"), widget);
|
||||||
status->setReadOnly(true);
|
status->setReadOnly(true);
|
||||||
|
|
@ -111,9 +118,11 @@ int main(int argc, char **argv)
|
||||||
vLayout->addWidget(resolutionBox);
|
vLayout->addWidget(resolutionBox);
|
||||||
vLayout->addWidget(new QLabel(QStringLiteral("Adjust far distance")));
|
vLayout->addWidget(new QLabel(QStringLiteral("Adjust far distance")));
|
||||||
vLayout->addWidget(distanceSlider);
|
vLayout->addWidget(distanceSlider);
|
||||||
|
#ifndef USE_SCATTER
|
||||||
vLayout->addWidget(new QLabel(QStringLiteral("Change color scheme")));
|
vLayout->addWidget(new QLabel(QStringLiteral("Change color scheme")));
|
||||||
vLayout->addWidget(gradientOneButton);
|
vLayout->addWidget(gradientOneButton);
|
||||||
vLayout->addWidget(gradientTwoButton);
|
vLayout->addWidget(gradientTwoButton);
|
||||||
|
#endif
|
||||||
vLayout->addWidget(status, 1, Qt::AlignBottom);
|
vLayout->addWidget(status, 1, Qt::AlignBottom);
|
||||||
|
|
||||||
widget->show();
|
widget->show();
|
||||||
|
|
@ -125,10 +134,12 @@ int main(int argc, char **argv)
|
||||||
QObject::connect(distanceSlider, &QSlider::valueChanged, datagen, &SurfaceData::setDistance);
|
QObject::connect(distanceSlider, &QSlider::valueChanged, datagen, &SurfaceData::setDistance);
|
||||||
QObject::connect(resolutionBox, SIGNAL(activated(int)), datagen, SLOT(setResolution(int)));
|
QObject::connect(resolutionBox, SIGNAL(activated(int)), datagen, SLOT(setResolution(int)));
|
||||||
QObject::connect(status, &QTextEdit::textChanged, datagen, &SurfaceData::scrollDown);
|
QObject::connect(status, &QTextEdit::textChanged, datagen, &SurfaceData::scrollDown);
|
||||||
|
#ifndef USE_SCATTER
|
||||||
QObject::connect(gradientOneButton, &QPushButton::clicked, datagen,
|
QObject::connect(gradientOneButton, &QPushButton::clicked, datagen,
|
||||||
&SurfaceData::useGradientOne);
|
&SurfaceData::useGradientOne);
|
||||||
QObject::connect(gradientTwoButton, &QPushButton::clicked, datagen,
|
QObject::connect(gradientTwoButton, &QPushButton::clicked, datagen,
|
||||||
&SurfaceData::useGradientTwo);
|
&SurfaceData::useGradientTwo);
|
||||||
|
#endif
|
||||||
|
|
||||||
datagen->setDistance(distanceSlider->value());
|
datagen->setDistance(distanceSlider->value());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,40 @@
|
||||||
|
|
||||||
#include "surfacedata.h"
|
#include "surfacedata.h"
|
||||||
#include "QKinectWrapper.h"
|
#include "QKinectWrapper.h"
|
||||||
|
#ifdef USE_SCATTER
|
||||||
|
#include <QtDataVisualization/QScatterDataProxy>
|
||||||
|
#else
|
||||||
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
|
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
|
||||||
|
#endif
|
||||||
#include <QtDataVisualization/Q3DValueAxis>
|
#include <QtDataVisualization/Q3DValueAxis>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
QT_DATAVISUALIZATION_USE_NAMESPACE
|
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) :
|
SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
|
||||||
m_surface(surface),
|
m_surface(surface),
|
||||||
m_statusArea(statusArea),
|
m_statusArea(statusArea),
|
||||||
|
|
@ -49,6 +74,7 @@ SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
|
||||||
m_surface->setGridVisible(false);
|
m_surface->setGridVisible(false);
|
||||||
m_surface->setSmoothSurfaceEnabled(false);
|
m_surface->setSmoothSurfaceEnabled(false);
|
||||||
m_surface->setActiveDataProxy(new QHeightMapSurfaceDataProxy());
|
m_surface->setActiveDataProxy(new QHeightMapSurfaceDataProxy());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Hide scroll bar
|
// Hide scroll bar
|
||||||
m_statusArea->verticalScrollBar()->setVisible(false);
|
m_statusArea->verticalScrollBar()->setVisible(false);
|
||||||
|
|
@ -69,7 +95,11 @@ void SurfaceData::updateData()
|
||||||
QImage depthMap = m_kinect.getDepth();
|
QImage depthMap = m_kinect.getDepth();
|
||||||
if (m_resize) // Resize for better performance
|
if (m_resize) // Resize for better performance
|
||||||
depthMap = depthMap.scaled(m_resolution);
|
depthMap = depthMap.scaled(m_resolution);
|
||||||
|
#ifdef USE_SCATTER
|
||||||
|
setData(depthMap);
|
||||||
|
#else
|
||||||
static_cast<QHeightMapSurfaceDataProxy *>(m_surface->activeDataProxy())->setHeightMap(depthMap);
|
static_cast<QHeightMapSurfaceDataProxy *>(m_surface->activeDataProxy())->setHeightMap(depthMap);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SurfaceData::updateStatus(QKinect::KinectStatus status)
|
void SurfaceData::updateStatus(QKinect::KinectStatus status)
|
||||||
|
|
@ -142,6 +172,15 @@ void SurfaceData::setResolution(int selection)
|
||||||
break;
|
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_statusArea->append(QString(QStringLiteral("<b>Resolution:</b> %1 x %2")).arg(
|
||||||
m_resolution.width()).arg(m_resolution.height()));
|
m_resolution.width()).arg(m_resolution.height()));
|
||||||
if (m_kinect.isStopped())
|
if (m_kinect.isStopped())
|
||||||
|
|
@ -154,6 +193,7 @@ void SurfaceData::scrollDown()
|
||||||
scrollbar->setValue(scrollbar->maximum());
|
scrollbar->setValue(scrollbar->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_SCATTER
|
||||||
void SurfaceData::useGradientOne()
|
void SurfaceData::useGradientOne()
|
||||||
{
|
{
|
||||||
m_surface->setTheme(QDataVis::ThemeIsabelle);
|
m_surface->setTheme(QDataVis::ThemeIsabelle);
|
||||||
|
|
@ -176,3 +216,37 @@ void SurfaceData::useGradientTwo()
|
||||||
m_surface->setGradient(gradient);
|
m_surface->setGradient(gradient);
|
||||||
m_statusArea->append(QStringLiteral("<b>Colors:</b> Highlight foreground"));
|
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
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,14 @@
|
||||||
#ifndef SURFACEDATA_H
|
#ifndef SURFACEDATA_H
|
||||||
#define SURFACEDATA_H
|
#define SURFACEDATA_H
|
||||||
|
|
||||||
|
//#define USE_SCATTER
|
||||||
|
|
||||||
#include "QKinectWrapper.h"
|
#include "QKinectWrapper.h"
|
||||||
#include <QtDataVisualization/q3dsurface.h>
|
#ifdef USE_SCATTER
|
||||||
|
#include <QtDataVisualization/Q3DScatter>
|
||||||
|
#else
|
||||||
|
#include <QtDataVisualization/Q3DSurface>
|
||||||
|
#endif
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
||||||
using namespace QtDataVisualization;
|
using namespace QtDataVisualization;
|
||||||
|
|
@ -30,7 +36,11 @@ class SurfaceData : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
#ifdef USE_SCATTER
|
||||||
|
explicit SurfaceData(Q3DScatter *surface, QTextEdit *statusLabel);
|
||||||
|
#else
|
||||||
explicit SurfaceData(Q3DSurface *surface, QTextEdit *statusLabel);
|
explicit SurfaceData(Q3DSurface *surface, QTextEdit *statusLabel);
|
||||||
|
#endif
|
||||||
~SurfaceData();
|
~SurfaceData();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
@ -41,14 +51,22 @@ public:
|
||||||
|
|
||||||
void setDistance(int distance);
|
void setDistance(int distance);
|
||||||
void scrollDown();
|
void scrollDown();
|
||||||
|
#ifndef USE_SCATTER
|
||||||
void useGradientOne();
|
void useGradientOne();
|
||||||
void useGradientTwo();
|
void useGradientTwo();
|
||||||
|
#else
|
||||||
|
void setData(const QImage &image);
|
||||||
|
#endif
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setResolution(int selection);
|
void setResolution(int selection);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef USE_SCATTER
|
||||||
|
Q3DScatter *m_surface;
|
||||||
|
#else
|
||||||
Q3DSurface *m_surface;
|
Q3DSurface *m_surface;
|
||||||
|
#endif
|
||||||
QTextEdit *m_statusArea;
|
QTextEdit *m_statusArea;
|
||||||
bool m_resize;
|
bool m_resize;
|
||||||
QSize m_resolution;
|
QSize m_resolution;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue