Commit 7cd9bfa88e27d283a5878ad1fff9fe607401a34f

Authored by David Mayerich
2 parents 474c351a 9c5854ec

Merge branch 'master' of git.stim.ee.uh.edu:codebase/stimlib

Showing 2 changed files with 151 additions and 66 deletions   Show diff stats
stim/biomodels/cellset.h
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 3
4 #include <stim/math/vec3.h> 4 #include <stim/math/vec3.h>
5 #include <vector> 5 #include <vector>
  6 +#include <list>
6 #include <unordered_map> 7 #include <unordered_map>
7 #include <fstream> 8 #include <fstream>
8 9
@@ -129,4 +130,4 @@ public: @@ -129,4 +130,4 @@ public:
129 }; //end class cellset 130 }; //end class cellset
130 }; //end namespace stim 131 }; //end namespace stim
131 132
132 -#endif  
133 \ No newline at end of file 133 \ No newline at end of file
  134 +#endif
stim/gl/gl_spider.h
@@ -68,6 +68,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -68,6 +68,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
68 std::vector<stim::vec3<float> > dV; //A list of all the direction vectors. 68 std::vector<stim::vec3<float> > dV; //A list of all the direction vectors.
69 std::vector<stim::vec3<float> > pV; //A list of all test positions (relative to p) 69 std::vector<stim::vec3<float> > pV; //A list of all test positions (relative to p)
70 std::vector<float> mV; //A list of all the size vectors. 70 std::vector<float> mV; //A list of all the size vectors.
  71 + std::vector<float> lV; //A list of all the size vectors.
71 72
72 stim::matrix<float, 4> cT; //current Transformation matrix (tissue)->(texture) 73 stim::matrix<float, 4> cT; //current Transformation matrix (tissue)->(texture)
73 GLuint texID; //OpenGL ID for the texture to be traced 74 GLuint texID; //OpenGL ID for the texture to be traced
@@ -93,6 +94,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -93,6 +94,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
93 GLuint radius_buffID; //framebuffer ID, radius templates 94 GLuint radius_buffID; //framebuffer ID, radius templates
94 GLuint radius_texID; //texture ID, radius templates 95 GLuint radius_texID; //texture ID, radius templates
95 96
  97 + GLuint length_buffID; //framebuffer ID, radius templates
  98 + GLuint length_texID; //texture ID, radius templates
  99 +
96 GLuint cylinder_buffID; //framebuffer ID, cylinder (surrounding fiber) 100 GLuint cylinder_buffID; //framebuffer ID, cylinder (surrounding fiber)
97 GLuint cylinder_texID; //texture ID, cylinder 101 GLuint cylinder_texID; //texture ID, cylinder
98 102
@@ -113,6 +117,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -113,6 +117,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
113 std::vector< stim::vec3<float> > cL; //centerline up to the current point 117 std::vector< stim::vec3<float> > cL; //centerline up to the current point
114 std::vector< stim::vec3<float> > cD; //directions up to the current point (debugging) 118 std::vector< stim::vec3<float> > cD; //directions up to the current point (debugging)
115 std::vector< float > cM; //radius up to the current point 119 std::vector< float > cM; //radius up to the current point
  120 + std::vector< float > cLen; //radius up to the current point
116 121
117 stim::glnetwork<float> nt; //network object holding the currently traced centerlines 122 stim::glnetwork<float> nt; //network object holding the currently traced centerlines
118 stim::glObj<float> sk; //OBJ file storing the network (identical to above) 123 stim::glObj<float> sk; //OBJ file storing the network (identical to above)
@@ -132,6 +137,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -132,6 +137,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
132 stim::cuda::cuda_texture t_dir; //cuda_texture object used as an interface between OpenGL and cuda for direction vectors. 137 stim::cuda::cuda_texture t_dir; //cuda_texture object used as an interface between OpenGL and cuda for direction vectors.
133 stim::cuda::cuda_texture t_pos; //cuda_texture object used as an interface between OpenGL and cuda for position vectors. 138 stim::cuda::cuda_texture t_pos; //cuda_texture object used as an interface between OpenGL and cuda for position vectors.
134 stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. 139 stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors.
  140 + stim::cuda::cuda_texture t_len; //cuda_texture object used as an interface between OpenGL and cuda for size vectors.
