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();
......
......@@ -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