Commit 97508a2e1c47dc33e10fe009f5f8adc7e6da706f

Authored by Pavel Govyadinov
1 parent fac43319

Added mehtods for creating and calling length templates, there is an error somew…

…here that causes a buffer overwrite
Showing 1 changed file with 105 additions and 14 deletions   Show diff stats
stim/gl/gl_spider.h
@@ -68,6 +68,7 @@ class gl_spider // : public virtual gl_texture<T> @@ -68,6 +68,7 @@ class gl_spider // : public virtual gl_texture<T>
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
@@ -132,6 +136,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -132,6 +136,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. 136 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. 137 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. 138 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_len; //cuda_texture object used as an interface between OpenGL and cuda for size vectors.
135 140
136 141
137 #ifdef DEBUG 142 #ifdef DEBUG
@@ -222,7 +227,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -222,7 +227,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 227 /// changes the x, y, z size of the spider to minimize the cost
223 /// function. 228 /// function.
224 void 229 void
225 - findOptimalScale() 230 + findOptimalRadius()
226 { 231 {
227 #ifdef TIMING 232 #ifdef TIMING
228 gpuStartTimer(); 233 gpuStartTimer();
@@ -243,6 +248,31 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -243,6 +248,31 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
243 setMagnitude(m*mV[best]); //adjust the magnitude. 248 setMagnitude(m*mV[best]); //adjust the magnitude.
244 } 249 }
245 250
  251 + /// Method for finding the best length for the spider.
  252 + /// changes the x, y, z size of the spider to minimize the cost
  253 + /// function.
  254 + void
  255 + findOptimalLength()
  256 + {
  257 + #ifdef TIMING
  258 + gpuStartTimer();
  259 + #endif
  260 + setMatrix(); //create the transformation.
  261 + glCallList(dList+3); //move the templates to p, d, m.
  262 + glFinish(); //flush the drawing pipeline.
  263 + #ifdef TIMING
  264 + size_time += gpuStopTimer();
  265 + #endif
  266 + int best = getCost(t_len.getTexture(), t_len.getAuxArray(), numSamplesMag); //get best cost.
  267 + #ifdef DEBUG
  268 +// name.str("");
  269 +// name << "Final_Cost_Size_" << iter << "_" << iter_siz << ".bmp";
  270 +// test(t_mag.getTexture(), n_pixels*2.0, numSamplesMag*n_pixels, name.str());
  271 +// iter_siz++;
  272 + #endif
  273 + setLength(mV[best]); //adjust the magnitude.
  274 + }
  275 +
246 276
247 277
248 278
@@ -485,6 +515,48 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -485,6 +515,48 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
485 glEndList(); ///finilize the displaylist. 515 glEndList(); ///finilize the displaylist.
486 } 516 }
487 517
  518 + ///@param float delta, How much the rectangles are allowed to expand.
  519 + ///Method for populating the buffer with the sampled texture.
  520 + ///Objects created are rectangles the with the created sizes.
  521 + ///All points are sampled from a texture.
  522 + ///Stored in a display list.
  523 + ///uses the default m <1,1,0>
  524 + void
  525 + genLengthVectors(float delta = 0.70)
  526 + {
  527 +
  528 + //Set up the vectors necessary for Rectangle creation.
  529 + stim::vec3<float> Y(1.0, 0.0, 0.0); //orthogonal vec.
  530 + stim::vec3<float> pos(0.0, 0.0, 0.0); //center of the future rect.
  531 + float mag = 1.0; ///size of the rectangle
  532 + stim::vec3<float> dir(0.0, 0.0, 1.0); ///normal of the rectangle plane.
  533 + stim::vec<float> temp(0.0,0.0,0.0);
  534 +
  535 + //Set up the variable necessary for vector creation.
  536 + float min = 1.0-delta; ///smallest size
  537 + float max = 1.0+delta; ///largers size.
  538 + float step = (max-min)/(numSamplesMag-1); ///the size variation from one rect to the next.
  539 + float factor;
  540 + glNewList(dList+3, GL_COMPILE);
  541 + for(int i = 0; i < numSamplesMag; i++){ ///for the number of position samples
  542 + //Create linear index
  543 + factor = (min+step*i)*mag; ///scaling factor
  544 + lV.push_back(factor); ///save the size factor for further use.
  545 + temp[0] = factor;
  546 + temp[1] = mag;
  547 + hor = stim::rect<float>(temp, ///generate a rectangle with the new vector as a normal.
  548 + pos, dir,
  549 + ((Y.cross(d)).cross(d))
  550 + .norm());
  551 + ver = stim::rect<float>(temp, ///generate another rectangle that's perpendicular the first but parallel to the cart vector.
  552 + pos, dir,
  553 + hor.n());
  554 + UpdateBuffer(0.0, 0.0+i*n_pixels); ///sample the necessary points and put them into a display list.
  555 + CHECK_OPENGL_ERROR
  556 + }
  557 + glEndList(); ///finilize the displaylist.
  558 + }
  559 +
