# HG changeset patch # User Eleni Maria Stea # Date 1391388766 -7200 # Node ID add30e2d525314e2c1460d5e6f8c34932e11c45a # Parent a93c8aa85e05a9c650fa8ca2d7812a39c2946ea4 foo diff -r a93c8aa85e05 -r add30e2d5253 notes --- a/notes Mon Feb 03 01:30:47 2014 +0200 +++ b/notes Mon Feb 03 02:52:46 2014 +0200 @@ -1,10 +1,3 @@ -Sigmoid 2 -k T=0,5 panta -gia windowing - -2o para8uro pou visualize to slice k sou epitrepei na allazeis ti -windowing function: - na balw to t tou gui -1000 ws 1000 k na ginetai map sto 0 ws 1 interpolation stin eval @@ -12,3 +5,8 @@ optimisations VBO + +******************* +MOTION sto main.cc pros to kontinotero akro: +map to x apo pixel se [0,1] k.a. +************ diff -r a93c8aa85e05 -r add30e2d5253 src/main.cc --- a/src/main.cc Mon Feb 03 01:30:47 2014 +0200 +++ b/src/main.cc Mon Feb 03 02:52:46 2014 +0200 @@ -19,6 +19,13 @@ static void mouse(int button, int state, int x, int y); static void motion(int x, int y); +static bool init_xfer(void); +static void display_xfer(void); +static void reshape_xfer(int x, int y); +static void motion_xfer(int x, int y); + +static int mainwin_id, xferwin_id; + static int win_xsz, win_ysz; static float cam_phi, cam_theta, cam_dist = 6; static std::vector key_state(256); @@ -37,14 +44,26 @@ int main(int argc, char **argv) { glutInit(&argc, argv); + if(argv[1]) + vol_fname = argv[1]; + + if(!init()) { + fprintf(stderr, "Failed to initialize program.\n"); + return 1; + } + + init_xfer(); + + glutMainLoop(); + return 0; +} + +static bool init() +{ glutInitWindowSize(512, 512); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); - if(argv[1]) - vol_fname = argv[1]; - - glutCreateWindow("CT scan"); - + mainwin_id = glutCreateWindow("CT scan"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); @@ -53,19 +72,7 @@ glutMotionFunc(motion); glewInit(); - if(!init()) { - fprintf(stderr, "Failed to initialize program.\n"); - return 1; - } - //call init - - glutMainLoop(); - return 0; -} - -static bool init() -{ glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); @@ -113,6 +120,11 @@ prev_thres2 = thres2; mesh->clear(); } + + glutSetWindow(xferwin_id); + glutPostRedisplay(); + glutSetWindow(mainwin_id); + glutPostRedisplay(); } static void res_change(int id) { @@ -294,3 +306,71 @@ glutPostRedisplay(); } } + +static bool init_xfer(void) +{ + glutSetWindow(mainwin_id); + int x = glutGet(GLUT_WINDOW_X); + int y = glutGet(GLUT_WINDOW_Y) + glutGet(GLUT_WINDOW_HEIGHT); + + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + glutInitWindowSize(512, 100); + glutInitWindowPosition(x, y); + + xferwin_id = glutCreateWindow("Transfer Function"); + glutDisplayFunc(display_xfer); + glutReshapeFunc(reshape_xfer); + glutMotionFunc(motion_xfer); + + return true; +} + +static void display_xfer(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + int num_val = glutGet(GLUT_WINDOW_WIDTH) / 4.0; + float x = 0; + float dx = 1.0 / num_val; + float low, high; + if(thres < thres2) { + low = thres; + high = thres2; + } + else { + low = thres2; + high = thres; + } + + glBegin(GL_QUADS); + for(int i=0; iget_slice_by_z((z + 1) / 2.0); @@ -187,8 +195,7 @@ int py = (y + 1) / 2.0 * img->get_height(); 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)); + return transfer_function(val, low_thres, high_thres); } static void cb_vertex(float x, float y, float z) diff -r a93c8aa85e05 -r add30e2d5253 src/volume.h --- a/src/volume.h Mon Feb 03 01:30:47 2014 +0200 +++ b/src/volume.h Mon Feb 03 02:52:46 2014 +0200 @@ -43,4 +43,6 @@ void draw() const; }; +float transfer_function(float x, float low_thres, float high_thres); + #endif // VOLUME_H_