From 21f03d551cf5782a05a95812713a47d20bb28d61 Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Tue, 10 Jan 2017 16:18:25 -0600 Subject: [PATCH] add functions for rendering networks from swc files --- main.cu | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------- 1 file changed, 135 insertions(+), 65 deletions(-) diff --git a/main.cu b/main.cu index e05aa6c..8801e52 100644 --- a/main.cu +++ b/main.cu @@ -39,6 +39,7 @@ stim::gl_network _GT; //splitted GT stim::gl_network _T; //splitted T unsigned ind = 0; //indicator of mapping +unsigned swc_ind = 0; //indicator of rendering swc file as networks std::vector _gt_t; // store indices of nearest edge points in _T for _GT std::vector _t_gt; // store indices of nearest edge points in _GT for _T @@ -122,38 +123,19 @@ void glut_render_modelview(){ //draws the network(s) void glut_render(void) { - if (ind == 0) { - if (num_nets == 1) { //if a single network is loaded - glut_render_single_projection(); //fill the entire viewport - glut_render_modelview(); //set up the modelview matrix with camera details - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen - GT.glCenterline0(); //render the GT network (the only one loaded) - } - - if (num_nets == 2) { //if two networks are loaded - - glut_render_left_projection(); //set up a projection for the left half of the window - glut_render_modelview(); //set up the modelview matrix using camera details - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen - - glEnable(GL_TEXTURE_1D); //enable texture mapping - 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 + //no mapping, just comparing + if (ind == 0) { + //working with obj files + if (swc_ind == 0) { + if (num_nets == 1) { //if a single network is loaded + glut_render_single_projection(); //fill the entire viewport + glut_render_modelview(); //set up the modelview matrix with camera details + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen + GT.glCenterline0(); //render the GT network (the only one loaded) + } - GT.glCenterline(); //render the GT network + if (num_nets == 2) { //if two networks are loaded - 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.glCenterline(); //render the T network - } - } - else { - if (num_nets == 1) { //if a single network is loaded - std::cout << "You should have at least two networks to do mapping." << std::endl; //exit program because there isn't enough network - exit(1); - } - if (num_nets == 2) { //if two networks are loaded - if (compareMode) { glut_render_left_projection(); //set up a projection for the left half of the window glut_render_modelview(); //set up the modelview matrix using camera details glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen @@ -162,24 +144,80 @@ 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.glCenterline(); //render the GT network + GT.glCenterline(); //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.glCenterline(); //render the T network - + T.glCenterline(); //render the T network + } + } + //working with swc files + else { + if (num_nets == 1) { //if a single network is loaded + glut_render_single_projection(); //fill the entire viewport + glut_render_modelview(); //set up the modelview matrix with camera details + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen + GT.glCenterline0_swc(); //render the GT network (the only one loaded) } - else { - glEnable(GL_DEPTH_TEST); + + if (num_nets == 2) { //if two networks are loaded + glut_render_left_projection(); //set up a projection for the left half of the window glut_render_modelview(); //set up the modelview matrix using camera details glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen - _GT.glRandColorCenterlineGT(dlist1, _gt_t, colormap); + glEnable(GL_TEXTURE_1D); //enable texture mapping + 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.glCenterline(); //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.glRandColorCenterlineT(dlist2, _t_gt, colormap); + T.glCenterline(); //render the T network + } + } + } + + //do mapping + else { + //working with obj files + if (swc_ind == 0) { + if (num_nets == 1) { //if a single network is loaded + std::cout << "You should have at least two networks to do mapping." << std::endl; //exit program because there isn't enough network + exit(1); + } + if (num_nets == 2) { //if two networks are loaded + if (compareMode) { + glut_render_left_projection(); //set up a projection for the left half of the window + glut_render_modelview(); //set up the modelview matrix using camera details + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen + + glEnable(GL_TEXTURE_1D); //enable texture mapping + 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.glCenterline(); //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.glCenterline(); //render the T network + + } + else { + glEnable(GL_DEPTH_TEST); + glut_render_left_projection(); //set up a projection for the left half of the window + glut_render_modelview(); //set up the modelview matrix using camera details + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen + + //_GT.glRandColorCenterlineGT(dlist1, _gt_t, colormap); + _GT.glCylinderGT(dlist1, _gt_t, colormap); + + 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.glCylinderT(dlist2, _t_gt, colormap); + } } } } @@ -383,13 +421,13 @@ void compare(float sigma, int device){ std::cout << "FPR: " << FNR << std::endl; } -void map(float sigma, int device){ +void map(float sigma, int device, float threshold){ - _GT.split(GT, T, sigma, device); - _T.split(T, GT, sigma, device); + _GT.split(GT, T, sigma, device, threshold); + _T.split(T, GT, sigma, device, threshold); - _GT.mapping(_T, _gt_t, device); - _T.mapping(_GT, _t_gt, device); + _GT.mapping(_T, _gt_t, device, threshold); + _T.mapping(_GT, _t_gt, device, threshold); size_t num = _gt_t.size(); // also create random color for unmapping edge, but won't be used though colormap.resize(3 * num); // 3 portions compound RGB @@ -437,7 +475,7 @@ void advertise(){ std::cout<<"========================================================================="<= 1){ //if at least one network file is specified - num_nets = 1; //set the number of networks to one - GT.load_obj(args.arg(0)); //load the specified file as the ground truth - /*GT.to_txt("Graph.txt");*/ + if (args["swc"].is_set()) { // if it is to load a swc file, right now we only load two files(.swc and .obj) + if (args.nargs() >= 1) { // if at least one network file is specified + num_nets = 1; // set the number of networks to one + GT.load_swc(args.arg(0)); // load the specified file as the ground truth + } + if (args.nargs() == 2) { //if two files are specified, they will be displayed in neighboring viewports and compared + 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?? + float sigma = args["sigma"].as_float(); //get the sigma value from the user + 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); + if (args["mapping"].is_set()) { + std::cout << "right now networks that are loaded from swc files do not need to be mapped with each other!" << std::endl; + exit(1); + } + else + compare(sigma, device); //run the comparison algorithm + } } - if(args.nargs() == 2){ //if two files are specified, they will be displayed in neighboring viewports and compared - int device = args["device"].as_int(); //get the device value from the user - num_nets = 2; //set the number of networks to two - float sigma = args["sigma"].as_float(); //get the sigma value from the user - 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()); - 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()){ - map(sigma, device); + else { //if it is to load a obj file + if (args.nargs() >= 1) { //if at least one network file is specified + num_nets = 1; //set the number of networks to one + GT.load_obj(args.arg(0)); //load the specified file as the ground truth + /*GT.to_txt("Graph.txt");*/ + } + if (args.nargs() == 2) { //if two files are specified, they will be displayed in neighboring viewports and compared + int device = args["device"].as_int(); //get the device value from the user + num_nets = 2; //set the number of networks to two + float sigma = args["sigma"].as_float(); //get the sigma value from the user + 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()); + 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(sigma, device, threshold); + } + else + compare(sigma, device); //run the comparison algorithm } - else - compare(sigma, device); //run the comparison algorithm } //if a GUI is requested, display the network using OpenGL if(args["gui"].is_set()){ - if(args["mapping"].is_set()){ - ind = 1; + if (args["swc"].is_set()) { + swc_ind = 1; + } + if (args["mapping"].is_set()) { + ind = 1; //set indicator of mapping to 1(true) bb = _GT.boundingbox(); //generate a bounding volume glut_initialize(); //create the GLUT window and set callback functions - glutMainLoop(); // enter GLUT event processing cycle + glutMainLoop(); //enter GLUT event processing cycle } - else{ + else { bb = GT.boundingbox(); //generate a bounding volume glut_initialize(); //create the GLUT window and set callback functions - glutMainLoop(); // enter GLUT event processing cycle + glutMainLoop(); //enter GLUT event processing cycle } } } -- libgit2 0.21.4