Commit 7f297fc6a0b6d24e56173842d78e9b124969cadc

Authored by Pavel Govyadinov
1 parent 34ec8a82

added more detailed comments, rewrote the m to be a float value instead of a vec…

…tor. remanded some variable for clarity fixed a couple of inconcistencies.
Showing 2 changed files with 209 additions and 318 deletions   Show diff stats
stim/biomodels/centerline.h
... ... @@ -163,25 +163,25 @@ public:
163 163  
164 164 /// Return the point on the fiber closest to q
165 165 /// @param q is the query point used to locate the nearest point on the fiber centerline
166   - stim::vec<T> nearest(stim::vec<T> q){
167   -
168   - stim::vec<double> temp( (double) q[0], (double) q[1], (double) q[2]);
169   -
170   - unsigned int idx = ann(temp); //determine the index of the nearest neighbor
171   -
172   - return stim::vec<T>((T) c[idx][0], (T) c[idx][1], (T) c[idx][2]); //return the nearest centerline point
173   - }
  166 +// stim::vec<T> nearest(stim::vec<T> q){
  167 +//
  168 +// stim::vec<double> temp( (double) q[0], (double) q[1], (double) q[2]);
  169 +//
  170 +// unsigned int idx = ann(temp); //determine the index of the nearest neighbor
  171 +//
  172 +// return stim::vec<T>((T) c[idx][0], (T) c[idx][1], (T) c[idx][2]); //return the nearest centerline point
  173 +// }
174 174  
175 175 /// Return the point index on the fiber closest to q
176 176 /// @param q is the query point used to locate the nearest point on the fiber centerline
177   - unsigned int nearest_idx(stim::vec<T> q){
178   -
179   - stim::vec<double> temp((double) q[0], (double) q[1], (double) q[2]);
180   -
181   - unsigned int idx = ann(temp); //determine the index of the nearest neighbor
182   -
183   - return idx; //return the nearest centerline point index
184   - }
  177 +// unsigned int nearest_idx(stim::vec<T> q){
  178 +//
  179 +// stim::vec<double> temp((double) q[0], (double) q[1], (double) q[2]);
  180 +//
  181 +// unsigned int idx = ann(temp); //determine the index of the nearest neighbor
  182 +//
  183 +// return idx; //return the nearest centerline point index
  184 +// }
