Commit 53b97ddc by Kai Westerkamp

Opengl functions

File read draw bounds
parent 1e6720cf
...@@ -15,7 +15,8 @@ void Camera::home() ...@@ -15,7 +15,8 @@ void Camera::home()
void Camera::setHome(QQuaternion *rotation, QVector3D *translation) void Camera::setHome(QQuaternion *rotation, QVector3D *translation)
{ {
//qDebug()<<*rotation<<" trans:"<<*translation; //qDebug()<<"Cam Home"<<*rotation<<" trans:"<<*translation;
this->homeRotation = rotation; this->homeRotation = rotation;
this->homeTranslation = translation; this->homeTranslation = translation;
home(); home();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "glview.h" #include "glview.h"
#include "scene.h" #include "scene.h"
#include "mainwindow.h" #include "mainwindow.h"
#include <iostream>
Controler::Controler(MainWindow *mainwindow,Scene *scene) Controler::Controler(MainWindow *mainwindow,Scene *scene)
{ {
...@@ -128,3 +129,86 @@ void Controler::setCamMode(){ ...@@ -128,3 +129,86 @@ void Controler::setCamMode(){
void Controler::setEditMode(){ void Controler::setEditMode(){
viewMode = EDIT; 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: ...@@ -25,6 +25,9 @@ public slots:
void setCamMode(); void setCamMode();
void setEditMode(); void setEditMode();
void addVolume();
void addVolume(QString filePath);
private: private:
MainWindow *mainwindow; MainWindow *mainwindow;
Scene *scene; Scene *scene;
......
...@@ -24,6 +24,8 @@ QSize GLView::sizeHint() const ...@@ -24,6 +24,8 @@ QSize GLView::sizeHint() const
void GLView::initializeGL ( ) { void GLView::initializeGL ( ) {
Q_ASSERT(initializeOpenGLFunctions());
glClearColor(0.0, 0.0, 0.0, 0.0); glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
...@@ -85,14 +87,14 @@ void GLView::paintGL () ...@@ -85,14 +87,14 @@ void GLView::paintGL ()
{ {
bool useFBO = true; bool useFBO = true;
//QOpenGLFunctions functions = QOpenGLContext::currentContext()->functions(); //QOpenGLFunctions functions = QOpenGLContext::currentContext()->functions();
QGLFunctions functions = QGLFunctions(this->context()); // QGLFunctions functions = QGLFunctions(this->context());
// QOpenGLFunctions_4_3_Core functions = *this;
shader->bind(); shader->bind();
if(useFBO){ if(useFBO){
functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo);
GLenum buffers[] = {GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1}; 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 //http://stackoverflow.com/questions/7207422/setting-up-opengl-multiple-render-targets
} }
...@@ -110,7 +112,6 @@ void GLView::paintGL () ...@@ -110,7 +112,6 @@ void GLView::paintGL ()
shader->setUniformValue("shaded",true); shader->setUniformValue("shaded",true);
//qDebug()<<"IsLinked"<<shader->isLinked();
//set Projection and Camera Rotation //set Projection and Camera Rotation
camera->setupCamera(aspect); camera->setupCamera(aspect);
...@@ -153,7 +154,7 @@ void GLView::paintGL () ...@@ -153,7 +154,7 @@ void GLView::paintGL ()
displayShader->bind(); displayShader->bind();
// //
functions.glBindFramebuffer(GL_FRAMEBUFFER,0); glBindFramebuffer(GL_FRAMEBUFFER,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,this->width(),this->height()); glViewport(0,0,this->width(),this->height());
...@@ -162,11 +163,11 @@ void GLView::paintGL () ...@@ -162,11 +163,11 @@ void GLView::paintGL ()
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
functions.glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,color); glBindTexture(GL_TEXTURE_2D,color);
displayShader->setUniformValue("Texture",0); displayShader->setUniformValue("Texture",0);
functions.glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,picID); glBindTexture(GL_TEXTURE_2D,picID);
displayShader->setUniformValue("TextureID",1); displayShader->setUniformValue("TextureID",1);
...@@ -293,10 +294,11 @@ void GLView::resizeGL(int width , int height ) ...@@ -293,10 +294,11 @@ void GLView::resizeGL(int width , int height )
{ {
aspect = 1.0*width/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); glGenFramebuffers(1, &fbo);
functions.glBindFramebuffer(GL_FRAMEBUFFER,fbo); glBindFramebuffer(GL_FRAMEBUFFER,fbo);
...@@ -321,26 +323,47 @@ void GLView::resizeGL(int width , int height ) ...@@ -321,26 +323,47 @@ void GLView::resizeGL(int width , int height )
// Create the depth buffer // Create the depth buffer
functions.glGenRenderbuffers(1, &depth); glGenRenderbuffers(1, &depth);
functions.glBindRenderbuffer(GL_RENDERBUFFER, depth); glBindRenderbuffer(GL_RENDERBUFFER, depth);
functions.glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,width,height); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,width,height);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color,0);
functions.glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,picID,0); glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,picID,0);
functions.glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,depth); 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){ if(err == GL_FRAMEBUFFER_COMPLETE){
qDebug()<<"FBO OK"; // qDebug()<<"FBO OK";
} else { } else {
qDebug()<<"FBO ERROR"<<err; 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) void GLView::setAcive(bool active)
......
...@@ -27,11 +27,13 @@ public slots: ...@@ -27,11 +27,13 @@ public slots:
void setGridSize(int size){gridSize = size;} void setGridSize(int size){gridSize = size;}
void setGridStepSize(int size){gridStepSize = size;} void setGridStepSize(int size){gridStepSize = size;}
void showGrid(bool bo){isGridEnabled = bo;} void showGrid(bool bo){isGridEnabled = bo;}
void loadData(int width, int height, int depth, char* data);
public: public:
GLView(Scene *scene,Camera * camera,Controler *controler ); GLView(Scene *scene,Camera * camera,Controler *controler );
void setHome(QQuaternion *rotation, QVector3D *translation); void setHome(QQuaternion *rotation, QVector3D *translation);
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
QSize sizeHint() const; QSize sizeHint() const;
...@@ -56,6 +58,9 @@ private: ...@@ -56,6 +58,9 @@ private:
GLuint picID; GLuint picID;
GLuint depth; GLuint depth;
GLuint texture3D;
void drawGrid(); void drawGrid();
void initShader(); void initShader();
......
...@@ -2,25 +2,8 @@ ...@@ -2,25 +2,8 @@
#include <treedelegate.h> #include <treedelegate.h>
MainWindow::MainWindow(QWidget *parent) void MainWindow::initViews()
: QMainWindow(parent)
{ {
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); Camera *perspectiveCam = new Camera(true);
perspectiveView = new GLView(scene,perspectiveCam,controler); perspectiveView = new GLView(scene,perspectiveCam,controler);
...@@ -39,14 +22,24 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -39,14 +22,24 @@ MainWindow::MainWindow(QWidget *parent)
new QVector3D(0.0,0.0,-4.0)); new QVector3D(0.0,0.0,-4.0));
topView = new GLView(scene,topCam,controler); 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); topSplit = new QSplitter(Qt::Horizontal,this);
bottomSplit = new QSplitter(Qt::Horizontal,this); bottomSplit = new QSplitter(Qt::Horizontal,this);
verticalSplit = new QSplitter(Qt::Vertical,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(perspectiveView);
topSplit->addWidget(frontView); topSplit->addWidget(frontView);
...@@ -56,42 +49,9 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -56,42 +49,9 @@ MainWindow::MainWindow(QWidget *parent)
verticalSplit->addWidget(topSplit); verticalSplit->addWidget(topSplit);
verticalSplit->addWidget(bottomSplit); verticalSplit->addWidget(bottomSplit);
setCentralWidget(verticalSplit); setCentralWidget(verticalSplit);
showQuad(); 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 //View Actions
singleView = new QAction("Single View",this); singleView = new QAction("Single View",this);
...@@ -121,22 +81,88 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -121,22 +81,88 @@ MainWindow::MainWindow(QWidget *parent)
viewMenu->addAction(singleView); viewMenu->addAction(singleView);
viewMenu->addAction(dualView); viewMenu->addAction(dualView);
viewMenu->addAction(quadView); viewMenu->addAction(quadView);
}
void MainWindow::initToolbar()
{
toolBar->addAction(cameraMode);
toolBar->addAction(editMode);
//Other Actions toolBar->addSeparator();
aboutAction = new QAction("About",menuBar); toolBar->addAction(camHome);
connect(aboutAction,SIGNAL(triggered()),this,SLOT(showAboutBox())); toolBar->addSeparator();
toolBar->addWidget(showGridButton);
toolBar->addWidget(gridSizeInput);
toolBar->addWidget(gridStepInput);
toolBar->addSeparator();
slider = new QSlider(Qt::Horizontal,toolBar); QToolButton* toolButton = new QToolButton();
slider->setMinimum( 0 ); toolButton->setIcon(QIcon(":/img/viewports.png"));
slider->setMaximum( 4 ); toolButton->setMenu(viewMenu);
connect(slider,SIGNAL(valueChanged(int)),scene,SLOT(setTesselation(int))); toolButton->setPopupMode(QToolButton::InstantPopup);
slider->setValue( 1 ); 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 = new QAction("Sphere",this);
spheresAdd->setIcon(QIcon(":/img/sphere.png")); spheresAdd->setIcon(QIcon(":/img/sphere.png"));
...@@ -168,7 +194,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -168,7 +194,7 @@ MainWindow::MainWindow(QWidget *parent)
volumeAdd = new QAction("Volume",this); volumeAdd = new QAction("Volume",this);
//activeDelete->setIcon(QIcon(":/img/delete.png")); //activeDelete->setIcon(QIcon(":/img/delete.png"));
connect(volumeAdd, SIGNAL(triggered()), scene, SLOT(addVolume())); connect(volumeAdd, SIGNAL(triggered()), controler, SLOT(addVolume()));
primitivesMenu->addAction(spheresAdd); primitivesMenu->addAction(spheresAdd);
...@@ -179,94 +205,99 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -179,94 +205,99 @@ MainWindow::MainWindow(QWidget *parent)
primitivesMenu->addAction(groupAdd); primitivesMenu->addAction(groupAdd);
primitivesMenu->addAction(activeDelete); primitivesMenu->addAction(activeDelete);
primitivesMenu->addAction(volumeAdd); 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); //Views
gridSizeInput->setRange(0,100); scene = new Scene();
gridSizeInput->setValue(5); 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); controler = new Controler(this,scene);
gridStepInput->setRange(1,10);
gridStepInput->setToolTip("Grid Step Size"); initViews();
connect(gridSizeInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridSize(int))); camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);//vor set Active View
connect(gridStepInput,SIGNAL(valueChanged(int)),perspectiveView,SLOT(setGridStepSize(int))); setActiveView(perspectiveView);
connect(showGridButton,SIGNAL(clicked(bool)),perspectiveView,SLOT(showGrid(bool)));
connect(gridSizeInput,SIGNAL(valueChanged(int)),topView,SLOT(setGridSize(int))); initSplits();
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))); //File Menu Actions
connect(gridStepInput,SIGNAL(valueChanged(int)),frontView,SLOT(setGridStepSize(int))); fileMenu = new QMenu("&File");
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()));
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 cameraMode = new QAction("Camera",this);
toolBar->addAction(cameraMode); cameraMode->setCheckable(true);
toolBar->addAction(editMode); cameraMode->setIcon(QIcon(":/img/camera.png"));
cameraMode->setChecked(true);
connect(cameraMode, SIGNAL(triggered()), controler, SLOT(setCamMode()));
interactionGroup->addAction(cameraMode);
toolBar->addSeparator(); editMode = new QAction("Edit",this);
toolBar->addAction(camHome); editMode->setCheckable(true);
toolBar->addSeparator(); 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 );
// Add Primitives
initPrimitivesMenu();
QToolButton* toolButton = new QToolButton(); initGrid();
toolButton->setIcon(QIcon(":/img/viewports.png"));
toolButton->setMenu(viewMenu);
toolButton->setPopupMode(QToolButton::InstantPopup);
QWidgetAction* toolButtonAction = new QWidgetAction(this);
toolButtonAction->setDefaultWidget(toolButton);
toolBar->addAction(toolButtonAction);
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); // Assemble Menus
fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu);
menuBar->addMenu(primitivesMenu);
menuBar->addAction(aboutAction);
addToolBar( toolBar); setMenuBar(menuBar);
scene->simpleScene();
//Assemble Tool Bar
initToolbar();
scene->simpleScene();
//controler->addVolume("D:/Projekte/GraPa/A3/lobster.raw");
setStatusBar(statusBar); setStatusBar(statusBar);
initDoc(); initDoc();
} }
...@@ -328,6 +359,11 @@ void MainWindow::updateGL() ...@@ -328,6 +359,11 @@ void MainWindow::updateGL()
topView->updateGL(); topView->updateGL();
} }
GLView** MainWindow::getViews(){
return views;
}
......
...@@ -69,6 +69,7 @@ private: ...@@ -69,6 +69,7 @@ private:
GLView *frontView; GLView *frontView;
GLView *leftView; GLView *leftView;
GLView *topView; GLView *topView;
GLView **views;
QTreeView *sceneView; QTreeView *sceneView;
...@@ -79,11 +80,23 @@ private: ...@@ -79,11 +80,23 @@ private:
void initDoc(); void initDoc();
void initViews();
public: public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
void setActiveView(GLView * active); void setActiveView(GLView * active);
GLView** getViews();
void initSplits();
void initToolbar();
void initGrid();
void initPrimitivesMenu();
public slots: public slots:
void updateGL(); void updateGL();
void updateStatusBar(); void updateStatusBar();
......
#include "scene.h" #include "scene.h"
#include <iostream>
Scene::Scene( ) Scene::Scene( )
...@@ -17,8 +17,6 @@ Scene::~Scene( ) ...@@ -17,8 +17,6 @@ Scene::~Scene( )
int Scene::simpleScene() int Scene::simpleScene()
{ {
addCube(); addCube();
moveActive(QVector3D(4,0,0)); moveActive(QVector3D(4,0,0));
...@@ -37,8 +35,6 @@ int Scene::simpleScene() ...@@ -37,8 +35,6 @@ int Scene::simpleScene()
moveActive(QVector3D(0,-1.5,-1.5)); moveActive(QVector3D(0,-1.5,-1.5));
//addVolume("D:/Projekte/GraPa/A3/MRI-head.raw");
return active->getID(); return active->getID();
} }
...@@ -65,7 +61,7 @@ void Scene::addSceneObjectTaActive(SceneObject *obj){ ...@@ -65,7 +61,7 @@ void Scene::addSceneObjectTaActive(SceneObject *obj){
activeIndex = index(parent->childCount()-1,0,parentIndex); activeIndex = index(parent->childCount()-1,0,parentIndex);
active = obj; 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(); emit activChanged();
} }
...@@ -114,7 +110,6 @@ void Scene::addNode() ...@@ -114,7 +110,6 @@ void Scene::addNode()
{ {
SceneNode *node = new SceneNode(); SceneNode *node = new SceneNode();
node->setName("Graph Node"); node->setName("Graph Node");
addSceneObjectTaActive(node); addSceneObjectTaActive(node);
} }
...@@ -125,9 +120,9 @@ void Scene::deletActive() ...@@ -125,9 +120,9 @@ void Scene::deletActive()
SceneNode *parent = static_cast<SceneNode*>(active->getParent()); SceneNode *parent = static_cast<SceneNode*>(active->getParent());
int pos = active->childNumber(); 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()) { foreach (SceneObject * t, parent->getChildren()) {
qDebug()<<t->getName()<<t->childNumber(); // qDebug()<<t->getName()<<t->childNumber();
} }
beginRemoveRows(parentIndex, pos, pos); beginRemoveRows(parentIndex, pos, pos);
...@@ -135,93 +130,12 @@ void Scene::deletActive() ...@@ -135,93 +130,12 @@ void Scene::deletActive()
endRemoveRows(); endRemoveRows();
active = parent; active = parent;
activeIndex = parentIndex; activeIndex = parentIndex;
qDebug()<<"Delet Active in Scene"<<active<<activeIndex<<active->getName(); // qDebug()<<"Delet Active in Scene"<<active<<activeIndex<<active->getName();
emit activChanged(); 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) void Scene::setTesselation(int tesselation)
{ {
this->tesselation = tesselation; this->tesselation = tesselation;
...@@ -249,8 +163,11 @@ SceneNode *Scene::getRoot() ...@@ -249,8 +163,11 @@ SceneNode *Scene::getRoot()
void Scene::moveActive(QVector3D dir) void Scene::moveActive(QVector3D dir)
{ {
if(active != NULL)
if(active != NULL){
active->move(dir); active->move(dir);
//qDebug()<<"Move Active"<<active->getName()<<dir;
}
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <scenenode.h> #include <scenenode.h>
#include <sceneobject.h> #include <sceneobject.h>
#include <sceneprimitive.h> #include <sceneprimitive.h>
#include <scenevolume.h>
class Scene: public QAbstractItemModel // QAbstractItemModel class Scene: public QAbstractItemModel // QAbstractItemModel
{ {
...@@ -55,11 +56,11 @@ public slots: ...@@ -55,11 +56,11 @@ public slots:
void addCone(); void addCone();
void addNode(); void addNode();
void deletActive(); void deletActive();
void addVolume();
void addVolume(QString filePath);
signals: signals:
void activChanged(); void activChanged();
void changedVolumeData(int width, int height, int depth, byte* data);
private: private:
SceneNode *root; SceneNode *root;
......
#include "scenevolume.h" #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 @@ ...@@ -6,8 +6,14 @@
class SceneVolume : public SceneObject class SceneVolume : public SceneObject
{ {
private:
double lx,ly,lz;
double dx,dy,dz;
int width,height,depth;
public: public:
SceneVolume(); SceneVolume(int width,int height, int depth, double dx, double dy, double dz);
void draw(QGLShaderProgram *shader);
}; };
#endif // SCENEVOLUME_H #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