volmetrics

annotate src/main.cc @ 33:3e4eb9a0d999

fixed t1, t2 selection with the mouse
author Eleni Maria Stea <elene.mst@gmail.com>
date Sun, 17 Aug 2014 02:25:01 +0300
parents 6d637706cfaf
children eb87d4a12bd3
rev   line source
eleni@0 1 #include <GL/glew.h>
eleni@0 2 #include <GL/glut.h>
elene@9 3 #include <GL/glui.h>
eleni@0 4
elene@17 5 #include <math.h>
eleni@0 6 #include <stdio.h>
eleni@0 7 #include <assert.h>
eleni@0 8
elene@9 9 #include <vector>
elene@9 10
elene@9 11 #include "mesh.h"
elene@22 12 #include "sdr.h"
elene@6 13 #include "volume.h"
eleni@1 14
elene@10 15 static bool init(void);
elene@10 16 static GLUI *create_ui(void);
elene@10 17 static void display(void);
elene@10 18 static void reshape(int x, int y);
elene@10 19 static void keyboard(unsigned char key, int x, int y);
elene@10 20 static void keyboard_up(unsigned char key, int x, int y);
elene@10 21 static void mouse(int button, int state, int x, int y);
elene@10 22 static void motion(int x, int y);
elene@16 23 static bool init_xfer(void);
elene@16 24 static void display_xfer(void);
elene@16 25 static void reshape_xfer(int x, int y);
elene@17 26 static void mouse_xfer(int button, int state, int x, int y);
elene@16 27 static void motion_xfer(int x, int y);
elene@25 28 static void volume_preview();
elene@25 29 static void draw_iso();
elene@25 30 static void draw_volume();
elene@16 31
elene@16 32 static int mainwin_id, xferwin_id;
elene@18 33 //todo keyb esc
elene@16 34
eleni@0 35 static int win_xsz, win_ysz;
elene@9 36 static float cam_phi, cam_theta, cam_dist = 6;
elene@9 37 static std::vector<bool> key_state(256);
eleni@0 38
elene@11 39 static const char *vol_fname = "data/test1.vol";
elene@22 40 static const char *vsdr_path = "data/shaders/transfer.v.glsl";
elene@22 41 static const char *fsdr_path = "data/shaders/transfer.f.glsl";
elene@25 42 static const char *vsdr_vol_path = "data/shaders/vol.v.glsl";
elene@25 43 static const char *fsdr_vol_path = "data/shaders/vol.f.glsl";
elene@25 44
elene@25 45 static unsigned int sprog;
elene@25 46 static unsigned int sprog_vol;
elene@6 47
elene@6 48 static Volume *vol;
elene@9 49 static Mesh *mesh;
elene@12 50 static float cur_z, thres = 0.5, thres2 = 1.0;
elene@25 51 static float slice_z = 0.5;
elene@9 52
elene@9 53 static int use_orig_vol_res = 1;
elene@9 54 static int vol_res[3]; // volume sampling resolution x/y/z
elene@26 55 static float bound_scale = 1.42;
elene@9 56
elene@9 57 static GLUI *ui;
eleni@1 58
elene@25 59 static int num_poly = 128;
elene@22 60
eleni@0 61 int main(int argc, char **argv)
eleni@0 62 {
elene@31 63 glutInitWindowSize(512, 512);
eleni@0 64 glutInit(&argc, argv);
elene@16 65 if(argv[1])
elene@16 66 vol_fname = argv[1];
elene@16 67
elene@16 68 if(!init()) {
elene@16 69 fprintf(stderr, "Failed to initialize program.\n");
elene@16 70 return 1;
elene@16 71 }
elene@16 72
elene@16 73 init_xfer();
elene@16 74
elene@16 75 glutMainLoop();
elene@16 76 return 0;
elene@16 77 }
elene@16 78
elene@16 79 static bool init()
elene@16 80 {
elene@11 81 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
eleni@0 82
elene@16 83 mainwin_id = glutCreateWindow("CT scan");
eleni@0 84 glutDisplayFunc(display);
eleni@0 85 glutReshapeFunc(reshape);
eleni@0 86 glutKeyboardFunc(keyboard);
elene@9 87 glutKeyboardUpFunc(keyboard_up);
eleni@0 88 glutMouseFunc(mouse);
eleni@0 89 glutMotionFunc(motion);
eleni@0 90
eleni@0 91 glewInit();
eleni@0 92
elene@11 93 glEnable(GL_DEPTH_TEST);
elene@11 94 glEnable(GL_NORMALIZE);
elene@11 95
elene@25 96 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
elene@25 97
elene@22 98 //FIXME shaders setup
elene@22 99 if(!(sprog = sdr_getprog(vsdr_path, fsdr_path)))
elene@22 100 {
elene@22 101 fprintf(stderr, "Failed to create shader program!\n");
elene@22 102 return false;
elene@22 103 }
elene@22 104
elene@25 105 if(!(sprog_vol = sdr_getprog(vsdr_vol_path, fsdr_vol_path)))
elene@25 106 {
elene@25 107 fprintf(stderr, "Failed to create shader program!\n");
elene@25 108 return false;
elene@25 109 }
elene@25 110
elene@9 111 vol = new Volume;
elene@11 112 if(!vol->load(vol_fname)) {
elene@11 113 fprintf(stderr, "Failed to load %s", vol_fname);
elene@9 114 return false;
elene@9 115 }
elene@9 116 mesh = new Mesh;
elene@9 117 cur_z = 0.5;
elene@9 118
elene@9 119 vol_res[0] = vol->get_slice(0)->get_width();
elene@9 120 vol_res[1] = vol->get_slice(0)->get_height();
elene@9 121 vol_res[2] = vol->get_slice_count();
elene@9 122
elene@26 123 num_poly = std::max(vol_res[0], std::max(vol_res[1], vol_res[2])) * bound_scale;
elene@26 124
elene@9 125 if(!(ui = create_ui())) {
elene@9 126 return false;
elene@9 127 }
elene@9 128
elene@9 129 return true;
elene@9 130 }
elene@9 131
elene@9 132 static GLUI_Spinner *res_spin[3];
elene@9 133 static void toggle_use_orig(int id)
elene@9 134 {
elene@9 135 for(int i=0; i<3; i++) {
elene@9 136 if(use_orig_vol_res) {
elene@9 137 res_spin[i]->disable();
elene@9 138 } else {
elene@9 139 res_spin[i]->enable();
elene@9 140 }
elene@9 141 }
elene@9 142 }
elene@9 143 static void thres_change(int id)
elene@9 144 {
elene@9 145 static float prev_thres = thres;
elene@12 146 static float prev_thres2 = thres2;
elene@9 147
elene@12 148 if(prev_thres != thres || prev_thres2 != thres2) {
elene@9 149 prev_thres = thres;
elene@12 150 prev_thres2 = thres2;
elene@23 151
elene@12 152 mesh->clear();
elene@23 153
elene@23 154 glutSetWindow(xferwin_id);
elene@23 155 glutPostRedisplay();
elene@23 156 glutSetWindow(mainwin_id);
elene@23 157 glutPostRedisplay();
elene@12 158 }
elene@23 159 }
elene@16 160
elene@12 161 static void res_change(int id)
elene@12 162 {
elene@12 163 static float prev_resx = vol_res[0];
elene@12 164 static float prev_resy = vol_res[1];
elene@12 165 static float prev_resz = vol_res[2];
elene@12 166
elene@12 167 if(prev_resx != vol_res[0] || prev_resy != vol_res[1] || prev_resz != vol_res[2]) {
elene@12 168 prev_resx = vol_res[0];
elene@12 169 prev_resy = vol_res[1];
elene@12 170 prev_resz = vol_res[2];
elene@9 171 mesh->clear();
elene@9 172 }
elene@9 173 }
elene@10 174 static GLUI *create_ui()
elene@9 175 {
elene@9 176 GLUI *ui = GLUI_Master.create_glui("ui");
elene@9 177 assert(ui);
elene@9 178
elene@9 179 ui->set_main_gfx_window(glutGetWindow());
elene@9 180
elene@12 181 GLUI_Panel *thres_panel = ui->add_panel("iso thresholds");
elene@12 182
elene@12 183 GLUI_Spinner *thres_spin = ui->add_spinner_to_panel(thres_panel, "T1", GLUI_SPINNER_FLOAT, &thres, 0, thres_change);
elene@9 184 thres_spin->set_float_limits(0, 1);
elene@9 185
elene@12 186 GLUI_Spinner *thres2_spin = ui->add_spinner_to_panel(thres_panel, "T2", GLUI_SPINNER_FLOAT, &thres2, 0, thres_change);
elene@12 187 thres2_spin->set_float_limits(0, 1);
elene@12 188
elene@29 189 #ifdef ISO
elene@9 190 GLUI_Panel *res_panel = ui->add_panel("volume resolution");
elene@9 191
elene@9 192 ui->add_checkbox_to_panel(res_panel, "original resolution", &use_orig_vol_res, 0, toggle_use_orig);
elene@9 193
elene@9 194 static const char *res_spin_name[] = {"x", "y", "z"};
elene@9 195 for(int i=0; i<3; i++) {
elene@12 196 res_spin[i] = ui->add_spinner_to_panel(res_panel, res_spin_name[i], GLUI_SPINNER_INT, vol_res + i, 0, res_change);
elene@9 197 res_spin[i]->set_int_limits(8, 256); // TODO limits as arguments or config
elene@9 198 res_spin[i]->disable();
elene@9 199 }
elene@29 200 #endif
elene@20 201 GLUI_Panel *preview_panel = ui->add_panel("volume preview");
elene@20 202
elene@22 203 GLUI_Spinner *preview_spin = ui->add_spinner_to_panel(preview_panel, "slice z", GLUI_SPINNER_FLOAT, &slice_z, 0);
elene@20 204 preview_spin->set_float_limits(0, 1);
elene@20 205
elene@9 206 return ui;
elene@9 207 }
elene@9 208
elene@18 209 static void volume_preview ()
elene@18 210 {
elene@18 211 float aspect = win_xsz / win_ysz;
elene@18 212
elene@21 213 glDisable(GL_DEPTH_TEST);
elene@18 214
elene@22 215 glUseProgram(sprog);
elene@23 216 int tmin_loc = glGetUniformLocation(sprog, "tmin");
elene@23 217 if(tmin_loc != -1)
elene@23 218 glUniform1f(tmin_loc, std::min(thres, thres2));
elene@23 219 int tmax_loc = glGetUniformLocation(sprog, "tmax");
elene@23 220 if(tmax_loc != -1)
elene@23 221 glUniform1f(tmax_loc, std::max(thres, thres2));
elene@22 222
elene@18 223 glMatrixMode(GL_MODELVIEW);
elene@18 224 glPushMatrix();
elene@18 225 glLoadIdentity();
elene@18 226
elene@18 227 glMatrixMode(GL_PROJECTION);
elene@18 228 glPushMatrix();
elene@18 229 glLoadIdentity();
elene@25 230 glOrtho(0, aspect, 0, 1, -1, 1);
elene@18 231
elene@18 232 glBindTexture(GL_TEXTURE_3D, vol->get_texture());
elene@18 233 glEnable(GL_TEXTURE_3D);
elene@18 234 glBegin(GL_QUADS);
elene@21 235 glColor3f(1.0, 1.0, 1.0);
elene@25 236 glTexCoord3f(0, 0, slice_z); glVertex3f(0, 1, 0);
elene@25 237 glTexCoord3f(0, 1, slice_z); glVertex3f(0, 0.75, 0);
elene@25 238 glTexCoord3f(1, 1, slice_z); glVertex3f(0.25, 0.75, 0);
elene@25 239 glTexCoord3f(1, 0, slice_z); glVertex3f(0.25, 1, 0);
elene@18 240 glEnd();
elene@18 241 glDisable(GL_TEXTURE_3D);
elene@18 242
elene@30 243 glUseProgram(0);
elene@30 244
elene@32 245 glLineWidth(2);
elene@21 246 glBegin(GL_LINE_LOOP);
elene@32 247 glColor3f(0.8, 0.3, 0.8);
elene@30 248 glVertex3f(0, 1, 0);
elene@30 249 glVertex3f(0, 0.75, 0);
elene@30 250 glVertex3f(0.25, 0.75, 0);
elene@30 251 glVertex3f(0.25, 1, 0);
elene@21 252 glEnd();
elene@21 253
elene@18 254 glMatrixMode(GL_PROJECTION);
elene@18 255 glPopMatrix();
elene@18 256
elene@18 257 glMatrixMode(GL_MODELVIEW);
elene@18 258 glPopMatrix();
elene@18 259
elene@21 260 glEnable(GL_DEPTH_TEST);
elene@25 261 }
elene@25 262
elene@25 263 static void draw_iso()
elene@25 264 {
elene@25 265 if(mesh->is_empty()) {
elene@25 266 printf("recalculating isosurface ... ");
elene@25 267 fflush(stdout);
elene@25 268 vol->create_mesh(mesh, thres, thres2, vol_res[0], vol_res[1], vol_res[2]);
elene@25 269 printf("done.\n");
elene@25 270 }
elene@25 271 mesh->draw();
elene@25 272 }
elene@25 273
elene@25 274 static void draw_volume()
elene@25 275 {
elene@25 276 glUseProgram(sprog_vol);
elene@25 277
elene@25 278 int tmin_loc = glGetUniformLocation(sprog_vol, "tmin");
elene@25 279 if(tmin_loc != -1)
elene@25 280 glUniform1f(tmin_loc, std::min(thres, thres2));
elene@25 281 int tmax_loc = glGetUniformLocation(sprog_vol, "tmax");
elene@25 282 if(tmax_loc != -1)
elene@25 283 glUniform1f(tmax_loc, std::max(thres, thres2));
elene@25 284
elene@25 285 int res_loc = glGetUniformLocation(sprog_vol, "res");
elene@25 286 if(res_loc != -1)
elene@26 287 glUniform3f(res_loc, (float)vol_res[0], (float)vol_res[1], (float)vol_res[2]);
elene@25 288
elene@30 289 glRotatef(-vol->get_volume_rotation(), 1, 0, 0);
elene@30 290
elene@25 291 glDisable(GL_DEPTH_TEST);
elene@25 292 glBindTexture(GL_TEXTURE_3D, vol->get_texture());
elene@25 293 glEnable(GL_TEXTURE_3D);
elene@25 294 glEnable(GL_BLEND);
elene@25 295 glBegin(GL_QUADS);
elene@25 296 for(int i=0; i<num_poly; i++)
elene@25 297 {
elene@25 298 float tex_z = (float)i / (float)num_poly;
elene@25 299 float z = 2 * tex_z - 1;
elene@25 300
elene@26 301 glTexCoord3f(0, 0, tex_z); glVertex3f(-bound_scale, -bound_scale, z * bound_scale);
elene@26 302 glTexCoord3f(0, 1, tex_z); glVertex3f(-bound_scale, bound_scale, z * bound_scale);
elene@26 303 glTexCoord3f(1, 1, tex_z); glVertex3f(bound_scale, bound_scale, z * bound_scale);
elene@26 304 glTexCoord3f(1, 0, tex_z); glVertex3f(bound_scale, -bound_scale, z * bound_scale);
elene@25 305 }
elene@25 306 glEnd();
elene@25 307 glDisable(GL_BLEND);
elene@25 308 glDisable(GL_TEXTURE_3D);
elene@25 309 glEnable(GL_DEPTH_TEST);
elene@25 310
elene@25 311 glUseProgram(0);
elene@18 312 }
elene@18 313
elene@10 314 static void display(void)
eleni@0 315 {
elene@9 316 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
elene@9 317
elene@9 318 glMatrixMode(GL_MODELVIEW);
elene@9 319 glLoadIdentity();
elene@9 320 glTranslatef(0, 0, -cam_dist);
elene@9 321 glRotatef(cam_phi, 1, 0, 0);
elene@9 322 glRotatef(cam_theta, 0, 1, 0);
elene@9 323
elene@25 324 //draw_slices();
elene@25 325 //draw_iso();
elene@25 326 draw_volume();
elene@9 327
elene@18 328 volume_preview();
eleni@0 329 glutSwapBuffers();
eleni@0 330 assert(glGetError() == GL_NO_ERROR);
eleni@0 331 }
eleni@0 332
elene@10 333 static void reshape(int x, int y)
eleni@0 334 {
eleni@0 335 glViewport(0, 0, x, y);
elene@9 336 glMatrixMode(GL_PROJECTION);
elene@9 337 glLoadIdentity();
elene@9 338 gluPerspective(45, (float)x / (float)y, 0.5, 500);
elene@9 339
elene@25 340 win_xsz = x;
elene@25 341 win_ysz = y;
eleni@0 342 }
eleni@0 343
elene@10 344 static void keyboard(unsigned char key, int x, int y)
eleni@0 345 {
elene@9 346 key_state[(int)key] = true;
elene@9 347
eleni@0 348 switch(key) {
eleni@0 349 case 27:
eleni@0 350 exit(0);
elene@9 351 case 'w':
elene@9 352 {
elene@9 353 static bool wire;
elene@9 354 wire = !wire;
elene@9 355 glPolygonMode(GL_FRONT_AND_BACK, wire ? GL_LINE : GL_FILL);
elene@9 356 }
elene@9 357 break;
eleni@0 358 default:
eleni@0 359 break;
eleni@0 360 }
eleni@0 361 }
eleni@0 362
elene@10 363 static void keyboard_up(unsigned char key, int x, int y)
elene@9 364 {
elene@9 365 key_state[(int) key] = false;
elene@9 366 }
elene@9 367
eleni@0 368 static int prev_x, prev_y;
elene@9 369 static bool bn_state[32];
elene@12 370 static float prev_thres, prev_thres2;
elene@9 371
elene@10 372 static void mouse(int bn, int state, int x, int y)
eleni@0 373 {
eleni@0 374 prev_x = x;
eleni@0 375 prev_y = y;
elene@9 376
elene@9 377 bn_state[bn - GLUT_LEFT_BUTTON] = (state == GLUT_DOWN);
elene@9 378
elene@9 379 if(state == GLUT_DOWN) {
elene@9 380 prev_thres = thres;
elene@12 381 prev_thres2 = thres2;
elene@9 382 }
elene@9 383 else {
elene@12 384 if(thres != prev_thres || thres2 != prev_thres2) {
elene@9 385 mesh->clear();
elene@9 386 }
elene@9 387 }
eleni@0 388 }
eleni@0 389
elene@10 390 static void motion(int x, int y)
eleni@0 391 {
eleni@0 392 int dx = x - prev_x;
eleni@0 393 int dy = y - prev_y;
elene@9 394
elene@9 395 if(!dx && !dy)
elene@9 396 return;
elene@9 397
eleni@0 398 prev_x = x;
eleni@0 399 prev_y = y;
elene@6 400
elene@9 401 if(key_state[(int)'t']) {
elene@9 402 thres = (float)x / (float)win_xsz;
elene@9 403 printf("threshold: %f\n", thres);
elene@9 404
elene@9 405 glutPostRedisplay();
elene@9 406 return;
elene@9 407 }
elene@9 408
elene@9 409 // camera
elene@9 410 if(bn_state[0]) {
elene@9 411 if(key_state[(int)'z']) {
elene@9 412 //zoom the camera
elene@9 413
elene@9 414 cam_dist += dy * 0.1;
elene@9 415
elene@9 416 if(cam_dist < 0)
elene@9 417 cam_dist = 0;
elene@9 418 }
elene@9 419 else {
elene@9 420 //rotate the camera
elene@9 421
elene@9 422 cam_phi += dy * 0.5;
elene@9 423 cam_theta += dx * 0.5;
elene@9 424
elene@9 425 if(cam_phi > 90)
elene@9 426 cam_phi = 90;
elene@9 427 if(cam_phi < -90)
elene@9 428 cam_phi = -90;
elene@9 429 }
elene@9 430
elene@6 431 glutPostRedisplay();
elene@6 432 }
eleni@0 433 }
elene@16 434
elene@16 435 static bool init_xfer(void)
elene@16 436 {
elene@16 437 glutSetWindow(mainwin_id);
elene@16 438 int x = glutGet(GLUT_WINDOW_X);
elene@16 439 int y = glutGet(GLUT_WINDOW_Y) + glutGet(GLUT_WINDOW_HEIGHT);
elene@16 440
elene@16 441 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
elene@16 442 glutInitWindowSize(512, 100);
elene@16 443 glutInitWindowPosition(x, y);
elene@16 444
elene@16 445 xferwin_id = glutCreateWindow("Transfer Function");
elene@16 446 glutDisplayFunc(display_xfer);
elene@16 447 glutReshapeFunc(reshape_xfer);
elene@17 448 glutMouseFunc(mouse_xfer);
elene@16 449 glutMotionFunc(motion_xfer);
elene@16 450
elene@16 451 return true;
elene@16 452 }
elene@16 453
elene@16 454 static void display_xfer(void)
elene@16 455 {
elene@16 456 glClear(GL_COLOR_BUFFER_BIT);
elene@16 457
elene@16 458 int num_val = glutGet(GLUT_WINDOW_WIDTH) / 4.0;
elene@16 459 float x = 0;
elene@16 460 float dx = 1.0 / num_val;
elene@16 461 float low, high;
elene@16 462 if(thres < thres2) {
elene@16 463 low = thres;
elene@16 464 high = thres2;
elene@16 465 }
elene@16 466 else {
elene@16 467 low = thres2;
elene@16 468 high = thres;
elene@16 469 }
elene@16 470
elene@17 471 //drawing the transfer function curve
elene@17 472
elene@17 473 glLineWidth(3);
elene@17 474 glBegin(GL_LINE_STRIP);
elene@17 475 glColor3f(0.8, 0.3, 0.8);
elene@17 476 for(int i=0; i<num_val; i++) {
elene@17 477 float val = transfer_function(x, low, high);
elene@17 478 glVertex2f(x, val);
elene@17 479 x += dx;
elene@17 480 }
elene@17 481 glEnd();
elene@17 482
elene@17 483 //threshold bars
elene@17 484
elene@17 485 glLineWidth(2);
elene@17 486 glBegin(GL_LINES);
elene@17 487 glColor3f(0.4, 0.4, 0.8);
elene@17 488 glVertex2f(low, 0);
elene@17 489 glVertex2f(low, 1);
elene@17 490 glColor3f(0.4, 0.8, 0.4);
elene@17 491 glVertex2f(high, 0);
elene@17 492 glVertex2f(high, 1);
elene@17 493 glEnd();
elene@17 494
elene@17 495 /*
elene@17 496 * gradient
elene@17 497 */
elene@17 498 /* glBegin(GL_QUADS);
elene@16 499 for(int i=0; i<num_val; i++) {
elene@16 500 float val = transfer_function(x, low, high);
elene@16 501 glColor3f(val, val, val);
elene@16 502 glVertex3f(x, 1.0, 0.0);
elene@16 503 glVertex3f(x, 0.0, 0.0);
elene@16 504
elene@16 505 val = transfer_function(x + dx, low, high);
elene@16 506 glColor3f(val, val, val);
elene@16 507 glVertex3f(x + dx, 0.0, 0.0);
elene@16 508 glVertex3f(x + dx, 1.0, 0.0);
elene@16 509 x += dx;
elene@16 510 }
elene@17 511 glEnd(); */
elene@16 512
elene@16 513 glutSwapBuffers();
elene@16 514 assert(glGetError() == GL_NO_ERROR);
elene@16 515 }
elene@16 516
elene@16 517 static void reshape_xfer(int x, int y)
elene@16 518 {
elene@16 519 glViewport(0.0, 0.0, x, y);
elene@16 520 glMatrixMode(GL_PROJECTION);
elene@16 521 glLoadIdentity();
elene@16 522 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
elene@16 523 }
elene@16 524
elene@17 525 static float *select_thres;
elene@17 526 static float prev_select_thres;
elene@17 527 static void mouse_xfer(int button, int state, int x, int y)
elene@17 528 {
elene@17 529 if(button == GLUT_LEFT_BUTTON) {
elene@17 530 if(state == GLUT_DOWN) {
elene@17 531 int width = glutGet(GLUT_WINDOW_WIDTH);
elene@17 532 float xpos = (float)x / (float)width;
elene@33 533 if(fabs(xpos - thres) <= fabs(xpos - thres2) && fabs(xpos - thres) < 0.1) {
elene@17 534 select_thres = &thres;
elene@17 535 }
elene@33 536 else if (fabs(xpos - thres2) < 0.1) {
elene@17 537 select_thres = &thres2;
elene@17 538 }
elene@33 539 else
elene@33 540 select_thres = 0;
elene@33 541
elene@33 542 if (select_thres)
elene@33 543 prev_select_thres = *select_thres;
elene@17 544 }
elene@17 545 else {
elene@33 546 if(!prev_select_thres || !select_thres) {
elene@33 547 select_thres = 0;
elene@33 548 return;
elene@33 549 }
elene@17 550 if(fabs(*select_thres - prev_select_thres) > 0.001) {
elene@17 551 mesh->clear();
elene@17 552 ui->sync_live();
elene@17 553 }
elene@17 554 select_thres = 0;
elene@17 555 }
elene@17 556 }
elene@17 557 }
elene@17 558
elene@16 559 static void motion_xfer(int x, int y)
elene@16 560 {
elene@17 561 if(!select_thres)
elene@17 562 return;
elene@17 563
elene@17 564 int width = glutGet(GLUT_WINDOW_WIDTH);
elene@17 565 float xpos = (float)x / (float)width;
elene@17 566
elene@17 567 *select_thres = xpos;
elene@23 568 thres_change(0);
elene@17 569
elene@17 570 glutPostRedisplay();
elene@17 571 glutSetWindow(mainwin_id);
elene@17 572 glutPostRedisplay();
elene@16 573 }