volmetrics

diff src/main.cc @ 16:add30e2d5253

foo
author Eleni Maria Stea <elene.mst@gmail.com>
date Mon, 03 Feb 2014 02:52:46 +0200
parents a93c8aa85e05
children 0f4fff558737
line diff
     1.1 --- a/src/main.cc	Mon Feb 03 01:30:47 2014 +0200
     1.2 +++ b/src/main.cc	Mon Feb 03 02:52:46 2014 +0200
     1.3 @@ -19,6 +19,13 @@
     1.4  static void mouse(int button, int state, int x, int y);
     1.5  static void motion(int x, int y);
     1.6  
     1.7 +static bool init_xfer(void);
     1.8 +static void display_xfer(void);
     1.9 +static void reshape_xfer(int x, int y);
    1.10 +static void motion_xfer(int x, int y);
    1.11 +
    1.12 +static int mainwin_id, xferwin_id;
    1.13 +
    1.14  static int win_xsz, win_ysz;
    1.15  static float cam_phi, cam_theta, cam_dist = 6;
    1.16  static std::vector<bool> key_state(256);
    1.17 @@ -37,14 +44,26 @@
    1.18  int main(int argc, char **argv)
    1.19  {
    1.20  	glutInit(&argc, argv);
    1.21 +	if(argv[1])
    1.22 +		vol_fname = argv[1];
    1.23 +
    1.24 +	if(!init()) {
    1.25 +		fprintf(stderr, "Failed to initialize program.\n");
    1.26 +		return 1;
    1.27 +	}
    1.28 +
    1.29 +	init_xfer();
    1.30 +
    1.31 +	glutMainLoop();
    1.32 +	return 0;
    1.33 +}
    1.34 +
    1.35 +static bool init()
    1.36 +{
    1.37  	glutInitWindowSize(512, 512);
    1.38  	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.39  
    1.40 -	if(argv[1])
    1.41 -		vol_fname = argv[1];
    1.42 -
    1.43 -	glutCreateWindow("CT scan");
    1.44 -
    1.45 +	mainwin_id = glutCreateWindow("CT scan");
    1.46  	glutDisplayFunc(display);
    1.47  	glutReshapeFunc(reshape);
    1.48  	glutKeyboardFunc(keyboard);
    1.49 @@ -53,19 +72,7 @@
    1.50  	glutMotionFunc(motion);
    1.51  
    1.52  	glewInit();
    1.53 -	if(!init()) {
    1.54 -		fprintf(stderr, "Failed to initialize program.\n");
    1.55 -		return 1;
    1.56 -	}
    1.57  
    1.58 -	//call init
    1.59 -
    1.60 -	glutMainLoop();
    1.61 -	return 0;
    1.62 -}
    1.63 -
    1.64 -static bool init()
    1.65 -{
    1.66  	glEnable(GL_DEPTH_TEST);
    1.67  	glEnable(GL_NORMALIZE);
    1.68  
    1.69 @@ -113,6 +120,11 @@
    1.70  		prev_thres2 = thres2;
    1.71  		mesh->clear();
    1.72  	}
    1.73 +
    1.74 +	glutSetWindow(xferwin_id);
    1.75 +	glutPostRedisplay();
    1.76 +	glutSetWindow(mainwin_id);
    1.77 +	glutPostRedisplay();
    1.78  }
    1.79  static void res_change(int id)
    1.80  {
    1.81 @@ -294,3 +306,71 @@
    1.82  		glutPostRedisplay();
    1.83  	}
    1.84  }
    1.85 +
    1.86 +static bool init_xfer(void)
    1.87 +{
    1.88 +	glutSetWindow(mainwin_id);
    1.89 +	int x = glutGet(GLUT_WINDOW_X);
    1.90 +	int y = glutGet(GLUT_WINDOW_Y) + glutGet(GLUT_WINDOW_HEIGHT);
    1.91 +
    1.92 +	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    1.93 +	glutInitWindowSize(512, 100);
    1.94 +	glutInitWindowPosition(x, y);
    1.95 +
    1.96 +	xferwin_id = glutCreateWindow("Transfer Function");
    1.97 +	glutDisplayFunc(display_xfer);
    1.98 +	glutReshapeFunc(reshape_xfer);
    1.99 +	glutMotionFunc(motion_xfer);
   1.100 +
   1.101 +	return true;
   1.102 +}
   1.103 +
   1.104 +static void display_xfer(void)
   1.105 +{
   1.106 +	glClear(GL_COLOR_BUFFER_BIT);
   1.107 +
   1.108 +	int num_val = glutGet(GLUT_WINDOW_WIDTH) / 4.0;
   1.109 +	float x = 0;
   1.110 +	float dx = 1.0 / num_val;
   1.111 +	float low, high;
   1.112 +	if(thres < thres2) {
   1.113 +		low = thres;
   1.114 +		high = thres2;
   1.115 +	}
   1.116 +	else {
   1.117 +		low = thres2;
   1.118 +		high = thres;
   1.119 +	}
   1.120 +
   1.121 +	glBegin(GL_QUADS);
   1.122 +	for(int i=0; i<num_val; i++) {
   1.123 +		float val = transfer_function(x, low, high);
   1.124 +		glColor3f(val, val, val);
   1.125 +		glVertex3f(x, 1.0, 0.0);
   1.126 +		glVertex3f(x, 0.0, 0.0);
   1.127 +
   1.128 +		val = transfer_function(x + dx, low, high);
   1.129 +		glColor3f(val, val, val);
   1.130 +		glVertex3f(x + dx, 0.0, 0.0);
   1.131 +		glVertex3f(x + dx, 1.0, 0.0);
   1.132 +		x += dx;
   1.133 +	}
   1.134 +	glEnd();
   1.135 +
   1.136 +	glutSwapBuffers();
   1.137 +	assert(glGetError() == GL_NO_ERROR);
   1.138 +}
   1.139 +
   1.140 +static void reshape_xfer(int x, int y)
   1.141 +{
   1.142 +	glViewport(0.0, 0.0, x, y);
   1.143 +	glMatrixMode(GL_PROJECTION);
   1.144 +	glLoadIdentity();
   1.145 +	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
   1.146 +}
   1.147 +
   1.148 +static void motion_xfer(int x, int y)
   1.149 +{
   1.150 +	//to pontiki sto kontinotero akro
   1.151 +	//glutPostRedisplay k sta 2 win
   1.152 +}