135 141
136 142
137 #ifdef DEBUG 143 #ifdef DEBUG
@@ -222,7 +228,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -222,7 +228,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
222 /// changes the x, y, z size of the spider to minimize the cost 228 /// changes the x, y, z size of the spider to minimize the cost
223 /// function. 229 /// function.
224 void 230 void
225 - findOptimalScale() 231 + findOptimalRadius()
226 { 232 {
227 #ifdef TIMING 233 #ifdef TIMING
228 gpuStartTimer(); 234 gpuStartTimer();
@@ -243,6 +249,31 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -243,6 +249,31 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
243 setMagnitude(m*mV[best]); //adjust the magnitude. 249 setMagnitude(m*mV[best]); //adjust the magnitude.
244 } 250 }
245 251
  252 + /// Method for finding the best length for the spider.
  253 + /// changes the x, y, z size of the spider to minimize the cost
  254 + /// function.
  255 + void
  256 + findOptimalLength()
  257 + {
  258 + #ifdef TIMING
  259 + gpuStartTimer();
  260 + #endif
  261 + setMatrix(); //create the transformation.
  262 + glCallList(dList+3); //move the templates to p, d, m.
  263 + glFinish(); //flush the drawing pipeline.
  264 + #ifdef TIMING
  265 + size_time += gpuStopTimer();
  266 + #endif
  267 + int best = getCost(t_len.getTexture(), t_len.getAuxArray(), numSamplesMag); //get best cost.
  268 + #ifdef DEBUG
  269 +// name.str("");
  270 +// name << "Final_Cost_Size_" << iter << "_" << iter_siz << ".bmp";
  271 +// test(t_mag.getTexture(), n_pixels*2.0, numSamplesMag*n_pixels, name.str());
  272 +// iter_siz++;
  273 + #endif
  274 + setLength(mV[best]); //adjust the magnitude.
  275 + }
  276 +
246 277
247 278
248 279
@@ -485,6 +516,48 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -485,6 +516,48 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
485 glEndList(); ///finilize the displaylist. 516 glEndList(); ///finilize the displaylist.
486 } 517 }
487 518
  519 + ///@param float delta, How much the rectangles are allowed to expand.
  520 + ///Method for populating the buffer with the sampled texture.
  521 + ///Objects created are rectangles the with the created sizes.
  522 + ///All points are sampled from a texture.
  523 + ///Stored in a display list.
  524 + ///uses the default m <1,1,0>
  525 + void
  526 + genLengthVectors(float delta = 0.70)
  527 + {
  528 +
  529 + //Set up the vectors necessary for Rectangle creation.
  530 + stim::vec3<float> Y(1.0, 0.0, 0.0); //orthogonal vec.
  531 + stim::vec3<float> pos(0.0, 0.0, 0.0); //center of the future rect.
  532 + float mag = 1.0; ///size of the rectangle
  533 + stim::vec3<float> dir(0.0, 0.0, 1.0); ///normal of the rectangle plane.
  534 + stim::vec<float> temp(0.0,0.0,0.0);
  535 +
  536 + //Set up the variable necessary for vector creation.
  537 + float min = 1.0-delta; ///smallest size
  538 + float max = 1.0+delta; ///largers size.
  539 + float step = (max-min)/(numSamplesMag-1); ///the size variation from one rect to the next.
  540 + float factor;
  541 + glNewList(dList+3, GL_COMPILE);
  542 + for(int i = 0; i < numSamplesMag; i++){ ///for the number of position samples
  543 + //Create linear index
  544 + factor = (min+step*i)*mag; ///scaling factor
  545 + lV.push_back(factor); ///save the size factor for further use.
  546 + temp[0] = factor;
  547 + temp[1] = mag;
  548 + hor = stim::rect<float>(temp, ///generate a rectangle with the new vector as a normal.
  549 + pos, dir,
  550 + ((Y.cross(d)).cross(d))
  551 + .norm());
  552 + ver = stim::rect<float>(temp, ///generate another rectangle that's perpendicular the first but parallel to the cart vector.
  553 + pos, dir,
  554 + hor.n());
  555 + UpdateBuffer(0.0, 0.0+i*n_pixels); ///sample the necessary points and put them into a display list.
  556 + CHECK_OPENGL_ERROR
  557 + }
  558 + glEndList(); ///finilize the displaylist.
  559 + }
  560 +
