qvolray
changeset 13:17d9dc2edc91
first qt version
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 10 Apr 2012 06:11:16 +0300 |
parents | 981fef9aa1be |
children | 88312413467c |
files | Makefile qvolray.pro src/main.cc src/sdr.c src/ui.cc src/ui.h src/volray.cc src/volray.h src/volume.cc src/volume.h |
diffstat | 10 files changed, 234 insertions(+), 316 deletions(-) [+] |
line diff
1.1 --- a/Makefile Mon Apr 09 23:43:13 2012 +0300 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,228 +0,0 @@ 1.4 -############################################################################# 1.5 -# Makefile for building: qvolray 1.6 -# Generated by qmake (2.01a) (Qt 4.7.4) on: Mon Apr 9 23:25:44 2012 1.7 -# Project: qvolray.pro 1.8 -# Template: app 1.9 -# Command: /usr/bin/qmake -o Makefile qvolray.pro 1.10 -############################################################################# 1.11 - 1.12 -####### Compiler, tools and options 1.13 - 1.14 -CC = gcc 1.15 -CXX = g++ 1.16 -DEFINES = -DQT_WEBKIT -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED 1.17 -CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) 1.18 -CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) 1.19 -INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I. -Isrc -I/usr/X11R6/include -I. 1.20 -LINK = g++ 1.21 -LFLAGS = -Wl,-O1 1.22 -LIBS = $(SUBLIBS) -L/usr/lib -L/usr/X11R6/lib -lQtOpenGL -lQtGui -lQtCore -lGLU -lGL -lpthread 1.23 -AR = ar cqs 1.24 -RANLIB = 1.25 -QMAKE = /usr/bin/qmake 1.26 -TAR = tar -cf 1.27 -COMPRESS = gzip -9f 1.28 -COPY = cp -f 1.29 -SED = sed 1.30 -COPY_FILE = $(COPY) 1.31 -COPY_DIR = $(COPY) -r 1.32 -STRIP = strip 1.33 -INSTALL_FILE = install -m 644 -p 1.34 -INSTALL_DIR = $(COPY_DIR) 1.35 -INSTALL_PROGRAM = install -m 755 -p 1.36 -DEL_FILE = rm -f 1.37 -SYMLINK = ln -f -s 1.38 -DEL_DIR = rmdir 1.39 -MOVE = mv -f 1.40 -CHK_DIR_EXISTS= test -d 1.41 -MKDIR = mkdir -p 1.42 - 1.43 -####### Output directory 1.44 - 1.45 -OBJECTS_DIR = ./ 1.46 - 1.47 -####### Files 1.48 - 1.49 -SOURCES = src/main.cc \ 1.50 - src/sdr.c \ 1.51 - src/volray.cc \ 1.52 - src/volume.cc 1.53 -OBJECTS = main.o \ 1.54 - sdr.o \ 1.55 - volray.o \ 1.56 - volume.o 1.57 -DIST = /usr/share/qt4/mkspecs/common/g++.conf \ 1.58 - /usr/share/qt4/mkspecs/common/unix.conf \ 1.59 - /usr/share/qt4/mkspecs/common/linux.conf \ 1.60 - /usr/share/qt4/mkspecs/qconfig.pri \ 1.61 - /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ 1.62 - /usr/share/qt4/mkspecs/features/qt_functions.prf \ 1.63 - /usr/share/qt4/mkspecs/features/qt_config.prf \ 1.64 - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 1.65 - /usr/share/qt4/mkspecs/features/default_pre.prf \ 1.66 - /usr/share/qt4/mkspecs/features/release.prf \ 1.67 - /usr/share/qt4/mkspecs/features/default_post.prf \ 1.68 - /usr/share/qt4/mkspecs/features/warn_on.prf \ 1.69 - /usr/share/qt4/mkspecs/features/qt.prf \ 1.70 - /usr/share/qt4/mkspecs/features/unix/opengl.prf \ 1.71 - /usr/share/qt4/mkspecs/features/unix/thread.prf \ 1.72 - /usr/share/qt4/mkspecs/features/moc.prf \ 1.73 - /usr/share/qt4/mkspecs/features/resources.prf \ 1.74 - /usr/share/qt4/mkspecs/features/uic.prf \ 1.75 - /usr/share/qt4/mkspecs/features/yacc.prf \ 1.76 - /usr/share/qt4/mkspecs/features/lex.prf \ 1.77 - /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 1.78 - qvolray.pro 1.79 -QMAKE_TARGET = qvolray 1.80 -DESTDIR = 1.81 -TARGET = qvolray 1.82 - 1.83 -first: all 1.84 -####### Implicit rules 1.85 - 1.86 -.SUFFIXES: .o .c .cpp .cc .cxx .C 1.87 - 1.88 -.cpp.o: 1.89 - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 1.90 - 1.91 -.cc.o: 1.92 - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 1.93 - 1.94 -.cxx.o: 1.95 - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 1.96 - 1.97 -.C.o: 1.98 - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 1.99 - 1.100 -.c.o: 1.101 - $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" 1.102 - 1.103 -####### Build rules 1.104 - 1.105 -all: Makefile $(TARGET) 1.106 - 1.107 -$(TARGET): $(OBJECTS) 1.108 - $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) 1.109 - 1.110 -Makefile: qvolray.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ 1.111 - /usr/share/qt4/mkspecs/common/unix.conf \ 1.112 - /usr/share/qt4/mkspecs/common/linux.conf \ 1.113 - /usr/share/qt4/mkspecs/qconfig.pri \ 1.114 - /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ 1.115 - /usr/share/qt4/mkspecs/features/qt_functions.prf \ 1.116 - /usr/share/qt4/mkspecs/features/qt_config.prf \ 1.117 - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 1.118 - /usr/share/qt4/mkspecs/features/default_pre.prf \ 1.119 - /usr/share/qt4/mkspecs/features/release.prf \ 1.120 - /usr/share/qt4/mkspecs/features/default_post.prf \ 1.121 - /usr/share/qt4/mkspecs/features/warn_on.prf \ 1.122 - /usr/share/qt4/mkspecs/features/qt.prf \ 1.123 - /usr/share/qt4/mkspecs/features/unix/opengl.prf \ 1.124 - /usr/share/qt4/mkspecs/features/unix/thread.prf \ 1.125 - /usr/share/qt4/mkspecs/features/moc.prf \ 1.126 - /usr/share/qt4/mkspecs/features/resources.prf \ 1.127 - /usr/share/qt4/mkspecs/features/uic.prf \ 1.128 - /usr/share/qt4/mkspecs/features/yacc.prf \ 1.129 - /usr/share/qt4/mkspecs/features/lex.prf \ 1.130 - /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 1.131 - /usr/lib/libQtOpenGL.prl \ 1.132 - /usr/lib/libQtGui.prl \ 1.133 - /usr/lib/libQtCore.prl 1.134 - $(QMAKE) -o Makefile qvolray.pro 1.135 -/usr/share/qt4/mkspecs/common/g++.conf: 1.136 -/usr/share/qt4/mkspecs/common/unix.conf: 1.137 -/usr/share/qt4/mkspecs/common/linux.conf: 1.138 -/usr/share/qt4/mkspecs/qconfig.pri: 1.139 -/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri: 1.140 -/usr/share/qt4/mkspecs/features/qt_functions.prf: 1.141 -/usr/share/qt4/mkspecs/features/qt_config.prf: 1.142 -/usr/share/qt4/mkspecs/features/exclusive_builds.prf: 1.143 -/usr/share/qt4/mkspecs/features/default_pre.prf: 1.144 -/usr/share/qt4/mkspecs/features/release.prf: 1.145 -/usr/share/qt4/mkspecs/features/default_post.prf: 1.146 -/usr/share/qt4/mkspecs/features/warn_on.prf: 1.147 -/usr/share/qt4/mkspecs/features/qt.prf: 1.148 -/usr/share/qt4/mkspecs/features/unix/opengl.prf: 1.149 -/usr/share/qt4/mkspecs/features/unix/thread.prf: 1.150 -/usr/share/qt4/mkspecs/features/moc.prf: 1.151 -/usr/share/qt4/mkspecs/features/resources.prf: 1.152 -/usr/share/qt4/mkspecs/features/uic.prf: 1.153 -/usr/share/qt4/mkspecs/features/yacc.prf: 1.154 -/usr/share/qt4/mkspecs/features/lex.prf: 1.155 -/usr/share/qt4/mkspecs/features/include_source_dir.prf: 1.156 -/usr/lib/libQtOpenGL.prl: 1.157 -/usr/lib/libQtGui.prl: 1.158 -/usr/lib/libQtCore.prl: 1.159 -qmake: FORCE 1.160 - @$(QMAKE) -o Makefile qvolray.pro 1.161 - 1.162 -dist: 1.163 - @$(CHK_DIR_EXISTS) .tmp/qvolray1.0.0 || $(MKDIR) .tmp/qvolray1.0.0 1.164 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/qvolray1.0.0/ && $(COPY_FILE) --parents src/sdr.h src/volray.h src/volume.h .tmp/qvolray1.0.0/ && $(COPY_FILE) --parents src/main.cc src/sdr.c src/volray.cc src/volume.cc .tmp/qvolray1.0.0/ && (cd `dirname .tmp/qvolray1.0.0` && $(TAR) qvolray1.0.0.tar qvolray1.0.0 && $(COMPRESS) qvolray1.0.0.tar) && $(MOVE) `dirname .tmp/qvolray1.0.0`/qvolray1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/qvolray1.0.0 1.165 - 1.166 - 1.167 -clean:compiler_clean 1.168 - -$(DEL_FILE) $(OBJECTS) 1.169 - -$(DEL_FILE) *~ core *.core 1.170 - 1.171 - 1.172 -####### Sub-libraries 1.173 - 1.174 -distclean: clean 1.175 - -$(DEL_FILE) $(TARGET) 1.176 - -$(DEL_FILE) Makefile 1.177 - 1.178 - 1.179 -check: first 1.180 - 1.181 -mocclean: compiler_moc_header_clean compiler_moc_source_clean 1.182 - 1.183 -mocables: compiler_moc_header_make_all compiler_moc_source_make_all 1.184 - 1.185 -compiler_moc_header_make_all: 1.186 -compiler_moc_header_clean: 1.187 -compiler_rcc_make_all: 1.188 -compiler_rcc_clean: 1.189 -compiler_image_collection_make_all: qmake_image_collection.cpp 1.190 -compiler_image_collection_clean: 1.191 - -$(DEL_FILE) qmake_image_collection.cpp 1.192 -compiler_moc_source_make_all: main.moc 1.193 -compiler_moc_source_clean: 1.194 - -$(DEL_FILE) main.moc 1.195 -main.moc: src/volray.h \ 1.196 - src/main.cc 1.197 - /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) src/main.cc -o main.moc 1.198 - 1.199 -compiler_uic_make_all: 1.200 -compiler_uic_clean: 1.201 -compiler_yacc_decl_make_all: 1.202 -compiler_yacc_decl_clean: 1.203 -compiler_yacc_impl_make_all: 1.204 -compiler_yacc_impl_clean: 1.205 -compiler_lex_make_all: 1.206 -compiler_lex_clean: 1.207 -compiler_clean: compiler_moc_source_clean 1.208 - 1.209 -####### Compile 1.210 - 1.211 -main.o: src/main.cc src/volray.h 1.212 - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o src/main.cc 1.213 - 1.214 -sdr.o: src/sdr.c src/sdr.h 1.215 - $(CC) -c $(CFLAGS) $(INCPATH) -o sdr.o src/sdr.c 1.216 - 1.217 -volray.o: src/volray.cc src/sdr.h \ 1.218 - src/volume.h 1.219 - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o volray.o src/volray.cc 1.220 - 1.221 -volume.o: src/volume.cc src/volume.h 1.222 - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o volume.o src/volume.cc 1.223 - 1.224 -####### Install 1.225 - 1.226 -install: FORCE 1.227 - 1.228 -uninstall: FORCE 1.229 - 1.230 -FORCE: 1.231 -
2.1 --- a/qvolray.pro Mon Apr 09 23:43:13 2012 +0300 2.2 +++ b/qvolray.pro Tue Apr 10 06:11:16 2012 +0300 2.3 @@ -4,6 +4,9 @@ 2.4 INCLUDEPATH += . src 2.5 QT += opengl 2.6 2.7 +QMAKE_CXXFLAGS += -std=c++0x 2.8 +LIBS += -lGLEW -limago -lvmath 2.9 + 2.10 # Input 2.11 -HEADERS += src/sdr.h src/volray.h src/volume.h 2.12 -SOURCES += src/main.cc src/sdr.c src/volray.cc src/volume.cc 2.13 +HEADERS += src/sdr.h src/volray.h src/volume.h src/ui.h 2.14 +SOURCES += src/main.cc src/sdr.c src/volray.cc src/volume.cc src/ui.cc
3.1 --- a/src/main.cc Mon Apr 09 23:43:13 2012 +0300 3.2 +++ b/src/main.cc Tue Apr 10 06:11:16 2012 +0300 3.3 @@ -1,51 +1,11 @@ 3.4 #include <QApplication> 3.5 -#include <QMainWindow> 3.6 -#include <QGLWidget> 3.7 -#include "volray.h" 3.8 - 3.9 -class GLView : public QGLWidget { 3.10 -private: 3.11 - Q_OBJECT; 3.12 - 3.13 - void initializeGL(); 3.14 - void resizeGL(int xsz, int ysz); 3.15 - void paintGL(); 3.16 - 3.17 -public: 3.18 - GLView(QWidget *parent = 0); 3.19 -}; 3.20 - 3.21 +#include "ui.h" 3.22 3.23 int main(int argc, char **argv) 3.24 { 3.25 QApplication app(argc, argv); 3.26 3.27 - QMainWindow win; 3.28 - GLView glview(&win); 3.29 + MainWindow gui; 3.30 3.31 - win.show(); 3.32 app.exec(); 3.33 } 3.34 - 3.35 - 3.36 -GLView::GLView(QWidget *parent) 3.37 - : QGLWidget(parent) 3.38 -{ 3.39 -} 3.40 - 3.41 -void GLView::initializeGL() 3.42 -{ 3.43 - glClearColor(1, 0, 0, 1); 3.44 - 3.45 - volray_init(); 3.46 -} 3.47 - 3.48 -void GLView::resizeGL(int xsz, int ysz) 3.49 -{ 3.50 - volray_resize(xsz, ysz); 3.51 -} 3.52 - 3.53 -void GLView::paintGL() 3.54 -{ 3.55 - volray_draw(); 3.56 -}
4.1 --- a/src/sdr.c Mon Apr 09 23:43:13 2012 +0300 4.2 +++ b/src/sdr.c Tue Apr 10 06:11:16 2012 +0300 4.3 @@ -249,13 +249,13 @@ 4.4 #define BEGIN_UNIFORM_CODE \ 4.5 int loc, curr_prog; \ 4.6 glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog); \ 4.7 - if(curr_prog != prog && bind_program(prog) == -1) { \ 4.8 + if((unsigned int)curr_prog != prog && bind_program(prog) == -1) { \ 4.9 return -1; \ 4.10 } \ 4.11 if((loc = glGetUniformLocation(prog, name)) != -1) 4.12 4.13 #define END_UNIFORM_CODE \ 4.14 - if(curr_prog != prog) { \ 4.15 + if((unsigned int)curr_prog != prog) { \ 4.16 bind_program(curr_prog); \ 4.17 } \ 4.18 return loc == -1 ? -1 : 0 4.19 @@ -313,13 +313,13 @@ 4.20 int loc, curr_prog; 4.21 4.22 glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog); 4.23 - if(curr_prog != prog && bind_program(prog) == -1) { 4.24 + if((unsigned int)curr_prog != prog && bind_program(prog) == -1) { 4.25 return -1; 4.26 } 4.27 4.28 loc = glGetAttribLocation(prog, (char*)name); 4.29 4.30 - if(curr_prog != prog) { 4.31 + if((unsigned int)curr_prog != prog) { 4.32 bind_program(curr_prog); 4.33 } 4.34 return loc;
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/ui.cc Tue Apr 10 06:11:16 2012 +0300 5.3 @@ -0,0 +1,129 @@ 5.4 +#include <stdio.h> 5.5 +#include <stdlib.h> 5.6 +#include <QtGui> 5.7 +#include "ui.h" 5.8 + 5.9 +static GLView *glview; 5.10 +static Volume *volume; 5.11 + 5.12 +MainWindow::MainWindow() 5.13 +{ 5.14 + setWindowTitle("Volume Renderer"); 5.15 + 5.16 + // OpenGL view 5.17 + glview = new GLView; 5.18 + setCentralWidget(glview); 5.19 + 5.20 + // actions 5.21 + QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this); 5.22 + act_open->setStatusTip("Open a volume dataset"); 5.23 + QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume())); 5.24 + 5.25 + QAction *act_quit = new QAction("&Quit", this); 5.26 + act_quit->setStatusTip("Quit"); 5.27 + QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close())); 5.28 + 5.29 + // menus 5.30 + QMenu *mfile = menuBar()->addMenu("&File"); 5.31 + mfile->addAction(act_open); 5.32 + mfile->addAction(act_quit); 5.33 + 5.34 + // toolbars 5.35 + QToolBar *tfile = addToolBar("&File"); 5.36 + tfile->addAction(act_open); 5.37 + 5.38 + statusBar(); 5.39 + show(); 5.40 +} 5.41 + 5.42 +void MainWindow::open_volume() 5.43 +{ 5.44 + QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)"); 5.45 + if(!fname.isNull()) { 5.46 + Volume *vol = new Volume; 5.47 + 5.48 + if(vol->load(qPrintable(fname))) { 5.49 + delete volume; 5.50 + volume = vol; 5.51 + volray_setvolume(vol); 5.52 + post_redisplay(); 5.53 + } else { 5.54 + delete vol; 5.55 + } 5.56 + } 5.57 +} 5.58 + 5.59 +void post_redisplay() 5.60 +{ 5.61 + glview->updateGL(); 5.62 +} 5.63 + 5.64 + 5.65 +GLView::GLView(QWidget *parent) 5.66 + : QGLWidget(QGLFormat(QGL::DoubleBuffer), parent) 5.67 +{ 5.68 +} 5.69 + 5.70 +QSize GLView::minimumSizeHint() const 5.71 +{ 5.72 + return QSize(320, 200); 5.73 +} 5.74 + 5.75 +QSize GLView::sizeHint() const 5.76 +{ 5.77 + return QSize(1280, 800); 5.78 +} 5.79 + 5.80 +void GLView::initializeGL() 5.81 +{ 5.82 + if(!volray_init()) { 5.83 + exit(0); 5.84 + } 5.85 + glClearColor(1, 0, 0, 1); 5.86 +} 5.87 + 5.88 +void GLView::resizeGL(int xsz, int ysz) 5.89 +{ 5.90 + volray_resize(xsz, ysz); 5.91 +} 5.92 + 5.93 +void GLView::paintGL() 5.94 +{ 5.95 + volray_draw(); 5.96 +} 5.97 + 5.98 +static int button_number(Qt::MouseButton bn) 5.99 +{ 5.100 + switch(bn) { 5.101 + case Qt::LeftButton: 5.102 + return 0; 5.103 + case Qt::MidButton: 5.104 + return 1; 5.105 + case Qt::RightButton: 5.106 + return 2; 5.107 + default: 5.108 + break; 5.109 + } 5.110 + return -1; 5.111 +} 5.112 + 5.113 +void GLView::mousePressEvent(QMouseEvent *ev) 5.114 +{ 5.115 + int bn = button_number(ev->button()); 5.116 + if(bn >= 0) { 5.117 + volray_mouse(bn, 1, ev->x(), ev->y()); 5.118 + } 5.119 +} 5.120 + 5.121 +void GLView::mouseReleaseEvent(QMouseEvent *ev) 5.122 +{ 5.123 + int bn = button_number(ev->button()); 5.124 + if(bn >= 0) { 5.125 + volray_mouse(bn, 0, ev->x(), ev->y()); 5.126 + } 5.127 +} 5.128 + 5.129 +void GLView::mouseMoveEvent(QMouseEvent *ev) 5.130 +{ 5.131 + volray_motion(ev->x(), ev->y()); 5.132 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/src/ui.h Tue Apr 10 06:11:16 2012 +0300 6.3 @@ -0,0 +1,41 @@ 6.4 +#ifndef UI_H_ 6.5 +#define UI_H_ 6.6 + 6.7 +#include <QMainWindow> 6.8 +#include <QGLWidget> 6.9 +#include "volray.h" 6.10 + 6.11 +class GLView; 6.12 + 6.13 +class MainWindow : public QMainWindow { 6.14 + Q_OBJECT 6.15 +private slots: 6.16 + void open_volume(); 6.17 + 6.18 +public: 6.19 + MainWindow(); 6.20 +}; 6.21 + 6.22 +class GLView : public QGLWidget { 6.23 + Q_OBJECT 6.24 + 6.25 +protected: 6.26 + void initializeGL(); 6.27 + void resizeGL(int xsz, int ysz); 6.28 + void paintGL(); 6.29 + 6.30 + void mousePressEvent(QMouseEvent *ev); 6.31 + void mouseReleaseEvent(QMouseEvent *ev); 6.32 + void mouseMoveEvent(QMouseEvent *ev); 6.33 + 6.34 +public: 6.35 + GLView(QWidget *parent = 0); 6.36 + 6.37 + QSize minimumSizeHint() const; 6.38 + QSize sizeHint() const; 6.39 +}; 6.40 + 6.41 +void post_redisplay(); 6.42 + 6.43 + 6.44 +#endif // UI_H_
7.1 --- a/src/volray.cc Mon Apr 09 23:43:13 2012 +0300 7.2 +++ b/src/volray.cc Tue Apr 10 06:11:16 2012 +0300 7.3 @@ -13,6 +13,7 @@ 7.4 #include <imago2.h> 7.5 #include "sdr.h" 7.6 #include "volume.h" 7.7 +#include "ui.h" 7.8 7.9 #define XFER_MAP_SZ 512 7.10 7.11 @@ -36,7 +37,7 @@ 7.12 static float cam_theta = 0, cam_phi = 0, cam_dist = 4.0; 7.13 static float cam_x, cam_y, cam_z; 7.14 7.15 -static vec2_t tex_scale; 7.16 +static Vector2 tex_scale; 7.17 static unsigned int vol_sdr, slice_sdr, ray_tex; 7.18 static int win_xsz, win_ysz; 7.19 static bool raytex_needs_recalc = true; 7.20 @@ -48,7 +49,7 @@ 7.21 static float cur_z = 0.0; 7.22 static float ray_step = 0.01; 7.23 7.24 -static Volume volume; 7.25 +static const Volume *volume; 7.26 7.27 7.28 bool volray_init() 7.29 @@ -70,12 +71,14 @@ 7.30 set_uniform_int(slice_sdr, "volume", 0); 7.31 set_uniform_int(slice_sdr, "xfer_tex", 1); 7.32 7.33 - if(!volume.load(fname)) { 7.34 - return false; 7.35 - } 7.36 return true; 7.37 } 7.38 7.39 +void volray_setvolume(const Volume *vol) 7.40 +{ 7.41 + volume = vol; 7.42 +} 7.43 + 7.44 void volray_draw(void) 7.45 { 7.46 /* recalculate primary ray texture if needed */ 7.47 @@ -87,9 +90,13 @@ 7.48 create_transfer_map(xfer_mean, xfer_sdev); 7.49 } 7.50 7.51 - render_volume(); 7.52 - draw_slice(); 7.53 - draw_xfer_func(); 7.54 + glClear(GL_COLOR_BUFFER_BIT); 7.55 + 7.56 + if(volume) { 7.57 + render_volume(); 7.58 + draw_slice(); 7.59 + draw_xfer_func(); 7.60 + } 7.61 7.62 assert(glGetError() == GL_NO_ERROR); 7.63 } 7.64 @@ -114,7 +121,7 @@ 7.65 7.66 /* tex unit0: volume data 3D texture */ 7.67 glActiveTexture(GL_TEXTURE0); 7.68 - glBindTexture(GL_TEXTURE_3D, volume.get_texture()); 7.69 + glBindTexture(GL_TEXTURE_3D, volume->get_texture()); 7.70 glEnable(GL_TEXTURE_3D); 7.71 7.72 /* tex unit1: primary rays in view space */ 7.73 @@ -159,7 +166,7 @@ 7.74 glTranslatef(-1, -1, 0); 7.75 7.76 glActiveTexture(GL_TEXTURE0); 7.77 - glBindTexture(GL_TEXTURE_3D, volume.get_texture()); 7.78 + glBindTexture(GL_TEXTURE_3D, volume->get_texture()); 7.79 glEnable(GL_TEXTURE_3D); 7.80 7.81 glActiveTexture(GL_TEXTURE1); 7.82 @@ -209,11 +216,11 @@ 7.83 7.84 glLineWidth(2.0); 7.85 glBegin(GL_LINE_LOOP); 7.86 - if(uimode == UIMODE_XFER) { 7.87 + /*if(uimode == UIMODE_XFER) { 7.88 glColor3f(1, 0, 0); 7.89 - } else { 7.90 + } else {*/ 7.91 glColor3f(0, 0, 1); 7.92 - } 7.93 + //} 7.94 glVertex2f(0, 0); 7.95 glVertex2f(1, 0); 7.96 glVertex2f(1, 1); 7.97 @@ -243,12 +250,12 @@ 7.98 7.99 case 'x': 7.100 uimode = UIMODE_XFER; 7.101 - glutPostRedisplay(); 7.102 + post_redisplay(); 7.103 break; 7.104 7.105 case 'c': 7.106 uimode = UIMODE_CURSOR; 7.107 - glutPostRedisplay(); 7.108 + post_redisplay(); 7.109 break; 7.110 7.111 default: 7.112 @@ -262,14 +269,14 @@ 7.113 case 'x': 7.114 if(uimode == UIMODE_XFER) { 7.115 uimode = UIMODE_DEFAULT; 7.116 - glutPostRedisplay(); 7.117 + post_redisplay(); 7.118 } 7.119 break; 7.120 7.121 case 'c': 7.122 if(uimode == UIMODE_CURSOR) { 7.123 uimode = UIMODE_DEFAULT; 7.124 - glutPostRedisplay(); 7.125 + post_redisplay(); 7.126 } 7.127 break; 7.128 7.129 @@ -277,25 +284,26 @@ 7.130 break; 7.131 } 7.132 } 7.133 +#endif 7.134 7.135 static int bnstate[32]; 7.136 static int prev_x, prev_y; 7.137 7.138 -void mouse(int bn, int state, int x, int y) 7.139 +void volray_mouse(int bn, int state, int x, int y) 7.140 { 7.141 - bnstate[bn - GLUT_LEFT_BUTTON] = state == GLUT_DOWN; 7.142 + bnstate[bn] = state; 7.143 prev_x = x; 7.144 prev_y = y; 7.145 } 7.146 7.147 -void motion(int x, int y) 7.148 +void volray_motion(int x, int y) 7.149 { 7.150 int dx = x - prev_x; 7.151 int dy = y - prev_y; 7.152 prev_x = x; 7.153 prev_y = y; 7.154 7.155 - switch(uimode) { 7.156 + /*switch(uimode) { 7.157 case UIMODE_XFER: 7.158 if(dx || dy) { 7.159 xfer_mean += dx / (float)win_xsz; 7.160 @@ -305,7 +313,7 @@ 7.161 xfer_sdev = xfer_sdev < 0.0 ? 0.0 : (xfer_sdev > 1.0 ? 1.0 : xfer_sdev); 7.162 7.163 xfertex_needs_recalc = true; 7.164 - glutPostRedisplay(); 7.165 + post_redisplay(); 7.166 } 7.167 break; 7.168 7.169 @@ -318,10 +326,10 @@ 7.170 cur_z = 1.0; 7.171 7.172 set_uniform_float(vol_sdr, "zclip", cur_z); 7.173 - glutPostRedisplay(); 7.174 + post_redisplay(); 7.175 break; 7.176 7.177 - default: 7.178 + default:*/ 7.179 /* view control */ 7.180 if(bnstate[0]) { 7.181 cam_theta += dx * 0.5; 7.182 @@ -329,25 +337,24 @@ 7.183 7.184 if(cam_phi <= -90) cam_phi = -89; 7.185 if(cam_phi >= 90) cam_phi = 89; 7.186 - 7.187 - glutPostRedisplay(); 7.188 + post_redisplay(); 7.189 } 7.190 7.191 if(bnstate[1]) { 7.192 cam_x += dx * 0.025; 7.193 cam_y += dy * 0.025; 7.194 - glutPostRedisplay(); 7.195 + post_redisplay(); 7.196 } 7.197 7.198 if(bnstate[2]) { 7.199 cam_dist += dy * 0.025; 7.200 if(cam_dist < 0.0) cam_dist = 0.0; 7.201 - glutPostRedisplay(); 7.202 + post_redisplay(); 7.203 } 7.204 - } 7.205 + //} 7.206 } 7.207 7.208 - 7.209 +#if 0 7.210 int parse_args(int argc, char **argv) 7.211 { 7.212 int i;
8.1 --- a/src/volray.h Mon Apr 09 23:43:13 2012 +0300 8.2 +++ b/src/volray.h Tue Apr 10 06:11:16 2012 +0300 8.3 @@ -1,8 +1,14 @@ 8.4 #ifndef VOLRAY_H_ 8.5 #define VOLRAY_H_ 8.6 8.7 +#include "volume.h" 8.8 + 8.9 bool volray_init(); 8.10 +void volray_setvolume(const Volume *vol); 8.11 void volray_resize(int xsz, int ysz); 8.12 void volray_draw(); 8.13 8.14 +void volray_mouse(int bn, int state, int x, int y); 8.15 +void volray_motion(int x, int y); 8.16 + 8.17 #endif // VOLRAY_H_
9.1 --- a/src/volume.cc Mon Apr 09 23:43:13 2012 +0300 9.2 +++ b/src/volume.cc Tue Apr 10 06:11:16 2012 +0300 9.3 @@ -44,14 +44,14 @@ 9.4 9.5 /* load the first image to determine slice dimensions */ 9.6 img_init(&img); 9.7 - if(img_load(&img, slist.begin().name.c_str()) == -1) { 9.8 - fprintf(stderr, "failed to load volume slice: %s\n", slist->name); 9.9 + if(img_load(&img, slist.begin()->c_str()) == -1) { 9.10 + fprintf(stderr, "failed to load volume slice: %s\n", slist.begin()->c_str()); 9.11 return false; 9.12 } 9.13 9.14 sz[0] = img.width; 9.15 sz[1] = img.height; 9.16 - printf("volume dimensions: %dx%dx%d\n", img.width, img.height, vol->sz[2]); 9.17 + printf("volume dimensions: %dx%dx%d\n", img.width, img.height, sz[2]); 9.18 9.19 /* allocate the whole volume at once */ 9.20 voxels = new float[sz[0] * sz[1] * sz[2] * 4]; 9.21 @@ -63,15 +63,15 @@ 9.22 int x, y, xsz, ysz; 9.23 float *pixels, *src; 9.24 9.25 - if(!(pixels = img_load_pixels(slice.name.c_str(), &xsz, &ysz, IMG_FMT_GREYF))) { 9.26 - fprintf(stderr, "failed to load volume slice: %s\n", slice.name.c_str()); 9.27 + if(!(pixels = (float*)img_load_pixels(slice.c_str(), &xsz, &ysz, IMG_FMT_GREYF))) { 9.28 + fprintf(stderr, "failed to load volume slice: %s\n", slice.c_str()); 9.29 delete [] voxels; 9.30 return false; 9.31 } 9.32 9.33 if(xsz != sz[0] || ysz != sz[1]) { 9.34 fprintf(stderr, "inconsistent dimensions for slice %s: %dx%d (%dx%d expected)\n", 9.35 - slice.name.c_str(), xsz, ysz, sz[0], sz[1]); 9.36 + slice.c_str(), xsz, ysz, sz[0], sz[1]); 9.37 delete [] voxels; 9.38 return false; 9.39 } 9.40 @@ -145,7 +145,7 @@ 9.41 } 9.42 } 9.43 9.44 -bool read_voldesc(const char *fname, std::list<std::string> *slist) const 9.45 +bool Volume::read_voldesc(const char *fname, std::list<std::string> *slist) 9.46 { 9.47 FILE *fp = 0; 9.48 char buf[512], *slash, *prefix = ""; 9.49 @@ -164,9 +164,9 @@ 9.50 return false; 9.51 } 9.52 9.53 - if((slash = strrchr(fname, '/'))) { 9.54 + if((slash = strrchr((char*)fname, '/'))) { 9.55 int len = slash - fname + 1; 9.56 - prefix = alloca(len + 1); 9.57 + prefix = (char*)alloca(len + 1); 9.58 memcpy(prefix, fname, len); 9.59 prefix[len] = 0; 9.60 }
10.1 --- a/src/volume.h Mon Apr 09 23:43:13 2012 +0300 10.2 +++ b/src/volume.h Tue Apr 10 06:11:16 2012 +0300 10.3 @@ -10,7 +10,7 @@ 10.4 float zaspect; 10.5 unsigned int tex; 10.6 10.7 - bool read_voldesc(const char *fname, std::list<std::string> *slist) const; 10.8 + bool read_voldesc(const char *fname, std::list<std::string> *slist); 10.9 10.10 public: 10.11 Volume();