185 185  
186 186 /// Returns the fiber centerline as an array of stim::vec points
187 187 std::vector< stim::vec<T> > get_centerline(){
... ...
stim/gl/gl_spider.h
... ... @@ -28,9 +28,6 @@
28 28 #include "../../../volume-spider/glnetwork.h"
29 29 #include <stim/visualization/cylinder.h>
30 30 #include <stim/cuda/testKernel.cuh>
31   -
32   -//#include <stim/cuda/testKernel.cuh>
33   -
34 31 #include <iostream>
35 32 #include <fstream>
36 33 #ifdef TIMING
... ... @@ -39,7 +36,6 @@
39 36 #endif
40 37  
41 38 #ifdef TESTING
42   - #include <iostream>
43 39 #include <cstdio>
44 40 #include <ctime>
45 41 #endif
... ... @@ -67,16 +63,16 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
67 63  
68 64 stim::vec3<float> p; //vector designating the position of the spider.
69 65 stim::vec3<float> d; //normalized direction of travel
70   - stim::vec<float> m; //size of the spider in tissue space
  66 + float m; //size of the spider in tissue space.
71 67  
72 68 std::vector<stim::vec3<float> > dV; //A list of all the direction vectors.
73 69 std::vector<stim::vec3<float> > pV; //A list of all test positions (relative to p)
74   - std::vector<stim::vec3<float> > mV; //A list of all the size vectors.
  70 + std::vector<float> mV; //A list of all the size vectors.
75 71  
76 72 stim::matrix<float, 4> cT; //current Transformation matrix (tissue)->(texture)
77 73 GLuint texID; //OpenGL ID for the texture to be traced
78   - stim::vec<float> S; //Size of a voxel in the volume.
79   - stim::vec<float> R; //Dimensions of the volume.
  74 + stim::vec3<float> S; //Size of a voxel in the volume.
  75 + stim::vec3<float> R; //Dimensions of the volume.
80 76  
81 77  
82 78 //GL and Cuda variables
... ... @@ -88,15 +84,17 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
88 84  
89 85 GLuint fboID; //framebuffer ID for direction templates
90 86 GLuint texbufferID; //texture ID for direction templates
  87 + GLuint direction_buffID; //framebuffer ID, position templates
  88 + GLuint direction_texID; //texture ID, position templates
91 89  
92   - GLuint pfboID; //framebuffer ID, position templates
93   - GLuint ptexbufferID; //texture ID, position templates
  90 + GLuint position_buffID; //framebuffer ID, position templates
  91 + GLuint position_texID; //texture ID, position templates
94 92  
95   - GLuint mfboID; //framebuffer ID, radius templates
96   - GLuint mtexbufferID; //texture ID, radius templates
  93 + GLuint radius_buffID; //framebuffer ID, radius templates
  94 + GLuint radius_texID; //texture ID, radius templates
97 95  
98   - GLuint bfboID; //framebuffer ID, cylinder (surrounding fiber)
99   - GLuint btexbufferID; //texture ID, cylinder
  96 + GLuint cylinder_buffID; //framebuffer ID, cylinder (surrounding fiber)
  97 + GLuint cylinder_texID; //texture ID, cylinder
100 98  
101 99 int numSamples; //The number of templates in the buffer.
102 100 int numSamplesPos;
... ... @@ -114,7 +112,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
114 112  
115 113 std::vector< stim::vec3<float> > cL; //centerline up to the current point
116 114 std::vector< stim::vec3<float> > cD; //directions up to the current point (debugging)
117   - std::vector< stim::vec<float> > cM; //radius up to the current point
  115 + std::vector< float > cM; //radius up to the current point
118 116  
119 117 stim::glnetwork<float> nt; //network object holding the currently traced centerlines
120 118 stim::glObj<float> sk; //OBJ file storing the network (identical to above)
... ... @@ -128,12 +126,12 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
128 126 stim::vec3<float> ups; //up direction for the selection camera
129 127 stim::vec3<float> ds; //direction for the selection camera
130 128  
131   - float t_length; //length of the template (in pixels)
  129 + float n_pixels; //length of the template (in pixels)
132 130  
133 131 //cuda texture variables that keep track of the binding.
134   - stim::cuda::cuda_texture t_dir;
135   - stim::cuda::cuda_texture t_pos;
136   - stim::cuda::cuda_texture t_mag;
  132 + 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.
  134 + stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors.
137 135  
138 136  
139 137 //--------------------------------------------------------------------------//
... ... @@ -147,30 +145,29 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
147 145 findOptimalDirection()
148 146 {
149 147 #ifdef TIMING
150   - gpuStartTimer();
  148 + gpuStartTimer(); //Timer for profiling
151 149 #endif
152 150 setMatrix(); //create the transformation matrix.
153 151 glCallList(dList); //move the templates to p, d, m.
154   - glFinish();
  152 + glFinish(); //flush the pipeline
155 153 #ifdef TIMING
156   - direction_time += gpuStopTimer();
  154 + direction_time += gpuStopTimer(); //profiling
157 155 #endif
158 156 #ifdef TESTING
159   -// test(texbufferID, GL_TEXTURE_2D,2*t_length,numSamples*t_length, "Final_Cost_Direction.bmp");
  157 +// test(texbufferID, GL_TEXTURE_2D,2*n_pixels,numSamples*n_pixels, "Final_Cost_Direction.bmp");
160 158 #endif
161 159  
162 160 int best = getCost(t_dir.getTexture(), t_dir.getAuxArray() ,numSamples); //find min cost.
163   - stim::vec<float> next( //find next vector.
  161 + stim::vec<float> next( ///calculate the next vector.
164 162 dV[best][0]*S[0]*R[0],
165 163 dV[best][1]*S[1]*R[1],
166 164 dV[best][2]*S[2]*R[2],
167 165 0);
168   - next = (cT*next).norm(); //find next vector.
169   - setPosition( p[0]+next[0]*m[0]/stepsize,
170   - p[1]+next[1]*m[0]/stepsize,
171   - p[2]+next[2]*m[0]/stepsize);
172   - setDirection(next[0], next[1], next[2]);
173   - //move forward and change direction.
  166 + next = (cT*next).norm(); ///transform the next vector into Tissue space.
  167 + setPosition( p[0]+next[0]*m/stepsize,
  168 + p[1]+next[1]*m/stepsize,
  169 + p[2]+next[2]*m/stepsize);
  170 + setDirection(next[0], next[1], next[2]); //move forward and change direction.
174 171 }
175 172  
176 173 /// Method for finding the best d (direction) for the spider.
... ... @@ -180,17 +177,18 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
180 177 findOptimalPosition()
181 178 {
182 179 #ifdef TIMING
183   - gpuStartTimer();
  180 + gpuStartTimer(); //timer for profiling
184 181 #endif
185 182 setMatrix(); //create the transformation matrix.
186 183 glCallList(dList+1); //move the templates to p, d, m.
187   - glFinish();
  184 + glFinish(); //flush the pipeline
188 185 // glFlush();
189 186 #ifdef TIMING
190   - position_time += gpuStopTimer();
  187 + position_time += gpuStopTimer(); ///timer for profiling
191 188 #endif
192 189  
193 190 #ifdef TESTING
  191 +// test(texbufferID, GL_TEXTURE_2D,2*n_pixels,numSamples*n_pixels, "Final_Cost_Direction.bmp");
194 192 #endif
195 193 int best = getCost(t_pos.getTexture(), t_pos.getAuxArray(), numSamplesPos); //find min cost.
196 194 stim::vec<float> next( //find next position.
... ... @@ -198,7 +196,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
198 196 pV[best][1],
199 197 pV[best][2],
200 198 1);
201   - next = cT*next; //find next position.
  199 + next = cT*next; //transform the next position vector into tissue space.
202 200 setPosition(
203 201 next[0]*S[0]*R[0],
204 202 next[1]*S[1]*R[1],
... ... @@ -217,14 +215,14 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
217 215 #endif
218 216 setMatrix(); //create the transformation.
219 217 glCallList(dList+2); //move the templates to p, d, m.
220   - glFinish();
  218 + glFinish(); //flush the drawing pipeline.
221 219 #ifdef TIMING
222 220 size_time += gpuStopTimer();
223 221 #endif
224 222 #ifdef TESTING
225 223 #endif
226 224 int best = getCost(t_mag.getTexture(), t_mag.getAuxArray(), numSamplesMag); //get best cost.
227   - setMagnitude(m[0]*mV[best][0]); //adjust the magnitude.
  225 + setMagnitude(m*mV[best]); //adjust the magnitude.
228 226 }
229 227  
230 228  
... ... @@ -236,80 +234,78 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
236 234 branchDetection2(int n = 8, int l_template = 8, int l_square = 8)
237 235 {
238 236 #ifdef TIMING
239   - gpuStartTimer();
  237 + gpuStartTimer(); ///timer for performance analysis
240 238 #endif
241 239  
242   - if(cL.size() < 4){}
  240 + if(cL.size() < 4){} ///if the size of the fiber is less then 4 we do nothing.
243 241 else{
244   - setMatrix(1);
245   - DrawLongCylinder(n, l_template, l_square);
  242 + setMatrix(1); ///finds the current transformation matrix
  243 + DrawLongCylinder(n, l_template, l_square); ///Draw the cylinder.
246 244 stim::cylinder<float> cyl(cL, cM);
247   - std::vector< stim::vec<float> > result = find_branch(btexbufferID, GL_TEXTURE_2D, n*l_square, (cL.size()-1)*l_template);
248   - stim::vec3<float> size(S[0]*R[0], S[1]*R[1], S[2]*R[2]);
249   - float pval;
250   - if(!result.empty())
  245 + std::vector< stim::vec<float> > result = find_branch(cylinder_texID, GL_TEXTURE_2D, n*l_square, (cL.size()-1)*l_template); ///find all the centers in cuda
  246 + stim::vec3<float> size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); ///the borders of the texture.
  247 + float pval; //pvalue associated with the points on the cylinder.
  248 + if(!result.empty()) ///if we have any points
251 249 {
252   - for(int i = 0; i < result.size(); i++)
  250 + for(int i = 0; i < result.size(); i++) ///for each point
253 251 {
254 252 int id = result[i][2];
255   - if(fmod(result[i][2], id) != 0 && id != 0)
  253 + if(fmod(result[i][2], id) != 0 && id != 0) ///if the remainer is odd
256 254 {
257 255  
258 256 pval = ((cyl.getl(id+1)-cyl.getl(id))*
259   - (fmod(result[i][2], id))+cyl.getl(id))/cyl.getl(cL.size()-1);
  257 + (fmod(result[i][2], id))+cyl.getl(id))/cyl.getl(cL.size()-1); ///calculate pvalue
260 258 }
261   - else if(id == 0)
  259 + else if(id == 0) ///if the point is on the edge
262 260 {
263   - pval = (cyl.getl(id+1)*result[i][2])/cyl.getl(cL.size()-1);
  261 + pval = (cyl.getl(id+1)*result[i][2])/cyl.getl(cL.size()-1);
264 262 }
265 263 else
266 264 {
267   - pval = (cyl.getl(id)/cyl.getl(cL.size()-1));
  265 + pval = (cyl.getl(id)/cyl.getl(cL.size()-1)); ///if the point is somewhere on the surface of the cylinder other than the edge
268 266 }
269   - stim::vec3<float> v = cyl.surf(pval, result[i][0]);
270   - stim::vec3<float> di = cyl.p(pval);
271   - float rad = cyl.r(pval);
272   -
273   - std::cout << v.str() << " " << di.str() << " " << rad << std::endl;
  267 + stim::vec3<float> v = cyl.surf(pval, result[i][0]); ///find the coordinates of the point at pval on the surface in tissue space.
  268 + stim::vec3<float> di = cyl.p(pval); ///find the coord of v in tissue space projected on the centerline.
  269 + float rad = cyl.r(pval); ///find the radius at the pvalue's location
274 270 if(
275 271 !(v[0] > size[0] || v[1] > size[1]
276 272 || v[2] > size[2] || v[0] < 0
277   - || v[1] < 0 || v[2] < 0))
  273 + || v[1] < 0 || v[2] < 0)) ///if the v point is INSIDE the volume
278 274 {
279   - setSeed(v);
280   - setSeedVec((v-di).norm());
281   - setSeedMag(rad);
  275 + setSeed(v); ///add a seedpoint's position.
  276 + setSeedVec((v-di).norm()); ///add a seedpoints direction
  277 + setSeedMag(rad); ///add the starting radius.
282 278 }
283 279 }
284 280 }
285 281 }
286 282 #ifdef TIMING
287   - branch_time += gpuStopTimer();
  283 + branch_time += gpuStopTimer(); ///timer for performance.