488 ///@param float v_x x-coordinate in buffer-space, 561 ///@param float v_x x-coordinate in buffer-space,
489 ///@param float v_y y-coordinate in buffer-space. 562 ///@param float v_y y-coordinate in buffer-space.
490 ///Samples the texture space. 563 ///Samples the texture space.
@@ -654,21 +727,21 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -654,21 +727,21 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
654 GL_COLOR_ATTACHMENT0, 727 GL_COLOR_ATTACHMENT0,
655 GL_TEXTURE_2D, 728 GL_TEXTURE_2D,
656 direction_texID, 729 direction_texID,
657 - 0);  
658 - glBindFramebuffer(GL_FRAMEBUFFER, direction_buffID);  
659 - GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};  
660 - glDrawBuffers(1, DrawBuffers);  
661 - glBindTexture(GL_TEXTURE_2D, direction_texID);  
662 - glClearColor(1,1,1,1);  
663 - glClear(GL_COLOR_BUFFER_BIT);  
664 - glMatrixMode(GL_PROJECTION); 730 + 0); ///Bind the texture to the 0th color attachement of the framebuffer
  731 + glBindFramebuffer(GL_FRAMEBUFFER, direction_buffID); ///Bind the buffer again (safety operation).
  732 + GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; ///Designate the texture to be the drawbuffer of the framebuffer
  733 + glDrawBuffers(1, DrawBuffers); ///Set the current drawbuffer to the texture.
  734 + glBindTexture(GL_TEXTURE_2D, direction_texID); ///Bind the Texture
  735 + glClearColor(1,1,1,1); ///Set clear color to white
  736 + glClear(GL_COLOR_BUFFER_BIT); ///Clear the texture
  737 + glMatrixMode(GL_PROJECTION);
665 glLoadIdentity(); 738 glLoadIdentity();
666 glMatrixMode(GL_MODELVIEW); 739 glMatrixMode(GL_MODELVIEW);
667 - glLoadIdentity();  
668 - glViewport(0,0,2.0*n_pixels, numSamples*n_pixels); 740 + glLoadIdentity(); ///Load identity matrix into the projection and modelview
  741 + glViewport(0,0,2.0*n_pixels, numSamples*n_pixels); ///Designate the viewport and orth
669 gluOrtho2D(0.0,2.0*n_pixels,0.0,numSamples*n_pixels); 742 gluOrtho2D(0.0,2.0*n_pixels,0.0,numSamples*n_pixels);
670 glEnable(GL_TEXTURE_3D); 743 glEnable(GL_TEXTURE_3D);
671 - glBindTexture(GL_TEXTURE_3D, texID); 744 + glBindTexture(GL_TEXTURE_3D, texID); ///Bind the larger 3D texture.
672 745
673 CHECK_OPENGL_ERROR 746 CHECK_OPENGL_ERROR
674 } 747 }
@@ -735,12 +808,12 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -735,12 +808,12 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
735 getCost(cudaTextureObject_t tObj, float* result, int n) 808 getCost(cudaTextureObject_t tObj, float* result, int n)
736 { 809 {
737 #ifdef TIMING 810 #ifdef TIMING
738 - gpuStartTimer(); 811 + gpuStartTimer(); ///Add timing variables
739 #endif 812 #endif
740 stim::vec<int> cost = 813 stim::vec<int> cost =
741 stim::cuda::get_cost(tObj, result, n, 2*n_pixels, n_pixels); ///call the cuda function with the appropriate texture buffer. 814 stim::cuda::get_cost(tObj, result, n, 2*n_pixels, n_pixels); ///call the cuda function with the appropriate texture buffer.
742 #ifdef TIMING 815 #ifdef TIMING
743 - cost_time += gpuStopTimer(); 816 + cost_time += gpuStopTimer();
744 #endif 817 #endif
745 current_cost = cost[1]; ///current cost. 818 current_cost = cost[1]; ///current cost.
746 return cost[0]; 819 return cost[0];
@@ -761,9 +834,6 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -761,9 +834,6 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
761 stim::rect<float> ver; 834 stim::rect<float> ver;
762 835
763 //Timing variables. 836 //Timing variables.
764 - #ifdef TESTING  
765 - std::clock_t start;  
766 - #endif  
767 837
768 //--------------------------------------------------------------------------// 838 //--------------------------------------------------------------------------//
769 //-----------------------------CONSTRUCTORS---------------------------------// 839 //-----------------------------CONSTRUCTORS---------------------------------//
@@ -845,7 +915,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -845,7 +915,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
845 #endif 915 #endif
846 } 916 }
847 917
848 - ///destructor 918 + ///destructor deletes all the texture and buffer objects.
849 ~gl_spider 919 ~gl_spider
850 (void) 920 (void)
851 { 921 {
@@ -856,6 +926,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -856,6 +926,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
856 glDeleteBuffers(1, &position_buffID); 926 glDeleteBuffers(1, &position_buffID);
857 glDeleteTextures(1, &radius_texID); 927 glDeleteTextures(1, &radius_texID);
858 glDeleteBuffers(1, &radius_buffID); 928 glDeleteBuffers(1, &radius_buffID);
  929 + glDeleteTextures(1, &length_texID);
  930 + glDeleteBuffers(1, &length_buffID);
859 glDeleteTextures(1, &cylinder_texID); 931 glDeleteTextures(1, &cylinder_texID);
860 glDeleteBuffers(1, &cylinder_buffID); 932 glDeleteBuffers(1, &cylinder_buffID);
861 } 933 }
@@ -882,7 +954,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -882,7 +954,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
882 iter_dir = 0; 954 iter_dir = 0;
883 iter_siz = 0; 955 iter_siz = 0;
884 #endif 956 #endif
885 - stepsize = 10.0; 957 + stepsize = 3.0;
886 n_pixels = 16.0; 958 n_pixels = 16.0;
887 959
888 srand(100); 960 srand(100);
@@ -893,6 +965,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -893,6 +965,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
893 CHECK_OPENGL_ERROR 965 CHECK_OPENGL_ERROR
894 GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID); 966 GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID);
895 CHECK_OPENGL_ERROR 967 CHECK_OPENGL_ERROR
  968 + GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, length_texID, length_buffID);
  969 + CHECK_OPENGL_ERROR