488 ///@param float v_x x-coordinate in buffer-space, 560 ///@param float v_x x-coordinate in buffer-space,
489 ///@param float v_y y-coordinate in buffer-space. 561 ///@param float v_y y-coordinate in buffer-space.
490 ///Samples the texture space. 562 ///Samples the texture space.
@@ -856,6 +928,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -856,6 +928,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
856 glDeleteBuffers(1, &position_buffID); 928 glDeleteBuffers(1, &position_buffID);
857 glDeleteTextures(1, &radius_texID); 929 glDeleteTextures(1, &radius_texID);
858 glDeleteBuffers(1, &radius_buffID); 930 glDeleteBuffers(1, &radius_buffID);
  931 + glDeleteTextures(1, &length_texID);
  932 + glDeleteBuffers(1, &length_buffID);
859 glDeleteTextures(1, &cylinder_texID); 933 glDeleteTextures(1, &cylinder_texID);
860 glDeleteBuffers(1, &cylinder_buffID); 934 glDeleteBuffers(1, &cylinder_buffID);
861 } 935 }
@@ -882,7 +956,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -882,7 +956,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
882 iter_dir = 0; 956 iter_dir = 0;
883 iter_siz = 0; 957 iter_siz = 0;
884 #endif 958 #endif
885 - stepsize = 10.0; 959 + stepsize = 3.0;
886 n_pixels = 16.0; 960 n_pixels = 16.0;
887 961
888 srand(100); 962 srand(100);
@@ -892,6 +966,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -892,6 +966,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
892 GenerateFBO(n_pixels*2, numSamplesPos*n_pixels, position_texID, position_buffID); 966 GenerateFBO(n_pixels*2, numSamplesPos*n_pixels, position_texID, position_buffID);
893 CHECK_OPENGL_ERROR 967 CHECK_OPENGL_ERROR
894 GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID); 968 GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID);
  969 +
  970 + CHECK_OPENGL_ERROR
  971 + GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, length_texID, length_buffID);
895 CHECK_OPENGL_ERROR 972 CHECK_OPENGL_ERROR
896 GenerateFBO(16, 216, cylinder_texID, cylinder_buffID); 973 GenerateFBO(16, 216, cylinder_texID, cylinder_buffID);
897 CHECK_OPENGL_ERROR 974 CHECK_OPENGL_ERROR
@@ -901,8 +978,10 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -901,8 +978,10 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
901 t_pos.Alloc(numSamplesPos); 978 t_pos.Alloc(numSamplesPos);
902 t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D); 979 t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D);
903 t_mag.Alloc(numSamplesMag); 980 t_mag.Alloc(numSamplesMag);
  981 + t_mag.MapCudaTexture(length_texID, GL_TEXTURE_2D);
  982 + t_mag.Alloc(numSamplesMag);
904 setMatrix(); 983 setMatrix();
905 - dList = glGenLists(3); 984 + dList = glGenLists(4);//????????????????????????????
906 glListBase(dList); 985 glListBase(dList);
907 Bind(direction_texID, direction_buffID, numSamples, n_pixels); 986 Bind(direction_texID, direction_buffID, numSamples, n_pixels);
908 genDirectionVectors(5*stim::PI/4); 987 genDirectionVectors(5*stim::PI/4);
@@ -913,6 +992,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -913,6 +992,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
913 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); 992 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
914 genMagnitudeVectors(); 993 genMagnitudeVectors();
915 Unbind(); 994 Unbind();
  995 + Bind(length_texID, length_buffID, numSamplesMag, n_pixels);
  996 + genLengthVectors();
  997 + Unbind();
916 Bind(cylinder_texID, cylinder_buffID, 27); 998 Bind(cylinder_texID, cylinder_buffID, 27);
917 // DrawCylinder(); 999 // DrawCylinder();
918 Unbind(); 1000 Unbind();
@@ -984,12 +1066,20 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -984,12 +1066,20 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
984 1066
985 1067
986 ///@param float mag, size of the sampled region. 1068 ///@param float mag, size of the sampled region.
987 - ///Sets the m vector to the input mag for both templates. 1069 + ///Sets the m value to the input mag for both templates.
988 void 1070 void
989 setMagnitude(float mag) 1071 setMagnitude(float mag)
990 { 1072 {
991 m = mag; 1073 m = mag;
992 } 1074 }
  1075 +
  1076 + ///@param float len, length of the sampled region.
  1077 + ///Sets the length value to the input len for both templates.
  1078 + void
  1079 + setLength(float len)
  1080 + {
  1081 + length = len;
  1082 + }