288 284 #endif
289 285 }
290 286  
291 287  
292 288 float uniformRandom()
293 289 {
294   - return ( (float)(rand()))/( (float)(RAND_MAX));
  290 + return ( (float)(rand()))/( (float)(RAND_MAX)); ///generates a random number between 0 and 1 using the uniform distribution.
295 291 }
296 292  
297 293 float normalRandom()
298 294 {
299 295 float u1 = uniformRandom();
300 296 float u2 = uniformRandom();
301   - return cos(2.0*atan(1.0)*u2)*sqrt(-1.0*log(u1));
  297 + return cos(2.0*atan(1.0)*u2)*sqrt(-1.0*log(u1)); ///generate a random number using the normal distribution between 0 and 1.
302 298 }
303 299  
304 300 stim::vec3<float> uniformRandVector()
305 301 {
306   - stim::vec3<float> r(uniformRandom(), uniformRandom(), 1.0);
  302 + stim::vec3<float> r(uniformRandom(), uniformRandom(), 1.0); ///generate a random vector using the uniform distribution between 0 and 1.
307 303 return r;
308 304 }
309 305  
310 306 stim::vec3<float> normalRandVector()
311 307 {
312   - stim::vec3<float> r(normalRandom(), normalRandom(), 1.0);
  308 + stim::vec3<float> r(normalRandom(), normalRandom(), 1.0); ///generate a random vector using the normal distribution between 0 and 1.
313 309 return r;
314 310 }
315 311  
... ... @@ -332,44 +328,44 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
332 328  
333 329 //Set up the vectors necessary for Rectangle creation.
334 330 stim::vec3<float> Y(1.0,0.0,0.0); //orthogonal vec.
335   - stim::vec3<float> pos(0.0,0.0,0.0);
336   - stim::vec3<float> mag(1.0, 1.0, 1.0);
337   - stim::vec3<float> dir(0.0, 0.0, 1.0);
  331 + stim::vec3<float> pos(0.0,0.0,0.0); //center point of a rectangle
  332 + float mag = 1.0; //size of the generated rectangle.
  333 + stim::vec3<float> dir(0.0, 0.0, 1.0); //normal of the rectangle
338 334  
339   - float PHI[2], Z[2], range;
340   - PHI[0] = solidAngle/2;
  335 + float PHI[2], Z[2], range;
  336 + PHI[0] = solidAngle/2; ///Project the solid angle into spherical coordinates
341 337 PHI[1] = asin(0);
342 338  
343   - Z[0] = cos(PHI[0]);
  339 + Z[0] = cos(PHI[0]); ///Project the z into spherical coordinates
344 340 Z[1] = cos(PHI[1]);
345 341  
346   - range = Z[0] - Z[1];
  342 + range = Z[0] - Z[1]; ///The range the possible values can be.
347 343  
348 344 float z, theta, phi;
349   - glNewList(dList, GL_COMPILE);
350   - for(int i = 0; i < numSamples; i++)
  345 + glNewList(dList, GL_COMPILE); ///create a display list of all the direction templates.
  346 + for(int i = 0; i < numSamples; i++) ///for each sample