896 GenerateFBO(16, 216, cylinder_texID, cylinder_buffID); 970 GenerateFBO(16, 216, cylinder_texID, cylinder_buffID);
897 CHECK_OPENGL_ERROR 971 CHECK_OPENGL_ERROR
898 t_dir.MapCudaTexture(direction_texID, GL_TEXTURE_2D); 972 t_dir.MapCudaTexture(direction_texID, GL_TEXTURE_2D);
@@ -901,8 +975,10 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -901,8 +975,10 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
901 t_pos.Alloc(numSamplesPos); 975 t_pos.Alloc(numSamplesPos);
902 t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D); 976 t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D);
903 t_mag.Alloc(numSamplesMag); 977 t_mag.Alloc(numSamplesMag);
  978 + t_len.MapCudaTexture(length_texID, GL_TEXTURE_2D);
  979 + t_len.Alloc(numSamplesMag);
904 setMatrix(); 980 setMatrix();
905 - dList = glGenLists(3); 981 + dList = glGenLists(4);
906 glListBase(dList); 982 glListBase(dList);
907 Bind(direction_texID, direction_buffID, numSamples, n_pixels); 983 Bind(direction_texID, direction_buffID, numSamples, n_pixels);
908 genDirectionVectors(5*stim::PI/4); 984 genDirectionVectors(5*stim::PI/4);
@@ -913,8 +989,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -913,8 +989,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
913 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); 989 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
914 genMagnitudeVectors(); 990 genMagnitudeVectors();
915 Unbind(); 991 Unbind();
916 - Bind(cylinder_texID, cylinder_buffID, 27);  
917 -// DrawCylinder(); 992 + Bind(length_texID, length_buffID, numSamplesMag, n_pixels);
  993 + genLengthVectors();
918 Unbind(); 994 Unbind();
919 } 995 }
920 996
@@ -984,12 +1060,20 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -984,12 +1060,20 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
984 1060
985 1061
986 ///@param float mag, size of the sampled region. 1062 ///@param float mag, size of the sampled region.
987 - ///Sets the m vector to the input mag for both templates. 1063 + ///Sets the m value to the input mag for both templates.
988 void 1064 void
989 setMagnitude(float mag) 1065 setMagnitude(float mag)
990 { 1066 {
991 m = mag; 1067 m = mag;
992 } 1068 }
  1069 +
  1070 + ///@param float len, length of the sampled region.
  1071 + ///Sets the length value to the input len for both templates.
  1072 + void
  1073 + setLength(float len)
  1074 + {
  1075 + length = len;
  1076 + }
