mirror of https://github.com/qt/qtdatavis3d.git
Kinect demo update
+ added compile-time option for using bars Change-Id: Icdab902c7969326cc09974c3e45e40e33a9144f9 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
This commit is contained in:
parent
f2a5c09144
commit
1628d6a966
|
|
@ -37,8 +37,10 @@ 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
|
#if defined(USE_SCATTER)
|
||||||
Q3DScatter *surface = new Q3DScatter();
|
Q3DScatter *surface = new Q3DScatter();
|
||||||
|
#elif defined(USE_BARS)
|
||||||
|
Q3DBars *surface = new Q3DBars();
|
||||||
#else
|
#else
|
||||||
Q3DSurface *surface = new Q3DSurface();
|
Q3DSurface *surface = new Q3DSurface();
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -76,7 +78,7 @@ int main(int argc, char **argv)
|
||||||
distanceSlider->setValue(50);
|
distanceSlider->setValue(50);
|
||||||
distanceSlider->setMaximum(200);
|
distanceSlider->setMaximum(200);
|
||||||
|
|
||||||
#ifndef USE_SCATTER
|
#if !defined(USE_SCATTER) && !defined(USE_BARS)
|
||||||
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);
|
||||||
|
|
@ -118,7 +120,7 @@ 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
|
#if !defined(USE_SCATTER) && !defined(USE_BARS)
|
||||||
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);
|
||||||
|
|
@ -134,7 +136,7 @@ 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
|
#if !defined(USE_SCATTER) && !defined(USE_BARS)
|
||||||
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,
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@
|
||||||
|
|
||||||
#include "surfacedata.h"
|
#include "surfacedata.h"
|
||||||
#include "QKinectWrapper.h"
|
#include "QKinectWrapper.h"
|
||||||
#ifdef USE_SCATTER
|
#if defined(USE_SCATTER)
|
||||||
#include <QtDataVisualization/QScatterDataProxy>
|
#include <QtDataVisualization/QScatterDataProxy>
|
||||||
|
#elif defined(USE_BARS)
|
||||||
|
#include <QtDataVisualization/QBarDataProxy>
|
||||||
#else
|
#else
|
||||||
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
|
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -34,7 +36,7 @@
|
||||||
|
|
||||||
QT_DATAVISUALIZATION_USE_NAMESPACE
|
QT_DATAVISUALIZATION_USE_NAMESPACE
|
||||||
|
|
||||||
#ifdef USE_SCATTER
|
#if defined(USE_SCATTER)
|
||||||
SurfaceData::SurfaceData(Q3DScatter *surface, QTextEdit *statusArea) :
|
SurfaceData::SurfaceData(Q3DScatter *surface, QTextEdit *statusArea) :
|
||||||
m_surface(surface),
|
m_surface(surface),
|
||||||
m_statusArea(statusArea),
|
m_statusArea(statusArea),
|
||||||
|
|
@ -43,9 +45,7 @@ SurfaceData::SurfaceData(Q3DScatter *surface, QTextEdit *statusArea) :
|
||||||
{
|
{
|
||||||
// Initialize scatter
|
// Initialize scatter
|
||||||
m_surface->setTheme(QDataVis::ThemeStoneMoss);
|
m_surface->setTheme(QDataVis::ThemeStoneMoss);
|
||||||
m_surface->setGridVisible(false);
|
|
||||||
m_surface->setObjectType(QDataVis::Dots, false);
|
m_surface->setObjectType(QDataVis::Dots, false);
|
||||||
m_surface->setSelectionMode(QDataVis::ModeNone);
|
|
||||||
m_surface->setShadowQuality(QDataVis::ShadowSoftLow);
|
m_surface->setShadowQuality(QDataVis::ShadowSoftLow);
|
||||||
m_surface->setCameraPosition(0.0, 85.0, 110);
|
m_surface->setCameraPosition(0.0, 85.0, 110);
|
||||||
m_surface->axisY()->setMax(255);
|
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->axisX()->setMax(m_resolution.width() / 2);
|
||||||
m_surface->axisZ()->setMin(-m_resolution.height() / 2);
|
m_surface->axisZ()->setMin(-m_resolution.height() / 2);
|
||||||
m_surface->axisZ()->setMax(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
|
#else
|
||||||
SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
|
SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
|
||||||
m_surface(surface),
|
m_surface(surface),
|
||||||
|
|
@ -71,11 +88,14 @@ SurfaceData::SurfaceData(Q3DSurface *surface, QTextEdit *statusArea) :
|
||||||
m_surface->axisY()->setMax(255);
|
m_surface->axisY()->setMax(255);
|
||||||
m_surface->setSurfaceGridEnabled(false);
|
m_surface->setSurfaceGridEnabled(false);
|
||||||
m_surface->setBackgroundVisible(false);
|
m_surface->setBackgroundVisible(false);
|
||||||
m_surface->setGridVisible(false);
|
|
||||||
m_surface->setSmoothSurfaceEnabled(false);
|
m_surface->setSmoothSurfaceEnabled(false);
|
||||||
m_surface->setActiveDataProxy(new QHeightMapSurfaceDataProxy());
|
m_surface->setActiveDataProxy(new QHeightMapSurfaceDataProxy());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Common initializers
|
||||||
|
m_surface->setSelectionMode(QDataVis::ModeNone);
|
||||||
|
m_surface->setGridVisible(false);
|
||||||
|
|
||||||
// Hide scroll bar
|
// Hide scroll bar
|
||||||
m_statusArea->verticalScrollBar()->setVisible(false);
|
m_statusArea->verticalScrollBar()->setVisible(false);
|
||||||
|
|
||||||
|
|
@ -95,7 +115,7 @@ 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
|
#if defined(USE_SCATTER) || defined(USE_BARS)
|
||||||
setData(depthMap);
|
setData(depthMap);
|
||||||
#else
|
#else
|
||||||
static_cast<QHeightMapSurfaceDataProxy *>(m_surface->activeDataProxy())->setHeightMap(depthMap);
|
static_cast<QHeightMapSurfaceDataProxy *>(m_surface->activeDataProxy())->setHeightMap(depthMap);
|
||||||
|
|
@ -172,13 +192,16 @@ void SurfaceData::setResolution(int selection)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#ifdef USE_SCATTER
|
#if defined(USE_SCATTER)
|
||||||
m_resize = true;
|
m_resize = true;
|
||||||
m_resolution /= 4;
|
m_resolution /= 4;
|
||||||
m_surface->axisX()->setMin(-m_resolution.width() / 2);
|
m_surface->axisX()->setMin(-m_resolution.width() / 2);
|
||||||
m_surface->axisX()->setMax(m_resolution.width() / 2);
|
m_surface->axisX()->setMax(m_resolution.width() / 2);
|
||||||
m_surface->axisZ()->setMin(-m_resolution.height() / 2);
|
m_surface->axisZ()->setMin(-m_resolution.height() / 2);
|
||||||
m_surface->axisZ()->setMax(m_resolution.height() / 2);
|
m_surface->axisZ()->setMax(m_resolution.height() / 2);
|
||||||
|
#elif defined(USE_BARS)
|
||||||
|
m_resize = true;
|
||||||
|
m_resolution /= 4;
|
||||||
#endif
|
#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(
|
||||||
|
|
@ -193,7 +216,7 @@ void SurfaceData::scrollDown()
|
||||||
scrollbar->setValue(scrollbar->maximum());
|
scrollbar->setValue(scrollbar->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef USE_SCATTER
|
#if !defined(USE_SCATTER) && !defined(USE_BARS)
|
||||||
void SurfaceData::useGradientOne()
|
void SurfaceData::useGradientOne()
|
||||||
{
|
{
|
||||||
m_surface->setTheme(QDataVis::ThemeIsabelle);
|
m_surface->setTheme(QDataVis::ThemeIsabelle);
|
||||||
|
|
@ -228,6 +251,7 @@ void SurfaceData::setData(const QImage &image)
|
||||||
int bitCount = imageWidth * 4 * (imageHeight - 1);
|
int bitCount = imageWidth * 4 * (imageHeight - 1);
|
||||||
int widthBits = imageWidth * 4;
|
int widthBits = imageWidth * 4;
|
||||||
|
|
||||||
|
#if defined(USE_SCATTER)
|
||||||
QScatterDataArray *dataArray = new QScatterDataArray;
|
QScatterDataArray *dataArray = new QScatterDataArray;
|
||||||
dataArray->resize(imageHeight * imageWidth);
|
dataArray->resize(imageHeight * imageWidth);
|
||||||
QScatterDataItem *ptrToDataArray = &dataArray->first();
|
QScatterDataItem *ptrToDataArray = &dataArray->first();
|
||||||
|
|
@ -247,6 +271,18 @@ void SurfaceData::setData(const QImage &image)
|
||||||
}
|
}
|
||||||
|
|
||||||
static_cast<QScatterDataProxy *>(m_surface->activeDataProxy())->resetArray(dataArray);
|
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
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,13 @@
|
||||||
#define SURFACEDATA_H
|
#define SURFACEDATA_H
|
||||||
|
|
||||||
//#define USE_SCATTER
|
//#define USE_SCATTER
|
||||||
|
//#define USE_BARS
|
||||||
|
|
||||||
#include "QKinectWrapper.h"
|
#include "QKinectWrapper.h"
|
||||||
#ifdef USE_SCATTER
|
#if defined(USE_SCATTER)
|
||||||
#include <QtDataVisualization/Q3DScatter>
|
#include <QtDataVisualization/Q3DScatter>
|
||||||
|
#elif defined(USE_BARS)
|
||||||
|
#include <QtDataVisualization/Q3DBars>
|
||||||
#else
|
#else
|
||||||
#include <QtDataVisualization/Q3DSurface>
|
#include <QtDataVisualization/Q3DSurface>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -36,8 +39,10 @@ class SurfaceData : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#ifdef USE_SCATTER
|
#if defined(USE_SCATTER)
|
||||||
explicit SurfaceData(Q3DScatter *surface, QTextEdit *statusLabel);
|
explicit SurfaceData(Q3DScatter *surface, QTextEdit *statusLabel);
|
||||||
|
#elif defined(USE_BARS)
|
||||||
|
explicit SurfaceData(Q3DBars *surface, QTextEdit *statusLabel);
|
||||||
#else
|
#else
|
||||||
explicit SurfaceData(Q3DSurface *surface, QTextEdit *statusLabel);
|
explicit SurfaceData(Q3DSurface *surface, QTextEdit *statusLabel);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -51,19 +56,21 @@ public:
|
||||||
|
|
||||||
void setDistance(int distance);
|
void setDistance(int distance);
|
||||||
void scrollDown();
|
void scrollDown();
|
||||||
#ifndef USE_SCATTER
|
#if defined(USE_SCATTER) || defined(USE_BARS)
|
||||||
|
void setData(const QImage &image);
|
||||||
|
#else
|
||||||
void useGradientOne();
|
void useGradientOne();
|
||||||
void useGradientTwo();
|
void useGradientTwo();
|
||||||
#else
|
|
||||||
void setData(const QImage &image);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setResolution(int selection);
|
void setResolution(int selection);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef USE_SCATTER
|
#if defined(USE_SCATTER)
|
||||||
Q3DScatter *m_surface;
|
Q3DScatter *m_surface;
|
||||||
|
#elif defined(USE_BARS)
|
||||||
|
Q3DBars *m_surface;
|
||||||
#else
|
#else
|
||||||
Q3DSurface *m_surface;
|
Q3DSurface *m_surface;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue