From 4d23da9ca2b95fdebeabba2152faccd0025b6d78 Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Fri, 13 Jan 2017 14:08:13 -0600 Subject: [PATCH] add 00_GT.swc,now everything is good --- data/00_GT.swc | 20 ++++++++++++++++++++ main.cu | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------ 2 files changed, 86 insertions(+), 42 deletions(-) diff --git a/data/00_GT.swc b/data/00_GT.swc index e69de29..7b9a9eb 100644 --- a/data/00_GT.swc +++ b/data/00_GT.swc @@ -0,0 +1,20 @@ +# converted from 00_GT.obj +1 1 99 677 0 0.5 -1 +2 1 88 563 0 0.5 1 +3 1 229 510 0 0.5 2 +4 1 181 372 0 0.5 3 +5 1 57 347 0 0.5 4 +6 1 316 596 0 0.5 3 +7 1 344 724 0 0.5 6 +8 1 385 425 0 0.5 3 +9 1 581 361 0 0.5 8 +10 1 574 223 0 0.5 9 +11 1 481 165 0 0.5 10 +12 1 341 199 0 0.5 11 +13 1 757 377 0 0.5 9 +14 1 818 229 0 0.5 13 +15 1 981 152 0 0.5 14 +16 1 793 508 0 0.5 13 +17 1 941 600 0 0.5 16 +18 1 679 601 0 0.5 16 +19 1 647 738 0 0.5 18 diff --git a/main.cu b/main.cu index 5204a56..a4c4b3c 100644 --- a/main.cu +++ b/main.cu @@ -47,7 +47,8 @@ std::vector _t_gt; // store indices of nearest edge points in _ float resample_rate = 0.5f; //sample rate for the network (fraction of sigma used as the maximum sample rate) float camera_factor = 1.2f; //start point of the camera as a function of X and Y size float orbit_factor = 0.01f; //degrees per pixel used to orbit the camera -float zoom_factor = 10.0; +float zoom_factor = 10.0f; +float radius_factor = 0.5f; //mouse click bool LButtonDown = false; // true when left button down @@ -74,7 +75,9 @@ GLuint dlist2; //OpenGL objects GLuint cmap_tex = 0; //texture name for the color map +float delta; float sigma = 3; //default sigma +float radius = 3; //equals to radius //sets an OpenGL viewport taking up the entire window void glut_render_single_projection(){ @@ -146,11 +149,12 @@ void glut_render(void) { glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map - GT.glCylinder(sigma); //render the GT network + GT.glCylinder(sigma, radius); //render the GT network glut_render_right_projection(); //set up a projection for the right half of the window glut_render_modelview(); //set up the modelview matrix using camera details - T.glCylinder(sigma); //render the T network + T.glCylinder(sigma, radius); //render the T network + sigma = radius; // set sigma equal to radius } } @@ -171,12 +175,12 @@ void glut_render(void) { glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map - _GT.glCylinder(sigma); //render the GT network + _GT.glCylinder(sigma, radius); //render the GT network glut_render_right_projection(); //set up a projection for the right half of the window glut_render_modelview(); //set up the modelview matrix using camera details - _T.glCylinder(sigma); //render the T network - + _T.glCylinder(sigma, radius); //render the T network + sigma = radius; //set sigma equal to radius } else { glEnable(GL_DEPTH_TEST); //enable depth @@ -185,12 +189,13 @@ void glut_render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen //_GT.glRandColorCenterlineGT(dlist1, _gt_t, colormap); - _GT.glRandColorCylinder1(dlist1, _gt_t, colormap, sigma); + _GT.glRandColorCylinder1(dlist1, _gt_t, colormap, sigma, radius); glut_render_right_projection(); //set up a projection for the right half of the window glut_render_modelview(); //set up the modelview matrix using camera details //_T.glRandColorCenterlineT(dlist2, _t_gt, colormap); - _T.glRandColorCylinder2(dlist2, _t_gt, colormap, sigma); + _T.glRandColorCylinder2(dlist2, _t_gt, colormap, sigma, radius); + sigma = radius; //set sigma equal to radius } } } @@ -310,20 +315,10 @@ void glut_mouse(int button, int state, int x, int y){ // define camera move based on mouse wheel move(actually we can combine this with glut_mouse) void glut_wheel(int wheel, int direction, int x, int y) { - /*float cam_move_fac; // camera move unit length - stim::vec3 eye = cam.getPosition(); // get the camera position (eye point) - stim::vec3 focus = cam.getLookAt(); // get the camera focal point - cam_move_fac = fabs(focus[2] - eye[2]) / 50; // divided by 50 - - if (direction > 0) // if it is button 3(up) - des -= cam_move_fac; - else // if it is button 4(down) - des += cam_move_fac;*/ - float delta; - if (direction > 0) // if it is button 3(up) + if (direction > 0) // if it is button 3(up), move closer delta = zoom_factor; - else // if it is button 4(down) + else // if it is button 4(down), leave farther delta = -zoom_factor; cam.Push(delta); @@ -332,19 +327,46 @@ void glut_wheel(int wheel, int direction, int x, int y) { // define keyboard inputs void glut_keyboard(unsigned char key, int x, int y){ - if(key == 'm') // if keyboard 'm' is pressed - { - if(compareMode && !mappingMode){ // if it is in compare mode - compareMode = false; - mappingMode = true; - } - else{ // if it is in mapping mode - compareMode = true; - mappingMode = false; - } - } - if (key == 27) { // if keyboard "ESC" is pressed - exit(0); // exit + + // register different keyboard operation + switch (key) { + + // change render mode + case 'm': // if keyboard 'm' is pressed, then change render mode + if (compareMode && !mappingMode && ind) { // if current mode is comparing mode + compareMode = false; + mappingMode = true; + } + else if (!compareMode && mappingMode && ind) { // if current mode is mapping mode + compareMode = true; + mappingMode = false; + } + break; + + // zooming + case 'w': // if keyboard 'w' is pressed, then move closer + delta = zoom_factor; + cam.Push(delta); + break; + case 's': // if keyboard 's' is pressed, then leave farther + delta = -zoom_factor; + cam.Push(delta); + break; + + // resample and re-render the cylinder in different radius + case 'd': // if keyboard 'd' is pressed, then increase radius by radius_factor + radius += radius_factor; + break; + case 'a': // if keyboard 'a' is pressed, then decrease radius by radius_factor + radius -= radius_factor; + // get rid of the degenerated case when radius decrease below 0 + if (radius < 0.001f) + radius = 0.2; + break; + + // close window and exit application + case 27: // if keyboard 'ESC' is pressed, then exit + exit(0); } glutPostRedisplay(); } @@ -396,13 +418,13 @@ void glut_initialize(){ glutMouseFunc(glut_mouse); //executed on a mouse click - sets starting mouse positions for rotations glutMotionFunc(glut_motion); //executed when the mouse is moved while a button is pressed if (ind == 1) { //only in mapping mode, keyboard will be used - glutKeyboardFunc(glut_keyboard); //register keyboard callback glutCreateMenu(glut_menu); //register menu option callback - glutAddMenuEntry("Comparing Mode", 1);//register menu 1 as comparing mode - glutAddMenuEntry("Mapping Mode", 2); //register menu 2 as mapping mode - glutAddMenuEntry("Exit", 3); //register menu 3 as exiting - glutAttachMenu(GLUT_RIGHT_BUTTON); //register right mouse to open menu option - } + glutAddMenuEntry("Comparing Mode", 1); //register menu 1 as comparing mode + glutAddMenuEntry("Mapping Mode", 2); //register menu 2 as mapping mode + glutAddMenuEntry("Exit", 3); //register menu 3 as exiting + glutAttachMenu(GLUT_RIGHT_BUTTON); //register right mouse to open menu option + } + glutKeyboardFunc(glut_keyboard); //register keyboard callback glutMouseWheelFunc(glut_wheel); texture_initialize(); //set up texture mapping (create texture maps, enable features) @@ -579,13 +601,14 @@ int main(int argc, char* argv[]) if (1 == swc_ind) { //loading swc files int device = args["device"].as_int(); //get the device value from the user num_nets = 2; //set the number of networks to two - //does it need to be resampled?? sigma = args["sigma"].as_float(); //get the sigma value from the user + radius = sigma; T.load_swc(args.arg(1)); //load the second (test) network if (args["features"].is_set()) //if the user wants to save features features(args["features"].as_string()); - GT = GT.resample(resample_rate * sigma); //resample both networks based on the sigma value - T = T.resample(resample_rate * sigma); + //does it need to be resampled?? + //GT = GT.resample(resample_rate * sigma); //resample both networks based on the sigma value + //T = T.resample(resample_rate * sigma); if (args["mapping"].is_set()) { float threshold = args["mapping"].as_float(); map_swc(sigma, device, threshold); @@ -599,6 +622,7 @@ int main(int argc, char* argv[]) int device = args["device"].as_int(); //get the device value from the user num_nets = 2; //set the number of networks to two sigma = args["sigma"].as_float(); //get the sigma value from the user + radius = sigma; T.load_obj(args.arg(1)); //load the second (test) network if (args["features"].is_set()) //if the user wants to save features features(args["features"].as_string()); -- libgit2 0.21.4