Commit 53b97ddc by Kai Westerkamp

Opengl functions

File read draw bounds
parent 1e6720cf
......@@ -15,7 +15,8 @@ void Camera::home()
void Camera::setHome(QQuaternion *rotation, QVector3D *translation)
{
//qDebug()<<*rotation<<" trans:"<<*translation;
//qDebug()<<"Cam Home"<<*rotation<<" trans:"<<*translation;
this->homeRotation = rotation;
this->homeTranslation = translation;
home();
......
......@@ -3,6 +3,7 @@
#include "glview.h"
#include "scene.h"
#include "mainwindow.h"
#include <iostream>
Controler::Controler(MainWindow *mainwindow,Scene *scene)
{
......@@ -128,3 +129,86 @@ void Controler::setCamMode(){
void Controler::setEditMode(){
viewMode = EDIT;
}
void Controler::addVolume()
{
QString fn = QFileDialog::getOpenFileName(NULL, tr("Open Volume..."),
QString("D:\\Projekte\\GraPa\\A3"), tr("Volume Files (*.raw )"));
if(fn.isEmpty())
return;
qDebug()<<"Opening File:"<<fn;
addVolume(fn);
}
void Controler::addVolume(QString filePath){
QFile file(filePath);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", file.errorString());
}
QByteArray line1 = file.readLine();
QTextStream l1(line1);
QStringList line1Text = l1.readLine().split(" ");
int x = line1Text[0].toInt();
int y = line1Text[1].toInt();
int z = line1Text[2].toInt();
qDebug()<<line1Text<< x << y << z;
QByteArray line2 = file.readLine();
QTextStream l2(line2);
QStringList line1Text2 = l2.readLine().split(" ");
double dx = line1Text2[0].toDouble();
double dy = line1Text2[1].toDouble();
double dz = line1Text2[2].toDouble();
qDebug()<<line1Text2<< dx <<dy << dz;
QByteArray rawdata = file.readAll();
//qDebug()<<rawdata;
char ***data = new char**[z];
int count = 0;
// std::cout<<std::hex;
for(int k = 0; k < z; k++)
{
data[k] = new char*[y];
for(int j = 0; j < y; j++)
{
data[k][j] = new char[x];
for(int i = 0; i < x; i++)
{
data[k][j][i] = rawdata.at(count++);
if(k == 150 ){
int temp = ((uchar)data[k][j][i])*9/256;
std::cout<<temp;
// std::cout<<((uint)data[k][j][i]);
}
}
if(k == 150){
//std::cout<<std::endl;
}
}
}
//qDebug()<<file.readData(data,file.size()-file.pos());
for(int i = 0; i < 4; i++)
mainwindow->getViews()[i]->loadData(x,y,z,rawdata.data());
SceneVolume *volume = new SceneVolume(x,y,z,dx,dy,dz);
scene->addSceneObjectTaActive(volume);
file.close();
qDebug()<<"File Read finish";
}
......@@ -25,6 +25,9 @@ public slots:
void setCamMode();
void setEditMode();
void addVolume();
void addVolume(QString filePath);
private:
MainWindow *mainwindow;
Scene *scene;
......
......@@ -24,6 +24,8 @@ QSize GLView::sizeHint() const
void GLView::initializeGL ( ) {
Q_ASSERT(initializeOpenGLFunctions());
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
......@@ -85,14 +87,14 @@ void GLView::paintGL ()
{
bool useFBO = true;
//QOpenGLFunctions functions = QOpenGLContext::currentContext()->functions();
QGLFunctions functions = QGLFunctions(this->context());
// QOpenGLFunctions_4_3_Core functions = *this;
// QGLFunctions functions = QGLFunctions(this->context());
shader->bind();
if(useFBO){
functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
glBindFramebuffer(GL_FRAMEBUFFER,fbo);
GLenum buffers[] = {GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1};
// functions.glDrawBuffers(2,buffers);
glDrawBuffers(2,buffers);
//http://stackoverflow.com/questions/7207422/setting-up-opengl-multiple-render-targets
}
......@@ -110,7 +112,6 @@ void GLView::paintGL ()
shader->setUniformValue("shaded",true);
//qDebug()<<"IsLinked"<<shader->isLinked();
//set Projection and Camera Rotation
camera->setupCamera(aspect);
......@@ -153,7 +154,7 @@ void GLView::paintGL ()
displayShader->bind();
//
functions.glBindFramebuffer(GL_FRAMEBUFFER,0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,this->width(),this->height());
......@@ -162,11 +163,11 @@ void GLView::paintGL ()
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
functions.glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,color);
displayShader->setUniformValue("Texture",0);
functions.glActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,picID);
displayShader->setUniformValue("TextureID",1);
......@@ -293,10 +294,11 @@ void GLView::resizeGL(int width , int height )
{
aspect = 1.0*width/height;
QGLFunctions functions = QGLFunctions(this->context());
//QGLFunctions functions = QGLFunctions(this->context());
//QOpenGLFunctions_4_3_Core functions = *this;
functions.glGenFramebuffers(1, &fbo);
functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo);
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER,fbo);
......@@ -321,26 +323,47 @@ void GLView::resizeGL(int width , int height )
// Create the depth buffer
functions.glGenRenderbuffers(1, &depth);
functions.glBindRenderbuffer(GL_RENDERBUFFER, depth);
functions.glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,width,height);
glGenRenderbuffers(1, &depth);
glBindRenderbuffer(GL_RENDERBUFFER, depth);
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,width,height);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,picID,0);
functions.glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,picID,0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth);
GLenum err = functions.glCheckFramebufferStatus(GL_FRAMEBUFFER);
GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(err == GL_FRAMEBUFFER_COMPLETE){
qDebug()<<"FBO OK";
// qDebug()<<"FBO OK";
} else {
qDebug()<<"FBO ERROR"<<err;
}
functions.glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void GLView::loadData(int width, int height, int depth, char* data )
{
glEnable(GL_TEXTURE_3D);
glGenTextures( 1, &texture3D );
glBindTexture(GL_TEXTURE_3D, texture3D);
// Filtering
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Wrap
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP );
glTexImage3D( GL_TEXTURE_3D, 0, GL_R8,//
width, height, depth, 0,
GL_RED, GL_UNSIGNED_BYTE, data); // Imagedata as ByteBuffer
}
void GLView::setAcive(bool active)
......
......@@ -27,11 +27,13 @@ public slots:
void setGridSize(int size){gridSize = size;}
void setGridStepSize(int size){gridStepSize = size;}
void showGrid(bool bo){isGridEnabled = bo;}
void loadData(int width, int height, int depth, char* data);
public:
GLView(Scene *scene,Camera * camera,Controler *controler );
void setHome(QQuaternion *rotation, QVector3D *translation);
QSize minimumSizeHint() const;
QSize sizeHint() const;
......@@ -56,6 +58,9 @@ private:
GLuint picID;
GLuint depth;
GLuint texture3D;
void drawGrid();
void initShader();
......
......@@ -2,25 +2,8 @@
#include <treedelegate.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
void MainWindow::initViews()
{
setWindowTitle("Hello Cube");
menuBar = new QMenuBar();
toolBar = new QToolBar("Shading",this);
statusBar = new QStatusBar(this);
//Views
scene = new Scene();
scene->setTesselation(1);
connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar()));
connect(scene,SIGNAL(activChanged()),this,SLOT(updateGL()));
controler = new Controler(this,scene);
Camera *perspectiveCam = new Camera(true);
perspectiveView = new GLView(scene,perspectiveCam,controler);
......@@ -39,14 +22,24 @@ MainWindow::MainWindow(QWidget *parent)
new QVector3D(0.0,0.0,-4.0));
topView = new GLView(scene,topCam,controler);
views = new GLView*[4];
views[0] = perspectiveView;
views[1] = frontView;
views[2] = leftView;
views[3] = topView;
}
void MainWindow::initSplits()
{
viewGoup = new QActionGroup(this);
viewMenu = new QMenu("View",this);
topSplit = new QSplitter(Qt::Horizontal,this);
bottomSplit = new QSplitter(Qt::Horizontal,this);
verticalSplit = new QSplitter(Qt::Vertical,this);
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);
setActiveView(perspectiveView);
topSplit->addWidget(perspectiveView);
topSplit->addWidget(frontView);
......@@ -56,42 +49,9 @@ MainWindow::MainWindow(QWidget *parent)
verticalSplit->addWidget(topSplit);
verticalSplit->addWidget(bottomSplit);
setCentralWidget(verticalSplit);
showQuad();
//showSingle();
//showDual();
//
//File Menu Actions
fileMenu = new QMenu("&File");
viewGoup = new QActionGroup(this);
viewMenu = new QMenu("View",this);
primitivesMenu = new QMenu("Primitives",this);
interactionGroup = new QActionGroup(this);
interactionMenu = new QMenu("Interaction",this);
exitAction = new QAction("E&xit",fileMenu);
exitAction->setShortcut(QKeySequence::Quit);
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
//Interaction Actions
cameraMode = new QAction("Camera",this);
cameraMode->setCheckable(true);
cameraMode->setIcon(QIcon(":/img/camera.png"));
cameraMode->setChecked(true);
connect(cameraMode, SIGNAL(triggered()), controler, SLOT(setCamMode()));
interactionGroup->addAction(cameraMode);
editMode = new QAction("Edit",this);
editMode->setCheckable(true);
editMode->setIcon(QIcon(":/img/select.png"));
connect(editMode, SIGNAL(triggered()), controler, SLOT(setEditMode()));
interactionGroup->addAction(editMode);
//View Actions
singleView = new QAction("Single View",this);
......@@ -121,22 +81,88 @@ MainWindow::MainWindow(QWidget *parent)
viewMenu->addAction(singleView);
viewMenu->addAction(dualView);
viewMenu->addAction(quadView);
}
void MainWindow::initToolbar()
{
toolBar->addAction(cameraMode);
toolBar->addAction(editMode);
//Other Actions
aboutAction = new QAction("About",menuBar);
connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox()));
toolBar->addSeparator();
toolBar->addAction(camHome);
toolBar->addSeparator();
toolBar->addWidget(showGridButton);
toolBar->addWidget(gridSizeInput);
toolBar->addWidget(gridStepInput);
toolBar->addSeparator();
slider = new QSlider(Qt::Horizontal,toolBar);
slider->setMinimum( 0 );
slider->setMaximum( 4 );
connect(slider,SIGNAL(valueChanged(int)),scene,SLOT(setTesselation(int)));
slider->setValue( 1 );
QToolButton* toolButton = new QToolButton();
toolButton->setIcon(QIcon(":/img/viewports.png"));
toolButton->setMenu(viewMenu);
toolButton->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* toolButtonAction = new QWidgetAction(this);
toolButtonAction->setDefaultWidget(toolButton);
toolBar->addAction(toolButtonAction);
// Add Primitives
QToolButton* primitives = new QToolButton();
primitives->setIcon(QIcon(":/img/box.png"));
primitives->setMenu(primitivesMenu);
primitives->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* primitiveActione = new QWidgetAction(this);
primitiveActione->setDefaultWidget(primitives);
toolBar->addAction(primitiveActione);
toolBar->addWidget(slider);
addToolBar( toolBar);
}
void MainWindow::initGrid()
{
showGridButton = new QToolButton(toolBar);
showGridButton->setCheckable(true);
gridSizeInput = new QSpinBox(toolBar);
gridSizeInput->setRange(0,100);
gridSizeInput->setValue(5);
gridSizeInput->setToolTip("Grid Size");
gridStepInput = new QSpinBox(toolBar);
gridStepInput->setRange(1,10);
gridStepInput->setToolTip("Grid Step Size");
connect(gridSizeInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),perspectiveView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),topView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),topView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),topView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),leftView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),leftView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),leftView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),frontView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),frontView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),frontView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),this,SLOT(updateGL()));
connect(gridStepInput,SIGNAL(valueChanged(int)),this,SLOT(updateGL()));
connect(showGridButton,SIGNAL(clicked(bool)),this,SLOT(updateGL()));
}
void MainWindow::initPrimitivesMenu()
{
primitivesMenu = new QMenu("Primitives",this);
spheresAdd = new QAction("Sphere",this);
spheresAdd->setIcon(QIcon(":/img/sphere.png"));
......@@ -168,7 +194,7 @@ MainWindow::MainWindow(QWidget *parent)
volumeAdd = new QAction("Volume",this);
//activeDelete->setIcon(QIcon(":/img/delete.png"));
connect(volumeAdd, SIGNAL(triggered()), scene, SLOT(addVolume()));
connect(volumeAdd, SIGNAL(triggered()), controler, SLOT(addVolume()));
primitivesMenu->addAction(spheresAdd);
......@@ -179,94 +205,99 @@ MainWindow::MainWindow(QWidget *parent)
primitivesMenu->addAction(groupAdd);
primitivesMenu->addAction(activeDelete);
primitivesMenu->addAction(volumeAdd);
}
showGridButton = new QToolButton(toolBar);
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Hello Cube");
showGridButton->setCheckable(true);
menuBar = new QMenuBar();
toolBar = new QToolBar("Shading",this);
statusBar = new QStatusBar(this);
gridSizeInput = new QSpinBox(toolBar);
gridSizeInput->setRange(0,100);
gridSizeInput->setValue(5);
//Views
scene = new Scene();
scene->setTesselation(1);
connect(scene,SIGNAL(activChanged()),this,SLOT(updateStatusBar()));
connect(scene,SIGNAL(activChanged()),this,SLOT(updateGL()));
gridSizeInput->setToolTip("Grid Size");
gridStepInput = new QSpinBox(toolBar);
gridStepInput->setRange(1,10);
controler = new Controler(this,scene);
gridStepInput->setToolTip("Grid Step Size");
initViews();
connect(gridSizeInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),perspectiveView,SLOT(showGrid(bool)));
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);//vor set Active View
setActiveView(perspectiveView);
connect(gridSizeInput,SIGNAL(valueChanged(int)),topView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),topView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),topView,SLOT(showGrid(bool)));
initSplits();
connect(gridSizeInput,SIGNAL(valueChanged(int)),leftView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),leftView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),leftView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),frontView,SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),frontView,SLOT(setGridStepSize(int)));
connect(showGridButton,SIGNAL(clicked(bool)),frontView,SLOT(showGrid(bool)));
//File Menu Actions
fileMenu = new QMenu("&File");
connect(gridSizeInput,SIGNAL(valueChanged(int)),this,SLOT(updateGL()));
connect(gridStepInput,SIGNAL(valueChanged(int)),this,SLOT(updateGL()));
connect(showGridButton,SIGNAL(clicked(bool)),this,SLOT(updateGL()));
exitAction = new QAction("E&xit",fileMenu);
exitAction->setShortcut(QKeySequence::Quit);
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
// Assemble Menus
fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu);
menuBar->addMenu(primitivesMenu);
menuBar->addAction(aboutAction);
setMenuBar(menuBar);
//Interaction Actions
interactionGroup = new QActionGroup(this);
interactionMenu = new QMenu("Interaction",this);
//Assemble Tool Bar
toolBar->addAction(cameraMode);
toolBar->addAction(editMode);
cameraMode = new QAction("Camera",this);
cameraMode->setCheckable(true);
cameraMode->setIcon(QIcon(":/img/camera.png"));
cameraMode->setChecked(true);
connect(cameraMode, SIGNAL(triggered()), controler, SLOT(setCamMode()));
interactionGroup->addAction(cameraMode);
toolBar->addSeparator();
toolBar->addAction(camHome);
toolBar->addSeparator();
editMode = new QAction("Edit",this);
editMode->setCheckable(true);
editMode->setIcon(QIcon(":/img/select.png"));
connect(editMode, SIGNAL(triggered()), controler, SLOT(setEditMode()));
interactionGroup->addAction(editMode);
toolBar->addWidget(showGridButton);
toolBar->addWidget(gridSizeInput);
toolBar->addWidget(gridStepInput);
toolBar->addSeparator();
//Other Actions
aboutAction = new QAction("About",menuBar);
connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox()));
slider = new QSlider(Qt::Horizontal,toolBar);
slider->setMinimum( 0 );
slider->setMaximum( 4 );
connect(slider,SIGNAL(valueChanged(int)),scene,SLOT(setTesselation(int)));
slider->setValue( 1 );
QToolButton* toolButton = new QToolButton();
toolButton->setIcon(QIcon(":/img/viewports.png"));
toolButton->setMenu(viewMenu);
toolButton->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* toolButtonAction = new QWidgetAction(this);
toolButtonAction->setDefaultWidget(toolButton);
toolBar->addAction(toolButtonAction);
// Add Primitives
initPrimitivesMenu();
QToolButton* primitives = new QToolButton();
primitives->setIcon(QIcon(":/img/box.png"));
primitives->setMenu(primitivesMenu);
primitives->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* primitiveActione = new QWidgetAction(this);
primitiveActione->setDefaultWidget(primitives);
toolBar->addAction(primitiveActione);
initGrid();
toolBar->addWidget(slider);
addToolBar( toolBar);
scene->simpleScene();
// Assemble Menus
fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu);
menuBar->addMenu(primitivesMenu);
menuBar->addAction(aboutAction);
setMenuBar(menuBar);
//Assemble Tool Bar
initToolbar();
scene->simpleScene();
//controler->addVolume("D:/Projekte/GraPa/A3/lobster.raw");
setStatusBar(statusBar);
initDoc();
}
......@@ -328,6 +359,11 @@ void MainWindow::updateGL()
topView->updateGL();
}
GLView** MainWindow::getViews(){
return views;
}
......
......@@ -69,6 +69,7 @@ private:
GLView *frontView;
GLView *leftView;
GLView *topView;
GLView **views;
QTreeView *sceneView;
......@@ -79,11 +80,23 @@ private:
void initDoc();
void initViews();
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void setActiveView(GLView * active);
GLView** getViews();
void initSplits();
void initToolbar();
void initGrid();
void initPrimitivesMenu();
public slots:
void updateGL();
void updateStatusBar();
......
#include "scene.h"
#include <iostream>
Scene::Scene( )
......@@ -17,8 +17,6 @@ Scene::~Scene( )
int Scene::simpleScene()
{
addCube();
moveActive(QVector3D(4,0,0));
......@@ -37,8 +35,6 @@ int Scene::simpleScene()
moveActive(QVector3D(0,-1.5,-1.5));
//addVolume("D:/Projekte/GraPa/A3/MRI-head.raw");
return active->getID();
}
......@@ -65,7 +61,7 @@ void Scene::addSceneObjectTaActive(SceneObject *obj){
activeIndex = index(parent->childCount()-1,0,parentIndex);
active = obj;
qDebug()<<"Adding"<<obj->getName()<<" to "<<getItem(parentIndex)->getName()<<" Active"<<getItem(activeIndex)->getName();
//qDebug()<<"Adding"<<obj->getName()<<" to "<<getItem(parentIndex)->getName()<<" Active"<<getItem(activeIndex)->getName();
emit activChanged();
}
......@@ -114,7 +110,6 @@ void Scene::addNode()
{
SceneNode *node = new SceneNode();
node->setName("Graph Node");
addSceneObjectTaActive(node);
}
......@@ -125,9 +120,9 @@ void Scene::deletActive()
SceneNode *parent = static_cast<SceneNode*>(active->getParent());
int pos = active->childNumber();
qDebug()<<"Delet Active in Scene"<<parentIndex<<parent->childCount()<<pos;
//qDebug()<<"Delet Active in Scene"<<parentIndex<<parent->childCount()<<pos;
foreach (SceneObject * t, parent->getChildren()) {
qDebug()<<t->getName()<<t->childNumber();
// qDebug()<<t->getName()<<t->childNumber();
}
beginRemoveRows(parentIndex, pos, pos);
......@@ -135,93 +130,12 @@ void Scene::deletActive()
endRemoveRows();
active = parent;
activeIndex = parentIndex;
qDebug()<<"Delet Active in Scene"<<active<<activeIndex<<active->getName();
// qDebug()<<"Delet Active in Scene"<<active<<activeIndex<<active->getName();
emit activChanged();
}
void Scene::addVolume()
{
QString fn = QFileDialog::getOpenFileName(NULL, tr("Open Volume..."),
QString("D:\\Projekte\\GraPa\\A3"), tr("Volume Files (*.raw )"));
if(fn.isEmpty())
return;
qDebug()<<"Opening File:"<<fn;
addVolume(fn);
}
void Scene::addVolume(QString filePath){
QFile file(filePath);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "error", file.errorString());
}
QByteArray line1 = file.readLine();
QTextStream l1(line1);
QStringList line1Text = l1.readLine().split(" ");
int x = line1Text[0].toInt();
int y = line1Text[1].toInt();
int z = line1Text[2].toInt();
qDebug()<<line1Text<< x << y << z;
QByteArray line2 = file.readLine();
QTextStream l2(line2);
QStringList line1Text2 = l2.readLine().split(" ");
double dx = line1Text2[0].toDouble();
double dy = line1Text2[1].toDouble();
double dz = line1Text2[2].toDouble();
qDebug()<<line1Text2<< dx <<dy << dz;
QByteArray rawdata = file.readAll();
//qDebug()<<rawdata;
char ***data = new char**[z];
int count = 0;
// std::cout<<std::hex;
for(int k = 0; k < z; k++)
{
data[k] = new char*[y];
for(int j = 0; j < y; j++)
{
if(k == 150){
std::cout<<std::endl;
}
data[k][j] = new char[x];
for(int i = 0; i < x; i++)
{
data[k][j][i] = rawdata.at(count++);
if(k == 150 ){
int temp = ((uchar)data[k][j][i])*9/256;
std::cout<<temp;
// std::cout<<((uint)data[k][j][i]);
}
}
}
}
//qDebug()<<file.readData(data,file.size()-file.pos());
file.close();
qDebug()<<"File Read finish";
}
void Scene::setTesselation(int tesselation)
{
this->tesselation = tesselation;
......@@ -249,8 +163,11 @@ SceneNode *Scene::getRoot()
void Scene::moveActive(QVector3D dir)
{
if(active != NULL)
if(active != NULL){
active->move(dir);
//qDebug()<<"Move Active"<<active->getName()<<dir;
}
}
......
......@@ -10,6 +10,7 @@
#include <scenenode.h>
#include <sceneobject.h>
#include <sceneprimitive.h>
#include <scenevolume.h>
class Scene: public QAbstractItemModel // QAbstractItemModel
{
......@@ -55,11 +56,11 @@ public slots:
void addCone();
void addNode();
void deletActive();
void addVolume();
void addVolume(QString filePath);
signals:
void activChanged();
void changedVolumeData(int width, int height, int depth, byte* data);
private:
SceneNode *root;
......
#include "scenevolume.h"
SceneVolume::SceneVolume()
SceneVolume::SceneVolume(int width,int height, int depth, double dx, double dy, double dz)
{
this->width = width;
this->height = height;
this->depth = depth;
this->dx = dx;
this->dy = dy;
this->dz = dz;
lx = width*dx;
ly = height*dy;
lz = depth*dz;
qDebug()<<lx<<ly<<lz;
double max = qMax(lx,qMax(ly,lz));
lx = lx/max;
ly = ly/max;
lz = lz/max;
qDebug()<<max<<lx<<ly<<lz;
this->setName("Volume");
}
void SceneVolume::draw(QGLShaderProgram *shader){
glPushMatrix();
applyTransformation();
float color[] = {0.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_AMBIENT,color);
GLfloat white[] = {1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,white);
GLfloat mShininess[] = {128};
glMaterialfv(GL_FRONT,GL_SHININESS,mShininess);
float x = lx/2;
float y = ly/2;
float z = lz/2;
glBegin(GL_QUADS);
glNormal3f(0,1,0);
glTexCoord3i(1,1,0);
glVertex3f( x, y, -z);
glTexCoord3i(0,1,0);
glVertex3f( -x, y, -z);
glTexCoord3i(0,1,1);
glVertex3f( -x, y, z);
glTexCoord3i(1,1,1);
glVertex3f( x, y, z);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,-1,0);
glTexCoord3i(1,0,1);
glVertex3f( x, -y, z);
glTexCoord3i(0,0,1);
glVertex3f( -x, -y, z);
glTexCoord3i(0,0,0);
glVertex3f( -x, -y, -z);
glTexCoord3i(1,0,0);
glVertex3f( x, -y, -z);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,0,1);
glTexCoord3i(1,1,1);
glVertex3f( x, y, z);
glTexCoord3i(0,1,1);
glVertex3f( -x, y, z);
glTexCoord3i(0,0,1);
glVertex3f( -x, -y, z);
glTexCoord3i(1,0,1);
glVertex3f( x, -y, z);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0,0,-1);
glTexCoord3i(1,0,0);
glVertex3f( x, -y, -z);
glTexCoord3i(0,0,0);
glVertex3f( -x, -y, -z);
glTexCoord3i(0,1,0);
glVertex3f( -x, y, -z);
glTexCoord3i(1,1,0);
glVertex3f( x, y, -z);
glEnd();
glBegin(GL_QUADS);
glNormal3f(-1,0,0);
glTexCoord3i(0,1,1);
glVertex3f( -x, y, z);
glTexCoord3i(0,1,0);
glVertex3f( -x, y, -z);
glTexCoord3i(0,0,0);
glVertex3f( -x, -y, -z);
glTexCoord3i(0,0,1);
glVertex3f( -x, -y, z);
glEnd();
glBegin(GL_QUADS);
glNormal3f(1,0,0);
glTexCoord3i(1,1,0);
glVertex3f( x, y, -z);
glTexCoord3i(1,1,1);
glVertex3f( x, y, z);
glTexCoord3i(1,0,1);
glVertex3f( x, -y, z);
glTexCoord3i(1,0,0);
glVertex3f( x, -y, -z);
glEnd();
glPopMatrix();
}
......@@ -6,8 +6,14 @@
class SceneVolume : public SceneObject
{
private:
double lx,ly,lz;
double dx,dy,dz;
int width,height,depth;
public:
SceneVolume();
SceneVolume(int width,int height, int depth, double dx, double dy, double dz);
void draw(QGLShaderProgram *shader);
};
#endif // SCENEVOLUME_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment