From 8303b04dc449cfd022dbf08a2bf0529e23540bd0 Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Mon, 12 Sep 2016 14:48:45 -0500 Subject: [PATCH] fixed the bug and added comments --- stim/gl/gl_spider.h | 60 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/stim/gl/gl_spider.h b/stim/gl/gl_spider.h index b6113af..153757e 100644 --- a/stim/gl/gl_spider.h +++ b/stim/gl/gl_spider.h @@ -117,6 +117,7 @@ class gl_spider // : public virtual gl_texture std::vector< stim::vec3 > cL; //centerline up to the current point std::vector< stim::vec3 > cD; //directions up to the current point (debugging) std::vector< float > cM; //radius up to the current point + std::vector< float > cLen; //radius up to the current point stim::glnetwork nt; //network object holding the currently traced centerlines stim::glObj sk; //OBJ file storing the network (identical to above) @@ -726,21 +727,21 @@ class gl_spider // : public virtual gl_texture GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, direction_texID, - 0); - glBindFramebuffer(GL_FRAMEBUFFER, direction_buffID); - GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; - glDrawBuffers(1, DrawBuffers); - glBindTexture(GL_TEXTURE_2D, direction_texID); - glClearColor(1,1,1,1); - glClear(GL_COLOR_BUFFER_BIT); - glMatrixMode(GL_PROJECTION); + 0); ///Bind the texture to the 0th color attachement of the framebuffer + glBindFramebuffer(GL_FRAMEBUFFER, direction_buffID); ///Bind the buffer again (safety operation). + GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; ///Designate the texture to be the drawbuffer of the framebuffer + glDrawBuffers(1, DrawBuffers); ///Set the current drawbuffer to the texture. + glBindTexture(GL_TEXTURE_2D, direction_texID); ///Bind the Texture + glClearColor(1,1,1,1); ///Set clear color to white + glClear(GL_COLOR_BUFFER_BIT); ///Clear the texture + glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glViewport(0,0,2.0*n_pixels, numSamples*n_pixels); + glLoadIdentity(); ///Load identity matrix into the projection and modelview + glViewport(0,0,2.0*n_pixels, numSamples*n_pixels); ///Designate the viewport and orth gluOrtho2D(0.0,2.0*n_pixels,0.0,numSamples*n_pixels); glEnable(GL_TEXTURE_3D); - glBindTexture(GL_TEXTURE_3D, texID); + glBindTexture(GL_TEXTURE_3D, texID); ///Bind the larger 3D texture. CHECK_OPENGL_ERROR } @@ -807,12 +808,12 @@ class gl_spider // : public virtual gl_texture getCost(cudaTextureObject_t tObj, float* result, int n) { #ifdef TIMING - gpuStartTimer(); + gpuStartTimer(); ///Add timing variables #endif stim::vec cost = stim::cuda::get_cost(tObj, result, n, 2*n_pixels, n_pixels); ///call the cuda function with the appropriate texture buffer. #ifdef TIMING - cost_time += gpuStopTimer(); + cost_time += gpuStopTimer(); #endif current_cost = cost[1]; ///current cost. return cost[0]; @@ -833,9 +834,6 @@ class gl_spider // : public virtual gl_texture stim::rect ver; //Timing variables. - #ifdef TESTING - std::clock_t start; - #endif //--------------------------------------------------------------------------// //-----------------------------CONSTRUCTORS---------------------------------// @@ -917,7 +915,7 @@ class gl_spider // : public virtual gl_texture #endif } - ///destructor + ///destructor deletes all the texture and buffer objects. ~gl_spider (void) { @@ -966,7 +964,6 @@ class gl_spider // : public virtual gl_texture GenerateFBO(n_pixels*2, numSamplesPos*n_pixels, position_texID, position_buffID); CHECK_OPENGL_ERROR GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID); - CHECK_OPENGL_ERROR GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, length_texID, length_buffID); CHECK_OPENGL_ERROR @@ -978,10 +975,10 @@ class gl_spider // : public virtual gl_texture t_pos.Alloc(numSamplesPos); t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D); t_mag.Alloc(numSamplesMag); - t_mag.MapCudaTexture(length_texID, GL_TEXTURE_2D); - t_mag.Alloc(numSamplesMag); + t_len.MapCudaTexture(length_texID, GL_TEXTURE_2D); + t_len.Alloc(numSamplesMag); setMatrix(); - dList = glGenLists(4);//???????????????????????????? + dList = glGenLists(4); glListBase(dList); Bind(direction_texID, direction_buffID, numSamples, n_pixels); genDirectionVectors(5*stim::PI/4); @@ -995,9 +992,6 @@ class gl_spider // : public virtual gl_texture Bind(length_texID, length_buffID, numSamplesMag, n_pixels); genLengthVectors(); Unbind(); - Bind(cylinder_texID, cylinder_buffID, 27); -// DrawCylinder(); - Unbind(); } //--------------------------------------------------------------------------// @@ -1128,22 +1122,22 @@ class gl_spider // : public virtual gl_texture stim::vec getRotation(stim::vec3 dir) { - stim::vec out(0.0,0.0,0.0,0.0); - stim::vec3 from(0.0,0.0,1.0); - out[0] = acos(dir.dot(from))*180/stim::PI; - if(out[0] < 1.1){ + stim::vec out(0.0,0.0,0.0,0.0); ///The 4D rotation matrix for GL rotation + stim::vec3 from(0.0,0.0,1.0); ///Converting from template always involves 0,0,1 as a starting vector + out[0] = acos(dir.dot(from))*180/stim::PI; ///angle of rotation + if(out[0] < 1.0){ out[0] = 0.0; out[1] = 0.0; out[2] = 0.0; out[3] = 1.0; - } - else if(out[0] < -179.0) + } ///if we rotate less what one degree don't rotate + else if(out[0] < -179.0) ///if we rotate more than -179 degrees rotate 180. { out[0] = 180.0; out[1] = 1.0; out[2] = 0.0; out[3] = 0.0; - } else { + } else { ///the rotational axis is the cross fromxdir. stim::vec3 temp(0.0, 0.0, 0.0);; temp = (from.cross(dir)).norm(); out[1] = temp[0]; @@ -1300,13 +1294,13 @@ class gl_spider // : public virtual gl_texture void setSeeds(std::string file) { - std::ifstream myfile(file.c_str()); + std::ifstream myfile(file.c_str()); ///open a stream string line; if(myfile.is_open()) { while (getline(myfile, line)) { - float x, y, z, u, v, w, m; + float x, y, z, u, v, w, m; ///read the xyz uvw and m coordinates. myfile >> x >> y >> z >> u >> v >> w >> m; setSeed(x, y, z); setSeedVec(u, v, w); -- libgit2 0.21.4