diff --git a/stim/gl/gl_spider.h b/stim/gl/gl_spider.h index 1554e6b..b6113af 100644 --- a/stim/gl/gl_spider.h +++ b/stim/gl/gl_spider.h @@ -68,6 +68,7 @@ class gl_spider // : public virtual gl_texture std::vector > dV; //A list of all the direction vectors. std::vector > pV; //A list of all test positions (relative to p) std::vector mV; //A list of all the size vectors. + std::vector lV; //A list of all the size vectors. stim::matrix cT; //current Transformation matrix (tissue)->(texture) GLuint texID; //OpenGL ID for the texture to be traced @@ -93,6 +94,9 @@ class gl_spider // : public virtual gl_texture GLuint radius_buffID; //framebuffer ID, radius templates GLuint radius_texID; //texture ID, radius templates + GLuint length_buffID; //framebuffer ID, radius templates + GLuint length_texID; //texture ID, radius templates + GLuint cylinder_buffID; //framebuffer ID, cylinder (surrounding fiber) GLuint cylinder_texID; //texture ID, cylinder @@ -132,6 +136,7 @@ class gl_spider // : public virtual gl_texture stim::cuda::cuda_texture t_dir; //cuda_texture object used as an interface between OpenGL and cuda for direction vectors. stim::cuda::cuda_texture t_pos; //cuda_texture object used as an interface between OpenGL and cuda for position vectors. stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. + stim::cuda::cuda_texture t_len; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. #ifdef DEBUG @@ -222,7 +227,7 @@ class gl_spider // : public virtual gl_texture /// changes the x, y, z size of the spider to minimize the cost /// function. void - findOptimalScale() + findOptimalRadius() { #ifdef TIMING gpuStartTimer(); @@ -243,6 +248,31 @@ class gl_spider // : public virtual gl_texture setMagnitude(m*mV[best]); //adjust the magnitude. } + /// Method for finding the best length for the spider. + /// changes the x, y, z size of the spider to minimize the cost + /// function. + void + findOptimalLength() + { + #ifdef TIMING + gpuStartTimer(); + #endif + setMatrix(); //create the transformation. + glCallList(dList+3); //move the templates to p, d, m. + glFinish(); //flush the drawing pipeline. + #ifdef TIMING + size_time += gpuStopTimer(); + #endif + int best = getCost(t_len.getTexture(), t_len.getAuxArray(), numSamplesMag); //get best cost. + #ifdef DEBUG +// name.str(""); +// name << "Final_Cost_Size_" << iter << "_" << iter_siz << ".bmp"; +// test(t_mag.getTexture(), n_pixels*2.0, numSamplesMag*n_pixels, name.str()); +// iter_siz++; + #endif + setLength(mV[best]); //adjust the magnitude. + } + @@ -485,6 +515,48 @@ class gl_spider // : public virtual gl_texture glEndList(); ///finilize the displaylist. } + ///@param float delta, How much the rectangles are allowed to expand. + ///Method for populating the buffer with the sampled texture. + ///Objects created are rectangles the with the created sizes. + ///All points are sampled from a texture. + ///Stored in a display list. + ///uses the default m <1,1,0> + void + genLengthVectors(float delta = 0.70) + { + + //Set up the vectors necessary for Rectangle creation. + stim::vec3 Y(1.0, 0.0, 0.0); //orthogonal vec. + stim::vec3 pos(0.0, 0.0, 0.0); //center of the future rect. + float mag = 1.0; ///size of the rectangle + stim::vec3 dir(0.0, 0.0, 1.0); ///normal of the rectangle plane. + stim::vec temp(0.0,0.0,0.0); + + //Set up the variable necessary for vector creation. + float min = 1.0-delta; ///smallest size + float max = 1.0+delta; ///largers size. + float step = (max-min)/(numSamplesMag-1); ///the size variation from one rect to the next. + float factor; + glNewList(dList+3, GL_COMPILE); + for(int i = 0; i < numSamplesMag; i++){ ///for the number of position samples + //Create linear index + factor = (min+step*i)*mag; ///scaling factor + lV.push_back(factor); ///save the size factor for further use. + temp[0] = factor; + temp[1] = mag; + hor = stim::rect(temp, ///generate a rectangle with the new vector as a normal. + pos, dir, + ((Y.cross(d)).cross(d)) + .norm()); + ver = stim::rect(temp, ///generate another rectangle that's perpendicular the first but parallel to the cart vector. + pos, dir, + hor.n()); + UpdateBuffer(0.0, 0.0+i*n_pixels); ///sample the necessary points and put them into a display list. + CHECK_OPENGL_ERROR + } + glEndList(); ///finilize the displaylist. + } + ///@param float v_x x-coordinate in buffer-space, ///@param float v_y y-coordinate in buffer-space. ///Samples the texture space. @@ -856,6 +928,8 @@ class gl_spider // : public virtual gl_texture glDeleteBuffers(1, &position_buffID); glDeleteTextures(1, &radius_texID); glDeleteBuffers(1, &radius_buffID); + glDeleteTextures(1, &length_texID); + glDeleteBuffers(1, &length_buffID); glDeleteTextures(1, &cylinder_texID); glDeleteBuffers(1, &cylinder_buffID); } @@ -882,7 +956,7 @@ class gl_spider // : public virtual gl_texture iter_dir = 0; iter_siz = 0; #endif - stepsize = 10.0; + stepsize = 3.0; n_pixels = 16.0; srand(100); @@ -892,6 +966,9 @@ 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 GenerateFBO(16, 216, cylinder_texID, cylinder_buffID); CHECK_OPENGL_ERROR @@ -901,8 +978,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); setMatrix(); - dList = glGenLists(3); + dList = glGenLists(4);//???????????????????????????? glListBase(dList); Bind(direction_texID, direction_buffID, numSamples, n_pixels); genDirectionVectors(5*stim::PI/4); @@ -913,6 +992,9 @@ class gl_spider // : public virtual gl_texture Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); genMagnitudeVectors(); Unbind(); + Bind(length_texID, length_buffID, numSamplesMag, n_pixels); + genLengthVectors(); + Unbind(); Bind(cylinder_texID, cylinder_buffID, 27); // DrawCylinder(); Unbind(); @@ -984,12 +1066,20 @@ class gl_spider // : public virtual gl_texture ///@param float mag, size of the sampled region. - ///Sets the m vector to the input mag for both templates. + ///Sets the m value to the input mag for both templates. void setMagnitude(float mag) { m = mag; } + + ///@param float len, length of the sampled region. + ///Sets the length value to the input len for both templates. + void + setLength(float len) + { + length = len; + } ///@param float x, voxel size in the x direction. ///@param float y, voxel size in the y direction. @@ -1041,17 +1131,13 @@ class gl_spider // : public virtual gl_texture 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; - #ifdef DEBUG - std::cout << "out is " << out << std::endl; - std::cout << "when rotating from " << from << " to " << dir << std::endl; - #endif - if(out[0] < 0.01){ + if(out[0] < 1.1){ out[0] = 0.0; out[1] = 0.0; out[2] = 0.0; out[3] = 1.0; } - else if(out[0] < -180.0+0.01) + else if(out[0] < -179.0) { out[0] = 180.0; out[1] = 1.0; @@ -1064,6 +1150,10 @@ class gl_spider // : public virtual gl_texture out[2] = temp[1]; out[3] = temp[2]; } + #ifdef DEBUG + std::cout << "out is " << out << std::endl; + std::cout << "when rotating from " << from << " to " << dir << std::endl; + #endif return out; } @@ -1303,7 +1393,7 @@ class gl_spider // : public virtual gl_texture findOptimalPosition(); Unbind(); Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); - findOptimalScale(); + findOptimalRadius(); Unbind(); CHECK_OPENGL_ERROR @@ -1351,12 +1441,13 @@ class gl_spider // : public virtual gl_texture outFile.open("New_Pos_Vectors.txt"); outFile << name.str().c_str(); } +/* void DrawCylinder() { glNewList(dList+3, GL_COMPILE); float z0 = -0.5; float z1 = 0.5; float r0 = 0.5; - float x,y; + float x,y; float xold = 0.5; float yold = 0.0; float step = 360.0/numSamples*32; //float step = 360.0/8.0; @@ -1387,7 +1478,7 @@ class gl_spider // : public virtual gl_texture glEnd(); glEndList(); } - +*/ ///need to return the cylinder. ///SOMETHING MIGHT BE GOING ON HERE IN GENERATE BUFFER. void @@ -1455,7 +1546,7 @@ class gl_spider // : public virtual gl_texture // Unbind(); //THIS IS EXPERIMENTAL Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); - findOptimalScale(); + findOptimalRadius(); Unbind(); //THIS IS EXPERIMENTAL -- libgit2 0.21.4