993 1077
994 ///@param float x, voxel size in the x direction. 1078 ///@param float x, voxel size in the x direction.
995 ///@param float y, voxel size in the y direction. 1079 ///@param float y, voxel size in the y direction.
@@ -1038,32 +1122,32 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1038,32 +1122,32 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1038 stim::vec<float> 1122 stim::vec<float>
1039 getRotation(stim::vec3<float> dir) 1123 getRotation(stim::vec3<float> dir)
1040 { 1124 {
1041 - stim::vec<float> out(0.0,0.0,0.0,0.0);  
1042 - stim::vec3<float> from(0.0,0.0,1.0);  
1043 - out[0] = acos(dir.dot(from))*180/stim::PI;  
1044 - #ifdef DEBUG  
1045 - std::cout << "out is " << out << std::endl;  
1046 - std::cout << "when rotating from " << from << " to " << dir << std::endl;  
1047 - #endif  
1048 - if(out[0] < 0.01){ 1125 + stim::vec<float> out(0.0,0.0,0.0,0.0); ///The 4D rotation matrix for GL rotation
  1126 + stim::vec3<float> from(0.0,0.0,1.0); ///Converting from template always involves 0,0,1 as a starting vector
  1127 + out[0] = acos(dir.dot(from))*180/stim::PI; ///angle of rotation
  1128 + if(out[0] < 1.0){
1049 out[0] = 0.0; 1129 out[0] = 0.0;
1050 out[1] = 0.0; 1130 out[1] = 0.0;
1051 out[2] = 0.0; 1131 out[2] = 0.0;
1052 out[3] = 1.0; 1132 out[3] = 1.0;
1053 - }  
1054 - else if(out[0] < -180.0+0.01) 1133 + } ///if we rotate less what one degree don't rotate
  1134 + else if(out[0] < -179.0) ///if we rotate more than -179 degrees rotate 180.
1055 { 1135 {
1056 out[0] = 180.0; 1136 out[0] = 180.0;
1057 out[1] = 1.0; 1137 out[1] = 1.0;
1058 out[2] = 0.0; 1138 out[2] = 0.0;
1059 out[3] = 0.0; 1139 out[3] = 0.0;
1060 - } else { 1140 + } else { ///the rotational axis is the cross fromxdir.
1061 stim::vec3<float> temp(0.0, 0.0, 0.0);; 1141 stim::vec3<float> temp(0.0, 0.0, 0.0);;
1062 temp = (from.cross(dir)).norm(); 1142 temp = (from.cross(dir)).norm();
1063 out[1] = temp[0]; 1143 out[1] = temp[0];
1064 out[2] = temp[1]; 1144 out[2] = temp[1];
1065 out[3] = temp[2]; 1145 out[3] = temp[2];
1066 } 1146 }
  1147 + #ifdef DEBUG
  1148 + std::cout << "out is " << out << std::endl;
  1149 + std::cout << "when rotating from " << from << " to " << dir << std::endl;
  1150 + #endif
1067 return out; 1151 return out;
1068 } 1152 }
1069 1153
@@ -1210,13 +1294,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1210,13 +1294,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1210 void 1294 void
1211 setSeeds(std::string file) 1295 setSeeds(std::string file)
1212 { 1296 {
1213 - std::ifstream myfile(file.c_str()); 1297 + std::ifstream myfile(file.c_str()); ///open a stream
1214 string line; 1298 string line;
1215 if(myfile.is_open()) 1299 if(myfile.is_open())
1216 { 1300 {
1217 while (getline(myfile, line)) 1301 while (getline(myfile, line))
1218 { 1302 {
1219 - float x, y, z, u, v, w, m; 1303 + float x, y, z, u, v, w, m; ///read the xyz uvw and m coordinates.
1220 myfile >> x >> y >> z >> u >> v >> w >> m; 1304 myfile >> x >> y >> z >> u >> v >> w >> m;
1221 setSeed(x, y, z); 1305 setSeed(x, y, z);
1222 setSeedVec(u, v, w); 1306 setSeedVec(u, v, w);
@@ -1303,7 +1387,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1303,7 +1387,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1303 findOptimalPosition(); 1387 findOptimalPosition();
1304 Unbind(); 1388 Unbind();
1305 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); 1389 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
1306 - findOptimalScale(); 1390 + findOptimalRadius();
1307 Unbind(); 1391 Unbind();
1308 CHECK_OPENGL_ERROR 1392 CHECK_OPENGL_ERROR
1309 1393
@@ -1351,12 +1435,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1351,12 +1435,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1351 outFile.open("New_Pos_Vectors.txt"); 1435 outFile.open("New_Pos_Vectors.txt");
1352 outFile << name.str().c_str(); 1436 outFile << name.str().c_str();
1353 } 1437 }
  1438 +/*
1354 void 1439 void
1355 DrawCylinder() 1440 DrawCylinder()
1356 { 1441 {
1357 glNewList(dList+3, GL_COMPILE); 1442 glNewList(dList+3, GL_COMPILE);
1358 float z0 = -0.5; float z1 = 0.5; float r0 = 0.5; 1443 float z0 = -0.5; float z1 = 0.5; float r0 = 0.5;
1359 - float x,y; 1444 + float x,y;
1360 float xold = 0.5; float yold = 0.0; 1445 float xold = 0.5; float yold = 0.0;
1361 float step = 360.0/numSamples*32; 1446 float step = 360.0/numSamples*32;
1362 //float step = 360.0/8.0; 1447 //float step = 360.0/8.0;
@@ -1387,7 +1472,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1387,7 +1472,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1387 glEnd(); 1472 glEnd();
1388 glEndList(); 1473 glEndList();
1389 } 1474 }
1390 - 1475 +*/
1391 ///need to return the cylinder. 1476 ///need to return the cylinder.
1392 ///SOMETHING MIGHT BE GOING ON HERE IN GENERATE BUFFER. 1477 ///SOMETHING MIGHT BE GOING ON HERE IN GENERATE BUFFER.
1393 void 1478 void
@@ -1455,7 +1540,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1455,7 +1540,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1455 // Unbind(); 1540 // Unbind();
1456 //THIS IS EXPERIMENTAL 1541 //THIS IS EXPERIMENTAL
1457 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); 1542 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
1458 - findOptimalScale(); 1543 + findOptimalRadius();
1459 Unbind(); 1544 Unbind();
1460 //THIS IS EXPERIMENTAL 1545 //THIS IS EXPERIMENTAL
1461 1546
@@ -1475,31 +1560,30 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1475,31 +1560,30 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1475 gpuStartTimer(); 1560 gpuStartTimer();
1476 #endif 1561 #endif
1477 1562
1478 -// float s = 3.0;  
1479 - GLuint selectBuf[2048];  
1480 - GLint hits;  
1481 - glSelectBuffer(2048, selectBuf);  
1482 - glDisable(GL_CULL_FACE);  
1483 - (void) glRenderMode(GL_SELECT); 1563 + GLuint selectBuf[2048]; ///size of the selection buffer in bytes.
  1564 + GLint hits; ///hit fibers
  1565 + glSelectBuffer(2048, selectBuf); ///bind the selection mode to the selection buffer.
  1566 + glDisable(GL_CULL_FACE); ///Disable cullFace
  1567 + (void) glRenderMode(GL_SELECT); ///initialize GL select mode.
1484 //Init Names stack 1568 //Init Names stack
1485 1569
1486 - glInitNames();  
1487 - glPushName(1); 1570 + glInitNames(); ///Initialize the naming array.
  1571 + glPushName(1); ///Push a single name to the stack.
1488 1572
1489 CHECK_OPENGL_ERROR 1573 CHECK_OPENGL_ERROR
1490 //What would that vessel see in front of it. 1574 //What would that vessel see in front of it.
1491 - camSel.setPosition(loc);  
1492 - camSel.setFocalDistance(mag/stepsize); 1575 + camSel.setPosition(loc); ///Set the viewing camera
  1576 + camSel.setFocalDistance(mag/stepsize); ///Set how far the fiber looks forward.
1493 camSel.LookAt((loc[0]+dir[0]*mag/stepsize), 1577 camSel.LookAt((loc[0]+dir[0]*mag/stepsize),
1494 (loc[1]+dir[1]*mag/stepsize), 1578 (loc[1]+dir[1]*mag/stepsize),
1495 - (loc[2]+dir[2]*mag/stepsize));  
1496 - ps = camSel.getPosition(); 1579 + (loc[2]+dir[2]*mag/stepsize)); ///Set the look direction
  1580 + ps = camSel.getPosition(); ///get all the necessary rotation variable for openGL
1497 ups = camSel.getUp(); 1581 ups = camSel.getUp();
1498 ds = camSel.getLookAt(); 1582 ds = camSel.getLookAt();
1499 - glMatrixMode(GL_PROJECTION);  
1500 - glPushMatrix(); 1583 + glMatrixMode(GL_PROJECTION); ///Push the projection matrix.
  1584 + glPushMatrix(); ///Reset the current projection matrix
1501 glLoadIdentity(); 1585 glLoadIdentity();
1502 - glOrtho(-mag/stepsize/2.0, mag/stepsize/2.0, -mag/stepsize/2.0, mag/stepsize/2.0, 0.0, mag/stepsize/2.0); 1586 + glOrtho(-mag/stepsize/2.0, mag/stepsize/2.0, -mag/stepsize/2.0, mag/stepsize/2.0, 0.0, mag/stepsize/2.0); ///Finalize the look paramenters
1503 glMatrixMode(GL_MODELVIEW); 1587 glMatrixMode(GL_MODELVIEW);
1504 glPushMatrix(); 1588 glPushMatrix();
1505 glLoadIdentity(); 1589 glLoadIdentity();
@@ -1508,36 +1592,36 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1508,36 +1592,36 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1508 gluLookAt(ps[0], ps[1], ps[2], 1592 gluLookAt(ps[0], ps[1], ps[2],
1509 ds[0], ds[1], ds[2], 1593 ds[0], ds[1], ds[2],
1510 ups[0], ups[1], ups[2]); 1594 ups[0], ups[1], ups[2]);
1511 -  
1512 - sk.Render(); 1595 + ///Set the look at distance
  1596 + sk.Render(); ///Render the network
1513 // nt.Render(); 1597 // nt.Render();
1514 1598
1515 CHECK_OPENGL_ERROR 1599 CHECK_OPENGL_ERROR
1516 1600
1517 1601
1518 - glLoadName((int) sk.numL()); 1602 + glLoadName((int) sk.numL()); ///Load all the names
1519 // glLoadName(nt.sizeE()); 1603 // glLoadName(nt.sizeE());
1520 1604
1521 - sk.RenderLine(cL); 1605 + sk.RenderLine(cL); ///Render the current line.
1522 // nt.RenderLine(cL); 1606 // nt.RenderLine(cL);
1523 1607
1524 // glPopName(); 1608 // glPopName();
1525 - glFlush(); 1609 + glFlush(); ///Flush the buffer
1526 1610
1527 glMatrixMode(GL_PROJECTION); 1611 glMatrixMode(GL_PROJECTION);
1528 glPopMatrix(); 1612 glPopMatrix();
1529 glMatrixMode(GL_MODELVIEW); 1613 glMatrixMode(GL_MODELVIEW);
1530 CHECK_OPENGL_ERROR 1614 CHECK_OPENGL_ERROR
1531 - glPopMatrix(); 1615 + glPopMatrix(); ///clear the vis matrices and pop the matrix
1532 1616
1533 // glEnable(GL_CULL_FACE); 1617 // glEnable(GL_CULL_FACE);
1534 - hits = glRenderMode(GL_RENDER);  
1535 - int found_hits = processHits(hits, selectBuf); 1618 + hits = glRenderMode(GL_RENDER); ///Check for hits.
  1619 + int found_hits = processHits(hits, selectBuf); ///Process the hits.
1536 #ifdef TIMING 1620 #ifdef TIMING
1537 hit_time += gpuStopTimer(); 1621 hit_time += gpuStopTimer();
1538 #endif 1622 #endif
1539 1623
1540 - return found_hits; 1624 + return found_hits; ///return whether we hit something or not.
1541 } 1625 }
1542 1626
1543 //Given a size of the array (hits) and the memory holding it (buffer) 1627 //Given a size of the array (hits) and the memory holding it (buffer)
@@ -1545,7 +1629,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1545,7 +1629,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1545 int 1629 int
1546 processHits(GLint hits, GLuint buffer[]) 1630 processHits(GLint hits, GLuint buffer[])
1547 { 1631 {
1548 - GLuint *ptr; 1632 + GLuint *ptr; ///pointer to the detection buffer
1549 ptr = (GLuint *) buffer; 1633 ptr = (GLuint *) buffer;
1550 ptr++; 1634 ptr++;
1551 ptr++; //Skip the minimum depth value. 1635 ptr++; //Skip the minimum depth value.