351 347 {
352   - z = uniformRandom()*range + Z[1];
353   - theta = uniformRandom()*stim::TAU;
354   - phi = acos(z);
355   - stim::vec3<float> sph(1, theta, phi);
356   - stim::vec3<float> cart = sph.sph2cart();
357   - dV.push_back(cart);
358   - if(cos(Y.dot(cart)) < 0.087)
  348 + z = uniformRandom()*range + Z[1]; ///generate a z coordinate
  349 + theta = uniformRandom()*stim::TAU; ///generate a theta coordinate
  350 + phi = acos(z); ///generate a phi from the z.
  351 + stim::vec3<float> sph(1, theta, phi); ///combine into a vector in spherical coordinates.
  352 + stim::vec3<float> cart = sph.sph2cart();///convert to cartesian.
  353 + dV.push_back(cart); ///save the generated vector for further use.
  354 + if(cos(Y.dot(cart)) < 0.087) ///make sure that the Y is not parallel to the new vector.
359 355 {
360 356 Y[0] = 0.0; Y[1] = 1.0;
361 357 }else{
362 358 Y[0] = 1.0; Y[1] = 0.0;
363 359 }
364   - hor = stim::rect<float>(mag,
  360 + hor = stim::rect<float>(mag, ///generate a rectangle with the new vectro as a normal.
365 361 pos, cart,
366 362 ((Y.cross(cart)).cross(cart)).norm());
367   - ver = stim::rect<float>(mag,
  363 + ver = stim::rect<float>(mag, ///generate another rectangle that's perpendicular the first but parallel to the cart vector.
368 364 pos, cart,
369 365 hor.n());
370   - UpdateBuffer(0.0, 0.0+i*t_length);
  366 + UpdateBuffer(0.0, 0.0+i*n_pixels); ///Put the necessary points into the diplaylist.
371 367 }
372   - glEndList();
  368 + glEndList(); ///finilize the display list.
373 369 }
374 370  
375 371 ///@param float delta, How much the rectangles vary in position.
... ... @@ -383,28 +379,28 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
383 379 {
384 380 //Set up the vectors necessary for Rectangle creation.
385 381 stim::vec3<float> Y(1.0,0.0,0.0); //orthogonal vec.
386   - stim::vec3<float> pos(0.0,0.0,0.0);
387   - stim::vec3<float> mag(1.0, 1.0, 1.0);
388   - stim::vec3<float> dir(0.0, 0.0, 1.0);
  382 + stim::vec3<float> pos(0.0,0.0,0.0); //center point of a rectangle
  383 + float mag = 1.0; ///size of each rectangle
  384 + stim::vec3<float> dir(0.0, 0.0, 1.0); ///normal of the rectangle plane.
389 385  
390 386 //Set up the variable necessary for vector creation.
391   - glNewList(dList+1, GL_COMPILE);
392   - for(int i = 0; i < numSamplesPos; i++)
  387 + glNewList(dList+1, GL_COMPILE); ///generate a new display list.
  388 + for(int i = 0; i < numSamplesPos; i++) ///for the number of position samples
393 389 {
394   - stim::vec3<float> temp = uniformRandVector();
395   - temp = temp*delta*2.0 - delta/2.0;
  390 + stim::vec3<float> temp = uniformRandVector(); ///generate a random point on a plane.
  391 + temp = temp*delta*2.0 - delta/2.0; ///scale the point
396 392 temp[2] = 0.0;
397   - pV.push_back(temp);
398   - hor = stim::rect<float>(mag,
  393 + pV.push_back(temp); ///save the point for further use.
  394 + hor = stim::rect<float>(mag, ///generate a rectangle with the new vector as a normal.
399 395 temp, dir,
400 396 ((Y.cross(d)).cross(d))
401 397 .norm());
402   - ver = stim::rect<float>(mag,
  398 + ver = stim::rect<float>(mag, ///generate another rectangle that's perpendicular the first but parallel to the cart vector.
403 399 temp, dir,
404 400 hor.n());
405   - UpdateBuffer(0.0, 0.0+i*t_length);
  401 + UpdateBuffer(0.0, 0.0+i*n_pixels); ///sample the necessary points and put them into a display list.
406 402 }
407   - glEndList();
  403 + glEndList(); ///finilize the display list.
408 404 }
409 405  
410 406 ///@param float delta, How much the rectangles are allowed to expand.
... ... @@ -419,35 +415,32 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
419 415  
420 416 //Set up the vectors necessary for Rectangle creation.
421 417 stim::vec3<float> Y(1.0, 0.0, 0.0); //orthogonal vec.
422   - stim::vec3<float> pos(0.0, 0.0, 0.0);
423   - stim::vec3<float> mag(1.0, 1.0, 1.0);
424   - stim::vec3<float> dir(0.0, 0.0, 1.0);
  418 + stim::vec3<float> pos(0.0, 0.0, 0.0); //center of the future rect.
  419 + float mag = 1.0; ///size of the rectangle
  420 + stim::vec3<float> dir(0.0, 0.0, 1.0); ///normal of the rectangle plane.
425 421  
426 422 //Set up the variable necessary for vector creation.
427   - int dim = (sqrt(numSamplesMag)-1)/2;
428   - float min = 1.0-delta;
429   - float max = 1.0+delta;
430   - float step = (max-min)/(numSamplesMag-1);
  423 + float min = 1.0-delta; ///smallest size
  424 + float max = 1.0+delta; ///largers size.
  425 + float step = (max-min)/(numSamplesMag-1); ///the size variation from one rect to the next.
431 426 float factor;
432   - stim::vec3<float> temp(0.0,0.0,0.0);
433 427  
434 428 glNewList(dList+2, GL_COMPILE);
435   - for(int i = 0; i < numSamplesMag; i++){
  429 + for(int i = 0; i < numSamplesMag; i++){ ///for the number of position samples
436 430 //Create linear index
437   - factor = (min+step*i)*mag[0];
438   - temp = factor;
439   - mV.push_back(temp);
440   - hor = stim::rect<float>(temp,
  431 + factor = (min+step*i)*mag; ///scaling factor
  432 + mV.push_back(factor); ///save the size factor for further use.
  433 + hor = stim::rect<float>(factor, ///generate a rectangle with the new vector as a normal.
441 434 pos, dir,
442 435 ((Y.cross(d)).cross(d))
443 436 .norm());
444   - ver = stim::rect<float>(temp,
  437 + ver = stim::rect<float>(factor, ///generate another rectangle that's perpendicular the first but parallel to the cart vector.
445 438 pos, dir,
446 439 hor.n());
447   - UpdateBuffer(0.0, 0.0+i*t_length);
  440 + UpdateBuffer(0.0, 0.0+i*n_pixels); ///sample the necessary points and put them into a display list.
448 441 CHECK_OPENGL_ERROR
449 442 }
450   - glEndList();
  443 + glEndList(); ///finilize the displaylist.
451 444 }
452 445  
453 446 ///@param float v_x x-coordinate in buffer-space,
... ... @@ -457,15 +450,15 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
457 450 void
458 451 UpdateBuffer(float v_x, float v_y)
459 452 {
460   - stim::vec3<float>p1;
461   - stim::vec3<float>p2;
462   - stim::vec3<float>p3;
463   - stim::vec3<float>p4;
464   - p1 = hor.p(1,1);
465   - p2 = hor.p(1,0);
466   - p3 = hor.p(0,0);
467   - p4 = hor.p(0,1);
468   - glBegin(GL_QUADS);
  453 + stim::vec3<float>p1; ///first point.
  454 + stim::vec3<float>p2; ///second point.
  455 + stim::vec3<float>p3; ///third point.
  456 + stim::vec3<float>p4; ///fourth point.
  457 + p1 = hor.p(1,1); ///generate the top right point from the horizontal template.
  458 + p2 = hor.p(1,0); ///generate the bottom right point from the horizonatal template.
  459 + p3 = hor.p(0,0); ///generate the bottom left point from the horizontal template.
  460 + p4 = hor.p(0,1); ///generate the top left point from the horizonatal template.
  461 + glBegin(GL_QUADS); ///generate the Quad from the 4 points.
469 462 glTexCoord3f(
470 463 p1[0],
471 464 p1[1],
... ... @@ -477,51 +470,51 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
477 470 p2[1],
478 471 p2[2]
479 472 );
480   - glVertex2f(v_x+t_length, v_y);
  473 + glVertex2f(v_x+n_pixels, v_y);
481 474 glTexCoord3f(
482 475 p3[0],
483 476 p3[1],
484 477 p3[2]
485 478 );
486   - glVertex2f(v_x+t_length, v_y+t_length);
  479 + glVertex2f(v_x+n_pixels, v_y+n_pixels);
487 480 glTexCoord3f(
488 481 p4[0],
489 482 p4[1],
490 483 p4[2]
491 484 );
492   - glVertex2f(v_x, v_y+t_length);
493   - glEnd();
494   -
495   - p1 = ver.p(1,1);
496   - p2 = ver.p(1,0);
497   - p3 = ver.p(0,0);
498   - p4 = ver.p(0,1);
499   - glBegin(GL_QUADS);
  485 + glVertex2f(v_x, v_y+n_pixels);
  486 + glEnd(); ///finish the quad.
  487 +
  488 + p1 = ver.p(1,1); ///generate the top right point from the vertical template.
  489 + p2 = ver.p(1,0); ///generate the bottom right point from the vertical template.
  490 + p3 = ver.p(0,0); ///generate the bottom left point from the vertical template.
  491 + p4 = ver.p(0,1); ///generate the top left point from the vertical template.
  492 + glBegin(GL_QUADS); ///generate the Quad from the 4 points.
500 493 glTexCoord3f(
501 494 p1[0],
502 495 p1[1],
503 496 p1[2]
504 497 );
505   - glVertex2f(v_x+t_length, v_y);
  498 + glVertex2f(v_x+n_pixels, v_y);
506 499 glTexCoord3f(
507 500 p2[0],
508 501 p2[1],
509 502 p2[2]
510 503 );
511   - glVertex2f(v_x+2.0*t_length, v_y);
  504 + glVertex2f(v_x+2.0*n_pixels, v_y);
512 505 glTexCoord3f(
513 506 p3[0],
514 507 p3[1],
515 508 p3[2]
516 509 );
517   - glVertex2f(v_x+2.0*t_length, v_y+t_length);
  510 + glVertex2f(v_x+2.0*n_pixels, v_y+n_pixels);
518 511 glTexCoord3f(
519 512 p4[0],
520 513 p4[1],
521 514 p4[2]
522 515 );
523   - glVertex2f(v_x+t_length, v_y+t_length);
524   - glEnd();
  516 + glVertex2f(v_x+n_pixels, v_y+n_pixels);
  517 + glEnd(); ///finish the quad.
525 518 }
526 519  
527 520  
... ... @@ -539,50 +532,24 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
539 532 void
540 533 GenerateFBO(unsigned int width, unsigned int height, GLuint &textureID, GLuint &framebufferID)
541 534 {
542   - glDeleteFramebuffers(1, &framebufferID);
543   - glGenFramebuffers(1, &framebufferID);
544   - glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
  535 + glDeleteFramebuffers(1, &framebufferID); ///clear the framebuffer.
  536 + glGenFramebuffers(1, &framebufferID); ///generate a clean buffer.
  537 + glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); ///bind the new buffer.
545 538 // int numChannels = 1;
546 539 // unsigned char* texels = new unsigned char[width * height * numChannels];
547   - glGenTextures(1, &textureID);
  540 + glGenTextures(1, &textureID); ///generate a texture that will attach to the buffer.
548 541 glBindTexture(GL_TEXTURE_2D, textureID);
549 542  
550 543 //Textures repeat and use linear interpolation, luminance format.
551   - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
552   - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
553   - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  544 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); ///Set up the texture to repeat at edges.
  545 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  546 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ///Set up the texture to use Linear interpolation
554 547 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
555   - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
  548 + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, ///Create the texture with no data.
556 549 width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
557 550 // delete[] texels;
558   - glBindFramebuffer(GL_FRAMEBUFFER, 0);
559   - glBindTexture(GL_TEXTURE_2D, 0);
560   - }
561   -
562   - ///@param uint width sets the width of the buffer.
563   - ///@param uint height sets the height of the buffer.
564   - ///Function for setting up the 2D buffer that stores the samples.
565   - void
566   - GenerateFBO(unsigned int width, unsigned int height)
567   - {
568   - glGenFramebuffers(1, &fboID);
569   - glBindFramebuffer(GL_FRAMEBUFFER, fboID);
570   -// int numChannels = 1;
571   -// unsigned char* texels = new unsigned char[width * height * numChannels];
572   - glGenTextures(1, &texbufferID);
573   - glBindTexture(GL_TEXTURE_2D, texbufferID);
574   -
575   - //Textures repeat and use linear interpolation, luminance format.
576   - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
577   - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
578   - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
579   - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
580   - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
581   - width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
582   -// delete[] texels;
583   - glBindFramebuffer(GL_FRAMEBUFFER, 0);
584   - glBindTexture(GL_TEXTURE_2D, 0);
585   - CHECK_OPENGL_ERROR
  551 + glBindFramebuffer(GL_FRAMEBUFFER, 0); ///Bind the frontbuffer
  552 + glBindTexture(GL_TEXTURE_2D, 0); ///Unbind the texture.
586 553 }
587 554  
588 555  
... ... @@ -614,9 +581,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
614 581 //rotate to the current direction of the spider.
615 582 glRotatef(rot[0], rot[1], rot[2], rot[3]);
616 583 //scale to the magnitude of the spider.
617   - glScalef(m[0],
618   - m[0],
619   - m[0]);
  584 + glScalef(m,
  585 + m,
  586 + m);
620 587 //get and store the current transformation matrix for later use.
621 588 glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
622 589 cT.set(curTrans);
... ... @@ -636,36 +603,6 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
636 603  
637 604 ///Method for controling the buffer and texture binding.
638 605 ///Clears the buffer upon binding.
639   - void
640   - Bind()
641   - {
642   - glBindFramebuffer(GL_FRAMEBUFFER, fboID);//set up GL buffer
643   - glFramebufferTexture2D(
644   - GL_FRAMEBUFFER,
645   - GL_COLOR_ATTACHMENT0,
646   - GL_TEXTURE_2D,
647   - texbufferID,
648   - 0);
649   - glBindFramebuffer(GL_FRAMEBUFFER, fboID);
650   - GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
651   - glDrawBuffers(1, DrawBuffers);
652   - glBindTexture(GL_TEXTURE_2D, texbufferID);
653   - glClearColor(1,1,1,1);
654   - glClear(GL_COLOR_BUFFER_BIT);
655   - glMatrixMode(GL_PROJECTION);
656   - glLoadIdentity();
657   - glMatrixMode(GL_MODELVIEW);
658   - glLoadIdentity();
659   - glViewport(0,0,2.0*t_length, numSamples*t_length);
660   - gluOrtho2D(0.0,2.0*t_length,0.0,numSamples*t_length);
661   - glEnable(GL_TEXTURE_3D);
662   - glBindTexture(GL_TEXTURE_3D, texID);
663   -
664   - CHECK_OPENGL_ERROR
665   - }
666   -
667   - ///Method for controling the buffer and texture binding.
668   - ///Clears the buffer upon binding.
669 606 ///@param GLuint &textureID, texture to be bound.
670 607 ///@param GLuint &framebufferID, framebuffer used for storage.
671 608 ///@param int nSamples, number of rectanges to create.
... ... @@ -673,25 +610,25 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
673 610 Bind(GLuint &textureID, GLuint &framebufferID, int nSamples, float len = 8.0)
674 611 {
675 612  
676   - glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);//set up GL buffer
677   - glFramebufferTexture2D(
  613 + glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); ///Bind the framebuffer.
  614 + glFramebufferTexture2D( ///associate it with the texture
678 615 GL_FRAMEBUFFER,
679 616 GL_COLOR_ATTACHMENT0,
680 617 GL_TEXTURE_2D,
681 618 textureID,
682 619 0);
683   - glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
684   - GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
685   - glDrawBuffers(1, DrawBuffers);
686   - glBindTexture(GL_TEXTURE_2D, textureID);
687   - glMatrixMode(GL_PROJECTION);
  620 + glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); ///Bind the framebuffer.
  621 + GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; ///generate the drawbuffer.
  622 + glDrawBuffers(1, DrawBuffers); ///set the drawbuffer.
  623 + glBindTexture(GL_TEXTURE_2D, textureID); ///Bind the texture passed.
  624 + glMatrixMode(GL_PROJECTION); ///clear out the draw matrices
688 625 glLoadIdentity();
689 626 glMatrixMode(GL_MODELVIEW);
690 627 glLoadIdentity();
691   - glViewport(0,0,2.0*len, nSamples*len);
692   - gluOrtho2D(0.0,2.0*len,0.0,nSamples*len);
693   - glEnable(GL_TEXTURE_3D);
694   - glBindTexture(GL_TEXTURE_3D, texID);
  628 + glViewport(0,0,2.0*len, nSamples*len); ///set up viewport
  629 + gluOrtho2D(0.0,2.0*len,0.0,nSamples*len); ///Set up ortho
  630 + glEnable(GL_TEXTURE_3D);
  631 + glBindTexture(GL_TEXTURE_3D, texID); ///bind the main texture (return to original state).
695 632  
696 633 CHECK_OPENGL_ERROR
697 634 }
... ... @@ -701,32 +638,14 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
701 638 Unbind()
702 639 {
703 640 //Finalize GL_buffer
704   - glBindTexture(GL_TEXTURE_3D, 0);
705   - CHECK_OPENGL_ERROR
706   - glBindTexture(GL_TEXTURE_2D, 0);
  641 + glBindTexture(GL_TEXTURE_3D, 0); ///Bind the front buffer.
707 642 CHECK_OPENGL_ERROR
708   - glBindFramebuffer(GL_FRAMEBUFFER, 0);
  643 + glBindTexture(GL_TEXTURE_2D, 0); ///Bind the default GL texture.
709 644 CHECK_OPENGL_ERROR
710   - glDisable(GL_TEXTURE_3D);
  645 + glBindFramebuffer(GL_FRAMEBUFFER, 0); ///Bind the defautl framebuffer.
711 646 CHECK_OPENGL_ERROR
712   - }
713   -
714   - ///Makes the spider take a step.
715   - ///starting with the current p, d, m, find the next optimal p, d, m.
716   - ///Performs the branch detection on each step.
717   - int
718   - StepP()
719   - {
720   - Bind();
  647 + glDisable(GL_TEXTURE_3D); ///Turn off texturing.
721 648 CHECK_OPENGL_ERROR
722   - findOptimalDirection();
723   - findOptimalPosition();
724   - findOptimalScale();
725   - Unbind();
726   - Bind(btexbufferID, bfboID, 27);
727   - branchDetection2();
728   - Unbind();
729   - return current_cost;
730 649 }
731 650  
732 651  
... ... @@ -741,27 +660,17 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
741 660 ///finds the minimum cost and sets the current_cost to that value.
742 661 /// and returns the index of the template with the minimal cost.
743 662 int
744   - getCost()
745   - {
746   - stim::vec<int> cost =
747   -// stim::cuda::get_cost(texbufferID, GL_TEXTURE_2D, numSamples);
748   - cudaDeviceSynchronize();
749   - current_cost = cost[1];
750   - return cost[0];
751   - }
752   -
753   - int
754 663 getCost(cudaTextureObject_t tObj, float* result, int n)
755 664 {
756 665 #ifdef TIMING
757 666 gpuStartTimer();
758 667 #endif
759 668 stim::vec<int> cost =
760   - stim::cuda::get_cost(tObj, result, n, 2*t_length, t_length);
  669 + stim::cuda::get_cost(tObj, result, n, 2*n_pixels, n_pixels); ///call the cuda function with the appropriate texture buffer.
761 670 #ifdef TIMING
762 671 cost_time += gpuStopTimer();
763 672 #endif
764   - current_cost = cost[1];
  673 + current_cost = cost[1]; ///current cost.
765 674 return cost[0];
766 675 }
767 676  
... ... @@ -798,7 +707,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
798 707 // std::cout << "I ran this constructor" << std::endl;
799 708 p = stim::vec3<float>(0.0, 0.0, 0.0);
800 709 d = stim::vec3<float>(0.0, 0.0, 1.0);
801   - m = stim::vec<float>(1.0, 1.0);
  710 + m = 1.0;
802 711 S = stim::vec3<float>(1.0, 1.0, 1.0);
803 712 R = stim::vec3<float>(1.0, 1.0, 1.0);
804 713 numSamples = samples;
... ... @@ -821,7 +730,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
821 730 {
822 731 p = stim::vec3<float>(pos_x, pos_y, pos_z);
823 732 d = stim::vec3<float>(dir_x, dir_y, dir_z);
824   - m = stim::vec<float>(mag_x, mag_x, mag_x);
  733 + m = mag_x;
825 734 S = stim::vec3<float>(1.0,1.0,1.0);
826 735 R = stim::vec3<float>(1.0,1.0,1.0);
827 736 numSamples = numsamples;
... ... @@ -839,7 +748,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
839 748 {
840 749 p = pos;
841 750 d = dir;
842   - m = vec<float>(mag, mag, mag);
  751 + m = mag;
843 752 S = vec3<float>(1.0,1.0,1.0);
844 753 R = vec3<float>(1.0,1.0,1.0);
845 754 numSamples = samples;
... ... @@ -852,14 +761,14 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
852 761 (void)
853 762 {
854 763 Unbind();
855   - glDeleteTextures(1, &texbufferID);
856   - glDeleteBuffers(1, &fboID);
857   - glDeleteTextures(1, &ptexbufferID);
858   - glDeleteBuffers(1, &pfboID);
859   - glDeleteTextures(1, &mtexbufferID);
860   - glDeleteBuffers(1, &mfboID);
861   - glDeleteTextures(1, &btexbufferID);
862   - glDeleteBuffers(1, &bfboID);
  764 + glDeleteTextures(1, &direction_texID);
  765 + glDeleteBuffers(1, &direction_buffID);
  766 + glDeleteTextures(1, &position_texID);
  767 + glDeleteBuffers(1, &position_buffID);
  768 + glDeleteTextures(1, &radius_texID);
  769 + glDeleteBuffers(1, &radius_buffID);
  770 + glDeleteTextures(1, &cylinder_texID);
  771 + glDeleteBuffers(1, &cylinder_buffID);
863 772 }
864 773  
865 774 ///@param GLuint id, texture that is going to be sampled.
... ... @@ -878,42 +787,39 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
878 787 network_time = 0;
879 788 hit_time = 0;
880 789 #endif
881   - stepsize = 2.5;
882   - t_length = 16.0;
  790 + stepsize = 3.0;
  791 + n_pixels = 16.0;
883 792  
884 793 srand(100);
885 794 texID = id;
886   - GenerateFBO(t_length*2, numSamples*t_length, texbufferID, fboID);
887   - std::cout << numSamples << std::endl;
  795 + GenerateFBO(n_pixels*2, numSamples*n_pixels, direction_texID, direction_buffID);
888 796 CHECK_OPENGL_ERROR
889   - GenerateFBO(t_length*2, numSamplesPos*t_length, ptexbufferID, pfboID);
890   - std::cout << numSamplesPos << std::endl;
  797 + GenerateFBO(n_pixels*2, numSamplesPos*n_pixels, position_texID, position_buffID);
891 798 CHECK_OPENGL_ERROR
892   - GenerateFBO(t_length*2, numSamplesMag*t_length, mtexbufferID, mfboID);
893   - std::cout << numSamplesMag << std::endl;
  799 + GenerateFBO(n_pixels*2, numSamplesMag*n_pixels, radius_texID, radius_buffID);
894 800 CHECK_OPENGL_ERROR
895   - GenerateFBO(16, 216, btexbufferID, bfboID);
  801 + GenerateFBO(16, 216, cylinder_texID, cylinder_buffID);
896 802 CHECK_OPENGL_ERROR
897 803 t_dir.MapCudaTexture(texbufferID, GL_TEXTURE_2D);
898 804 t_dir.Alloc(numSamples);
899   - t_pos.MapCudaTexture(ptexbufferID, GL_TEXTURE_2D);
  805 + t_pos.MapCudaTexture(position_texID, GL_TEXTURE_2D);
900 806 t_pos.Alloc(numSamplesPos);
901   - t_mag.MapCudaTexture(mtexbufferID, GL_TEXTURE_2D);
  807 + t_mag.MapCudaTexture(radius_texID, GL_TEXTURE_2D);
902 808 t_mag.Alloc(numSamplesMag);
903 809 setMatrix();
904 810 dList = glGenLists(3);
905 811 glListBase(dList);
906   - Bind(texbufferID, fboID, numSamples, t_length);
  812 + Bind(direction_texID, direction_buffID, numSamples, n_pixels);
907 813 genDirectionVectors(5*stim::PI/4);
908 814 Unbind();
909   - Bind(ptexbufferID, pfboID, numSamplesPos, t_length);
  815 + Bind(position_texID, position_buffID, numSamplesPos, n_pixels);
910 816 genPositionVectors();
911 817 Unbind();
912   - Bind(mtexbufferID, mfboID, numSamplesMag, t_length);
  818 + Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
913 819 genMagnitudeVectors();
914 820 Unbind();
915   - Bind(btexbufferID, bfboID, 27);
916   - DrawCylinder();
  821 + Bind(cylinder_texID, cylinder_buffID, 27);
  822 + DrawCylinder();
917 823 Unbind();
918 824 }
919 825  
... ... @@ -981,22 +887,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
981 887 d[2] = z;
982 888 }
983 889  
984   - ///@param stim::vec<float> dir, the new d.
985   - ///Sets the m vector to the input vector mag.
986   - void
987   - setMagnitude(stim::vec<float> mag)
988   - {
989   - m[0] = mag[0];
990   - m[1] = mag[0];
991   - }
992 890  
993 891 ///@param float mag, size of the sampled region.
994 892 ///Sets the m vector to the input mag for both templates.
995 893 void
996 894 setMagnitude(float mag)
997 895 {
998   - m[0] = mag;
999   - m[1] = mag;
  896 + m = mag;
1000 897 }
1001 898  
1002 899 ///@param float x, voxel size in the x direction.
... ... @@ -1269,7 +1166,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1269 1166 GLuint
1270 1167 getFB()
1271 1168 {
1272   - return bfboID;
  1169 + return cylinder_buffID;
1273 1170 }
1274 1171  
1275 1172 //--------------------------------------------------------------------------//
... ... @@ -1293,14 +1190,14 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1293 1190 int
1294 1191 Step()
1295 1192 {
1296   - Bind(texbufferID, fboID, numSamples, t_length);
  1193 + Bind(direction_texID, direction_buffID, numSamples, n_pixels);
1297 1194 CHECK_OPENGL_ERROR
1298 1195 findOptimalDirection();
1299 1196 Unbind();
1300   - Bind(ptexbufferID, pfboID, numSamplesPos, t_length);
  1197 + Bind(position_texID, position_buffID, numSamplesPos, n_pixels);
1301 1198 findOptimalPosition();
1302 1199 Unbind();
1303   - Bind(mtexbufferID, mfboID, numSamplesMag, t_length);
  1200 + Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels);
1304 1201 findOptimalScale();
1305 1202 Unbind();
1306 1203 CHECK_OPENGL_ERROR
... ... @@ -1387,12 +1284,13 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1387 1284 }
1388 1285  
1389 1286 ///need to return the cylinder.
  1287 +///SOMETHING MIGHT BE GOING ON HERE IN GENERATE BUFFER.
