Commit 8303b04dc449cfd022dbf08a2bf0529e23540bd0
1 parent
97508a2e
fixed the bug and added comments
Showing
1 changed file
with
27 additions
and
33 deletions
Show diff stats
stim/gl/gl_spider.h
@@ -117,6 +117,7 @@ class gl_spider // : public virtual gl_texture<T> | @@ -117,6 +117,7 @@ class gl_spider // : public virtual gl_texture<T> | ||
117 | 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 |
118 | 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) |
119 | 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 | ||
120 | 121 | ||
121 | stim::glnetwork<float> nt; //network object holding the currently traced centerlines | 122 | stim::glnetwork<float> nt; //network object holding the currently traced centerlines |
122 | 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) |
@@ -726,21 +727,21 @@ class gl_spider // : public virtual gl_texture<T> | @@ -726,21 +727,21 @@ class gl_spider // : public virtual gl_texture<T> | ||
726 | GL_COLOR_ATTACHMENT0, | 727 | GL_COLOR_ATTACHMENT0, |
727 | GL_TEXTURE_2D, | 728 | GL_TEXTURE_2D, |
728 | direction_texID, | 729 | direction_texID, |
729 | - 0); | ||
730 | - glBindFramebuffer(GL_FRAMEBUFFER, direction_buffID); | ||
731 | - GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; | ||
732 | - glDrawBuffers(1, DrawBuffers); | ||
733 | - glBindTexture(GL_TEXTURE_2D, direction_texID); | ||
734 | - glClearColor(1,1,1,1); | ||
735 | - glClear(GL_COLOR_BUFFER_BIT); | ||
736 | - 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); | ||
737 | glLoadIdentity(); | 738 | glLoadIdentity(); |
738 | glMatrixMode(GL_MODELVIEW); | 739 | glMatrixMode(GL_MODELVIEW); |
739 | - glLoadIdentity(); | ||
740 | - 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 | ||
741 | 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); |
742 | glEnable(GL_TEXTURE_3D); | 743 | glEnable(GL_TEXTURE_3D); |
743 | - glBindTexture(GL_TEXTURE_3D, texID); | 744 | + glBindTexture(GL_TEXTURE_3D, texID); ///Bind the larger 3D texture. |
744 | 745 | ||
745 | CHECK_OPENGL_ERROR | 746 | CHECK_OPENGL_ERROR |
746 | } | 747 | } |
@@ -807,12 +808,12 @@ class gl_spider // : public virtual gl_texture<T> | @@ -807,12 +808,12 @@ class gl_spider // : public virtual gl_texture<T> | ||
807 | getCost(cudaTextureObject_t tObj, float* result, int n) | 808 | getCost(cudaTextureObject_t tObj, float* result, int n) |
808 | { | 809 | { |
809 | #ifdef TIMING | 810 | #ifdef TIMING |
810 | - gpuStartTimer(); | 811 | + gpuStartTimer(); ///Add timing variables |
811 | #endif | 812 | #endif |
812 | stim::vec<int> cost = | 813 | stim::vec<int> cost = |
813 | 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. |
814 | #ifdef TIMING | 815 | #ifdef TIMING |
815 | - cost_time += gpuStopTimer(); | 816 | + cost_time += gpuStopTimer(); |
816 | #endif | 817 | #endif |
817 | current_cost = cost[1]; ///current cost. | 818 | current_cost = cost[1]; ///current cost. |
818 | return cost[0]; | 819 | return cost[0]; |
@@ -833,9 +834,6 @@ class gl_spider // : public virtual gl_texture<T> | @@ -833,9 +834,6 @@ class gl_spider // : public virtual gl_texture<T> | ||
833 | stim::rect<float> ver; | 834 | stim::rect<float> ver; |
834 | 835 | ||
835 | //Timing variables. | 836 | //Timing variables. |
836 | - #ifdef TESTING | ||
837 | - std::clock_t start; | ||
838 | - #endif | ||
839 | 837 | ||
840 | //--------------------------------------------------------------------------// | 838 | //--------------------------------------------------------------------------// |
841 | //-----------------------------CONSTRUCTORS---------------------------------// | 839 | //-----------------------------CONSTRUCTORS---------------------------------// |
@@ -917,7 +915,7 @@ class gl_spider // : public virtual gl_texture<T> | @@ -917,7 +915,7 @@ class gl_spider // : public virtual gl_texture<T> | ||
917 | #endif | 915 | #endif |
918 | } | 916 | } |
919 | 917 | ||
920 | - ///destructor | 918 | + ///destructor deletes all the texture and buffer objects. |
921 | ~gl_spider | 919 | ~gl_spider |
922 | (void) | 920 | (void) |
923 | { | 921 | { |
@@ -966,7 +964,6 @@ class gl_spider // : public virtual gl_texture<T> | @@ -966,7 +964,6 @@ class gl_spider // : public virtual gl_texture<T> | ||
966 | GenerateFBO(n_pixels*2, numSamplesPos*n_pixels, position_texID, position_buffID); | 964 | GenerateFBO(n_pixels*2, numSamplesPos*n_pixels, position_texID, position_buffID); |
967 | CHECK_OPENGL_ERROR | 965 | CHECK_OPENGL_ERROR |
968 | GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID); | 966 | GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID); |
969 | - | ||
970 | CHECK_OPENGL_ERROR | 967 | CHECK_OPENGL_ERROR |
971 | GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, length_texID, length_buffID); | 968 | GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, length_texID, length_buffID); |
972 | CHECK_OPENGL_ERROR | 969 | CHECK_OPENGL_ERROR |
@@ -978,10 +975,10 @@ class gl_spider // : public virtual gl_texture<T> | @@ -978,10 +975,10 @@ class gl_spider // : public virtual gl_texture<T> | ||
978 | t_pos.Alloc(numSamplesPos); | 975 | t_pos.Alloc(numSamplesPos); |
979 | t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D); | 976 | t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D); |
980 | t_mag.Alloc(numSamplesMag); | 977 | t_mag.Alloc(numSamplesMag); |
981 | - t_mag.MapCudaTexture(length_texID, GL_TEXTURE_2D); | ||
982 | - t_mag.Alloc(numSamplesMag); | 978 | + t_len.MapCudaTexture(length_texID, GL_TEXTURE_2D); |
979 | + t_len.Alloc(numSamplesMag); | ||
983 | setMatrix(); | 980 | setMatrix(); |
984 | - dList = glGenLists(4);//???????????????????????????? | 981 | + dList = glGenLists(4); |
985 | glListBase(dList); | 982 | glListBase(dList); |
986 | Bind(direction_texID, direction_buffID, numSamples, n_pixels); | 983 | Bind(direction_texID, direction_buffID, numSamples, n_pixels); |
987 | genDirectionVectors(5*stim::PI/4); | 984 | genDirectionVectors(5*stim::PI/4); |
@@ -995,9 +992,6 @@ class gl_spider // : public virtual gl_texture<T> | @@ -995,9 +992,6 @@ class gl_spider // : public virtual gl_texture<T> | ||
995 | Bind(length_texID, length_buffID, numSamplesMag, n_pixels); | 992 | Bind(length_texID, length_buffID, numSamplesMag, n_pixels); |
996 | genLengthVectors(); | 993 | genLengthVectors(); |
997 | Unbind(); | 994 | Unbind(); |
998 | - Bind(cylinder_texID, cylinder_buffID, 27); | ||
999 | -// DrawCylinder(); | ||
1000 | - Unbind(); | ||
1001 | } | 995 | } |
1002 | 996 | ||
1003 | //--------------------------------------------------------------------------// | 997 | //--------------------------------------------------------------------------// |
@@ -1128,22 +1122,22 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1128,22 +1122,22 @@ class gl_spider // : public virtual gl_texture<T> | ||
1128 | stim::vec<float> | 1122 | stim::vec<float> |
1129 | getRotation(stim::vec3<float> dir) | 1123 | getRotation(stim::vec3<float> dir) |
1130 | { | 1124 | { |
1131 | - stim::vec<float> out(0.0,0.0,0.0,0.0); | ||
1132 | - stim::vec3<float> from(0.0,0.0,1.0); | ||
1133 | - out[0] = acos(dir.dot(from))*180/stim::PI; | ||
1134 | - if(out[0] < 1.1){ | 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){ | ||
1135 | out[0] = 0.0; | 1129 | out[0] = 0.0; |
1136 | out[1] = 0.0; | 1130 | out[1] = 0.0; |
1137 | out[2] = 0.0; | 1131 | out[2] = 0.0; |
1138 | out[3] = 1.0; | 1132 | out[3] = 1.0; |
1139 | - } | ||
1140 | - else if(out[0] < -179.0) | 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. | ||
1141 | { | 1135 | { |
1142 | out[0] = 180.0; | 1136 | out[0] = 180.0; |
1143 | out[1] = 1.0; | 1137 | out[1] = 1.0; |
1144 | out[2] = 0.0; | 1138 | out[2] = 0.0; |
1145 | out[3] = 0.0; | 1139 | out[3] = 0.0; |
1146 | - } else { | 1140 | + } else { ///the rotational axis is the cross fromxdir. |
1147 | stim::vec3<float> temp(0.0, 0.0, 0.0);; | 1141 | stim::vec3<float> temp(0.0, 0.0, 0.0);; |
1148 | temp = (from.cross(dir)).norm(); | 1142 | temp = (from.cross(dir)).norm(); |
1149 | out[1] = temp[0]; | 1143 | out[1] = temp[0]; |
@@ -1300,13 +1294,13 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1300,13 +1294,13 @@ class gl_spider // : public virtual gl_texture<T> | ||
1300 | void | 1294 | void |
1301 | setSeeds(std::string file) | 1295 | setSeeds(std::string file) |
1302 | { | 1296 | { |
1303 | - std::ifstream myfile(file.c_str()); | 1297 | + std::ifstream myfile(file.c_str()); ///open a stream |
1304 | string line; | 1298 | string line; |
1305 | if(myfile.is_open()) | 1299 | if(myfile.is_open()) |
1306 | { | 1300 | { |
1307 | while (getline(myfile, line)) | 1301 | while (getline(myfile, line)) |
1308 | { | 1302 | { |
1309 | - float x, y, z, u, v, w, m; | 1303 | + float x, y, z, u, v, w, m; ///read the xyz uvw and m coordinates. |
1310 | myfile >> x >> y >> z >> u >> v >> w >> m; | 1304 | myfile >> x >> y >> z >> u >> v >> w >> m; |
1311 | setSeed(x, y, z); | 1305 | setSeed(x, y, z); |
1312 | setSeedVec(u, v, w); | 1306 | setSeedVec(u, v, w); |