glviewvol

changeset 11:73edd1b7c2da

changed the name to glviewvol
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 31 Dec 2014 07:53:53 +0200
parents 89efc666105c
children 773f89037a35
files .hgignore Makefile src/dicomview.cc src/dicomview.h src/main.cc src/viewer.cc src/viewer.h src/xfer_view.cc
diffstat 8 files changed, 280 insertions(+), 280 deletions(-) [+]
line diff
     1.1 --- a/.hgignore	Wed Dec 31 05:21:47 2014 +0200
     1.2 +++ b/.hgignore	Wed Dec 31 07:53:53 2014 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  \.o$
     1.5  \.d$
     1.6  \.swp$
     1.7 -^dicomview$
     1.8 +^glviewvol$
     1.9  ^data/
     2.1 --- a/Makefile	Wed Dec 31 05:21:47 2014 +0200
     2.2 +++ b/Makefile	Wed Dec 31 07:53:53 2014 +0200
     2.3 @@ -3,7 +3,7 @@
     2.4  obj = $(csrc:.c=.o) $(ccsrc:.cc=.o)
     2.5  dep = $(obj:.o=.d)
     2.6  
     2.7 -bin = dicomview
     2.8 +bin = glviewvol
     2.9  
    2.10  opt = -O3 -ffast-math
    2.11  dbg = -g
     3.1 --- a/src/dicomview.cc	Wed Dec 31 05:21:47 2014 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,248 +0,0 @@
     3.4 -#include <stdio.h>
     3.5 -#include <stdlib.h>
     3.6 -#include "opengl.h"
     3.7 -#include "dicomview.h"
     3.8 -#include "rend_fast.h"
     3.9 -#include "opt.h"
    3.10 -#include "volume.h"
    3.11 -#include "xfer_view.h"
    3.12 -
    3.13 -static int win_width, win_height;
    3.14 -static float cam_theta, cam_phi, cam_dist = 4;
    3.15 -static float pre_rot = -90;
    3.16 -static int splitter_y = -1;
    3.17 -
    3.18 -#define SPLITTER_WIDTH			5
    3.19 -
    3.20 -static Renderer *rend;
    3.21 -static Volume *vol;
    3.22 -static TransferFunc *xfer;
    3.23 -
    3.24 -extern "C" {
    3.25 -
    3.26 -int init()
    3.27 -{
    3.28 -	if(!opt.fname) {
    3.29 -		fprintf(stderr, "you must specify the volume data filename\n");
    3.30 -		return -1;
    3.31 -	}
    3.32 -
    3.33 -	switch(opt.rend_type) {
    3.34 -	case REND_FAST:
    3.35 -		rend = new RendererFast;
    3.36 -		break;
    3.37 -	default:
    3.38 -		return -1;
    3.39 -	}
    3.40 -
    3.41 -	if(!rend->init()) {
    3.42 -		fprintf(stderr, "renderer initialization failed\n");
    3.43 -		return -1;
    3.44 -	}
    3.45 -
    3.46 -	VoxelVolume *voxvol = new VoxelVolume;
    3.47 -	if(!voxvol->load(opt.fname)) {
    3.48 -		fprintf(stderr, "failed to load volume data from: %s\n", opt.fname);
    3.49 -		return -1;
    3.50 -	}
    3.51 -	vol = voxvol;
    3.52 -	rend->set_volume(vol);
    3.53 -
    3.54 -	xfer = new TransferWindow;
    3.55 -	rend->set_transfer_function(xfer);
    3.56 -
    3.57 -	if(!xfview_init(xfer)) {
    3.58 -		return -1;
    3.59 -	}
    3.60 -
    3.61 -	return 0;
    3.62 -}
    3.63 -
    3.64 -void cleanup()
    3.65 -{
    3.66 -	xfview_destroy();
    3.67 -
    3.68 -	rend->destroy();
    3.69 -	delete rend;
    3.70 -	delete vol;
    3.71 -	delete xfer;
    3.72 -}
    3.73 -
    3.74 -void ev_display()
    3.75 -{
    3.76 -	glClear(GL_COLOR_BUFFER_BIT);
    3.77 -
    3.78 -	// render the main view
    3.79 -	glViewport(0, win_height - splitter_y, win_width, splitter_y);
    3.80 -
    3.81 -	glMatrixMode(GL_PROJECTION);
    3.82 -	glLoadIdentity();
    3.83 -	gluPerspective(50.0, (float)win_width / (float)splitter_y, 0.1, 100.0);
    3.84 -
    3.85 -	glMatrixMode(GL_MODELVIEW);
    3.86 -	glLoadIdentity();
    3.87 -	glTranslatef(0, 0, -cam_dist);
    3.88 -	glRotatef(cam_phi + pre_rot, 1, 0, 0);
    3.89 -	glRotatef(cam_theta, 0, 1, 0);
    3.90 -
    3.91 -	rend->update(0);
    3.92 -	rend->render();
    3.93 -
    3.94 -	// draw the transfer function view
    3.95 -	glViewport(0, 0, win_width, win_height - splitter_y);
    3.96 -
    3.97 -	xfview_draw();
    3.98 -
    3.99 -	// draw the GUI
   3.100 -	glViewport(0, 0, win_width, win_height);
   3.101 -
   3.102 -	glMatrixMode(GL_PROJECTION);
   3.103 -	glLoadIdentity();
   3.104 -	glOrtho(0, win_width, win_height, 0, -1, 1);
   3.105 -
   3.106 -	glMatrixMode(GL_MODELVIEW);
   3.107 -	glLoadIdentity();
   3.108 -
   3.109 -	glBegin(GL_QUADS);
   3.110 -	glColor3f(1, 1, 1);
   3.111 -	glVertex2f(0, splitter_y + SPLITTER_WIDTH / 2);
   3.112 -	glVertex2f(win_width, splitter_y + SPLITTER_WIDTH / 2);
   3.113 -	glVertex2f(win_width, splitter_y - SPLITTER_WIDTH / 2);
   3.114 -	glVertex2f(0, splitter_y - SPLITTER_WIDTH / 2);
   3.115 -	glEnd();
   3.116 -
   3.117 -	swap_buffers();
   3.118 -}
   3.119 -
   3.120 -void ev_reshape(int x, int y)
   3.121 -{
   3.122 -	if(splitter_y < 0) {	// not initialized yet
   3.123 -		splitter_y = (int)(y * 0.85);
   3.124 -	} else {
   3.125 -		// calculate where the splitter was relative to the window height
   3.126 -		// and based on that, it's new position
   3.127 -		float split = (float)splitter_y / (float)win_height;
   3.128 -		splitter_y = (int)(y * split);
   3.129 -	}
   3.130 -
   3.131 -	win_width = x;
   3.132 -	win_height = y;
   3.133 -
   3.134 -	glViewport(0, 0, x, y);
   3.135 -	if(rend) {
   3.136 -		rend->reshape(x, y);
   3.137 -	}
   3.138 -}
   3.139 -
   3.140 -static bool zscaling;
   3.141 -
   3.142 -void ev_keyboard(int key, int press, int x, int y)
   3.143 -{
   3.144 -	RendererFast *fr;
   3.145 -
   3.146 -	switch(key) {
   3.147 -	case 27:
   3.148 -		if(press) {
   3.149 -			quit();
   3.150 -		}
   3.151 -		break;
   3.152 -
   3.153 -	case 'z':
   3.154 -	case 'Z':
   3.155 -		zscaling = press;
   3.156 -		break;
   3.157 -
   3.158 -	case '=':
   3.159 -		if(press && (fr = dynamic_cast<RendererFast*>(rend))) {
   3.160 -			int n = fr->get_proxy_count();
   3.161 -			int add = n / 4;
   3.162 -			n += add < 1 ? 1 : add;
   3.163 -			printf("proxy count: %d\n", n);
   3.164 -			fr->set_proxy_count(n);
   3.165 -			redisplay();
   3.166 -		}
   3.167 -		break;
   3.168 -
   3.169 -	case '-':
   3.170 -		if(press && (fr = dynamic_cast<RendererFast*>(rend))) {
   3.171 -			int n = fr->get_proxy_count();
   3.172 -			int sub = n / 4;
   3.173 -			n -= sub < 1 ? 1 : sub;
   3.174 -
   3.175 -			if(n < 1) n = 1;
   3.176 -
   3.177 -			printf("proxy count: %d\n", n);
   3.178 -			fr->set_proxy_count(n);
   3.179 -			redisplay();
   3.180 -		}
   3.181 -		break;
   3.182 -
   3.183 -	default:
   3.184 -		break;
   3.185 -	}
   3.186 -}
   3.187 -
   3.188 -static bool bnstate[8];
   3.189 -static int prev_x, prev_y;
   3.190 -
   3.191 -#define ON_SPLITTER(y)	(abs(y - splitter_y) <= SPLITTER_WIDTH / 2)
   3.192 -static bool splitter_dragging;
   3.193 -
   3.194 -void ev_mouse_button(int bn, int press, int x, int y)
   3.195 -{
   3.196 -	bnstate[bn] = press != 0;
   3.197 -	prev_x = x;
   3.198 -	prev_y = y;
   3.199 -
   3.200 -	splitter_dragging = bn == 0 && press && ON_SPLITTER(y);
   3.201 -
   3.202 -	if(!splitter_dragging && y > splitter_y) {
   3.203 -		xfview_button(bn, press, x, y);
   3.204 -	}
   3.205 -}
   3.206 -
   3.207 -void ev_mouse_motion(int x, int y)
   3.208 -{
   3.209 -	int dx = x - prev_x;
   3.210 -	int dy = y - prev_y;
   3.211 -	prev_x = x;
   3.212 -	prev_y = y;
   3.213 -
   3.214 -	if((dx | dy) == 0) return;
   3.215 -
   3.216 -	if(bnstate[0] && zscaling) {
   3.217 -		float s = rend->get_zscale() + (float)dy / (float)win_height;
   3.218 -		rend->set_zscale(s < 0.0 ? 0.0 : s);
   3.219 -		redisplay();
   3.220 -		return;
   3.221 -	}
   3.222 -
   3.223 -	if(splitter_dragging) {
   3.224 -		splitter_y += dy;
   3.225 -		redisplay();
   3.226 -		return;
   3.227 -	}
   3.228 -
   3.229 -	if(y > splitter_y) {
   3.230 -		xfview_motion(x, y);
   3.231 -		return;
   3.232 -	}
   3.233 -
   3.234 -	// main view motion handling
   3.235 -	if(bnstate[0]) {
   3.236 -		cam_theta += dx * 0.5;
   3.237 -		cam_phi += dy * 0.5;
   3.238 -
   3.239 -		if(cam_phi < -90) cam_phi = -90;
   3.240 -		if(cam_phi > 90) cam_phi = 90;
   3.241 -		redisplay();
   3.242 -	}
   3.243 -	if(bnstate[2]) {
   3.244 -		cam_dist += dy * 0.1;
   3.245 -
   3.246 -		if(cam_dist < 0.0) cam_dist = 0.0;
   3.247 -		redisplay();
   3.248 -	}
   3.249 -}
   3.250 -
   3.251 -}	// extern "C"
     4.1 --- a/src/dicomview.h	Wed Dec 31 05:21:47 2014 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,28 +0,0 @@
     4.4 -#ifndef DICOMVIEW_H_
     4.5 -#define DICOMVIEW_H_
     4.6 -
     4.7 -#ifdef __cplusplus
     4.8 -extern "C" {
     4.9 -#endif
    4.10 -
    4.11 -int init();
    4.12 -void cleanup();
    4.13 -
    4.14 -void ev_display();
    4.15 -void ev_reshape(int x, int y);
    4.16 -void ev_keyboard(int key, int press, int x, int y);
    4.17 -void ev_mouse_button(int bn, int press, int x, int y);
    4.18 -void ev_mouse_motion(int x, int y);
    4.19 -
    4.20 -// functions provided by the frontend
    4.21 -void swap_buffers();
    4.22 -void redisplay();
    4.23 -void quit();
    4.24 -void get_window_size(int *xsz, int *ysz);
    4.25 -unsigned int get_modifiers();
    4.26 -
    4.27 -#ifdef __cplusplus
    4.28 -}
    4.29 -#endif
    4.30 -
    4.31 -#endif	// DICOMVIEW_H_
     5.1 --- a/src/main.cc	Wed Dec 31 05:21:47 2014 +0200
     5.2 +++ b/src/main.cc	Wed Dec 31 07:53:53 2014 +0200
     5.3 @@ -10,7 +10,7 @@
     5.4  #include <GL/glut.h>
     5.5  #endif
     5.6  
     5.7 -#include "dicomview.h"
     5.8 +#include "viewer.h"
     5.9  #include "opt.h"
    5.10  
    5.11  static void display();
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/viewer.cc	Wed Dec 31 07:53:53 2014 +0200
     6.3 @@ -0,0 +1,248 @@
     6.4 +#include <stdio.h>
     6.5 +#include <stdlib.h>
     6.6 +#include "opengl.h"
     6.7 +#include "viewer.h"
     6.8 +#include "rend_fast.h"
     6.9 +#include "opt.h"
    6.10 +#include "volume.h"
    6.11 +#include "xfer_view.h"
    6.12 +
    6.13 +static int win_width, win_height;
    6.14 +static float cam_theta, cam_phi, cam_dist = 4;
    6.15 +static float pre_rot = -90;
    6.16 +static int splitter_y = -1;
    6.17 +
    6.18 +#define SPLITTER_WIDTH			5
    6.19 +
    6.20 +static Renderer *rend;
    6.21 +static Volume *vol;
    6.22 +static TransferFunc *xfer;
    6.23 +
    6.24 +extern "C" {
    6.25 +
    6.26 +int init()
    6.27 +{
    6.28 +	if(!opt.fname) {
    6.29 +		fprintf(stderr, "you must specify the volume data filename\n");
    6.30 +		return -1;
    6.31 +	}
    6.32 +
    6.33 +	switch(opt.rend_type) {
    6.34 +	case REND_FAST:
    6.35 +		rend = new RendererFast;
    6.36 +		break;
    6.37 +	default:
    6.38 +		return -1;
    6.39 +	}
    6.40 +
    6.41 +	if(!rend->init()) {
    6.42 +		fprintf(stderr, "renderer initialization failed\n");
    6.43 +		return -1;
    6.44 +	}
    6.45 +
    6.46 +	VoxelVolume *voxvol = new VoxelVolume;
    6.47 +	if(!voxvol->load(opt.fname)) {
    6.48 +		fprintf(stderr, "failed to load volume data from: %s\n", opt.fname);
    6.49 +		return -1;
    6.50 +	}
    6.51 +	vol = voxvol;
    6.52 +	rend->set_volume(vol);
    6.53 +
    6.54 +	xfer = new TransferWindow;
    6.55 +	rend->set_transfer_function(xfer);
    6.56 +
    6.57 +	if(!xfview_init(xfer)) {
    6.58 +		return -1;
    6.59 +	}
    6.60 +
    6.61 +	return 0;
    6.62 +}
    6.63 +
    6.64 +void cleanup()
    6.65 +{
    6.66 +	xfview_destroy();
    6.67 +
    6.68 +	rend->destroy();
    6.69 +	delete rend;
    6.70 +	delete vol;
    6.71 +	delete xfer;
    6.72 +}
    6.73 +
    6.74 +void ev_display()
    6.75 +{
    6.76 +	glClear(GL_COLOR_BUFFER_BIT);
    6.77 +
    6.78 +	// render the main view
    6.79 +	glViewport(0, win_height - splitter_y, win_width, splitter_y);
    6.80 +
    6.81 +	glMatrixMode(GL_PROJECTION);
    6.82 +	glLoadIdentity();
    6.83 +	gluPerspective(50.0, (float)win_width / (float)splitter_y, 0.1, 100.0);
    6.84 +
    6.85 +	glMatrixMode(GL_MODELVIEW);
    6.86 +	glLoadIdentity();
    6.87 +	glTranslatef(0, 0, -cam_dist);
    6.88 +	glRotatef(cam_phi + pre_rot, 1, 0, 0);
    6.89 +	glRotatef(cam_theta, 0, 1, 0);
    6.90 +
    6.91 +	rend->update(0);
    6.92 +	rend->render();
    6.93 +
    6.94 +	// draw the transfer function view
    6.95 +	glViewport(0, 0, win_width, win_height - splitter_y);
    6.96 +
    6.97 +	xfview_draw();
    6.98 +
    6.99 +	// draw the GUI
   6.100 +	glViewport(0, 0, win_width, win_height);
   6.101 +
   6.102 +	glMatrixMode(GL_PROJECTION);
   6.103 +	glLoadIdentity();
   6.104 +	glOrtho(0, win_width, win_height, 0, -1, 1);
   6.105 +
   6.106 +	glMatrixMode(GL_MODELVIEW);
   6.107 +	glLoadIdentity();
   6.108 +
   6.109 +	glBegin(GL_QUADS);
   6.110 +	glColor3f(1, 1, 1);
   6.111 +	glVertex2f(0, splitter_y + SPLITTER_WIDTH / 2);
   6.112 +	glVertex2f(win_width, splitter_y + SPLITTER_WIDTH / 2);
   6.113 +	glVertex2f(win_width, splitter_y - SPLITTER_WIDTH / 2);
   6.114 +	glVertex2f(0, splitter_y - SPLITTER_WIDTH / 2);
   6.115 +	glEnd();
   6.116 +
   6.117 +	swap_buffers();
   6.118 +}
   6.119 +
   6.120 +void ev_reshape(int x, int y)
   6.121 +{
   6.122 +	if(splitter_y < 0) {	// not initialized yet
   6.123 +		splitter_y = (int)(y * 0.85);
   6.124 +	} else {
   6.125 +		// calculate where the splitter was relative to the window height
   6.126 +		// and based on that, it's new position
   6.127 +		float split = (float)splitter_y / (float)win_height;
   6.128 +		splitter_y = (int)(y * split);
   6.129 +	}
   6.130 +
   6.131 +	win_width = x;
   6.132 +	win_height = y;
   6.133 +
   6.134 +	glViewport(0, 0, x, y);
   6.135 +	if(rend) {
   6.136 +		rend->reshape(x, y);
   6.137 +	}
   6.138 +}
   6.139 +
   6.140 +static bool zscaling;
   6.141 +
   6.142 +void ev_keyboard(int key, int press, int x, int y)
   6.143 +{
   6.144 +	RendererFast *fr;
   6.145 +
   6.146 +	switch(key) {
   6.147 +	case 27:
   6.148 +		if(press) {
   6.149 +			quit();
   6.150 +		}
   6.151 +		break;
   6.152 +
   6.153 +	case 'z':
   6.154 +	case 'Z':
   6.155 +		zscaling = press;
   6.156 +		break;
   6.157 +
   6.158 +	case '=':
   6.159 +		if(press && (fr = dynamic_cast<RendererFast*>(rend))) {
   6.160 +			int n = fr->get_proxy_count();
   6.161 +			int add = n / 4;
   6.162 +			n += add < 1 ? 1 : add;
   6.163 +			printf("proxy count: %d\n", n);
   6.164 +			fr->set_proxy_count(n);
   6.165 +			redisplay();
   6.166 +		}
   6.167 +		break;
   6.168 +
   6.169 +	case '-':
   6.170 +		if(press && (fr = dynamic_cast<RendererFast*>(rend))) {
   6.171 +			int n = fr->get_proxy_count();
   6.172 +			int sub = n / 4;
   6.173 +			n -= sub < 1 ? 1 : sub;
   6.174 +
   6.175 +			if(n < 1) n = 1;
   6.176 +
   6.177 +			printf("proxy count: %d\n", n);
   6.178 +			fr->set_proxy_count(n);
   6.179 +			redisplay();
   6.180 +		}
   6.181 +		break;
   6.182 +
   6.183 +	default:
   6.184 +		break;
   6.185 +	}
   6.186 +}
   6.187 +
   6.188 +static bool bnstate[8];
   6.189 +static int prev_x, prev_y;
   6.190 +
   6.191 +#define ON_SPLITTER(y)	(abs(y - splitter_y) <= SPLITTER_WIDTH / 2)
   6.192 +static bool splitter_dragging;
   6.193 +
   6.194 +void ev_mouse_button(int bn, int press, int x, int y)
   6.195 +{
   6.196 +	bnstate[bn] = press != 0;
   6.197 +	prev_x = x;
   6.198 +	prev_y = y;
   6.199 +
   6.200 +	splitter_dragging = bn == 0 && press && ON_SPLITTER(y);
   6.201 +
   6.202 +	if(!splitter_dragging && y > splitter_y) {
   6.203 +		xfview_button(bn, press, x, y);
   6.204 +	}
   6.205 +}
   6.206 +
   6.207 +void ev_mouse_motion(int x, int y)
   6.208 +{
   6.209 +	int dx = x - prev_x;
   6.210 +	int dy = y - prev_y;
   6.211 +	prev_x = x;
   6.212 +	prev_y = y;
   6.213 +
   6.214 +	if((dx | dy) == 0) return;
   6.215 +
   6.216 +	if(bnstate[0] && zscaling) {
   6.217 +		float s = rend->get_zscale() + (float)dy / (float)win_height;
   6.218 +		rend->set_zscale(s < 0.0 ? 0.0 : s);
   6.219 +		redisplay();
   6.220 +		return;
   6.221 +	}
   6.222 +
   6.223 +	if(splitter_dragging) {
   6.224 +		splitter_y += dy;
   6.225 +		redisplay();
   6.226 +		return;
   6.227 +	}
   6.228 +
   6.229 +	if(y > splitter_y) {
   6.230 +		xfview_motion(x, y);
   6.231 +		return;
   6.232 +	}
   6.233 +
   6.234 +	// main view motion handling
   6.235 +	if(bnstate[0]) {
   6.236 +		cam_theta += dx * 0.5;
   6.237 +		cam_phi += dy * 0.5;
   6.238 +
   6.239 +		if(cam_phi < -90) cam_phi = -90;
   6.240 +		if(cam_phi > 90) cam_phi = 90;
   6.241 +		redisplay();
   6.242 +	}
   6.243 +	if(bnstate[2]) {
   6.244 +		cam_dist += dy * 0.1;
   6.245 +
   6.246 +		if(cam_dist < 0.0) cam_dist = 0.0;
   6.247 +		redisplay();
   6.248 +	}
   6.249 +}
   6.250 +
   6.251 +}	// extern "C"
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/viewer.h	Wed Dec 31 07:53:53 2014 +0200
     7.3 @@ -0,0 +1,28 @@
     7.4 +#ifndef VIEWER_H_
     7.5 +#define VIEWER_H_
     7.6 +
     7.7 +#ifdef __cplusplus
     7.8 +extern "C" {
     7.9 +#endif
    7.10 +
    7.11 +int init();
    7.12 +void cleanup();
    7.13 +
    7.14 +void ev_display();
    7.15 +void ev_reshape(int x, int y);
    7.16 +void ev_keyboard(int key, int press, int x, int y);
    7.17 +void ev_mouse_button(int bn, int press, int x, int y);
    7.18 +void ev_mouse_motion(int x, int y);
    7.19 +
    7.20 +// functions provided by the frontend
    7.21 +void swap_buffers();
    7.22 +void redisplay();
    7.23 +void quit();
    7.24 +void get_window_size(int *xsz, int *ysz);
    7.25 +unsigned int get_modifiers();
    7.26 +
    7.27 +#ifdef __cplusplus
    7.28 +}
    7.29 +#endif
    7.30 +
    7.31 +#endif	// VIEWER_H_
     8.1 --- a/src/xfer_view.cc	Wed Dec 31 05:21:47 2014 +0200
     8.2 +++ b/src/xfer_view.cc	Wed Dec 31 07:53:53 2014 +0200
     8.3 @@ -2,7 +2,7 @@
     8.4  #include <math.h>
     8.5  #include "opengl.h"
     8.6  #include "xfer_view.h"
     8.7 -#include "dicomview.h"
     8.8 +#include "viewer.h"
     8.9  
    8.10  static TransferFunc *xfer;
    8.11