1390 1288 void
1391 1289 DrawLongCylinder(int n = 8, int l_template = 8,int l_square = 8)
1392 1290 {
1393 1291 int cylLen = cL.size()-1;
1394   - GenerateFBO(n*l_square, cylLen*l_template, btexbufferID, bfboID);
1395   - Bind(btexbufferID, bfboID, cylLen, l_template*l_square/2.0);
  1292 + GenerateFBO(n*l_square, cylLen*l_template, cylinder_texID, cylinder_buffID);
  1293 + Bind(cylinder_texID, cylinder_buffID, cylLen, l_template*l_square/2.0);
1396 1294 stim::cylinder<float> cyl(cL, cM);
1397 1295 std::vector<std::vector<stim::vec3<float> > > p = cyl.getPoints(n);
1398 1296 for(int i = 0; i < p.size()-1; i++) ///number of circles
... ... @@ -1636,12 +1534,9 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1636 1534 {
1637 1535 //starting (seed) position and magnitude.
1638 1536 stim::vec3<float> spos = getPosition();
1639   -// std::cout << "I did this" << std::endl;
1640   -// findOptimalScale();
1641 1537 stim::vec<float> smag = getMagnitude();
1642 1538 stim::vec3<float> sdir = getDirection();
1643 1539  
1644   - Bind();
1645 1540 // sk.Begin(stim::OBJ_LINE);
1646 1541  
1647 1542  
... ... @@ -1662,7 +1557,6 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1662 1557 int cost = Step();
1663 1558 if (cost > min_cost){
1664 1559 running = false;
1665   -// sk.End();
1666 1560 branchDetection2();
1667 1561 addToNetwork(cL, cM);
1668 1562 std::cout << "the cost of " << cost << " > " << min_cost << std::endl;
... ... @@ -1698,7 +1592,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1698 1592 }
1699 1593 else
1700 1594 {
1701   - h = selectObject(p, getDirection(), m[0]);
  1595 + h = selectObject(p, getDirection(), m);
1702 1596 //Have we hit something previously traced?
1703 1597 if(h != -1){
1704 1598 std::cout << "I hit the fiber " << h << std::endl;
... ... @@ -1709,11 +1603,8 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
1709 1603 }
1710 1604 else {
1711 1605 cL.push_back(stim::vec3<float>(p[0], p[1],p[2]));
1712   - cM.push_back(stim::vec<float>(m[0], m[0]));
1713   -// Bind(btexbufferID, bfboID, 27);
1714   - Unbind();
  1606 + cM.push_back(m);
1715 1607 CHECK_OPENGL_ERROR
1716   -
1717 1608 }
1718 1609 }
1719 1610 }
... ...