# HG changeset patch # User Eleni Maria Stea # Date 1391300288 -7200 # Node ID 1272e33356082a99c11e039f733c62f4a4b12bbd # Parent c5af275b6a600a6771796b47071ae2c5acd03123 using 2 thresholds (sigmoid functions) custom resolution in polygonization diff -r c5af275b6a60 -r 1272e3335608 notes --- a/notes Mon Jan 27 01:22:02 2014 +0200 +++ b/notes Sun Feb 02 02:18:08 2014 +0200 @@ -1,4 +1,5 @@ -3d texture ap ta slices -sunartisi pou na ftiaxnei to isosurface -mesh class -i volume class tha ftiaxnei ena mesh i 8a bazei data mesa s ena mesh +Sigmoid 2 +k T=0,5 panta +gia windowing + +na balw to t tou gui -1000 ws 1000 k na ginetai map sto 0 ws 1 diff -r c5af275b6a60 -r 1272e3335608 src/main.cc --- a/src/main.cc Mon Jan 27 01:22:02 2014 +0200 +++ b/src/main.cc Sun Feb 02 02:18:08 2014 +0200 @@ -27,7 +27,7 @@ static Volume *vol; static Mesh *mesh; -static float cur_z, thres = 0.5; +static float cur_z, thres = 0.5, thres2 = 1.0; static int use_orig_vol_res = 1; static int vol_res[3]; // volume sampling resolution x/y/z @@ -106,9 +106,24 @@ static void thres_change(int id) { static float prev_thres = thres; + static float prev_thres2 = thres2; - if(prev_thres != thres) { + if(prev_thres != thres || prev_thres2 != thres2) { prev_thres = thres; + prev_thres2 = thres2; + mesh->clear(); + } +} +static void res_change(int id) +{ + static float prev_resx = vol_res[0]; + static float prev_resy = vol_res[1]; + static float prev_resz = vol_res[2]; + + if(prev_resx != vol_res[0] || prev_resy != vol_res[1] || prev_resz != vol_res[2]) { + prev_resx = vol_res[0]; + prev_resy = vol_res[1]; + prev_resz = vol_res[2]; mesh->clear(); } } @@ -119,16 +134,21 @@ ui->set_main_gfx_window(glutGetWindow()); - GLUI_Spinner *thres_spin = ui->add_spinner("iso threshold", GLUI_SPINNER_FLOAT, &thres, 0, thres_change); + GLUI_Panel *thres_panel = ui->add_panel("iso thresholds"); + + GLUI_Spinner *thres_spin = ui->add_spinner_to_panel(thres_panel, "T1", GLUI_SPINNER_FLOAT, &thres, 0, thres_change); thres_spin->set_float_limits(0, 1); + GLUI_Spinner *thres2_spin = ui->add_spinner_to_panel(thres_panel, "T2", GLUI_SPINNER_FLOAT, &thres2, 0, thres_change); + thres2_spin->set_float_limits(0, 1); + GLUI_Panel *res_panel = ui->add_panel("volume resolution"); ui->add_checkbox_to_panel(res_panel, "original resolution", &use_orig_vol_res, 0, toggle_use_orig); static const char *res_spin_name[] = {"x", "y", "z"}; for(int i=0; i<3; i++) { - res_spin[i] = ui->add_spinner_to_panel(res_panel, res_spin_name[i], GLUI_SPINNER_INT, vol_res + i); + res_spin[i] = ui->add_spinner_to_panel(res_panel, res_spin_name[i], GLUI_SPINNER_INT, vol_res + i, 0, res_change); res_spin[i]->set_int_limits(8, 256); // TODO limits as arguments or config res_spin[i]->disable(); } @@ -161,7 +181,7 @@ if(mesh->is_empty()) { printf("recalculating isosurface ... "); fflush(stdout); - vol->create_mesh(mesh, thres); + vol->create_mesh(mesh, thres, thres2, vol_res[0], vol_res[1], vol_res[2]); printf("done.\n"); } mesh->draw(); @@ -210,7 +230,7 @@ static int prev_x, prev_y; static bool bn_state[32]; -static float prev_thres; +static float prev_thres, prev_thres2; static void mouse(int bn, int state, int x, int y) { @@ -221,9 +241,10 @@ if(state == GLUT_DOWN) { prev_thres = thres; + prev_thres2 = thres2; } else { - if(thres != prev_thres) { + if(thres != prev_thres || thres2 != prev_thres2) { mesh->clear(); } } diff -r c5af275b6a60 -r 1272e3335608 src/volume.cc --- a/src/volume.cc Mon Jan 27 01:22:02 2014 +0200 +++ b/src/volume.cc Sun Feb 02 02:18:08 2014 +0200 @@ -168,6 +168,16 @@ static Mesh *cur_mesh; static Volume *cur_vol; +static float low_thres, high_thres; + +static float smoothstep(float x, float low, float high) +{ + if(x < low) return 0.0; + if(x >= high) return 1.0; + + x = (x - low) / (high - low); + return x * x * (3.0 - 2.0 * x); +} static float cb_eval(float x, float y, float z) { @@ -177,7 +187,9 @@ int px = (x + 1) / 2.0 * img->get_width(); int py = (y + 1) / 2.0 * img->get_height(); - return pixels[px + img->get_width() * py]; + float val = pixels[px + img->get_width() * py]; + float dt = 0.25 * (high_thres - low_thres); + return smoothstep(val, low_thres - dt, low_thres + dt) * (1 - smoothstep(val, high_thres - dt, high_thres + dt)); } static void cb_vertex(float x, float y, float z) @@ -193,14 +205,28 @@ cur_mesh->add_vertex(Vector3(x, y, z)); } -void Volume::create_mesh(Mesh *mesh, float threshold) +void Volume::create_mesh(Mesh *mesh, float tmin, float tmax, int xres, int yres, int zres) { + if (tmin > tmax) { + float t = tmax; + tmax = tmin; + tmin = t; + } + low_thres = tmin; high_thres = tmax; + + if(xres <= 0) + xres = width; + if(yres <= 0) + yres = height; + if(zres <= 0) + zres = slices.size(); + cur_mesh = mesh; cur_vol = this; metasurface *ms = msurf_create(); - msurf_threshold(ms, threshold); - msurf_resolution(ms, width, height, slices.size()); + msurf_threshold(ms, 0.5); + msurf_resolution(ms, xres, yres, zres); msurf_vertex_func(ms, cb_vertex); msurf_eval_func(ms, cb_eval); msurf_polygonize(ms); diff -r c5af275b6a60 -r 1272e3335608 src/volume.h --- a/src/volume.h Mon Jan 27 01:22:02 2014 +0200 +++ b/src/volume.h Sun Feb 02 02:18:08 2014 +0200 @@ -38,7 +38,7 @@ unsigned int get_texture() const; - void create_mesh(Mesh *mesh, float threshold); + void create_mesh(Mesh *mesh, float tmin, float tmax, int xres, int yres, int zres); void draw() const; };