qvolray
diff src/volray.cc @ 13:17d9dc2edc91
first qt version
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 10 Apr 2012 06:11:16 +0300 |
parents | 8990b5d2c7fe |
children | 3d05c261a2f4 |
line diff
1.1 --- a/src/volray.cc Mon Apr 09 23:43:13 2012 +0300 1.2 +++ b/src/volray.cc Tue Apr 10 06:11:16 2012 +0300 1.3 @@ -13,6 +13,7 @@ 1.4 #include <imago2.h> 1.5 #include "sdr.h" 1.6 #include "volume.h" 1.7 +#include "ui.h" 1.8 1.9 #define XFER_MAP_SZ 512 1.10 1.11 @@ -36,7 +37,7 @@ 1.12 static float cam_theta = 0, cam_phi = 0, cam_dist = 4.0; 1.13 static float cam_x, cam_y, cam_z; 1.14 1.15 -static vec2_t tex_scale; 1.16 +static Vector2 tex_scale; 1.17 static unsigned int vol_sdr, slice_sdr, ray_tex; 1.18 static int win_xsz, win_ysz; 1.19 static bool raytex_needs_recalc = true; 1.20 @@ -48,7 +49,7 @@ 1.21 static float cur_z = 0.0; 1.22 static float ray_step = 0.01; 1.23 1.24 -static Volume volume; 1.25 +static const Volume *volume; 1.26 1.27 1.28 bool volray_init() 1.29 @@ -70,12 +71,14 @@ 1.30 set_uniform_int(slice_sdr, "volume", 0); 1.31 set_uniform_int(slice_sdr, "xfer_tex", 1); 1.32 1.33 - if(!volume.load(fname)) { 1.34 - return false; 1.35 - } 1.36 return true; 1.37 } 1.38 1.39 +void volray_setvolume(const Volume *vol) 1.40 +{ 1.41 + volume = vol; 1.42 +} 1.43 + 1.44 void volray_draw(void) 1.45 { 1.46 /* recalculate primary ray texture if needed */ 1.47 @@ -87,9 +90,13 @@ 1.48 create_transfer_map(xfer_mean, xfer_sdev); 1.49 } 1.50 1.51 - render_volume(); 1.52 - draw_slice(); 1.53 - draw_xfer_func(); 1.54 + glClear(GL_COLOR_BUFFER_BIT); 1.55 + 1.56 + if(volume) { 1.57 + render_volume(); 1.58 + draw_slice(); 1.59 + draw_xfer_func(); 1.60 + } 1.61 1.62 assert(glGetError() == GL_NO_ERROR); 1.63 } 1.64 @@ -114,7 +121,7 @@ 1.65 1.66 /* tex unit0: volume data 3D texture */ 1.67 glActiveTexture(GL_TEXTURE0); 1.68 - glBindTexture(GL_TEXTURE_3D, volume.get_texture()); 1.69 + glBindTexture(GL_TEXTURE_3D, volume->get_texture()); 1.70 glEnable(GL_TEXTURE_3D); 1.71 1.72 /* tex unit1: primary rays in view space */ 1.73 @@ -159,7 +166,7 @@ 1.74 glTranslatef(-1, -1, 0); 1.75 1.76 glActiveTexture(GL_TEXTURE0); 1.77 - glBindTexture(GL_TEXTURE_3D, volume.get_texture()); 1.78 + glBindTexture(GL_TEXTURE_3D, volume->get_texture()); 1.79 glEnable(GL_TEXTURE_3D); 1.80 1.81 glActiveTexture(GL_TEXTURE1); 1.82 @@ -209,11 +216,11 @@ 1.83 1.84 glLineWidth(2.0); 1.85 glBegin(GL_LINE_LOOP); 1.86 - if(uimode == UIMODE_XFER) { 1.87 + /*if(uimode == UIMODE_XFER) { 1.88 glColor3f(1, 0, 0); 1.89 - } else { 1.90 + } else {*/ 1.91 glColor3f(0, 0, 1); 1.92 - } 1.93 + //} 1.94 glVertex2f(0, 0); 1.95 glVertex2f(1, 0); 1.96 glVertex2f(1, 1); 1.97 @@ -243,12 +250,12 @@ 1.98 1.99 case 'x': 1.100 uimode = UIMODE_XFER; 1.101 - glutPostRedisplay(); 1.102 + post_redisplay(); 1.103 break; 1.104 1.105 case 'c': 1.106 uimode = UIMODE_CURSOR; 1.107 - glutPostRedisplay(); 1.108 + post_redisplay(); 1.109 break; 1.110 1.111 default: 1.112 @@ -262,14 +269,14 @@ 1.113 case 'x': 1.114 if(uimode == UIMODE_XFER) { 1.115 uimode = UIMODE_DEFAULT; 1.116 - glutPostRedisplay(); 1.117 + post_redisplay(); 1.118 } 1.119 break; 1.120 1.121 case 'c': 1.122 if(uimode == UIMODE_CURSOR) { 1.123 uimode = UIMODE_DEFAULT; 1.124 - glutPostRedisplay(); 1.125 + post_redisplay(); 1.126 } 1.127 break; 1.128 1.129 @@ -277,25 +284,26 @@ 1.130 break; 1.131 } 1.132 } 1.133 +#endif 1.134 1.135 static int bnstate[32]; 1.136 static int prev_x, prev_y; 1.137 1.138 -void mouse(int bn, int state, int x, int y) 1.139 +void volray_mouse(int bn, int state, int x, int y) 1.140 { 1.141 - bnstate[bn - GLUT_LEFT_BUTTON] = state == GLUT_DOWN; 1.142 + bnstate[bn] = state; 1.143 prev_x = x; 1.144 prev_y = y; 1.145 } 1.146 1.147 -void motion(int x, int y) 1.148 +void volray_motion(int x, int y) 1.149 { 1.150 int dx = x - prev_x; 1.151 int dy = y - prev_y; 1.152 prev_x = x; 1.153 prev_y = y; 1.154 1.155 - switch(uimode) { 1.156 + /*switch(uimode) { 1.157 case UIMODE_XFER: 1.158 if(dx || dy) { 1.159 xfer_mean += dx / (float)win_xsz; 1.160 @@ -305,7 +313,7 @@ 1.161 xfer_sdev = xfer_sdev < 0.0 ? 0.0 : (xfer_sdev > 1.0 ? 1.0 : xfer_sdev); 1.162 1.163 xfertex_needs_recalc = true; 1.164 - glutPostRedisplay(); 1.165 + post_redisplay(); 1.166 } 1.167 break; 1.168 1.169 @@ -318,10 +326,10 @@ 1.170 cur_z = 1.0; 1.171 1.172 set_uniform_float(vol_sdr, "zclip", cur_z); 1.173 - glutPostRedisplay(); 1.174 + post_redisplay(); 1.175 break; 1.176 1.177 - default: 1.178 + default:*/ 1.179 /* view control */ 1.180 if(bnstate[0]) { 1.181 cam_theta += dx * 0.5; 1.182 @@ -329,25 +337,24 @@ 1.183 1.184 if(cam_phi <= -90) cam_phi = -89; 1.185 if(cam_phi >= 90) cam_phi = 89; 1.186 - 1.187 - glutPostRedisplay(); 1.188 + post_redisplay(); 1.189 } 1.190 1.191 if(bnstate[1]) { 1.192 cam_x += dx * 0.025; 1.193 cam_y += dy * 0.025; 1.194 - glutPostRedisplay(); 1.195 + post_redisplay(); 1.196 } 1.197 1.198 if(bnstate[2]) { 1.199 cam_dist += dy * 0.025; 1.200 if(cam_dist < 0.0) cam_dist = 0.0; 1.201 - glutPostRedisplay(); 1.202 + post_redisplay(); 1.203 } 1.204 - } 1.205 + //} 1.206 } 1.207 1.208 - 1.209 +#if 0 1.210 int parse_args(int argc, char **argv) 1.211 { 1.212 int i;