#include "test3DvisuData.h"
#include <QPushButton>
#include <iostream>
#include <QtDataVisualization/qcustom3dlabel.h>
#include <QtDataVisualization/q3dscatter.h>
#include <QtDataVisualization/q3dsurface.h>
#include <QtDataVisualization/QCustom3DVolume>
#include <QtDataVisualization/Q3DInputHandler>
#include <QtDataVisualization/QHeightMapSurfaceDataProxy>
#include <QApplication>
#define PROBLEM true
/// Short class for debugging objects creation
template<typename T> class GraphTest: public T{
const int mLabel;
static int label;
std::string name;
public:
GraphTest(const std::string & in):T(),mLabel(label++),name(in){
std::cout<<" ctor "<< name <<mLabel<< std::endl;
};
~GraphTest(){
std::cout<<" ~dtor "<< name << mLabel<<std::endl;
};
};
template <typename T>int GraphTest<T>::label = 0;
ViewerTest::ViewerTest():m3DImageHolder(nullptr),m3DGraph(nullptr),m3DGraphSurface(nullptr){
setLayout(mMainLayout);
mMainLayout->addLayout(mButtonsLayout);
mMainLayout->addLayout(m3DLayoutHolder);
mButtonsLayout->addWidget(mHide);
mButtonsLayout->addWidget(mNewScat);
mButtonsLayout->addWidget(mNewSurf);
connect(mNewSurf,&QPushButton::released,this,&ViewerTest::buildSurface);
connect(mNewScat,&QPushButton::released,this,&ViewerTest::buildScatter);
connect(mHide,&QPushButton::released,this,&ViewerTest::hideAll);
}
///This part is just the data construction
void ViewerTest::build(TYPE type) {
if(type==SCATTER) {
m3DGraph = new /*QtD::Q3DScatter();*/GraphTest<QtD::Q3DScatter>("inData3D");
m3DGraph->scene()->activeCamera()->setCameraPreset( QtD::Q3DCamera::CameraPresetIsometricRight );
m3DGraph->setOrthoProjection(true);
QtD::QCustom3DVolume *vol = new QtD::QCustom3DVolume;
vol->setScaling(
QVector3D(m3DGraph->axisX()->max() - m3DGraph->axisX()->min(),
(m3DGraph->axisY()->max() - m3DGraph->axisY()->min()) * 1.0f,
m3DGraph->axisZ()->max() - m3DGraph->axisZ()->min()));
vol->setScalingAbsolute(false);
// Build the data
unsigned int height(20),width(20),depth(20);
QVector<uchar> *vectorData = new QVector<uchar>(height * width * depth * 4, 0);
vol->setTextureWidth(width);vol->setTextureHeight(height);vol->setTextureDepth(depth);
vol
->setTextureFormat
(QImage::Format_ARGB32);
for (int z = 0; z < height; z++) {
for (int y = 0; y < depth; y++) {
for (int x = 0; x < width; x++) {
for( int c = 0; c<4; c++){
(*vectorData)[(x + width * z + width * height * y) * 4 + c] =
c==0?x*5:(c==1?y*5:(c==2?z*5:20));
}
}
}
}
vol->setTextureData(vectorData);
m3DGraph->addCustomItem(vol);
}
///// ------------------
else if(type==SURF){
for(uint x=0; x<20; x++){
for(uint y=0; y<20; y++){
image.
setPixelColor(x,y,
QColor(x
*y
));
}
}
QtD::QHeightMapSurfaceDataProxy *proxy = new QtD::QHeightMapSurfaceDataProxy(image);
QtD::QSurface3DSeries *serie = new QtD::QSurface3DSeries(proxy);
serie->setDrawMode(QtD::QSurface3DSeries::DrawSurface);
m3DGraphSurface = new GraphTest<QtD::Q3DSurface>("inData3DSurface");
m3DGraphSurface->addSeries(serie);
m3DGraphSurface->seriesList().at(0)->setColorStyle( QtD::Q3DTheme::ColorStyleRangeGradient );
}
}