volmetrics

changeset 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 77a376198d38
files notes src/main.cc src/volume.cc src/volume.h
diffstat 4 files changed, 64 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/notes	Mon Jan 27 01:22:02 2014 +0200
     1.2 +++ b/notes	Sun Feb 02 02:18:08 2014 +0200
     1.3 @@ -1,4 +1,5 @@
     1.4 -3d texture ap ta slices
     1.5 -sunartisi pou na ftiaxnei to isosurface
     1.6 -mesh class
     1.7 -i volume class tha ftiaxnei ena mesh i 8a bazei data mesa s ena mesh
     1.8 +Sigmoid 2
     1.9 +k T=0,5 panta
    1.10 +gia windowing
    1.11 +
    1.12 +na balw to t tou gui -1000 ws 1000 k na ginetai map sto 0 ws 1
     2.1 --- a/src/main.cc	Mon Jan 27 01:22:02 2014 +0200
     2.2 +++ b/src/main.cc	Sun Feb 02 02:18:08 2014 +0200
     2.3 @@ -27,7 +27,7 @@
     2.4  
     2.5  static Volume *vol;
     2.6  static Mesh *mesh;
     2.7 -static float cur_z, thres = 0.5;
     2.8 +static float cur_z, thres = 0.5, thres2 = 1.0;
     2.9  
    2.10  static int use_orig_vol_res = 1;
    2.11  static int vol_res[3]; // volume sampling resolution x/y/z
    2.12 @@ -106,9 +106,24 @@
    2.13  static void thres_change(int id)
    2.14  {
    2.15  	static float prev_thres = thres;
    2.16 +	static float prev_thres2 = thres2;
    2.17  
    2.18 -	if(prev_thres != thres) {
    2.19 +	if(prev_thres != thres || prev_thres2 != thres2) {
    2.20  		prev_thres = thres;
    2.21 +		prev_thres2 = thres2;
    2.22 +		mesh->clear();
    2.23 +	}
    2.24 +}
    2.25 +static void res_change(int id)
    2.26 +{
    2.27 +	static float prev_resx = vol_res[0];
    2.28 +	static float prev_resy = vol_res[1];
    2.29 +	static float prev_resz = vol_res[2];
    2.30 +
    2.31 +	if(prev_resx != vol_res[0] || prev_resy != vol_res[1] || prev_resz != vol_res[2]) {
    2.32 +		prev_resx = vol_res[0];
    2.33 +		prev_resy = vol_res[1];
    2.34 +		prev_resz = vol_res[2];
    2.35  		mesh->clear();
    2.36  	}
    2.37  }
    2.38 @@ -119,16 +134,21 @@
    2.39  
    2.40  	ui->set_main_gfx_window(glutGetWindow());
    2.41  
    2.42 -	GLUI_Spinner *thres_spin = ui->add_spinner("iso threshold", GLUI_SPINNER_FLOAT, &thres, 0, thres_change);
    2.43 +	GLUI_Panel *thres_panel = ui->add_panel("iso thresholds");
    2.44 +
    2.45 +	GLUI_Spinner *thres_spin = ui->add_spinner_to_panel(thres_panel, "T1", GLUI_SPINNER_FLOAT, &thres, 0, thres_change);
    2.46  	thres_spin->set_float_limits(0, 1);
    2.47  
    2.48 +	GLUI_Spinner *thres2_spin = ui->add_spinner_to_panel(thres_panel, "T2", GLUI_SPINNER_FLOAT, &thres2, 0, thres_change);
    2.49 +	thres2_spin->set_float_limits(0, 1);
    2.50 +
    2.51  	GLUI_Panel *res_panel = ui->add_panel("volume resolution");
    2.52  
    2.53  	ui->add_checkbox_to_panel(res_panel, "original resolution", &use_orig_vol_res, 0, toggle_use_orig);
    2.54  
    2.55  	static const char *res_spin_name[] = {"x", "y", "z"};
    2.56  	for(int i=0; i<3; i++) {
    2.57 -		res_spin[i] = ui->add_spinner_to_panel(res_panel, res_spin_name[i], GLUI_SPINNER_INT, vol_res + i);
    2.58 +		res_spin[i] = ui->add_spinner_to_panel(res_panel, res_spin_name[i], GLUI_SPINNER_INT, vol_res + i, 0, res_change);
    2.59  		res_spin[i]->set_int_limits(8, 256); // TODO limits as arguments or config
    2.60  		res_spin[i]->disable();
    2.61  	}
    2.62 @@ -161,7 +181,7 @@
    2.63  	if(mesh->is_empty()) {
    2.64  		printf("recalculating isosurface ... ");
    2.65  		fflush(stdout);
    2.66 -		vol->create_mesh(mesh, thres);
    2.67 +		vol->create_mesh(mesh, thres, thres2, vol_res[0], vol_res[1], vol_res[2]);
    2.68  		printf("done.\n");
    2.69  	}
    2.70  	mesh->draw();
    2.71 @@ -210,7 +230,7 @@
    2.72  
    2.73  static int prev_x, prev_y;
    2.74  static bool bn_state[32];
    2.75 -static float prev_thres;
    2.76 +static float prev_thres, prev_thres2;
    2.77  
    2.78  static void mouse(int bn, int state, int x, int y)
    2.79  {
    2.80 @@ -221,9 +241,10 @@
    2.81  
    2.82  	if(state == GLUT_DOWN) {
    2.83  		prev_thres = thres;
    2.84 +		prev_thres2 = thres2;
    2.85  	}
    2.86  	else {
    2.87 -		if(thres != prev_thres) {
    2.88 +		if(thres != prev_thres || thres2 != prev_thres2) {
    2.89  			mesh->clear();
    2.90  		}
    2.91  	}
     3.1 --- a/src/volume.cc	Mon Jan 27 01:22:02 2014 +0200
     3.2 +++ b/src/volume.cc	Sun Feb 02 02:18:08 2014 +0200
     3.3 @@ -168,6 +168,16 @@
     3.4  
     3.5  static Mesh *cur_mesh;
     3.6  static Volume *cur_vol;
     3.7 +static float low_thres, high_thres;
     3.8 +
     3.9 +static float smoothstep(float x, float low, float high)
    3.10 +{
    3.11 +	if(x < low) return 0.0;
    3.12 +	if(x >= high) return 1.0;
    3.13 +
    3.14 +	x = (x - low) / (high - low);
    3.15 +	return x * x * (3.0 - 2.0 * x);
    3.16 +}
    3.17  
    3.18  static float cb_eval(float x, float y, float z)
    3.19  {
    3.20 @@ -177,7 +187,9 @@
    3.21  	int px = (x + 1) / 2.0 * img->get_width();
    3.22  	int py = (y + 1) / 2.0 * img->get_height();
    3.23  
    3.24 -	return pixels[px + img->get_width() * py];
    3.25 +	float val = pixels[px + img->get_width() * py];
    3.26 +	float dt = 0.25 * (high_thres - low_thres);
    3.27 +	return smoothstep(val, low_thres - dt, low_thres + dt) * (1 - smoothstep(val, high_thres - dt, high_thres + dt));
    3.28  }
    3.29  
    3.30  static void cb_vertex(float x, float y, float z)
    3.31 @@ -193,14 +205,28 @@
    3.32  	cur_mesh->add_vertex(Vector3(x, y, z));
    3.33  }
    3.34  
    3.35 -void Volume::create_mesh(Mesh *mesh, float threshold)
    3.36 +void Volume::create_mesh(Mesh *mesh, float tmin, float tmax, int xres, int yres, int zres)
    3.37  {
    3.38 +	if (tmin > tmax) {
    3.39 +		float t = tmax;
    3.40 +		tmax = tmin;
    3.41 +		tmin = t;
    3.42 +	}
    3.43 +	low_thres = tmin; high_thres = tmax;
    3.44 +
    3.45 +	if(xres <= 0)
    3.46 +		xres = width;
    3.47 +	if(yres <= 0)
    3.48 +		yres = height;
    3.49 +	if(zres <= 0)
    3.50 +		zres = slices.size();
    3.51 +
    3.52  	cur_mesh = mesh;
    3.53  	cur_vol = this;
    3.54  
    3.55  	metasurface *ms = msurf_create();
    3.56 -	msurf_threshold(ms, threshold);
    3.57 -	msurf_resolution(ms, width, height, slices.size());
    3.58 +	msurf_threshold(ms, 0.5);
    3.59 +	msurf_resolution(ms, xres, yres, zres);
    3.60  	msurf_vertex_func(ms, cb_vertex);
    3.61  	msurf_eval_func(ms, cb_eval);
    3.62  	msurf_polygonize(ms);
     4.1 --- a/src/volume.h	Mon Jan 27 01:22:02 2014 +0200
     4.2 +++ b/src/volume.h	Sun Feb 02 02:18:08 2014 +0200
     4.3 @@ -38,7 +38,7 @@
     4.4  
     4.5  	unsigned int get_texture() const;
     4.6  
     4.7 -	void create_mesh(Mesh *mesh, float threshold);
     4.8 +	void create_mesh(Mesh *mesh, float tmin, float tmax, int xres, int yres, int zres);
     4.9  
    4.10  	void draw() const;
    4.11  };