qvolray
changeset 27:011ac823600c
broken up the OpenGL code to multiple source files (untested)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Apr 2012 06:37:31 +0300 |
parents | f4cc61b5a3eb |
children | aeef3c2ae472 |
files | .hgignore qvolray.pro src/ui.cc src/ui.h src/ui_maingl.cc src/ui_maingl.h src/ui_sliceview.cc src/ui_sliceview.h |
diffstat | 8 files changed, 142 insertions(+), 79 deletions(-) [+] |
line diff
1.1 --- a/.hgignore Sat Apr 14 04:59:14 2012 +0300 1.2 +++ b/.hgignore Sat Apr 14 06:37:31 2012 +0300 1.3 @@ -12,3 +12,6 @@ 1.4 \.pdb$ 1.5 ^ipch 1.6 \.sdf$ 1.7 +^moc_.*\.cpp$ 1.8 +^Makefile$ 1.9 +^qvolray.app
2.1 --- a/qvolray.pro Sat Apr 14 04:59:14 2012 +0300 2.2 +++ b/qvolray.pro Sat Apr 14 06:37:31 2012 +0300 2.3 @@ -21,6 +21,16 @@ 2.4 QMAKE_LIBDIR += /opt/local/lib 2.5 } 2.6 2.7 -# Input 2.8 -HEADERS += src/sdr.h src/volray.h src/volume.h src/ui.h 2.9 -SOURCES += src/main.cc src/sdr.c src/volray.cc src/volume.cc src/ui.cc src/demo.cc 2.10 +# the moc needs to run for these headers 2.11 +HEADERS = src/ui.h \ 2.12 + src/ui_maingl.h \ 2.13 + src/ui_sliceview.h 2.14 + 2.15 +SOURCES = src/main.cc \ 2.16 + src/sdr.c \ 2.17 + src/volray.cc \ 2.18 + src/volume.cc \ 2.19 + src/ui.cc \ 2.20 + src/ui_maingl.cc \ 2.21 + src/ui_sliceview.cc \ 2.22 + src/demo.cc
3.1 --- a/src/ui.cc Sat Apr 14 04:59:14 2012 +0300 3.2 +++ b/src/ui.cc Sat Apr 14 06:37:31 2012 +0300 3.3 @@ -1,21 +1,18 @@ 3.4 #include <stdio.h> 3.5 #include <stdlib.h> 3.6 -#include <vector> 3.7 #include <QtGui> 3.8 #include "ui.h" 3.9 3.10 static Volume *volume; 3.11 3.12 -static GLView *maingl; 3.13 -static std::vector<GLView*> glviews; 3.14 +static MainGLView *maingl; 3.15 3.16 MainWindow::MainWindow() 3.17 { 3.18 setWindowTitle("Volume Renderer"); 3.19 3.20 // OpenGL view 3.21 - maingl = new GLView; 3.22 - glviews.push_back(maingl); 3.23 + maingl = new MainGLView; 3.24 setCentralWidget(maingl); 3.25 3.26 // side-window 3.27 @@ -68,8 +65,7 @@ 3.28 { 3.29 QGroupBox *groupbox = new QGroupBox("Volume slice"); 3.30 { 3.31 - GLView *slice_view = new GLView; 3.32 - glviews.push_back(slice_view); 3.33 + slice_view = new SliceGLView(maingl); 3.34 3.35 QCheckBox *chk_clip = new QCheckBox("clip"); 3.36 chk_clip->setChecked(false); 3.37 @@ -112,72 +108,3 @@ 3.38 { 3.39 maingl->updateGL(); 3.40 } 3.41 - 3.42 - 3.43 -GLView::GLView(QWidget *parent) 3.44 - : QGLWidget(QGLFormat(QGL::DoubleBuffer), parent) 3.45 -{ 3.46 -} 3.47 - 3.48 -QSize GLView::minimumSizeHint() const 3.49 -{ 3.50 - return QSize(320, 200); 3.51 -} 3.52 - 3.53 -QSize GLView::sizeHint() const 3.54 -{ 3.55 - return QSize(1280, 800); 3.56 -} 3.57 - 3.58 -void GLView::initializeGL() 3.59 -{ 3.60 - if(!volray_init()) { 3.61 - exit(0); 3.62 - } 3.63 -} 3.64 - 3.65 -void GLView::resizeGL(int xsz, int ysz) 3.66 -{ 3.67 - volray_resize(xsz, ysz); 3.68 -} 3.69 - 3.70 -void GLView::paintGL() 3.71 -{ 3.72 - volray_draw(); 3.73 -} 3.74 - 3.75 -static int button_number(Qt::MouseButton bn) 3.76 -{ 3.77 - switch(bn) { 3.78 - case Qt::LeftButton: 3.79 - return 0; 3.80 - case Qt::MidButton: 3.81 - return 1; 3.82 - case Qt::RightButton: 3.83 - return 2; 3.84 - default: 3.85 - break; 3.86 - } 3.87 - return -1; 3.88 -} 3.89 - 3.90 -void GLView::mousePressEvent(QMouseEvent *ev) 3.91 -{ 3.92 - int bn = button_number(ev->button()); 3.93 - if(bn >= 0) { 3.94 - volray_mouse(bn, 1, ev->x(), ev->y()); 3.95 - } 3.96 -} 3.97 - 3.98 -void GLView::mouseReleaseEvent(QMouseEvent *ev) 3.99 -{ 3.100 - int bn = button_number(ev->button()); 3.101 - if(bn >= 0) { 3.102 - volray_mouse(bn, 0, ev->x(), ev->y()); 3.103 - } 3.104 -} 3.105 - 3.106 -void GLView::mouseMoveEvent(QMouseEvent *ev) 3.107 -{ 3.108 - volray_motion(ev->x(), ev->y()); 3.109 -}
4.1 --- a/src/ui.h Sat Apr 14 04:59:14 2012 +0300 4.2 +++ b/src/ui.h Sat Apr 14 06:37:31 2012 +0300 4.3 @@ -4,6 +4,8 @@ 4.4 #include <QMainWindow> 4.5 #include <QDockWidget> 4.6 #include "volray.h" 4.7 +#include "ui_maingl.h" 4.8 +#include "ui_sliceview.h" 4.9 4.10 class SideWindow; 4.11
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/ui_maingl.cc Sat Apr 14 06:37:31 2012 +0300 5.3 @@ -0,0 +1,71 @@ 5.4 +#include <QtGui> 5.5 +#include "ui_maingl.h" 5.6 +#include "volray.h" 5.7 + 5.8 +MainGLView::MainGLView() 5.9 + : QGLWidget(QGLFormat(QGL::DoubleBuffer), 0) 5.10 +{ 5.11 +} 5.12 + 5.13 +QSize MainGLView::minimumSizeHint() const 5.14 +{ 5.15 + return QSize(320, 200); 5.16 +} 5.17 + 5.18 +QSize MainGLView::sizeHint() const 5.19 +{ 5.20 + return QSize(1280, 800); 5.21 +} 5.22 + 5.23 +void MainGLView::initializeGL() 5.24 +{ 5.25 + if(!volray_init()) { 5.26 + exit(0); 5.27 + } 5.28 +} 5.29 + 5.30 +void MainGLView::resizeGL(int xsz, int ysz) 5.31 +{ 5.32 + volray_resize(xsz, ysz); 5.33 +} 5.34 + 5.35 +void MainGLView::paintGL() 5.36 +{ 5.37 + volray_draw(); 5.38 +} 5.39 + 5.40 +static int button_number(Qt::MouseButton bn) 5.41 +{ 5.42 + switch(bn) { 5.43 + case Qt::LeftButton: 5.44 + return 0; 5.45 + case Qt::MidButton: 5.46 + return 1; 5.47 + case Qt::RightButton: 5.48 + return 2; 5.49 + default: 5.50 + break; 5.51 + } 5.52 + return -1; 5.53 +} 5.54 + 5.55 +void MainGLView::mousePressEvent(QMouseEvent *ev) 5.56 +{ 5.57 + int bn = button_number(ev->button()); 5.58 + if(bn >= 0) { 5.59 + volray_mouse(bn, 1, ev->x(), ev->y()); 5.60 + } 5.61 +} 5.62 + 5.63 +void MainGLView::mouseReleaseEvent(QMouseEvent *ev) 5.64 +{ 5.65 + int bn = button_number(ev->button()); 5.66 + if(bn >= 0) { 5.67 + volray_mouse(bn, 0, ev->x(), ev->y()); 5.68 + } 5.69 +} 5.70 + 5.71 +void MainGLView::mouseMoveEvent(QMouseEvent *ev) 5.72 +{ 5.73 + volray_motion(ev->x(), ev->y()); 5.74 +}
6.1 --- a/src/ui_maingl.h Sat Apr 14 04:59:14 2012 +0300 6.2 +++ b/src/ui_maingl.h Sat Apr 14 06:37:31 2012 +0300 6.3 @@ -1,3 +1,6 @@ 6.4 +#ifndef UI_MAINGL_H_ 6.5 +#define UI_MAINGL_H_ 6.6 + 6.7 #include <QGLWidget> 6.8 6.9 class MainGLView : public QGLWidget { 6.10 @@ -18,3 +21,5 @@ 6.11 QSize minimumSizeHint() const; 6.12 QSize sizeHint() const; 6.13 }; 6.14 + 6.15 +#endif // UI_MAINGL_H_
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/src/ui_sliceview.cc Sat Apr 14 06:37:31 2012 +0300 7.3 @@ -0,0 +1,25 @@ 7.4 +#include "ui_sliceview.h" 7.5 + 7.6 +SliceGLView::SliceGLView(QGLWidget *share_widget) 7.7 + : QGLWidget(QGLFormat(QGL::DoubleBuffer), 0, share_widget) 7.8 +{ 7.9 +} 7.10 + 7.11 +QSize SliceGLView::minimumSizeHint() const 7.12 +{ 7.13 + return QSize(160, 160); 7.14 +} 7.15 + 7.16 +void SliceGLView::initializeGL() 7.17 +{ 7.18 +} 7.19 + 7.20 +void SliceGLView::resizeGL(int xsz, int ysz) 7.21 +{ 7.22 + glViewport(0, 0, xsz, ysz); 7.23 +} 7.24 + 7.25 +void SliceGLView::paintGL() 7.26 +{ 7.27 + glClear(GL_COLOR_BUFFER_BIT); 7.28 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/src/ui_sliceview.h Sat Apr 14 06:37:31 2012 +0300 8.3 @@ -0,0 +1,20 @@ 8.4 +#ifndef UI_SLICEVIEW_H_ 8.5 +#define UI_SLICEVIEW_H_ 8.6 + 8.7 +#include <QGLWidget> 8.8 + 8.9 +class SliceGLView : public QGLWidget { 8.10 +private: 8.11 + Q_OBJECT 8.12 + 8.13 + void initializeGL(); 8.14 + void resizeGL(int xsz, int ysz); 8.15 + void paintGL(); 8.16 + 8.17 +public: 8.18 + SliceGLView(QGLWidget *share_widget = 0); 8.19 + 8.20 + QSize minimumSizeHint() const; 8.21 +}; 8.22 + 8.23 +#endif // UI_SLICEVIEW_H_