Commit c0274af6 by Kai Westerkamp

transfer functions

parent 9fa4f133
...@@ -45,7 +45,7 @@ void Camera::setupCamera(GLdouble aspect ) ...@@ -45,7 +45,7 @@ void Camera::setupCamera(GLdouble aspect )
if(persp){ if(persp){
perspective(45.0,aspect,0.01,100.0); perspective(45.0,aspect,0.01,100.0);
} else { } else {
int size = 4; int size = 2;
glOrtho(-size*aspect,size*aspect,-size,size,0.01,100.0); glOrtho(-size*aspect,size*aspect,-size,size,0.01,100.0);
} }
......
...@@ -10,6 +10,7 @@ Controler::Controler(MainWindow *mainwindow,Scene *scene) ...@@ -10,6 +10,7 @@ Controler::Controler(MainWindow *mainwindow,Scene *scene)
this->mainwindow = mainwindow; this->mainwindow = mainwindow;
this->scene = scene; this->scene = scene;
viewMode = CAMERA; viewMode = CAMERA;
} }
void Controler::mousePressed(GLView* view, QMouseEvent *event) void Controler::mousePressed(GLView* view, QMouseEvent *event)
...@@ -37,7 +38,7 @@ void Controler::mouseMoveEvent(GLView* view, QMouseEvent *event) ...@@ -37,7 +38,7 @@ void Controler::mouseMoveEvent(GLView* view, QMouseEvent *event)
} }
} }
void Controler::wheelEvent(GLView* view, QWheelEvent *event ) { void Controler::wheelEvent(GLView* view, QWheelEvent *event ) {
activeView = view; activeView = view;
mainwindow->setActiveView(view); mainwindow->setActiveView(view);
...@@ -59,7 +60,7 @@ void Controler::mouseMoveEvent(GLView* view, QMouseEvent *event) ...@@ -59,7 +60,7 @@ void Controler::mouseMoveEvent(GLView* view, QMouseEvent *event)
} }
mainwindow->updateGL(); mainwindow->updateGL();
} }
QVector3D* Controler::trackballPoint(int x, int y){ QVector3D* Controler::trackballPoint(int x, int y){
...@@ -173,6 +174,12 @@ void Controler::addVolume(QString filePath){ ...@@ -173,6 +174,12 @@ void Controler::addVolume(QString filePath){
char ***data = new char**[z]; char ***data = new char**[z];
int* histogram = new int[256];
for(int i = 0; i < 256; i++)
{
histogram[i] = 0;
}
int count = 0; int count = 0;
// std::cout<<std::hex; // std::cout<<std::hex;
...@@ -187,9 +194,12 @@ void Controler::addVolume(QString filePath){ ...@@ -187,9 +194,12 @@ void Controler::addVolume(QString filePath){
data[k][j] = new char[x]; data[k][j] = new char[x];
for(int i = 0; i < x; i++) for(int i = 0; i < x; i++)
{ {
data[k][j][i] = rawdata.at(count++); uchar value = rawdata.at(count++);
data[k][j][i] = value;
histogram[value]++;
if(k == printLine ){ if(k == printLine ){
int temp = ((uchar)data[k][j][i])*9/256; int temp = value*9/256;
std::cout<<temp; std::cout<<temp;
} }
} }
...@@ -199,6 +209,8 @@ void Controler::addVolume(QString filePath){ ...@@ -199,6 +209,8 @@ void Controler::addVolume(QString filePath){
} }
} }
//qDebug()<<file.readData(data,file.size()-file.pos()); //qDebug()<<file.readData(data,file.size()-file.pos());
int type = GL_UNSIGNED_BYTE; int type = GL_UNSIGNED_BYTE;
if(rawdata.size()>x*y*z) if(rawdata.size()>x*y*z)
...@@ -211,8 +223,27 @@ void Controler::addVolume(QString filePath){ ...@@ -211,8 +223,27 @@ void Controler::addVolume(QString filePath){
scene->addSceneObjectTaActive(volume); scene->addSceneObjectTaActive(volume);
file.close(); file.close();
uchar *trans = new uchar[4*256];
for(int i = 0; i < 256; i+=1){
int index = i*4;
trans[index] = i;
trans[index+1] = i;
trans[index+2] = i;
trans[index+3] = i;
}
for(int i = 0; i < 4; i++){
// mainwindow->getViews()[i]->loadTransfer(trans);
}
this->mainwindow->transEditor->setHistogram(histogram);
// this->mainwindow->transEditor->setTransferFunction(trans);
qDebug()<<"File Read finish"; qDebug()<<"File Read finish";
......
...@@ -255,8 +255,6 @@ void CubeWidget::mousePressEvent(QMouseEvent *event ) ...@@ -255,8 +255,6 @@ void CubeWidget::mousePressEvent(QMouseEvent *event )
lastSpeherePos = trackballPoint(event->pos().x(),event->pos().y()); lastSpeherePos = trackballPoint(event->pos().x(),event->pos().y());
lastScreenPos = new QPointF(event->screenPos()); lastScreenPos = new QPointF(event->screenPos());
event->accept(); event->accept();
} }
void CubeWidget::mouseMoveEvent(QMouseEvent *event ) void CubeWidget::mouseMoveEvent(QMouseEvent *event )
...@@ -312,7 +310,6 @@ QVector3D* CubeWidget::trackballPoint(int x, int y){ ...@@ -312,7 +310,6 @@ QVector3D* CubeWidget::trackballPoint(int x, int y){
zo = qMax(qCos(M_PI_2*d),qreal(0.0)); //qMin(d,1.0f) zo = qMax(qCos(M_PI_2*d),qreal(0.0)); //qMin(d,1.0f)
QVector3D *pos = new QVector3D(xo,yo,zo); QVector3D *pos = new QVector3D(xo,yo,zo);
pos->normalize(); pos->normalize();
// qDebug()<<"x:"<< xo << " y:"<<yo<<" z:"<<zo; // qDebug()<<"x:"<< xo << " y:"<<yo<<" z:"<<zo;
......
...@@ -17,9 +17,10 @@ float stepsize = 0.001; ...@@ -17,9 +17,10 @@ float stepsize = 0.001;
vec4 transfer(float scalar){ vec4 transfer(float scalar){
float pos = (scalar*255.0/256.0 + 0.5*256.0); float pos = (scalar*255.0/256.0 + 1/256.0/2);
return vec4(scalar); //return vec4(scalar);
//return texture1D(transferData,pos); //return vec4(pos);
return texture1D(transferData,pos);
} }
vec3 phong(vec3 color, vec3 normal){ vec3 phong(vec3 color, vec3 normal){
...@@ -101,10 +102,9 @@ void main(void) ...@@ -101,10 +102,9 @@ void main(void)
} }
// gl_FragColor = vec4(gl_TexCoord[0].xyz,1); //gl_FragColor = vec4(texture1D(transferData,front.x));
//gl_FragColor = vec4(vec3(count),1);
//gl_FragColor = vec4(normalize(step),1); //gl_FragColor = vec4(gl_TexCoord[0].xyz,1);
//gl_FragColor = vec4(normalize(gl_ModelViewProjectionMatrixInverse*vec4(0,1,0,0.0)));
//gl_FragColor = vec4(texture3D(volumeData,vec3(front.xy,0.5)).x); //gl_FragColor = vec4(texture3D(volumeData,vec3(front.xy,0.5)).x);
} }
} }
......
...@@ -12,6 +12,7 @@ GLView::GLView(Scene *scene,Camera * camera,Controler *controler ) ...@@ -12,6 +12,7 @@ GLView::GLView(Scene *scene,Camera * camera,Controler *controler )
gridStepSize = 1; gridStepSize = 1;
isGridEnabled = false; isGridEnabled = false;
MIP = false; MIP = false;
afterInit = false;
} }
QSize GLView::minimumSizeHint() const QSize GLView::minimumSizeHint() const
...@@ -53,6 +54,7 @@ void GLView::initializeGL ( ) { ...@@ -53,6 +54,7 @@ void GLView::initializeGL ( ) {
//Shader Setup //Shader Setup
initShader(); initShader();
shader->bind(); shader->bind();
afterInit = true;
} }
void GLView::initShader() void GLView::initShader()
...@@ -432,18 +434,23 @@ void GLView::loadData(int width, int height, int depth, char* data, int type ) ...@@ -432,18 +434,23 @@ void GLView::loadData(int width, int height, int depth, char* data, int type )
void GLView::loadTransfer(uchar* data ) void GLView::loadTransfer(uchar* data )
{ {
// uchar *test = new uchar[4*256];
// for(int i = 0; i< 4*256;i++){
// test[i] = data[i];
// }
glGenTextures( 1, &transferFunction ); glGenTextures( 1, &transferFunction );
glBindTexture(GL_TEXTURE_1D, transferFunction); glBindTexture(GL_TEXTURE_1D, transferFunction);
// Filtering // Filtering
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
// Wrap // Wrap
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA,256,0,GL_RGBA,GL_UNSIGNED_BYTE,data); glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA,256,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
if(afterInit) updateGL();
} }
......
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
Camera *getCamera(); Camera *getCamera();
private: private:
bool afterInit;
QGLShaderProgram *shader; QGLShaderProgram *shader;
QGLShaderProgram *displayShader; QGLShaderProgram *displayShader;
Scene *scene; Scene *scene;
......
...@@ -25,7 +25,8 @@ SOURCES += main.cpp\ ...@@ -25,7 +25,8 @@ SOURCES += main.cpp\
sceneobject.cpp \ sceneobject.cpp \
scenenode.cpp \ scenenode.cpp \
treedelegate.cpp \ treedelegate.cpp \
scenevolume.cpp scenevolume.cpp \
transferfunctioneditor.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
cubewidget.h \ cubewidget.h \
...@@ -38,7 +39,8 @@ HEADERS += mainwindow.h \ ...@@ -38,7 +39,8 @@ HEADERS += mainwindow.h \
scenenode.h \ scenenode.h \
glut.h \ glut.h \
treedelegate.h \ treedelegate.h \
scenevolume.h scenevolume.h \
transferfunctioneditor.h
RESOURCES += \ RESOURCES += \
hellocube.qrc hellocube.qrc
...@@ -48,3 +50,6 @@ DISTFILES += \ ...@@ -48,3 +50,6 @@ DISTFILES += \
phong.vert \ phong.vert \
display.frag \ display.frag \
display.vert display.vert
FORMS += \
transferui.ui
...@@ -279,6 +279,8 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -279,6 +279,8 @@ MainWindow::MainWindow(QWidget *parent)
// Assemble Menus // Assemble Menus
fileMenu->addAction(exitAction); fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu); menuBar->addMenu(fileMenu);
...@@ -325,9 +327,92 @@ void MainWindow::initDoc() ...@@ -325,9 +327,92 @@ void MainWindow::initDoc()
dock->setWidget(sceneView); dock->setWidget(sceneView);
//Transfer Function Doc
QDockWidget *transferDock = new QDockWidget("Transfer Function Editor",this);
transferDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
transEditor = new TransferFunctionEditor(this);
connect(transEditor,SIGNAL(dataChanged(uchar*)),perspectiveView,SLOT(loadTransfer(uchar*)));
connect(transEditor,SIGNAL(dataChanged(uchar*)),frontView,SLOT(loadTransfer(uchar*)));
connect(transEditor,SIGNAL(dataChanged(uchar*)),leftView,SLOT(loadTransfer(uchar*)));
connect(transEditor,SIGNAL(dataChanged(uchar*)),topView,SLOT(loadTransfer(uchar*)));
QPushButton *save = new QPushButton("Save");
connect(save,SIGNAL(released()),transEditor,SLOT(save()));
QPushButton *load = new QPushButton("Load");
connect(load,SIGNAL(released()),transEditor,SLOT(load()));
QPushButton *reset = new QPushButton("Reset");
connect(reset,SIGNAL(released()),transEditor,SLOT(reset()));
QPushButton *Smooth = new QPushButton("smooth");
connect(Smooth,SIGNAL(released()),transEditor,SLOT(smooth()));
QCheckBox *red = new QCheckBox("red");
red->setChecked(true);
connect(red,SIGNAL(clicked(bool)),transEditor,SLOT(paintRed(bool)));
QCheckBox *green = new QCheckBox("green");
green->setChecked(true);
connect(green,SIGNAL(clicked(bool)),transEditor,SLOT(paintGreen(bool)));
QCheckBox *blue = new QCheckBox("blue");
blue->setChecked(true);
connect(blue,SIGNAL(clicked(bool)),transEditor,SLOT(paintBlue(bool)));
QCheckBox *alpha = new QCheckBox("alpha");
alpha->setChecked(true);
connect(alpha,SIGNAL(clicked(bool)),transEditor,SLOT(paintAlpha(bool)));
QWidget *all = new QWidget;
QWidget *buttons = new QWidget;
QWidget *left = new QWidget;
QWidget *right = new QWidget;
QVBoxLayout *checkLayout = new QVBoxLayout;
checkLayout->addWidget(red);
checkLayout->addWidget(green);
checkLayout->addWidget(blue);
checkLayout->addWidget(alpha);
right->setLayout(checkLayout);
QGridLayout *butLayout = new QGridLayout;
butLayout->addWidget(save,0,0);
butLayout->addWidget(load,0,1);
butLayout->addWidget(reset,1,0);
butLayout->addWidget(Smooth,1,1);
left->setLayout(butLayout);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->addWidget(left);
buttonsLayout->addWidget(right);
buttons->setLayout(buttonsLayout);
QVBoxLayout *allLayout = new QVBoxLayout;
allLayout->addWidget(transEditor);
allLayout->addWidget(buttons);
all->setLayout(allLayout);
transferDock->setWidget(all);
transferDock->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
addDockWidget(Qt::RightDockWidgetArea, transferDock);
addDockWidget(Qt::RightDockWidgetArea, dock); addDockWidget(Qt::RightDockWidgetArea, dock);
} }
void MainWindow::updateStatusBar() void MainWindow::updateStatusBar()
......
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
#include <QStatusBar> #include <QStatusBar>
#include <QSlider> #include <QSlider>
#include <QSplitter> #include <QSplitter>
#include <QPushButton>
#include <glview.h> #include <glview.h>
#include <scene.h> #include <scene.h>
#include <camera.h> #include <camera.h>
#include <controler.h> #include <controler.h>
#include <transferfunctioneditor.h>
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
...@@ -80,6 +82,7 @@ private: ...@@ -80,6 +82,7 @@ private:
QTimer *timer; QTimer *timer;
void initDoc(); void initDoc();
void initViews(); void initViews();
...@@ -99,6 +102,9 @@ public: ...@@ -99,6 +102,9 @@ public:
void initPrimitivesMenu(); void initPrimitivesMenu();
TransferFunctionEditor *transEditor;
public slots: public slots:
void updateGL(); void updateGL();
void updateStatusBar(); void updateStatusBar();
......
...@@ -122,9 +122,9 @@ void Scene::deletActive() ...@@ -122,9 +122,9 @@ void Scene::deletActive()
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);
parent->remove(pos); parent->remove(pos);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "scenenode.h" #include "scenenode.h"
int SceneNode::idCount = 1; int SceneObject::idCount = 1;
SceneObject::SceneObject() SceneObject::SceneObject()
{ {
......
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