glviewvol
diff src/dicomview.cc @ 4:04330eb80b36
lots of stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 29 Dec 2014 05:41:36 +0200 |
parents | 32c4a7160350 |
children | f22be47a3572 |
line diff
1.1 --- a/src/dicomview.cc Sun Dec 28 21:48:15 2014 +0200 1.2 +++ b/src/dicomview.cc Mon Dec 29 05:41:36 2014 +0200 1.3 @@ -1,12 +1,17 @@ 1.4 #include <stdio.h> 1.5 +#include <stdlib.h> 1.6 #include "opengl.h" 1.7 #include "dicomview.h" 1.8 #include "rend_fast.h" 1.9 #include "opt.h" 1.10 #include "volume.h" 1.11 +#include "xfer_view.h" 1.12 1.13 static int win_width, win_height; 1.14 static float cam_theta, cam_phi, cam_dist = 6; 1.15 +static int splitter_y = -1; 1.16 + 1.17 +#define SPLITTER_WIDTH 5 1.18 1.19 static Renderer *rend; 1.20 static Volume *vol; 1.21 @@ -41,11 +46,17 @@ 1.22 vol = voxvol; 1.23 rend->set_volume(vol); 1.24 1.25 + if(!xfview_init(rend)) { 1.26 + return -1; 1.27 + } 1.28 + 1.29 return 0; 1.30 } 1.31 1.32 void cleanup() 1.33 { 1.34 + xfview_destroy(); 1.35 + 1.36 rend->destroy(); 1.37 delete rend; 1.38 delete vol; 1.39 @@ -55,16 +66,66 @@ 1.40 { 1.41 glClear(GL_COLOR_BUFFER_BIT); 1.42 1.43 + // render the main view 1.44 + glViewport(0, win_height - splitter_y, win_width, splitter_y); 1.45 + 1.46 + glMatrixMode(GL_PROJECTION); 1.47 + glLoadIdentity(); 1.48 + gluPerspective(50.0, (float)win_width / (float)splitter_y, 0.1, 100.0); 1.49 + 1.50 + glMatrixMode(GL_MODELVIEW); 1.51 + glLoadIdentity(); 1.52 + glTranslatef(0, 0, -cam_dist); 1.53 + glRotatef(cam_phi, 1, 0, 0); 1.54 + glRotatef(cam_theta, 0, 1, 0); 1.55 + 1.56 rend->update(0); 1.57 rend->render(); 1.58 + 1.59 + // draw the transfer function view 1.60 + glViewport(0, 0, win_width, win_height - splitter_y); 1.61 + 1.62 + xfview_draw(); 1.63 + 1.64 + // draw the GUI 1.65 + glViewport(0, 0, win_width, win_height); 1.66 + 1.67 + glMatrixMode(GL_PROJECTION); 1.68 + glLoadIdentity(); 1.69 + glOrtho(0, win_width, win_height, 0, -1, 1); 1.70 + 1.71 + glMatrixMode(GL_MODELVIEW); 1.72 + glLoadIdentity(); 1.73 + 1.74 + glBegin(GL_QUADS); 1.75 + glColor3f(1, 1, 1); 1.76 + glVertex2f(0, splitter_y + SPLITTER_WIDTH / 2); 1.77 + glVertex2f(win_width, splitter_y + SPLITTER_WIDTH / 2); 1.78 + glVertex2f(win_width, splitter_y - SPLITTER_WIDTH / 2); 1.79 + glVertex2f(0, splitter_y - SPLITTER_WIDTH / 2); 1.80 + glEnd(); 1.81 + 1.82 + swap_buffers(); 1.83 } 1.84 1.85 void ev_reshape(int x, int y) 1.86 { 1.87 + if(splitter_y < 0) { // not initialized yet 1.88 + splitter_y = (int)(y * 0.85); 1.89 + } else { 1.90 + // calculate where the splitter was relative to the window height 1.91 + // and based on that, it's new position 1.92 + float split = (float)splitter_y / (float)win_height; 1.93 + splitter_y = (int)(y * split); 1.94 + } 1.95 + 1.96 win_width = x; 1.97 win_height = y; 1.98 1.99 glViewport(0, 0, x, y); 1.100 + if(rend) { 1.101 + rend->reshape(x, y); 1.102 + } 1.103 } 1.104 1.105 void ev_keyboard(int key, int press, int x, int y) 1.106 @@ -77,12 +138,60 @@ 1.107 } 1.108 } 1.109 1.110 +static bool bnstate[8]; 1.111 +static int prev_x, prev_y; 1.112 + 1.113 +#define ON_SPLITTER(y) (abs(y - splitter_y) <= SPLITTER_WIDTH / 2) 1.114 +static bool splitter_dragging; 1.115 + 1.116 void ev_mouse_button(int bn, int press, int x, int y) 1.117 { 1.118 + bnstate[bn] = press != 0; 1.119 + prev_x = x; 1.120 + prev_y = y; 1.121 + 1.122 + splitter_dragging = bn == 0 && press && ON_SPLITTER(y); 1.123 + 1.124 + if(!splitter_dragging && y > splitter_y) { 1.125 + xfview_button(bn, press, x, y); 1.126 + } 1.127 } 1.128 1.129 void ev_mouse_motion(int x, int y) 1.130 { 1.131 + int dx = x - prev_x; 1.132 + int dy = y - prev_y; 1.133 + prev_x = x; 1.134 + prev_y = y; 1.135 + 1.136 + if((dx | dy) == 0) return; 1.137 + 1.138 + if(splitter_dragging) { 1.139 + splitter_y += dy; 1.140 + redisplay(); 1.141 + return; 1.142 + } 1.143 + 1.144 + if(y > splitter_y) { 1.145 + xfview_motion(x, y); 1.146 + return; 1.147 + } 1.148 + 1.149 + // main view motion handling 1.150 + if(bnstate[0]) { 1.151 + cam_theta += dx * 0.5; 1.152 + cam_phi += dy * 0.5; 1.153 + 1.154 + if(cam_phi < -90) cam_phi = -90; 1.155 + if(cam_phi > 90) cam_phi = 90; 1.156 + redisplay(); 1.157 + } 1.158 + if(bnstate[2]) { 1.159 + cam_dist += dy * 0.1; 1.160 + 1.161 + if(cam_dist < 0.0) cam_dist = 0.0; 1.162 + redisplay(); 1.163 + } 1.164 } 1.165 1.166 } // extern "C"