volmetrics
diff src/main.cc @ 12:1272e3335608
using 2 thresholds (sigmoid functions)
custom resolution in polygonization
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Sun, 02 Feb 2014 02:18:08 +0200 |
parents | c5af275b6a60 |
children | a93c8aa85e05 |
line diff
1.1 --- a/src/main.cc Mon Jan 27 01:22:02 2014 +0200 1.2 +++ b/src/main.cc Sun Feb 02 02:18:08 2014 +0200 1.3 @@ -27,7 +27,7 @@ 1.4 1.5 static Volume *vol; 1.6 static Mesh *mesh; 1.7 -static float cur_z, thres = 0.5; 1.8 +static float cur_z, thres = 0.5, thres2 = 1.0; 1.9 1.10 static int use_orig_vol_res = 1; 1.11 static int vol_res[3]; // volume sampling resolution x/y/z 1.12 @@ -106,9 +106,24 @@ 1.13 static void thres_change(int id) 1.14 { 1.15 static float prev_thres = thres; 1.16 + static float prev_thres2 = thres2; 1.17 1.18 - if(prev_thres != thres) { 1.19 + if(prev_thres != thres || prev_thres2 != thres2) { 1.20 prev_thres = thres; 1.21 + prev_thres2 = thres2; 1.22 + mesh->clear(); 1.23 + } 1.24 +} 1.25 +static void res_change(int id) 1.26 +{ 1.27 + static float prev_resx = vol_res[0]; 1.28 + static float prev_resy = vol_res[1]; 1.29 + static float prev_resz = vol_res[2]; 1.30 + 1.31 + if(prev_resx != vol_res[0] || prev_resy != vol_res[1] || prev_resz != vol_res[2]) { 1.32 + prev_resx = vol_res[0]; 1.33 + prev_resy = vol_res[1]; 1.34 + prev_resz = vol_res[2]; 1.35 mesh->clear(); 1.36 } 1.37 } 1.38 @@ -119,16 +134,21 @@ 1.39 1.40 ui->set_main_gfx_window(glutGetWindow()); 1.41 1.42 - GLUI_Spinner *thres_spin = ui->add_spinner("iso threshold", GLUI_SPINNER_FLOAT, &thres, 0, thres_change); 1.43 + GLUI_Panel *thres_panel = ui->add_panel("iso thresholds"); 1.44 + 1.45 + GLUI_Spinner *thres_spin = ui->add_spinner_to_panel(thres_panel, "T1", GLUI_SPINNER_FLOAT, &thres, 0, thres_change); 1.46 thres_spin->set_float_limits(0, 1); 1.47 1.48 + GLUI_Spinner *thres2_spin = ui->add_spinner_to_panel(thres_panel, "T2", GLUI_SPINNER_FLOAT, &thres2, 0, thres_change); 1.49 + thres2_spin->set_float_limits(0, 1); 1.50 + 1.51 GLUI_Panel *res_panel = ui->add_panel("volume resolution"); 1.52 1.53 ui->add_checkbox_to_panel(res_panel, "original resolution", &use_orig_vol_res, 0, toggle_use_orig); 1.54 1.55 static const char *res_spin_name[] = {"x", "y", "z"}; 1.56 for(int i=0; i<3; i++) { 1.57 - res_spin[i] = ui->add_spinner_to_panel(res_panel, res_spin_name[i], GLUI_SPINNER_INT, vol_res + i); 1.58 + res_spin[i] = ui->add_spinner_to_panel(res_panel, res_spin_name[i], GLUI_SPINNER_INT, vol_res + i, 0, res_change); 1.59 res_spin[i]->set_int_limits(8, 256); // TODO limits as arguments or config 1.60 res_spin[i]->disable(); 1.61 } 1.62 @@ -161,7 +181,7 @@ 1.63 if(mesh->is_empty()) { 1.64 printf("recalculating isosurface ... "); 1.65 fflush(stdout); 1.66 - vol->create_mesh(mesh, thres); 1.67 + vol->create_mesh(mesh, thres, thres2, vol_res[0], vol_res[1], vol_res[2]); 1.68 printf("done.\n"); 1.69 } 1.70 mesh->draw(); 1.71 @@ -210,7 +230,7 @@ 1.72 1.73 static int prev_x, prev_y; 1.74 static bool bn_state[32]; 1.75 -static float prev_thres; 1.76 +static float prev_thres, prev_thres2; 1.77 1.78 static void mouse(int bn, int state, int x, int y) 1.79 { 1.80 @@ -221,9 +241,10 @@ 1.81 1.82 if(state == GLUT_DOWN) { 1.83 prev_thres = thres; 1.84 + prev_thres2 = thres2; 1.85 } 1.86 else { 1.87 - if(thres != prev_thres) { 1.88 + if(thres != prev_thres || thres2 != prev_thres2) { 1.89 mesh->clear(); 1.90 } 1.91 }