qvolray
changeset 26:f4cc61b5a3eb
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Apr 2012 04:59:14 +0300 |
parents | 63bc059778d0 |
children | 011ac823600c |
files | sdr/volray.p.glsl src/ui.cc src/ui.h src/ui_maingl.h |
diffstat | 4 files changed, 50 insertions(+), 32 deletions(-) [+] |
line diff
1.1 --- a/sdr/volray.p.glsl Sat Apr 14 01:13:43 2012 +0300 1.2 +++ b/sdr/volray.p.glsl Sat Apr 14 04:59:14 2012 +0300 1.3 @@ -21,7 +21,7 @@ 1.4 1.5 vec3 sky(Ray ray); 1.6 vec3 ray_march(Ray ray, float t0, float t1); 1.7 -vec3 shade(Ray ray, vec3 pos, vec3 norm); 1.8 +vec3 shade(Ray ray, vec3 pos, vec3 norm, vec3 ldir); 1.9 Ray get_primary_ray(); 1.10 ISect intersect_aabb(Ray ray, AABBox aabb); 1.11 ISect intersect_sphere(Ray ray, float rad); 1.12 @@ -78,6 +78,7 @@ 1.13 float energy = 1.0; 1.14 float t = t0; 1.15 vec3 col = vec3(0.0, 0.0, 0.0); 1.16 + const vec3 ldir = normalize(vec3(-1, 1, -4)); 1.17 1.18 1.19 while(t < t1) { 1.20 @@ -90,7 +91,7 @@ 1.21 float energy_drop = exp(val * -ray_step); // * scatter_coeff ? 1.22 energy *= energy_drop; 1.23 1.24 - vec3 irrad = shade(ray, pos, normalize(norm)); 1.25 + vec3 irrad = shade(ray, pos, normalize(norm), ldir); 1.26 1.27 col += (1.0 - energy_drop) * energy * irrad; 1.28 if(energy < 0.001) { 1.29 @@ -101,11 +102,10 @@ 1.30 return col; 1.31 } 1.32 1.33 -vec3 shade(Ray ray, vec3 pos, vec3 norm) 1.34 +vec3 shade(Ray ray, vec3 pos, vec3 norm, vec3 ldir) 1.35 { 1.36 - vec3 ldir = -normalize(ray.dir); 1.37 - vec3 vdir = ldir; 1.38 - vec3 hdir = ldir;//normalize(ldir + vdir); 1.39 + vec3 vdir = -normalize(ray.dir); 1.40 + vec3 hdir = normalize(ldir + vdir); 1.41 1.42 float ndotl = abs(dot(ldir, norm)); 1.43 float ndoth = abs(dot(hdir, norm));
2.1 --- a/src/ui.cc Sat Apr 14 01:13:43 2012 +0300 2.2 +++ b/src/ui.cc Sat Apr 14 04:59:14 2012 +0300 2.3 @@ -1,18 +1,22 @@ 2.4 #include <stdio.h> 2.5 #include <stdlib.h> 2.6 +#include <vector> 2.7 #include <QtGui> 2.8 #include "ui.h" 2.9 2.10 -static GLView *glview; 2.11 static Volume *volume; 2.12 2.13 +static GLView *maingl; 2.14 +static std::vector<GLView*> glviews; 2.15 + 2.16 MainWindow::MainWindow() 2.17 { 2.18 setWindowTitle("Volume Renderer"); 2.19 2.20 // OpenGL view 2.21 - glview = new GLView; 2.22 - setCentralWidget(glview); 2.23 + maingl = new GLView; 2.24 + glviews.push_back(maingl); 2.25 + setCentralWidget(maingl); 2.26 2.27 // side-window 2.28 sidewin = new SideWindow; 2.29 @@ -64,6 +68,9 @@ 2.30 { 2.31 QGroupBox *groupbox = new QGroupBox("Volume slice"); 2.32 { 2.33 + GLView *slice_view = new GLView; 2.34 + glviews.push_back(slice_view); 2.35 + 2.36 QCheckBox *chk_clip = new QCheckBox("clip"); 2.37 chk_clip->setChecked(false); 2.38 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int))); 2.39 @@ -74,6 +81,7 @@ 2.40 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int))); 2.41 2.42 QVBoxLayout *vbox = new QVBoxLayout; 2.43 + vbox->addWidget(slice_view); 2.44 vbox->addWidget(chk_clip); 2.45 vbox->addWidget(zslider); 2.46 2.47 @@ -102,7 +110,7 @@ 2.48 2.49 void post_redisplay() 2.50 { 2.51 - glview->updateGL(); 2.52 + maingl->updateGL(); 2.53 } 2.54 2.55
3.1 --- a/src/ui.h Sat Apr 14 01:13:43 2012 +0300 3.2 +++ b/src/ui.h Sat Apr 14 04:59:14 2012 +0300 3.3 @@ -3,15 +3,16 @@ 3.4 3.5 #include <QMainWindow> 3.6 #include <QDockWidget> 3.7 -#include <QGLWidget> 3.8 #include "volray.h" 3.9 3.10 -class GLView; 3.11 class SideWindow; 3.12 3.13 +// This is the main application window (duh) 3.14 class MainWindow : public QMainWindow { 3.15 +private: 3.16 Q_OBJECT 3.17 -private: 3.18 + 3.19 + MainGLView *maingl; 3.20 SideWindow *sidewin; 3.21 3.22 private slots: 3.23 @@ -21,8 +22,15 @@ 3.24 MainWindow(); 3.25 }; 3.26 3.27 +/* This is the detachable window with the volume slice view 3.28 + * transfer function, etc 3.29 + */ 3.30 class SideWindow : public QDockWidget { 3.31 +private: 3.32 Q_OBJECT 3.33 + 3.34 + SliceGLView *slice_view; 3.35 + 3.36 private slots: 3.37 void zslider_change(int val); 3.38 void clip_change(int checked); 3.39 @@ -31,25 +39,7 @@ 3.40 SideWindow(); 3.41 }; 3.42 3.43 -class GLView : public QGLWidget { 3.44 - Q_OBJECT 3.45 - 3.46 -protected: 3.47 - void initializeGL(); 3.48 - void resizeGL(int xsz, int ysz); 3.49 - void paintGL(); 3.50 - 3.51 - void mousePressEvent(QMouseEvent *ev); 3.52 - void mouseReleaseEvent(QMouseEvent *ev); 3.53 - void mouseMoveEvent(QMouseEvent *ev); 3.54 - 3.55 -public: 3.56 - GLView(QWidget *parent = 0); 3.57 - 3.58 - QSize minimumSizeHint() const; 3.59 - QSize sizeHint() const; 3.60 -}; 3.61 - 3.62 +// call to force a redisplay on all GL views 3.63 void post_redisplay(); 3.64 3.65
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/ui_maingl.h Sat Apr 14 04:59:14 2012 +0300 4.3 @@ -0,0 +1,20 @@ 4.4 +#include <QGLWidget> 4.5 + 4.6 +class MainGLView : public QGLWidget { 4.7 + Q_OBJECT 4.8 + 4.9 +protected: 4.10 + void initializeGL(); 4.11 + void resizeGL(int xsz, int ysz); 4.12 + void paintGL(); 4.13 + 4.14 + void mousePressEvent(QMouseEvent *ev); 4.15 + void mouseReleaseEvent(QMouseEvent *ev); 4.16 + void mouseMoveEvent(QMouseEvent *ev); 4.17 + 4.18 +public: 4.19 + MainGLView(); 4.20 + 4.21 + QSize minimumSizeHint() const; 4.22 + QSize sizeHint() const; 4.23 +};