Commit 21f03d551cf5782a05a95812713a47d20bb28d61

Authored by Jiaming Guo
1 parent 68944dbf

add functions for rendering networks from swc files

Showing 1 changed file with 135 additions and 65 deletions   Show diff stats
@@ -39,6 +39,7 @@ stim::gl_network<float> _GT; //splitted GT @@ -39,6 +39,7 @@ stim::gl_network<float> _GT; //splitted GT
39 stim::gl_network<float> _T; //splitted T 39 stim::gl_network<float> _T; //splitted T
40 40
41 unsigned ind = 0; //indicator of mapping 41 unsigned ind = 0; //indicator of mapping
  42 +unsigned swc_ind = 0; //indicator of rendering swc file as networks
42 43
43 std::vector<unsigned> _gt_t; // store indices of nearest edge points in _T for _GT 44 std::vector<unsigned> _gt_t; // store indices of nearest edge points in _T for _GT
44 std::vector<unsigned> _t_gt; // store indices of nearest edge points in _GT for _T 45 std::vector<unsigned> _t_gt; // store indices of nearest edge points in _GT for _T
@@ -122,38 +123,19 @@ void glut_render_modelview(){ @@ -122,38 +123,19 @@ void glut_render_modelview(){
122 //draws the network(s) 123 //draws the network(s)
123 void glut_render(void) { 124 void glut_render(void) {
124 125
125 - if (ind == 0) {  
126 - if (num_nets == 1) { //if a single network is loaded  
127 - glut_render_single_projection(); //fill the entire viewport  
128 - glut_render_modelview(); //set up the modelview matrix with camera details  
129 - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen  
130 - GT.glCenterline0(); //render the GT network (the only one loaded)  
131 - }  
132 -  
133 - if (num_nets == 2) { //if two networks are loaded  
134 -  
135 - glut_render_left_projection(); //set up a projection for the left half of the window  
136 - glut_render_modelview(); //set up the modelview matrix using camera details  
137 - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen  
138 -  
139 - glEnable(GL_TEXTURE_1D); //enable texture mapping  
140 - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color  
141 - glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map 126 + //no mapping, just comparing
  127 + if (ind == 0) {
  128 + //working with obj files
  129 + if (swc_ind == 0) {
  130 + if (num_nets == 1) { //if a single network is loaded
  131 + glut_render_single_projection(); //fill the entire viewport
  132 + glut_render_modelview(); //set up the modelview matrix with camera details
  133 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
  134 + GT.glCenterline0(); //render the GT network (the only one loaded)
  135 + }
142 136
143 - GT.glCenterline(); //render the GT network 137 + if (num_nets == 2) { //if two networks are loaded
144 138
145 - glut_render_right_projection(); //set up a projection for the right half of the window  
146 - glut_render_modelview(); //set up the modelview matrix using camera details  
147 - T.glCenterline(); //render the T network  
148 - }  
149 - }  
150 - else {  
151 - if (num_nets == 1) { //if a single network is loaded  
152 - std::cout << "You should have at least two networks to do mapping." << std::endl; //exit program because there isn't enough network  
153 - exit(1);  
154 - }  
155 - if (num_nets == 2) { //if two networks are loaded  
156 - if (compareMode) {  
157 glut_render_left_projection(); //set up a projection for the left half of the window 139 glut_render_left_projection(); //set up a projection for the left half of the window
158 glut_render_modelview(); //set up the modelview matrix using camera details 140 glut_render_modelview(); //set up the modelview matrix using camera details
159 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen 141 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
@@ -162,24 +144,80 @@ void glut_render(void) { @@ -162,24 +144,80 @@ void glut_render(void) {
162 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color 144 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color
163 glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map 145 glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map
164 146
165 - _GT.glCenterline(); //render the GT network 147 + GT.glCenterline(); //render the GT network
166 148
167 glut_render_right_projection(); //set up a projection for the right half of the window 149 glut_render_right_projection(); //set up a projection for the right half of the window
168 glut_render_modelview(); //set up the modelview matrix using camera details 150 glut_render_modelview(); //set up the modelview matrix using camera details
169 - _T.glCenterline(); //render the T network  
170 - 151 + T.glCenterline(); //render the T network
  152 + }
  153 + }
  154 + //working with swc files
  155 + else {
  156 + if (num_nets == 1) { //if a single network is loaded
  157 + glut_render_single_projection(); //fill the entire viewport
  158 + glut_render_modelview(); //set up the modelview matrix with camera details
  159 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
  160 + GT.glCenterline0_swc(); //render the GT network (the only one loaded)
171 } 161 }
172 - else {  
173 - glEnable(GL_DEPTH_TEST); 162 +
  163 + if (num_nets == 2) { //if two networks are loaded
  164 +
174 glut_render_left_projection(); //set up a projection for the left half of the window 165 glut_render_left_projection(); //set up a projection for the left half of the window
175 glut_render_modelview(); //set up the modelview matrix using camera details 166 glut_render_modelview(); //set up the modelview matrix using camera details
176 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen 167 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
177 168
178 - _GT.glRandColorCenterlineGT(dlist1, _gt_t, colormap); 169 + glEnable(GL_TEXTURE_1D); //enable texture mapping
  170 + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color
  171 + glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map
  172 +
  173 + GT.glCenterline(); //render the GT network
179 174
180 glut_render_right_projection(); //set up a projection for the right half of the window 175 glut_render_right_projection(); //set up a projection for the right half of the window
181 glut_render_modelview(); //set up the modelview matrix using camera details 176 glut_render_modelview(); //set up the modelview matrix using camera details
182 - _T.glRandColorCenterlineT(dlist2, _t_gt, colormap); 177 + T.glCenterline(); //render the T network
  178 + }
  179 + }
  180 + }
  181 +
  182 + //do mapping
  183 + else {
  184 + //working with obj files
  185 + if (swc_ind == 0) {
  186 + if (num_nets == 1) { //if a single network is loaded
  187 + std::cout << "You should have at least two networks to do mapping." << std::endl; //exit program because there isn't enough network
  188 + exit(1);
  189 + }
  190 + if (num_nets == 2) { //if two networks are loaded
  191 + if (compareMode) {
  192 + glut_render_left_projection(); //set up a projection for the left half of the window
  193 + glut_render_modelview(); //set up the modelview matrix using camera details
  194 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
  195 +
  196 + glEnable(GL_TEXTURE_1D); //enable texture mapping
  197 + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color
  198 + glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map
  199 +
  200 + _GT.glCenterline(); //render the GT network
  201 +
  202 + glut_render_right_projection(); //set up a projection for the right half of the window
  203 + glut_render_modelview(); //set up the modelview matrix using camera details
  204 + _T.glCenterline(); //render the T network
  205 +
  206 + }
  207 + else {
  208 + glEnable(GL_DEPTH_TEST);
  209 + glut_render_left_projection(); //set up a projection for the left half of the window
  210 + glut_render_modelview(); //set up the modelview matrix using camera details
  211 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen
  212 +
  213 + //_GT.glRandColorCenterlineGT(dlist1, _gt_t, colormap);
  214 + _GT.glCylinderGT(dlist1, _gt_t, colormap);
  215 +
  216 + glut_render_right_projection(); //set up a projection for the right half of the window
  217 + glut_render_modelview(); //set up the modelview matrix using camera details
  218 + //_T.glRandColorCenterlineT(dlist2, _t_gt, colormap);
  219 + _T.glCylinderT(dlist2, _t_gt, colormap);
  220 + }
183 } 221 }
184 } 222 }
185 } 223 }
@@ -383,13 +421,13 @@ void compare(float sigma, int device){ @@ -383,13 +421,13 @@ void compare(float sigma, int device){
383 std::cout << "FPR: " << FNR << std::endl; 421 std::cout << "FPR: " << FNR << std::endl;
384 } 422 }
385 423
386 -void map(float sigma, int device){ 424 +void map(float sigma, int device, float threshold){
387 425
388 - _GT.split(GT, T, sigma, device);  
389 - _T.split(T, GT, sigma, device); 426 + _GT.split(GT, T, sigma, device, threshold);
  427 + _T.split(T, GT, sigma, device, threshold);
390 428
391 - _GT.mapping(_T, _gt_t, device);  
392 - _T.mapping(_GT, _t_gt, device); 429 + _GT.mapping(_T, _gt_t, device, threshold);
  430 + _T.mapping(_GT, _t_gt, device, threshold);
393 431
394 size_t num = _gt_t.size(); // also create random color for unmapping edge, but won't be used though 432 size_t num = _gt_t.size(); // also create random color for unmapping edge, but won't be used though
395 colormap.resize(3 * num); // 3 portions compound RGB 433 colormap.resize(3 * num); // 3 portions compound RGB
@@ -437,7 +475,7 @@ void advertise(){ @@ -437,7 +475,7 @@ void advertise(){
437 std::cout<<"========================================================================="<<std::endl; 475 std::cout<<"========================================================================="<<std::endl;
438 std::cout<<"Thank you for using the NetMets network comparison tool!"<<std::endl; 476 std::cout<<"Thank you for using the NetMets network comparison tool!"<<std::endl;
439 std::cout<<"Scalable Tissue Imaging and Modeling (STIM) Lab, University of Houston"<<std::endl; 477 std::cout<<"Scalable Tissue Imaging and Modeling (STIM) Lab, University of Houston"<<std::endl;
440 - std::cout<<"Developers: Pranathi Vemuri, David Mayerich"<<std::endl; 478 + std::cout<<"Developers: Pranathi Vemuri, David Mayerich, Jiaming Guo"<<std::endl;
441 std::cout<<"Source: https://git.stim.ee.uh.edu/segmentation/netmets" <<std::endl; 479 std::cout<<"Source: https://git.stim.ee.uh.edu/segmentation/netmets" <<std::endl;
442 std::cout<<"========================================================================="<<std::endl<<std::endl; 480 std::cout<<"========================================================================="<<std::endl<<std::endl;
443 481
@@ -447,6 +485,8 @@ void advertise(){ @@ -447,6 +485,8 @@ void advertise(){
447 std::cout<<" load a file and display it using OpenGL"<<std::endl<<std::endl; 485 std::cout<<" load a file and display it using OpenGL"<<std::endl<<std::endl;
448 std::cout<<" netmets file1 file2 --device 0"<<std::endl; 486 std::cout<<" netmets file1 file2 --device 0"<<std::endl;
449 std::cout<<" compare two files using device 0 (if there isn't a gpu, use cpu)"<<std::endl<<std::endl; 487 std::cout<<" compare two files using device 0 (if there isn't a gpu, use cpu)"<<std::endl<<std::endl;
  488 + std::cout<<" netmets file1 file2 --mapping value"<<std::endl;
  489 + std::cout<<" mapping two files in random colors with a threshold of value"<<std::endl<<std::endl;
450 } 490 }
451 491
452 int main(int argc, char* argv[]) 492 int main(int argc, char* argv[])
@@ -460,6 +500,7 @@ int main(int argc, char* argv[]) @@ -460,6 +500,7 @@ int main(int argc, char* argv[])
460 args.add("device", "choose specific device to run", "0"); 500 args.add("device", "choose specific device to run", "0");
461 args.add("features", "save features to a CSV file, specify file name"); 501 args.add("features", "save features to a CSV file, specify file name");
462 args.add("mapping", "mapping input according to similarity"); 502 args.add("mapping", "mapping input according to similarity");
  503 + args.add("swc", "load swc file instead of obj file");
463 504
464 args.parse(argc, argv); //parse the user arguments 505 args.parse(argc, argv); //parse the user arguments
465 506
@@ -469,40 +510,69 @@ int main(int argc, char* argv[]) @@ -469,40 +510,69 @@ int main(int argc, char* argv[])
469 exit(1); //exit 510 exit(1); //exit
470 } 511 }
471 512
472 - if(args.nargs() >= 1){ //if at least one network file is specified  
473 - num_nets = 1; //set the number of networks to one  
474 - GT.load_obj(args.arg(0)); //load the specified file as the ground truth  
475 - /*GT.to_txt("Graph.txt");*/ 513 + if (args["swc"].is_set()) { // if it is to load a swc file, right now we only load two files(.swc and .obj)
  514 + if (args.nargs() >= 1) { // if at least one network file is specified
  515 + num_nets = 1; // set the number of networks to one
  516 + GT.load_swc(args.arg(0)); // load the specified file as the ground truth
  517 + }
  518 + if (args.nargs() == 2) { //if two files are specified, they will be displayed in neighboring viewports and compared
  519 + int device = args["device"].as_int(); //get the device value from the user
  520 + num_nets = 2; //set the number of networks to two
  521 + //does it need to be resampled??
  522 + float sigma = args["sigma"].as_float(); //get the sigma value from the user
  523 + T.load_swc(args.arg(1)); //load the second (test) network
  524 + if (args["features"].is_set()) //if the user wants to save features
  525 + features(args["features"].as_string());
  526 + GT = GT.resample(resample_rate * sigma); //resample both networks based on the sigma value
  527 + T = T.resample(resample_rate * sigma);
  528 + if (args["mapping"].is_set()) {
  529 + std::cout << "right now networks that are loaded from swc files do not need to be mapped with each other!" << std::endl;
  530 + exit(1);
  531 + }
  532 + else
  533 + compare(sigma, device); //run the comparison algorithm
  534 + }
476 } 535 }
477 536
478 - if(args.nargs() == 2){ //if two files are specified, they will be displayed in neighboring viewports and compared  
479 - int device = args["device"].as_int(); //get the device value from the user  
480 - num_nets = 2; //set the number of networks to two  
481 - float sigma = args["sigma"].as_float(); //get the sigma value from the user  
482 - T.load_obj(args.arg(1)); //load the second (test) network  
483 - if(args["features"].is_set()) //if the user wants to save features  
484 - features(args["features"].as_string());  
485 - GT = GT.resample(resample_rate * sigma); //resample both networks based on the sigma value  
486 - T = T.resample(resample_rate * sigma);  
487 - if(args["mapping"].is_set()){  
488 - map(sigma, device); 537 + else { //if it is to load a obj file
  538 + if (args.nargs() >= 1) { //if at least one network file is specified
  539 + num_nets = 1; //set the number of networks to one
  540 + GT.load_obj(args.arg(0)); //load the specified file as the ground truth
  541 + /*GT.to_txt("Graph.txt");*/
  542 + }
  543 + if (args.nargs() == 2) { //if two files are specified, they will be displayed in neighboring viewports and compared
  544 + int device = args["device"].as_int(); //get the device value from the user
  545 + num_nets = 2; //set the number of networks to two
  546 + float sigma = args["sigma"].as_float(); //get the sigma value from the user
  547 + T.load_obj(args.arg(1)); //load the second (test) network
  548 + if (args["features"].is_set()) //if the user wants to save features
  549 + features(args["features"].as_string());
  550 + GT = GT.resample(resample_rate * sigma); //resample both networks based on the sigma value
  551 + T = T.resample(resample_rate * sigma);
  552 + if (args["mapping"].is_set()) {
  553 + float threshold = args["mapping"].as_float();
  554 + map(sigma, device, threshold);
  555 + }
  556 + else
  557 + compare(sigma, device); //run the comparison algorithm
489 } 558 }
490 - else  
491 - compare(sigma, device); //run the comparison algorithm  
492 } 559 }
493 560
494 //if a GUI is requested, display the network using OpenGL 561 //if a GUI is requested, display the network using OpenGL
495 if(args["gui"].is_set()){ 562 if(args["gui"].is_set()){
496 - if(args["mapping"].is_set()){  
497 - ind = 1; 563 + if (args["swc"].is_set()) {
  564 + swc_ind = 1;
  565 + }
  566 + if (args["mapping"].is_set()) {
  567 + ind = 1; //set indicator of mapping to 1(true)
498 bb = _GT.boundingbox(); //generate a bounding volume 568 bb = _GT.boundingbox(); //generate a bounding volume
499 glut_initialize(); //create the GLUT window and set callback functions 569 glut_initialize(); //create the GLUT window and set callback functions
500 - glutMainLoop(); // enter GLUT event processing cycle 570 + glutMainLoop(); //enter GLUT event processing cycle
501 } 571 }
502 - else{ 572 + else {
503 bb = GT.boundingbox(); //generate a bounding volume 573 bb = GT.boundingbox(); //generate a bounding volume
504 glut_initialize(); //create the GLUT window and set callback functions 574 glut_initialize(); //create the GLUT window and set callback functions
505 - glutMainLoop(); // enter GLUT event processing cycle 575 + glutMainLoop(); //enter GLUT event processing cycle
506 } 576 }
507 } 577 }
508 } 578 }