993 1083
994 ///@param float x, voxel size in the x direction. 1084 ///@param float x, voxel size in the x direction.
995 ///@param float y, voxel size in the y direction. 1085 ///@param float y, voxel size in the y direction.
@@ -1041,17 +1131,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1041,17 +1131,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1041 stim::vec<float> out(0.0,0.0,0.0,0.0); 1131 stim::vec<float> out(0.0,0.0,0.0,0.0);
1042 stim::vec3<float> from(0.0,0.0,1.0); 1132 stim::vec3<float> from(0.0,0.0,1.0);
1043 out[0] = acos(dir.dot(from))*180/stim::PI; 1133 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){ 1134 + if(out[0] < 1.1){
1049 out[0] = 0.0; 1135 out[0] = 0.0;
1050 out[1] = 0.0; 1136 out[1] = 0.0;
1051 out[2] = 0.0; 1137 out[2] = 0.0;
1052 out[3] = 1.0; 1138 out[3] = 1.0;
1053 } 1139 }
1054 - else if(out[0] < -180.0+0.01) 1140 + else if(out[0] < -179.0)
1055 { 1141 {
1056 out[0] = 180.0; 1142 out[0] = 180.0;
1057 out[1] = 1.0; 1143 out[1] = 1.0;
@@ -1064,6 +1150,10 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1064,6 +1150,10 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1064 out[2] = temp[1]; 1150 out[2] = temp[1];
1065 out[3] = temp[2]; 1151 out[3] = temp[2];
1066 } 1152 }
  1153 + #ifdef DEBUG
  1154 + std::cout << "out is " << out << std::endl;
  1155 + std::cout << "when rotating from " << from << " to " << dir << std::endl;
  1156 + #endif
1067 return out; 1157 return out;
1068 } 1158 }
1069 1159
@@ -1303,7 +1393,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1303,7 +1393,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1303 findOptimalPosition(); 1393 findOptimalPosition();
1304 Unbind(); 1394 Unbind();
1305 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); 1395 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
1306 - findOptimalScale(); 1396 + findOptimalRadius();
1307 Unbind(); 1397 Unbind();
1308 CHECK_OPENGL_ERROR 1398 CHECK_OPENGL_ERROR
1309 1399
@@ -1351,12 +1441,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1351,12 +1441,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1351 outFile.open("New_Pos_Vectors.txt"); 1441 outFile.open("New_Pos_Vectors.txt");
1352 outFile << name.str().c_str(); 1442 outFile << name.str().c_str();
1353 } 1443 }
  1444 +/*
1354 void 1445 void
1355 DrawCylinder() 1446 DrawCylinder()
1356 { 1447 {
1357 glNewList(dList+3, GL_COMPILE); 1448 glNewList(dList+3, GL_COMPILE);
1358 float z0 = -0.5; float z1 = 0.5; float r0 = 0.5; 1449 float z0 = -0.5; float z1 = 0.5; float r0 = 0.5;
1359 - float x,y; 1450 + float x,y;
1360 float xold = 0.5; float yold = 0.0; 1451 float xold = 0.5; float yold = 0.0;
1361 float step = 360.0/numSamples*32; 1452 float step = 360.0/numSamples*32;
1362 //float step = 360.0/8.0; 1453 //float step = 360.0/8.0;
@@ -1387,7 +1478,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1387,7 +1478,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1387 glEnd(); 1478 glEnd();
1388 glEndList(); 1479 glEndList();
1389 } 1480 }
1390 - 1481 +*/
1391 ///need to return the cylinder. 1482 ///need to return the cylinder.
1392 ///SOMETHING MIGHT BE GOING ON HERE IN GENERATE BUFFER. 1483 ///SOMETHING MIGHT BE GOING ON HERE IN GENERATE BUFFER.
1393 void 1484 void
@@ -1455,7 +1546,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt; @@ -1455,7 +1546,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1455 // Unbind(); 1546 // Unbind();
1456 //THIS IS EXPERIMENTAL 1547 //THIS IS EXPERIMENTAL
1457 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); 1548 Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
1458 - findOptimalScale(); 1549 + findOptimalRadius();
1459 Unbind(); 1550 Unbind();
1460 //THIS IS EXPERIMENTAL 1551 //THIS IS EXPERIMENTAL
1461 1552