Commit 035d798f5b89a6f60dab19e6c5c24ef2c1f73fd6

Authored by Pavel Govyadinov
1 parent ac430567

modified the spider to have a separate buffer for each of the predictor correcto…

…r algorithms. Now using ~400 position and ~100 size templates.
stim/cuda/spider_cost.cuh
... ... @@ -150,7 +150,7 @@ namespace stim{
150 150  
151 151 // stringstream name; //for debugging
152 152 // name << "Test.bmp";
153   -// stim::gpu2image<float>(print, name.str(),16,218,0,1);
  153 +// stim::gpu2image<float>(print, name.str(),16,218,0,256);
154 154  
155 155 t.UnmapCudaTexture();
156 156 cleanUP();
... ...
stim/gl/gl_spider.h
... ... @@ -74,11 +74,15 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
74 74  
75 75 GLuint mfboID; //buffer object for magnitude adjustment.
76 76 GLuint mtexbufferID; //texture object for magnitude adjustment.
77   - GLuint bfboId; //buffer object for position adjustment.
  77 + GLuint bfboID; //buffer object for position adjustment.
78 78 GLuint btexbufferID; //buffer object for position adjustment.
79 79  
80 80 int numSamples; //The number of templates in the buffer.
81   - float stepsize = 4.0; //Step size.
  81 + int numSamplesPos;
  82 + int numSamplesMag;
  83 +
  84 +// float stepsize = 4.0; //Step size.
  85 + float stepsize = 3.0; //Step size.
82 86 int current_cost; //variable to store the cost of the current step.
83 87  
84 88  
... ... @@ -113,7 +117,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
113 117 {
114 118 setMatrix(); //create the transformation matrix.
115 119 glCallList(dList); //move the templates to p, d, m.
116   - int best = getCost(); //find min cost.
  120 + int best = getCost(texbufferID,numSamples); //find min cost.
117 121 stim::vec<float> next( //find next vector.
118 122 dV[best][0]*S[0]*R[0],
119 123 dV[best][1]*S[1]*R[1],
... ... @@ -135,7 +139,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
135 139 {
136 140 setMatrix(); //create the transformation matrix.
137 141 glCallList(dList+1); //move the templates to p, d, m.
138   - int best = getCost(); //find min cost.
  142 + int best = getCost(ptexbufferID, numSamplesPos); //find min cost.
139 143 stim::vec<float> next( //find next position.
140 144 pV[best][0],
141 145 pV[best][1],
... ... @@ -157,7 +161,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
157 161 {
158 162 setMatrix(); //create the transformation.
159 163 glCallList(dList+2); //move the templates to p, d, m.
160   - int best = getCost(); //get best cost.
  164 + int best = getCost(mtexbufferID, numSamplesMag); //get best cost.
161 165 setMagnitude(m[0]*mV[best][0]); //adjust the magnitude.
162 166 }
163 167  
... ... @@ -288,7 +292,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
288 292  
289 293 //Set up the variable necessary for vector creation.
290 294 vec<float> temp(0,0,0);
291   - int dim = (sqrt(numSamples)-1)/2; //number of position vectors.
  295 + int dim = (sqrt(numSamplesPos)-1)/2; //number of position vectors.
292 296 stim::rect<float> samplingPlane = //plane from which we pull position samples
293 297 stim::rect<float>(p, d);
294 298 samplingPlane.scale(mag[0]*delta, mag[0]*delta);
... ... @@ -338,15 +342,15 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
338 342 vec<float> dir(0.0, 0.0, 1.0);
339 343  
340 344 //Set up the variable necessary for vector creation.
341   - int dim = (sqrt(numSamples)-1)/2;
  345 + int dim = (sqrt(numSamplesMag)-1)/2;
342 346 float min = 1.0-delta;
343 347 float max = 1.0+delta;
344   - float step = (max-min)/(numSamples-1);
  348 + float step = (max-min)/(numSamplesMag-1);
345 349 float factor;
346 350 vec<float> temp(0.0,0.0,0.0);
347 351  
348 352 glNewList(dList+2, GL_COMPILE);
349   - for(int i = 0; i < numSamples; i++){
  353 + for(int i = 0; i < numSamplesMag; i++){
350 354 //Create linear index
351 355 factor = (min+step*i)*mag[0];
352 356 temp = factor;
... ... @@ -585,8 +589,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
585 589 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
586 590 glDrawBuffers(1, DrawBuffers);
587 591 glBindTexture(GL_TEXTURE_2D, textureID);
588   - glClearColor(1,1,1,1);
589   - glClear(GL_COLOR_BUFFER_BIT);
  592 +// glClearColor(1,1,1,1);
  593 +// glClear(GL_COLOR_BUFFER_BIT);
590 594 glMatrixMode(GL_PROJECTION);
591 595 glLoadIdentity();
592 596 glMatrixMode(GL_MODELVIEW);
... ... @@ -629,7 +633,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
629 633 findOptimalPosition();
630 634 findOptimalScale();
631 635 Unbind();
632   - Bind(btexbufferID, bfboId, 27);
  636 + Bind(btexbufferID, bfboID, 27);
633 637 branchDetection();
634 638 Unbind();
635 639  
... ... @@ -670,6 +674,23 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
670 674 return cost[0];
671 675 }
672 676  
  677 + int
  678 + getCost(GLuint tID, int n)
  679 + {
  680 + #ifdef TESTING
  681 + start = std::clock();
  682 + #endif
  683 + stim::vec<int> cost =
  684 + stim::cuda::get_cost(tID, GL_TEXTURE_2D, n);
  685 + cudaDeviceSynchronize();
  686 + #ifdef TESTING
  687 + duration_cuda = duration_cuda +
  688 + (std::clock() - start) / (double) CLOCKS_PER_SEC;
  689 + num_cuda = num_cuda + 1.0;
  690 + #endif
  691 + current_cost = cost[1];
  692 + return cost[0];
  693 + }
673 694  
674 695 public:
675 696  
... ... @@ -706,7 +727,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
706 727 ///Best results if samples is can create a perfect root.
707 728 ///Default Constructor
708 729 gl_spider
709   - (int samples = 1089)
  730 + (int samples = 1089, int samplespos = 400,int samplesmag = 144)
710 731 {
711 732 p = vec<float>(0.0, 0.0, 0.0);
712 733 d = vec<float>(0.0, 0.0, 1.0);
... ... @@ -714,6 +735,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
714 735 S = vec<float>(1.0, 1.0, 1.0);
715 736 R = vec<float>(1.0, 1.0, 1.0);
716 737 numSamples = samples;
  738 + numSamplesPos = samplespos;
  739 + numSamplesMag = samplesmag;
717 740 }
718 741  
719 742 ///Position constructor: floats.
... ... @@ -727,14 +750,16 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
727 750 ///@param int samples, number of templates this spider is going to use.
728 751 gl_spider
729 752 (float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z,
730   - float mag_x, int numSamples = 1089)
  753 + float mag_x, int numsamples = 1089, int numsamplespos = 400, int numsamplesmag =144)
731 754 {
732 755 p = vec<float>(pos_x, pos_y, pos_z);
733 756 d = vec<float>(dir_x, dir_y, dir_z);
734 757 m = vec<float>(mag_x, mag_x, mag_x);
735 758 S = vec<float>(1.0,1.0,1.0);
736 759 R = vec<float>(1.0,1.0,1.0);
737   -// numSamples = samples;
  760 + numSamples = numsamples;
  761 + numSamplesPos = numsamplespos;
  762 + numSamplesMag = numsamplesmag;
738 763 }
739 764  
740 765 ///Position constructor: vecs of floats.
... ... @@ -743,7 +768,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
743 768 ///@param float mag, size of the vector.
744 769 ///@param int samples, number of templates this spider is going to use.
745 770 gl_spider
746   - (stim::vec<float> pos, stim::vec<float> dir, float mag, int samples = 1089)
  771 + (stim::vec<float> pos, stim::vec<float> dir, float mag, int samples = 1089, int samplesPos = 400, int samplesMag = 144)
747 772 {
748 773 p = pos;
749 774 d = dir;
... ... @@ -751,6 +776,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
751 776 S = vec<float>(1.0,1.0,1.0);
752 777 R = vec<float>(1.0,1.0,1.0);
753 778 numSamples = samples;
  779 + numSamplesPos = samplesPos;
  780 + numSamplesMag = samplesMag;
754 781 }
755 782  
756 783 ///destructor
... ... @@ -760,12 +787,12 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
760 787 Unbind();
761 788 glDeleteTextures(1, &texbufferID);
762 789 glDeleteBuffers(1, &fboID);
763   - /* glDeleteTextures(1, &ptexbufferID);
764   - glDeleteBuffers(1, &pfboId);
  790 + glDeleteTextures(1, &ptexbufferID);
  791 + glDeleteBuffers(1, &pfboID);
765 792 glDeleteTextures(1, &mtexbufferID);
766   - glDeleteBuffers(1, &mfboId); */
  793 + glDeleteBuffers(1, &mfboID);
767 794 glDeleteTextures(1, &btexbufferID);
768   - glDeleteBuffers(1, &bfboId);
  795 + glDeleteBuffers(1, &bfboID);
769 796 }
770 797  
771 798 ///@param GLuint id, texture that is going to be sampled.
... ... @@ -776,19 +803,26 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
776 803 attachSpider(GLuint id)
777 804 {
778 805 texID = id;
779   - GenerateFBO(16, numSamples*8);
780   - GenerateFBO(16, 216, btexbufferID, bfboId);
  806 + //GenerateFBO(16, numSamples*8);
  807 + GenerateFBO(16, numSamples*8, texbufferID, fboID);
  808 + GenerateFBO(16, numSamplesPos*8, ptexbufferID, pfboID);
  809 + GenerateFBO(16, numSamplesMag*8, mtexbufferID, mfboID);
  810 + GenerateFBO(16, 216, btexbufferID, bfboID);
781 811 setDims(0.6, 0.6, 1.0);
782 812 setSize(512.0, 512.0, 426.0);
783 813 setMatrix();
784 814 dList = glGenLists(3);
785 815 glListBase(dList);
786   - Bind();
787   - genDirectionVectors(5*M_PI/4);
788   - genPositionVectors();
789   - genMagnitudeVectors();
790   - Unbind();
791   - Bind(btexbufferID, bfboId, 27);
  816 + Bind(texbufferID, fboID, numSamples);
  817 + genDirectionVectors(5*M_PI/4);
  818 +// Unbind();
  819 + Bind(ptexbufferID, bfboID, numSamplesPos);
  820 + genPositionVectors();
  821 +// Unbind();
  822 + Bind(mtexbufferID, mfboID, numSamplesMag);
  823 + genMagnitudeVectors();
  824 +// Unbind();
  825 + Bind(btexbufferID, bfboID, 27);
792 826 DrawCylinder();
793 827 Unbind();
794 828 }
... ... @@ -1086,7 +1120,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1086 1120 GLuint
1087 1121 getFB()
1088 1122 {
1089   - return bfboId;
  1123 + return bfboID;
1090 1124 }
1091 1125  
1092 1126 //--------------------------------------------------------------------------//
... ... @@ -1110,15 +1144,19 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1110 1144 int
1111 1145 Step()
1112 1146 {
1113   - Bind();
  1147 + Bind(texbufferID, fboID, numSamples);
1114 1148 CHECK_OPENGL_ERROR
1115 1149 #ifdef TESTING
1116 1150 start = std::clock();
1117 1151 #endif
1118   - findOptimalDirection();
1119   - findOptimalPosition();
1120   - findOptimalScale();
1121   - Unbind();
  1152 + findOptimalDirection();
  1153 + //Unbind();
  1154 + Bind(ptexbufferID, pfboID, numSamplesPos);
  1155 + findOptimalPosition();
  1156 + //Unbind();
  1157 + Bind(mtexbufferID, mfboID, numSamplesMag);
  1158 + findOptimalScale();
  1159 + //Unbind();
1122 1160 CHECK_OPENGL_ERROR
1123 1161  
1124 1162 #ifdef TESTING
... ... @@ -1279,7 +1317,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1279 1317 cL.push_back(stim::vec<float>(p[0], p[1],p[2]));//
1280 1318 sk.TexCoord(m[0]);
1281 1319 sk.Vertex(p[0], p[1], p[2]);
1282   - Bind(btexbufferID, bfboId, 27);
  1320 + Bind(btexbufferID, bfboID, 27);
1283 1321 CHECK_OPENGL_ERROR
1284 1322 branchDetection();
1285 1323 CHECK_OPENGL_ERROR
... ... @@ -1386,7 +1424,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1386 1424 }
1387 1425 else
1388 1426 {
1389   - printf ("%u ", *ptr);
  1427 +// printf ("%u ", *ptr);
1390 1428 return *ptr;
1391 1429 }
1392 1430 }
... ... @@ -1441,8 +1479,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1441 1479 void
1442 1480 printSizes()
1443 1481 {
1444   - std::cout << nt.sizeE() << "edges" << std::endl;
1445   - std::cout << nt.sizeV() << "nodes" << std::endl;
  1482 + std::cout << nt.sizeE() << " edges " << std::endl;
  1483 + std::cout << nt.sizeV() << " nodes " << std::endl;
1446 1484  
1447 1485 }
1448 1486  
... ... @@ -1531,7 +1569,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1531 1569 cM.push_back(m[0]);
1532 1570 sk.TexCoord(m[0]);
1533 1571 sk.Vertex(p[0], p[1], p[2]);
1534   - Bind(btexbufferID, bfboId, 27);
  1572 + Bind(btexbufferID, bfboID, 27);
1535 1573 CHECK_OPENGL_ERROR
1536 1574 branchDetection();
1537 1575 CHECK_OPENGL_ERROR
... ...
stim/gl/gl_texture.h
... ... @@ -31,10 +31,9 @@ template&lt;typename T&gt;
31 31 class gl_texture : public virtual image_stack<T>
32 32 {
33 33 private:
34   - ///Method: setTextureType
35 34 /// Sets the internal texture_type, based on the data
36 35 /// size. Either 3D, 2D, 1D textures.
37   -
  36 +
38 37 void
39 38 setTextureType()
40 39 {
... ... @@ -60,16 +59,14 @@ class gl_texture : public virtual image_stack&lt;T&gt;
60 59  
61 60 public:
62 61  
63   - ///Method: Basic Constructor
64   - /// Creates an instance of the gl_texture object.
  62 + ///default constructor
65 63 gl_texture()
66 64 {
67 65  
68 66 }
69 67  
70   - ///Method: Path Constructor
71   - ///@param string file_path path to the directory with the files.
72   - /// Creates an instance of the gl_texture object with a path to the data.
  68 + ///@param string path to the directory with the image files.
  69 + ///Creates an instance of the gl_texture object with a path to the data.
73 70  
74 71 gl_texture(std::string file_path)
75 72 {
... ... @@ -77,8 +74,8 @@ class gl_texture : public virtual image_stack&lt;T&gt;
77 74 image_stack<T>::load_images(path.append("/*.jpg"));
78 75 setTextureType();
79 76 }
80   - ///Method:getSize
81   - ///returns the dimentions of
  77 +
  78 + ///returns the dimentions of the data in the x, y, z directions.
82 79 vec<int>
83 80 getSize()
84 81 {
... ... @@ -86,7 +83,6 @@ class gl_texture : public virtual image_stack&lt;T&gt;
86 83 return size;
87 84 }
88 85  
89   - ///Method:setTexParam
90 86 ///@param GLint interp --GL_LINEAR, GL_NEAREST...
91 87 ///@param GLint twrap --GL_REPEAR, GL_CLAMP_TO_EDGE...
92 88 ///@param GLenum dataType --GL_UNSIGNED_BYTE, GL_FLOAT16...
... ... @@ -103,7 +99,7 @@ class gl_texture : public virtual image_stack&lt;T&gt;
103 99 type = dataType;
104 100 format = dataFormat;
105 101 }
106   - ///Method:setDims
  102 +
107 103 ///@param x size of the voxel in x direction
108 104 ///@param y size of the voxel in y direction
109 105 ///@param z size of the voxel in z direction
... ... @@ -116,9 +112,7 @@ class gl_texture : public virtual image_stack&lt;T&gt;
116 112 S[3] = z;
117 113 }
118 114  
119   - ///Method:getDims
120   - /// get the dimenstions of the voxels.
121   -
  115 + ///Returns a stim::vec that contains the x, y, z sizes of the voxel.
122 116 vec<float>
123 117 getDims()
124 118 {
... ... @@ -126,11 +120,8 @@ class gl_texture : public virtual image_stack&lt;T&gt;
126 120 return dims;
127 121 }
128 122  
129   - ///Method:setPath
130 123 ///@param file_Path location of the directory with the files
131 124 /// Sets the path and calls the loader on that path.
132   -
133   -
134 125 void
135 126 setPath(std::string file_path)
136 127 {
... ... @@ -139,19 +130,14 @@ class gl_texture : public virtual image_stack&lt;T&gt;
139 130 setTextureType();
140 131 }
141 132  
142   - ///Method: getPath
143   - ///Outputs: string path
144   - /// Returns the path associated with an instance of the gl_texture class.
145   -
  133 + /// Returns an std::string path associated with an instance of the gl_texture class.
146 134 std::string
147 135 getPath()
148 136 {
149 137 return path;
150 138 }
151 139  
152   - ///Method: getTexture
153   - ///Outputs: GLuint texID
154   - /// Returns the id of the texture create by/associated with the
  140 + /// Returns the GLuint id of the texture created by/associated with the
155 141 /// instance of the gl_texture class.
156 142  
157 143 GLuint
... ... @@ -160,7 +146,6 @@ class gl_texture : public virtual image_stack&lt;T&gt;
160 146 return texID;
161 147 }
162 148  
163   - ///Method: createTexture
164 149 /// Creates a texture and from the loaded data and
165 150 /// assigns that texture to texID
166 151 //TO DO :::: 1D textures
... ...