volmetrics

changeset 16:add30e2d5253

foo
author Eleni Maria Stea <elene.mst@gmail.com>
date Mon, 03 Feb 2014 02:52:46 +0200
parents a93c8aa85e05
children 0f4fff558737
files notes src/main.cc src/volume.cc src/volume.h
diffstat 4 files changed, 113 insertions(+), 26 deletions(-) [+]
line diff
     1.1 --- a/notes	Mon Feb 03 01:30:47 2014 +0200
     1.2 +++ b/notes	Mon Feb 03 02:52:46 2014 +0200
     1.3 @@ -1,10 +1,3 @@
     1.4 -Sigmoid 2
     1.5 -k T=0,5 panta
     1.6 -gia windowing
     1.7 -
     1.8 -2o para8uro pou visualize to slice k sou epitrepei na allazeis ti
     1.9 -windowing function:
    1.10 -
    1.11  na balw to t tou gui -1000 ws 1000 k na ginetai map sto 0 ws 1
    1.12  
    1.13  interpolation stin eval
    1.14 @@ -12,3 +5,8 @@
    1.15  optimisations
    1.16  
    1.17  VBO
    1.18 +
    1.19 +*******************
    1.20 +MOTION sto main.cc pros to kontinotero akro:
    1.21 +map to x apo pixel se [0,1] k.a.
    1.22 +************
     2.1 --- a/src/main.cc	Mon Feb 03 01:30:47 2014 +0200
     2.2 +++ b/src/main.cc	Mon Feb 03 02:52:46 2014 +0200
     2.3 @@ -19,6 +19,13 @@
     2.4  static void mouse(int button, int state, int x, int y);
     2.5  static void motion(int x, int y);
     2.6  
     2.7 +static bool init_xfer(void);
     2.8 +static void display_xfer(void);
     2.9 +static void reshape_xfer(int x, int y);
    2.10 +static void motion_xfer(int x, int y);
    2.11 +
    2.12 +static int mainwin_id, xferwin_id;
    2.13 +
    2.14  static int win_xsz, win_ysz;
    2.15  static float cam_phi, cam_theta, cam_dist = 6;
    2.16  static std::vector<bool> key_state(256);
    2.17 @@ -37,14 +44,26 @@
    2.18  int main(int argc, char **argv)
    2.19  {
    2.20  	glutInit(&argc, argv);
    2.21 +	if(argv[1])
    2.22 +		vol_fname = argv[1];
    2.23 +
    2.24 +	if(!init()) {
    2.25 +		fprintf(stderr, "Failed to initialize program.\n");
    2.26 +		return 1;
    2.27 +	}
    2.28 +
    2.29 +	init_xfer();
    2.30 +
    2.31 +	glutMainLoop();
    2.32 +	return 0;
    2.33 +}
    2.34 +
    2.35 +static bool init()
    2.36 +{
    2.37  	glutInitWindowSize(512, 512);
    2.38  	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    2.39  
    2.40 -	if(argv[1])
    2.41 -		vol_fname = argv[1];
    2.42 -
    2.43 -	glutCreateWindow("CT scan");
    2.44 -
    2.45 +	mainwin_id = glutCreateWindow("CT scan");
    2.46  	glutDisplayFunc(display);
    2.47  	glutReshapeFunc(reshape);
    2.48  	glutKeyboardFunc(keyboard);
    2.49 @@ -53,19 +72,7 @@
    2.50  	glutMotionFunc(motion);
    2.51  
    2.52  	glewInit();
    2.53 -	if(!init()) {
    2.54 -		fprintf(stderr, "Failed to initialize program.\n");
    2.55 -		return 1;
    2.56 -	}
    2.57  
    2.58 -	//call init
    2.59 -
    2.60 -	glutMainLoop();
    2.61 -	return 0;
    2.62 -}
    2.63 -
    2.64 -static bool init()
    2.65 -{
    2.66  	glEnable(GL_DEPTH_TEST);
    2.67  	glEnable(GL_NORMALIZE);
    2.68  
    2.69 @@ -113,6 +120,11 @@
    2.70  		prev_thres2 = thres2;
    2.71  		mesh->clear();
    2.72  	}
    2.73 +
    2.74 +	glutSetWindow(xferwin_id);
    2.75 +	glutPostRedisplay();
    2.76 +	glutSetWindow(mainwin_id);
    2.77 +	glutPostRedisplay();
    2.78  }
    2.79  static void res_change(int id)
    2.80  {
    2.81 @@ -294,3 +306,71 @@
    2.82  		glutPostRedisplay();
    2.83  	}
    2.84  }
    2.85 +
    2.86 +static bool init_xfer(void)
    2.87 +{
    2.88 +	glutSetWindow(mainwin_id);
    2.89 +	int x = glutGet(GLUT_WINDOW_X);
    2.90 +	int y = glutGet(GLUT_WINDOW_Y) + glutGet(GLUT_WINDOW_HEIGHT);
    2.91 +
    2.92 +	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    2.93 +	glutInitWindowSize(512, 100);
    2.94 +	glutInitWindowPosition(x, y);
    2.95 +
    2.96 +	xferwin_id = glutCreateWindow("Transfer Function");
    2.97 +	glutDisplayFunc(display_xfer);
    2.98 +	glutReshapeFunc(reshape_xfer);
    2.99 +	glutMotionFunc(motion_xfer);
   2.100 +
   2.101 +	return true;
   2.102 +}
   2.103 +
   2.104 +static void display_xfer(void)
   2.105 +{
   2.106 +	glClear(GL_COLOR_BUFFER_BIT);
   2.107 +
   2.108 +	int num_val = glutGet(GLUT_WINDOW_WIDTH) / 4.0;
   2.109 +	float x = 0;
   2.110 +	float dx = 1.0 / num_val;
   2.111 +	float low, high;
   2.112 +	if(thres < thres2) {
   2.113 +		low = thres;
   2.114 +		high = thres2;
   2.115 +	}
   2.116 +	else {
   2.117 +		low = thres2;
   2.118 +		high = thres;
   2.119 +	}
   2.120 +
   2.121 +	glBegin(GL_QUADS);
   2.122 +	for(int i=0; i<num_val; i++) {
   2.123 +		float val = transfer_function(x, low, high);
   2.124 +		glColor3f(val, val, val);
   2.125 +		glVertex3f(x, 1.0, 0.0);
   2.126 +		glVertex3f(x, 0.0, 0.0);
   2.127 +
   2.128 +		val = transfer_function(x + dx, low, high);
   2.129 +		glColor3f(val, val, val);
   2.130 +		glVertex3f(x + dx, 0.0, 0.0);
   2.131 +		glVertex3f(x + dx, 1.0, 0.0);
   2.132 +		x += dx;
   2.133 +	}
   2.134 +	glEnd();
   2.135 +
   2.136 +	glutSwapBuffers();
   2.137 +	assert(glGetError() == GL_NO_ERROR);
   2.138 +}
   2.139 +
   2.140 +static void reshape_xfer(int x, int y)
   2.141 +{
   2.142 +	glViewport(0.0, 0.0, x, y);
   2.143 +	glMatrixMode(GL_PROJECTION);
   2.144 +	glLoadIdentity();
   2.145 +	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
   2.146 +}
   2.147 +
   2.148 +static void motion_xfer(int x, int y)
   2.149 +{
   2.150 +	//to pontiki sto kontinotero akro
   2.151 +	//glutPostRedisplay k sta 2 win
   2.152 +}
     3.1 --- a/src/volume.cc	Mon Feb 03 01:30:47 2014 +0200
     3.2 +++ b/src/volume.cc	Mon Feb 03 02:52:46 2014 +0200
     3.3 @@ -178,6 +178,14 @@
     3.4  	x = (x - low) / (high - low);
     3.5  	return x * x * (3.0 - 2.0 * x);
     3.6  }
     3.7 +
     3.8 +float transfer_function(float x, float low_thres, float high_thres)
     3.9 +{
    3.10 +	float dt = 0.25 * (high_thres - low_thres);
    3.11 +	return smoothstep(x, low_thres - dt, low_thres + dt) *
    3.12 +		(1 - smoothstep(x, high_thres - dt, high_thres + dt));
    3.13 +}
    3.14 +
    3.15  static float cb_eval(float x, float y, float z)
    3.16  {
    3.17  	const Image *img = cur_vol->get_slice_by_z((z + 1) / 2.0);
    3.18 @@ -187,8 +195,7 @@
    3.19  	int py = (y + 1) / 2.0 * img->get_height();
    3.20  
    3.21  	float val = pixels[px + img->get_width() * py];
    3.22 -	float dt = 0.25 * (high_thres - low_thres);
    3.23 -	return smoothstep(val, low_thres - dt, low_thres + dt) * (1 - smoothstep(val, high_thres - dt, high_thres + dt));
    3.24 +	return transfer_function(val, low_thres, high_thres);
    3.25  }
    3.26  
    3.27  static void cb_vertex(float x, float y, float z)
     4.1 --- a/src/volume.h	Mon Feb 03 01:30:47 2014 +0200
     4.2 +++ b/src/volume.h	Mon Feb 03 02:52:46 2014 +0200
     4.3 @@ -43,4 +43,6 @@
     4.4  	void draw() const;
     4.5  };
     4.6  
     4.7 +float transfer_function(float x, float low_thres, float high_thres);
     4.8 +
     4.9  #endif // VOLUME_H_