Commit ac4305670804ca86139701eb2aff0f77d8d12f2d

Authored by Pavel Govyadinov
1 parent 6b8621f8

comments comments comments, reorganized methods, added constructors and access methods.

Showing 1 changed file with 248 additions and 186 deletions   Show diff stats
stim/gl/gl_spider.h
... ... @@ -74,7 +74,6 @@ class gl_spider : public virtual gl_texture<T>
74 74  
75 75 GLuint mfboID; //buffer object for magnitude adjustment.
76 76 GLuint mtexbufferID; //texture object for magnitude adjustment.
77   -
78 77 GLuint bfboId; //buffer object for position adjustment.
79 78 GLuint btexbufferID; //buffer object for position adjustment.
80 79  
... ... @@ -106,26 +105,26 @@ class gl_spider : public virtual gl_texture<T>
106 105 //-------------------------------PRIVATE METHODS----------------------------//
107 106 //--------------------------------------------------------------------------//
108 107  
109   -
110 108 /// Method for finding the best scale for the spider.
111 109 /// changes the x, y, z size of the spider to minimize the cost
112 110 /// function.
113 111 void
114 112 findOptimalDirection()
115 113 {
116   - setMatrix();
117   - glCallList(dList);
118   - int best = getCost();
119   - stim::vec<float> next(
  114 + setMatrix(); //create the transformation matrix.
  115 + glCallList(dList); //move the templates to p, d, m.
  116 + int best = getCost(); //find min cost.
  117 + stim::vec<float> next( //find next vector.
120 118 dV[best][0]*S[0]*R[0],
121 119 dV[best][1]*S[1]*R[1],
122 120 dV[best][2]*S[2]*R[2],
123 121 0);
124   - next = (cT*next).norm();
  122 + next = (cT*next).norm(); //find next vector.
125 123 setPosition( p[0]+next[0]*m[0]/stepsize,
126 124 p[1]+next[1]*m[0]/stepsize,
127 125 p[2]+next[2]*m[0]/stepsize);
128 126 setDirection(next[0], next[1], next[2]);
  127 + //move forward and change direction.
129 128 }
130 129  
131 130 /// Method for finding the best d (direction) for the spider.
... ... @@ -134,20 +133,20 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
134 133 void
135 134 findOptimalPosition()
136 135 {
137   - setMatrix();
138   - glCallList(dList+1);
139   - int best = getCost();
140   - stim::vec<float> next(
  136 + setMatrix(); //create the transformation matrix.
  137 + glCallList(dList+1); //move the templates to p, d, m.
  138 + int best = getCost(); //find min cost.
  139 + stim::vec<float> next( //find next position.
141 140 pV[best][0],
142 141 pV[best][1],
143 142 pV[best][2],
144 143 1);
145   - next = cT*next;
  144 + next = cT*next; //find next position.
146 145 setPosition(
147 146 next[0]*S[0]*R[0],
148 147 next[1]*S[1]*R[1],
149 148 next[2]*S[2]*R[2]
150   - );
  149 + ); //adjust position.
151 150 }
152 151  
153 152 /// Method for finding the best scale for the spider.
... ... @@ -156,13 +155,15 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
156 155 void
157 156 findOptimalScale()
158 157 {
159   - setMatrix();
160   - glCallList(dList+2);
161   - int best = getCost();
162   - setMagnitude(m[0]*mV[best][0]);
  158 + setMatrix(); //create the transformation.
  159 + glCallList(dList+2); //move the templates to p, d, m.
  160 + int best = getCost(); //get best cost.
  161 + setMagnitude(m[0]*mV[best][0]); //adjust the magnitude.
163 162 }
164 163  
165 164  
  165 + ///subject to change.
  166 + ///finds branches.
166 167 void
167 168 branchDetection()
168 169 {
... ... @@ -212,16 +213,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
212 213  
213 214 }
214 215  
215   -
216   -
217   - void
218   - Optimize()
219   - {
220   - /*find the optimum d and scale */
221   - }
222   -
223   -
224   -
225 216  
226 217 //--------------------------------------------------------------------------//
227 218 //---------------------TEMPLATE CREATION METHODS----------------------------//
... ... @@ -236,10 +227,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
236 227 void
237 228 genDirectionVectors(float solidAngle = 5/M_PI*4)
238 229 {
239   - //ofstream file;
240   - //file.open("dvectors.txt");
241 230 //Set up the vectors necessary for Rectangle creation.
242   - vec<float> Y(1.0,0.0,0.0);
  231 + vec<float> Y(1.0,0.0,0.0); //orthogonal vec.
243 232 vec<float> pos(0.0,0.0,0.0);
244 233 vec<float> mag(1.0, 1.0, 1.0);
245 234 vec<float> dir(0.0, 0.0, 1.0);
... ... @@ -248,12 +237,12 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
248 237 vec<float> d_s = d.cart2sph().norm();
249 238 vec<float> temp(0,0,0);
250 239 int dim = (sqrt(numSamples)-1)/2;
251   - float p0 = -M_PI;
252   - float dt = solidAngle/(2.0 * ((float)dim + 1.0));
253   - float dp = p0/(2.0*((float)dim + 1.0));
  240 + float p0 = -M_PI; //phi angle in spherical coordinates.
  241 + float dt = solidAngle/(2.0 * ((float)dim + 1.0)); //step size in Theta.
  242 + float dp = p0/(2.0*((float)dim + 1.0)); //step size in Phi.
254 243  
255   - glNewList(dList, GL_COMPILE);
256   - //Loop over the space
  244 + glNewList(dList, GL_COMPILE);
  245 + //Loop over the above defined space creating distinct vectors.
257 246 int idx = 0;
258 247 for(int i = -dim; i <= dim; i++){
259 248 for(int j = -dim; j <= dim; j++){
... ... @@ -282,28 +271,30 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
282 271 glEndList();
283 272 }
284 273  
285   - ///@param solidAngle, the size of the arc to sample.
  274 + ///@param float delta, How much the rectangles vary in position.
286 275 ///Method for populating the buffer with the sampled texture.
  276 + ///Objects created are rectangles the with the created positions.
  277 + ///All points are sampled from a texture.
  278 + ///Stored in a display list.
287 279 ///uses the default vector <0,0,0>
288 280 void
289 281 genPositionVectors(float delta = 0.4)
290 282 {
291 283 //Set up the vectors necessary for Rectangle creation.
292   - vec<float> Y(1.0,0.0,0.0);
  284 + vec<float> Y(1.0,0.0,0.0); //orthogonal vec.
293 285 vec<float> pos(0.0,0.0,0.0);
294 286 vec<float> mag(1.0, 1.0, 1.0);
295 287 vec<float> dir(0.0, 0.0, 1.0);
296 288  
297 289 //Set up the variable necessary for vector creation.
298 290 vec<float> temp(0,0,0);
299   - int dim = (sqrt(numSamples)-1)/2;
300   - stim::rect<float> samplingPlane =
  291 + int dim = (sqrt(numSamples)-1)/2; //number of position vectors.
  292 + stim::rect<float> samplingPlane = //plane from which we pull position samples
301 293 stim::rect<float>(p, d);
302 294 samplingPlane.scale(mag[0]*delta, mag[0]*delta);
303   - float step = 1.0/(dim);
  295 + float step = 1.0/(dim); //step size.
304 296  
305   - //Loop over the samples, keeping the original p sample
306   - //in the center of the resulting texture.
  297 + //Loop over the samples, keeping the original p samples in the center of the resulting texture to create a large number of position vectors.
307 298 int idx;
308 299 glNewList(dList+1, GL_COMPILE);
309 300 for(int i = -dim; i <= dim; i++){
... ... @@ -330,16 +321,18 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
330 321 glEndList();
331 322 }
332 323  
333   - ///@param solidAngle, the size of the arc to sample.
  324 + ///@param float delta, How much the rectangles are allowed to expand.
334 325 ///Method for populating the buffer with the sampled texture.
  326 + ///Objects created are rectangles the with the created sizes.
  327 + ///All points are sampled from a texture.
  328 + ///Stored in a display list.
335 329 ///uses the default m <1,1,0>
336 330 void
337 331 genMagnitudeVectors(float delta = 0.70)
338   -// genMagnitudeVectors(float delta = 0.50)
339 332 {
340 333  
341 334 //Set up the vectors necessary for Rectangle creation.
342   - vec<float> Y(1.0,0.0,0.0);
  335 + vec<float> Y(1.0,0.0,0.0); //orthogonal vec.
343 336 vec<float> pos(0.0,0.0,0.0);
344 337 vec<float> mag(1.0, 1.0, 1.0);
345 338 vec<float> dir(0.0, 0.0, 1.0);
... ... @@ -370,10 +363,11 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
370 363 }
371 364 glEndList();
372 365 }
373   - ///@param v_x x-coordinate in buffer-space,
374   - ///@param v_y y-coordinate in buffer-space.
375   - ///Samples the texturespace and places a sample in the provided coordinates
376   - ///of bufferspace.
  366 +
  367 + ///@param float v_x x-coordinate in buffer-space,
  368 + ///@param float v_y y-coordinate in buffer-space.
  369 + ///Samples the texture space.
  370 + ///places a sample in the provided coordinates of bufferspace.
377 371 void
378 372 UpdateBuffer(float v_x, float v_y)
379 373 {
... ... @@ -451,9 +445,12 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
451 445 //--------------------------------GL METHODS--------------------------------//
452 446 //--------------------------------------------------------------------------//
453 447  
454   - ///@param width sets the width of the buffer.
455   - ///@param height sets the height of the buffer.
  448 + ///@param uint width sets the width of the buffer.
  449 + ///@param uint height sets the height of the buffer.
  450 + ///@param GLuint &textureID gives the texture ID of the texture to be initialized.
  451 + ///@param GLuint &framebufferID gives the buffer ID of the texture to be initialized.
456 452 ///Function for setting up the 2D buffer that stores the samples.
  453 + ///Initiates and sets parameters.
457 454 void
458 455 GenerateFBO(unsigned int width, unsigned int height, GLuint &textureID, GLuint &framebufferID)
459 456 {
... ... @@ -463,6 +460,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
463 460 unsigned char* texels = new unsigned char[width * height * numChannels];
464 461 glGenTextures(1, &textureID);
465 462 glBindTexture(GL_TEXTURE_2D, textureID);
  463 +
  464 + //Textures repeat and use linear interpolation, luminance format.
466 465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
467 466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
468 467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
... ... @@ -472,11 +471,11 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
472 471 delete[] texels;
473 472 glBindFramebuffer(GL_FRAMEBUFFER, 0);
474 473 glBindTexture(GL_TEXTURE_2D, 0);
475   - CHECK_OPENGL_ERROR
  474 + CHECK_OPENGL_ERROR
476 475 }
477 476  
478   - ///@param width sets the width of the buffer.
479   - ///@param height sets the height of the buffer.
  477 + ///@param uint width sets the width of the buffer.
  478 + ///@param uint height sets the height of the buffer.
480 479 ///Function for setting up the 2D buffer that stores the samples.
481 480 void
482 481 GenerateFBO(unsigned int width, unsigned int height)
... ... @@ -487,6 +486,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
487 486 unsigned char* texels = new unsigned char[width * height * numChannels];
488 487 glGenTextures(1, &texbufferID);
489 488 glBindTexture(GL_TEXTURE_2D, texbufferID);
  489 +
  490 + //Textures repeat and use linear interpolation, luminance format.
490 491 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
491 492 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
492 493 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
... ... @@ -496,42 +497,45 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
496 497 delete[] texels;
497 498 glBindFramebuffer(GL_FRAMEBUFFER, 0);
498 499 glBindTexture(GL_TEXTURE_2D, 0);
499   - CHECK_OPENGL_ERROR
  500 + CHECK_OPENGL_ERROR
500 501 }
501 502  
502 503  
503   - ///Method for using the gl manipulation to alighn templates from
  504 + ///Method for using the gl manipulation to align templates from
504 505 ///Template space (-0.5 0.5) to Texture space (0.0, 1.0),
505 506 ///Based on the p of the spider in real space (arbitrary).
  507 + ///All transformation happen in glMatrixMode(GL_TEXTURE).
506 508 void setMatrix()
507 509 {
508   - float curTrans[16];
509   - stim::vec<float> rot = getRotation(d);
  510 + float curTrans[16]; //array to store the matrix values.
  511 + stim::vec<float> rot = getRotation(d); //get the rotation parameters for the current direction vector.
510 512 glMatrixMode(GL_TEXTURE);
511 513 glLoadIdentity();
512   - glScalef(1.0/S[0]/R[0], 1.0/S[1]/R[1], 1.0/S[2]/R[2]);
513   -
514 514  
  515 + //Scale by the voxel size and number of slices.
  516 + glScalef(1.0/S[0]/R[0], 1.0/S[1]/R[1], 1.0/S[2]/R[2]);
  517 + //translate to the current position of the spider in the texture.
515 518 glTranslatef(p[0],
516 519 p[1],
517 520 p[2]);
518   -
  521 + //rotate to the current direction of the spider.
519 522 glRotatef(rot[0], rot[1], rot[2], rot[3]);
520   -
  523 + //scale to the magnitude of the spider.
521 524 glScalef(m[0],
522 525 m[0],
523 526 m[0]);
524   -
  527 + //get and store the current transformation matrix for later use.
525 528 glGetFloatv(GL_TEXTURE_MATRIX, curTrans);
526 529 cT.set(curTrans);
527 530 // printTransform();
528 531  
529 532 CHECK_OPENGL_ERROR
  533 + //revert back to default gl mode.
530 534 glMatrixMode(GL_MODELVIEW);
531 535 }
532 536  
533   - ///Method for controling the buffer and texture binding in order to properly
534   - ///do the render to texture.
  537 + ///Method for controling the buffer and texture binding.
  538 + ///Clears the buffer upon binding.
535 539 void
536 540 Bind()
537 541 {
... ... @@ -561,34 +565,26 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
561 565 CHECK_OPENGL_ERROR
562 566 }
563 567  
564   - ///Method for controling the buffer and texture binding in order to properly
565   - ///do the render to texture.
566   - ///@param GLuint tbID
  568 + ///Method for controling the buffer and texture binding.
  569 + ///Clears the buffer upon binding.
  570 + ///@param GLuint &textureID, texture to be bound.
  571 + ///@param GLuint &framebufferID, framebuffer used for storage.
  572 + ///@param int nSamples, number of rectanges to create.
567 573 void
568 574 Bind(GLuint &textureID, GLuint &framebufferID, int nSamples)
569 575 {
570 576 float len = 8.0;
571 577 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);//set up GL buffer
572   - CHECK_OPENGL_ERROR
573   -
574 578 glFramebufferTexture2D(
575 579 GL_FRAMEBUFFER,
576 580 GL_COLOR_ATTACHMENT0,
577 581 GL_TEXTURE_2D,
578 582 textureID,
579 583 0);
580   - CHECK_OPENGL_ERROR
581   -
582 584 glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);
583   - CHECK_OPENGL_ERROR
584   -
585 585 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
586 586 glDrawBuffers(1, DrawBuffers);
587   - CHECK_OPENGL_ERROR
588   -
589 587 glBindTexture(GL_TEXTURE_2D, textureID);
590   - CHECK_OPENGL_ERROR
591   -
592 588 glClearColor(1,1,1,1);
593 589 glClear(GL_COLOR_BUFFER_BIT);
594 590 glMatrixMode(GL_PROJECTION);
... ... @@ -603,7 +599,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
603 599 CHECK_OPENGL_ERROR
604 600 }
605 601  
606   - ///Method for Unbinding all of the texture resources
  602 + ///Unbinds all texture resources.
607 603 void
608 604 Unbind()
609 605 {
... ... @@ -617,6 +613,34 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
617 613 glDisable(GL_TEXTURE_3D);
618 614 CHECK_OPENGL_ERROR
619 615 }
  616 +
  617 + ///Makes the spider take a step.
  618 + ///starting with the current p, d, m, find the next optimal p, d, m.
  619 + ///Performs the branch detection on each step.
  620 + int
  621 + StepP()
  622 + {
  623 + Bind();
  624 + CHECK_OPENGL_ERROR
  625 + #ifdef TESTING
  626 + start = std::clock();
  627 + #endif
  628 + findOptimalDirection();
  629 + findOptimalPosition();
  630 + findOptimalScale();
  631 + Unbind();
  632 + Bind(btexbufferID, bfboId, 27);
  633 + branchDetection();
  634 + Unbind();
  635 +
  636 + #ifdef TESTING
  637 + duration_sampling = duration_sampling +
  638 + (std::clock() - start) / (double) CLOCKS_PER_SEC;
  639 + num_sampling = num_sampling + 1.0;
  640 + #endif
  641 + return current_cost;
  642 + }
  643 +
620 644  
621 645  
622 646  
... ... @@ -625,8 +649,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
625 649 //--------------------------------------------------------------------------//
626 650  
627 651  
628   - ///Entry-point into the cuda code for calculating the cost
629   - /// of a given samples array (in texture form)
  652 + ///Entry-point into the cuda code for calculating the cost of a given samples array (in texture form)
  653 + ///finds the minimum cost and sets the current_cost to that value.
  654 + /// and returns the index of the template with the minimal cost.
630 655 int
631 656 getCost()
632 657 {
... ... @@ -645,8 +670,22 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
645 670 return cost[0];
646 671 }
647 672  
  673 +
648 674 public:
  675 +
  676 + ///ininializes the cuda device and environment.
  677 + void
  678 + initCuda()
  679 + {
  680 + stim::cudaSetDevice();
  681 + //GLint max;
  682 + //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
  683 + //std::cout << max << std::endl;
  684 + }
  685 +
  686 + //horizonal rectangle forming the spider.
649 687 stim::rect<float> hor;
  688 + //vectical rectangle forming the spider.
650 689 stim::rect<float> ver;
651 690  
652 691 //Testing and Timing variables.
... ... @@ -663,8 +702,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
663 702 //--------------------------------------------------------------------------//
664 703  
665 704  
666   - ///@param samples, the number of samples this spider is going to use.
667   - ///best results if samples is can create a perfect root.
  705 + ///@param int samples, the number of samples this spider is going to use.
  706 + ///Best results if samples is can create a perfect root.
668 707 ///Default Constructor
669 708 gl_spider
670 709 (int samples = 1089)
... ... @@ -674,13 +713,18 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
674 713 m = vec<float>(1.0, 1.0);
675 714 S = vec<float>(1.0, 1.0, 1.0);
676 715 R = vec<float>(1.0, 1.0, 1.0);
677   - //setPosition(0.0,0.0,0.0);
678   - //setDirection(0.0,0.0,1.0);
679   - //setMagnitude(1.0);
680 716 numSamples = samples;
681 717 }
682 718  
683   - ///temporary constructor for convenience, will be removed in further updates.
  719 + ///Position constructor: floats.
  720 + ///@param float pos_x, position x.
  721 + ///@param float pos_y, position y.
  722 + ///@param float pos_z, position z.
  723 + ///@param float dir_x, direction x.
  724 + ///@param float dir_y, direction y.
  725 + ///@param float dir_z, direction z.
  726 + ///@param float mag_x, size of the vector.
  727 + ///@param int samples, number of templates this spider is going to use.
684 728 gl_spider
685 729 (float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z,
686 730 float mag_x, int numSamples = 1089)
... ... @@ -690,12 +734,26 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
690 734 m = vec<float>(mag_x, mag_x, mag_x);
691 735 S = vec<float>(1.0,1.0,1.0);
692 736 R = vec<float>(1.0,1.0,1.0);
693   - //setPosition(pos_x, pos_y, pos_z);
694   - //setDirection(dir_x, dir_y, dir_z);
695   - //setMagnitude(mag_x);
696   -
  737 +// numSamples = samples;
697 738 }
698   -
  739 +
  740 + ///Position constructor: vecs of floats.
  741 + ///@param stim::vec<float> pos, position.
  742 + ///@param stim::vec<float> dir, direction.
  743 + ///@param float mag, size of the vector.
  744 + ///@param int samples, number of templates this spider is going to use.
  745 + gl_spider
  746 + (stim::vec<float> pos, stim::vec<float> dir, float mag, int samples = 1089)
  747 + {
  748 + p = pos;
  749 + d = dir;
  750 + m = vec<float>(mag, mag, mag);
  751 + S = vec<float>(1.0,1.0,1.0);
  752 + R = vec<float>(1.0,1.0,1.0);
  753 + numSamples = samples;
  754 + }
  755 +
  756 + ///destructor
699 757 ~gl_spider
700 758 (void)
701 759 {
... ... @@ -710,7 +768,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
710 768 glDeleteBuffers(1, &bfboId);
711 769 }
712 770  
713   - ///@param GLuint id texture that is going to be sampled.
  771 + ///@param GLuint id, texture that is going to be sampled.
714 772 ///Attached the spider to the texture with the given GLuint ID.
715 773 ///Samples in the default d acting as the init method.
716 774 ///Also acts an init.
... ... @@ -730,7 +788,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
730 788 genPositionVectors();
731 789 genMagnitudeVectors();
732 790 Unbind();
733   - ///temporarily changed to 216
734 791 Bind(btexbufferID, bfboId, 27);
735 792 DrawCylinder();
736 793 Unbind();
... ... @@ -760,7 +817,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
760 817 return m;
761 818 }
762 819  
763   - ///@param vector pos, the new p.
  820 + ///@param stim::vec<float> pos, the new p.
764 821 ///Sets the p vector to input vector pos.
765 822 void
766 823 setPosition(vec<float> pos)
... ... @@ -768,9 +825,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
768 825 p = pos;
769 826 }
770 827  
771   - ///@param x x-coordinate.
772   - ///@param y y-coordinate.
773   - ///@param z z-coordinate.
  828 + ///@param float x x-coordinate.
  829 + ///@param float y y-coordinate.
  830 + ///@param float z z-coordinate.
774 831 ///Sets the p vector to the input float coordinates x,y,z.
775 832 void
776 833 setPosition(float x, float y, float z)
... ... @@ -780,7 +837,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
780 837 p[2] = z;
781 838 }
782 839  
783   - ///@param vector dir, the new d.
  840 + ///@param stim::vec<float> dir, the new d.
784 841 ///Sets the d vector to input vector dir.
785 842 void
786 843 setDirection(vec<float> dir)
... ... @@ -788,9 +845,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
788 845 d = dir;
789 846 }
790 847  
791   - ///@param x x-coordinate.
792   - ///@param y y-coordinate.
793   - ///@param z z-coordinate.
  848 + ///@param stim::vec<float> x x-coordinate.
  849 + ///@param stim::vec<float> y y-coordinate.
  850 + ///@param stim::vec<float> z z-coordinate.
794 851 ///Sets the d vector to the input float coordinates x,y,z.
795 852 void
796 853 setDirection(float x, float y, float z)
... ... @@ -800,7 +857,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
800 857 d[2] = z;
801 858 }
802 859  
803   - ///@param vector dir, the new d.
  860 + ///@param stim::vec<float> dir, the new d.
804 861 ///Sets the m vector to the input vector mag.
805 862 void
806 863 setMagnitude(vec<float> mag)
... ... @@ -809,7 +866,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
809 866 m[1] = mag[0];
810 867 }
811 868  
812   - ///@param mag size of the sampled region.
  869 + ///@param float mag, size of the sampled region.
813 870 ///Sets the m vector to the input mag for both templates.
814 871 void
815 872 setMagnitude(float mag)
... ... @@ -818,7 +875,10 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
818 875 m[1] = mag;
819 876 }
820 877  
821   -
  878 + ///@param float x, voxel size in the x direction.
  879 + ///@param float y, voxel size in the y direction.
  880 + ///@param float z, voxel size in the z direction.
  881 + ///Sets the voxel sizes in each direction. necessary for non-standard data.
822 882 void
823 883 setDims(float x, float y, float z)
824 884 {
... ... @@ -827,6 +887,18 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
827 887 S[2] = z;
828 888 }
829 889  
  890 + ///@param stim::vec<float> Dims, voxel size.
  891 + ///Sets the voxel sizes in each direction. necessary for non-standard data.
  892 + void
  893 + setDims(stim::vec<float> Dims)
  894 + {
  895 + S = Dims;
  896 + }
  897 +
  898 + ///@param float x, size of the data in the x direction.
  899 + ///@param float y, size of the data in the y direction.
  900 + ///@param float z, size of the data in the z direction.
  901 + ///Sets the data volume sizes in each direction.
830 902 void
831 903 setSize(float x, float y, float z)
832 904 {
... ... @@ -834,10 +906,19 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
834 906 R[1] = y;
835 907 R[2] = z;
836 908 }
  909 +
  910 + ///@param stim::vec<float> Dims, size of the volume.
  911 + ///Sets the data volume sizes in each direction.
  912 + void
  913 + setSize(stim::vec<float> Siz)
  914 + {
  915 + S = Siz;
  916 + }
837 917  
838   - ///@param dir, the vector to which we are rotating
839   - ///given a vector to align to, finds the required
840   - ///axis and angle for glRotatef
  918 + ///@param stim::vec<float> dir, the vector to which we are rotating.
  919 + ///given a vector to align to, finds the required axis and angle for glRotatef.
  920 + ///rotates from 0.0, 0.0, 1.0 to dir.
  921 + ///return is in degrees for use with glRotatef.
841 922 stim::vec<float>
842 923 getRotation(stim::vec<float> dir)
843 924 {
... ... @@ -859,7 +940,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
859 940 return out;
860 941 }
861 942  
862   - ///@param pos, the position of the seed to be added.
  943 + ///@param stim::vec<float> pos, the position of the seed to be added.
863 944 ///Adds a seed to the seed list.
864 945 ///Assumes that the coordinates passes are in tissue space.
865 946 void
... ... @@ -868,12 +949,17 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
868 949 seeds.push(pos);
869 950 }
870 951  
  952 + ///@param stim::vec<float> dir, the direction of the seed to be added.
  953 + ///Adds a seed to the seed directions list.
871 954 void
872 955 setSeedVec(stim::vec<float> dir)
873 956 {
874 957 seedsvecs.push(dir);
875 958 }
876 959  
  960 + ///@param float mag, the size of the seed to be added.
  961 + ///Adds a seed to the seed list.
  962 + ///Assumes that the coordinates passes are in tissue space.
877 963 void
878 964 setSeedMag(float mag)
879 965 {
... ... @@ -881,7 +967,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
881 967 }
882 968  
883 969  
884   - ///@param x, y, z: variables for the x, y and z coordinate of the seed
  970 + ///@param float x, x-position of the seed to be added.
  971 + ///@param float y, y-position of the seed to be added.
  972 + ///@param float z, z-position of the seed to be added.
885 973 ///Adds a seed to the seed list.
886 974 ///Assumes that the coordinates passes are in tissue space.
887 975 void
... ... @@ -890,12 +978,17 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
890 978 seeds.push(stim::vec<float>(x, y, z));
891 979 }
892 980  
  981 + ///@param float x, x-direction of the seed to be added.
  982 + ///@param float y, y-direction of the seed to be added.
  983 + ///@param float z, z-direction of the seed to be added.
  984 + ///Adds a seed to the seed directions list.
893 985 void
894 986 setSeedVec(float x, float y, float z)
895 987 {
896 988 seedsvecs.push(stim::vec<float>(x, y, z));
897 989 }
898   -
  990 +
  991 + ///Method to get the top of the seed positions stack.
899 992 stim::vec<float>
900 993 getLastSeed()
901 994 {
... ... @@ -903,6 +996,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
903 996 return tp;
904 997 }
905 998  
  999 + ///Method to get the top of the seed direction stack.
906 1000 stim::vec<float>
907 1001 getLastSeedVec()
908 1002 {
... ... @@ -910,6 +1004,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
910 1004 return tp;
911 1005 }
912 1006  
  1007 + ///Method to get the top of the seed magnitude stack.
913 1008 float
914 1009 getLastSeedMag()
915 1010 {
... ... @@ -917,6 +1012,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
917 1012 return tp;
918 1013 }
919 1014  
  1015 + ///deletes all data associated with the last seed.
920 1016 void
921 1017 popSeed()
922 1018 {
... ... @@ -924,20 +1020,24 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
924 1020 seedsvecs.pop();
925 1021 seedsmags.pop();
926 1022 }
927   -
  1023 +
  1024 + ///returns the seeds position stack.
928 1025 std::stack<stim::vec<float> >
929 1026 getSeeds()
930 1027 {
931 1028 return seeds;
932 1029 }
933 1030  
  1031 + ///returns true if all seed stacks are empty, else false.
934 1032 bool
935 1033 Empty()
936 1034 {
  1035 + //return (seeds.empty() && seedsvecs.empty() && seedsmags.empty());
937 1036 return (seeds.empty() && seedsvecs.empty());
938 1037 }
939   - ///@param string file: variables for the x, y and z coordinate of the seed
940   - ///Adds a seed to the seed list.
  1038 +
  1039 + ///@param std::string file:file with variables to populate the seed stacks.
  1040 + ///Adds a seed to the seed list, including the position, direction and magnitude.
941 1041 ///Assumes that the coordinates passes are in tissue space.
942 1042 void
943 1043 setSeeds(std::string file)
... ... @@ -948,16 +1048,11 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
948 1048 {
949 1049 while (getline(myfile, line))
950 1050 {
951   - float x, y, z, u, v, w;
952   - myfile >> x >> y >> z >> u >> v >> w;
953   - seeds.push(stim::vec<float>(
954   - ((float) x),
955   - ((float) y),
956   - ((float) z)));
957   - seedsvecs.push(stim::vec<float>(
958   - ((float) u),
959   - ((float) v),
960   - ((float) w)));
  1051 + float x, y, z, u, v, w, m;
  1052 + myfile >> x >> y >> z >> u >> v >> w >> m;
  1053 + setSeed(x, y , z);
  1054 + setSeedVec(u, v, w);
  1055 + setSeedMag(m);
961 1056 }
962 1057 myfile.close();
963 1058 } else {
... ... @@ -965,17 +1060,26 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
965 1060 }
966 1061 }
967 1062  
  1063 + ///Saves the network to a file.
968 1064 void
969 1065 saveNetwork(std::string name)
970 1066 {
971 1067 sk.save(name);
972 1068 }
973 1069  
  1070 + ///returns a COPY of the entire stim::glObj object.
974 1071 stim::glObj<float>
975 1072 getNetwork()
976 1073 {
977 1074 return sk;
978 1075 }
  1076 +
  1077 + ///returns a COPY of the entire stim::glnetwork object.
  1078 + stim::glnetwork<T>
  1079 + getGLNetwork()
  1080 + {
  1081 + return nt;
  1082 + }
979 1083  
980 1084 ///Function to get back the framebuffer Object attached to the spider.
981 1085 ///For external access.
... ... @@ -1012,7 +1116,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1012 1116 start = std::clock();
1013 1117 #endif
1014 1118 findOptimalDirection();
1015   - //test(texbufferID, GL_TEXTURE_2D);
1016 1119 findOptimalPosition();
1017 1120 findOptimalScale();
1018 1121 Unbind();
... ... @@ -1026,35 +1129,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1026 1129 return current_cost;
1027 1130 }
1028 1131  
1029   - int
1030   - StepP()
1031   - {
1032   - Bind();
1033   - CHECK_OPENGL_ERROR
1034   - #ifdef TESTING
1035   - start = std::clock();
1036   - #endif
1037   - findOptimalDirection();
1038   - //test(texbufferID, GL_TEXTURE_2D);
1039   - findOptimalPosition();
1040   - findOptimalScale();
1041   - Unbind();
1042   - CHECK_OPENGL_ERROR
1043   - Bind(btexbufferID, bfboId, 27);
1044   - CHECK_OPENGL_ERROR
1045   - branchDetection();
1046   - CHECK_OPENGL_ERROR
1047   - Unbind();
1048   - CHECK_OPENGL_ERROR
1049   -
1050   - #ifdef TESTING
1051   - duration_sampling = duration_sampling +
1052   - (std::clock() - start) / (double) CLOCKS_PER_SEC;
1053   - num_sampling = num_sampling + 1.0;
1054   - #endif
1055   - return current_cost;
1056   - }
1057   -
1058 1132  
1059 1133 void
1060 1134 printTransform()
... ... @@ -1062,16 +1136,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1062 1136 std::cout << cT << std::endl;
1063 1137 }
1064 1138  
1065   - /* Method for initializing the cuda devices, necessary only
1066   - there are multiple cuda devices */
1067   - void
1068   - initCuda()
1069   - {
1070   - stim::cudaSetDevice();
1071   - //GLint max;
1072   - //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
1073   - //std::cout << max << std::endl;
1074   - }
1075 1139  
1076 1140 //--------------------------------------------------------------------------//
1077 1141 //-----------------------------EXPERIMENTAL METHODS-------------------------//
... ... @@ -1084,28 +1148,28 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1084 1148 float z0 = -0.5; float z1 = 0.5; float r0 = 0.5;
1085 1149 float x,y;
1086 1150 float xold = 0.5; float yold = 0.0;
1087   -// float step = 360.0/numSamples*32;
1088   - float step = 360.0/8.0;
  1151 + float step = 360.0/numSamples*32;
  1152 + //float step = 360.0/8.0;
1089 1153 glEnable(GL_TEXTURE_3D);
1090 1154 glBindTexture(GL_TEXTURE_3D, texID);
1091   - glBegin(GL_QUADS);
  1155 + glBegin(GL_QUAD_STRIP);
1092 1156 int j = 0;
1093 1157 for(float i = step; i <= 360.0; i += step)
1094 1158 {
1095 1159 x=r0*cos(i*2.0*M_PI/360.0);
1096 1160 y=r0*sin(i*2.0*M_PI/360.0);
1097 1161 glTexCoord3f(x,y,z0);
1098   -// glVertex2f(0.0, j*6.4+6.4);
1099   - glVertex2f(0.0, j*27.+27.);
  1162 + glVertex2f(0.0, j*6.4+6.4);
  1163 +// glVertex2f(0.0, j*27.0+27.0);
1100 1164 glTexCoord3f(x,y,z1);
1101   -// glVertex2f(16.0, j*6.4+6.4);
1102   - glVertex2f(16.0, j*27.+27.);
  1165 + glVertex2f(16.0, j*6.4+6.4);
  1166 +// glVertex2f(16.0, j*27.0+27.0);
1103 1167 glTexCoord3f(xold,yold,z1);
1104   -// glVertex2f(16.0, j*6.4);
1105   - glVertex2f(16.0, j*27.);
  1168 + glVertex2f(16.0, j*6.4);
  1169 +// glVertex2f(16.0, j*27.0);
1106 1170 glTexCoord3f(xold,yold,z0);
1107   -// glVertex2f(0.0, j*6.4);
1108   - glVertex2f(0.0, j*27.);
  1171 + glVertex2f(0.0, j*6.4);
  1172 +// glVertex2f(0.0, j*27.0);
1109 1173 xold=x;
1110 1174 yold=y;
1111 1175 j++;
... ... @@ -1128,22 +1192,27 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1128 1192 {
1129 1193 //clear the currently traced line and start a new one.
1130 1194 cL.clear();
  1195 + cM.clear();
1131 1196 sk.Begin(stim::OBJ_LINE);
1132 1197 stim::vec<float> curSeed = seeds.top();
1133 1198 // std::cout << "The current seeds is " << curSeed << std::endl;
1134 1199 stim::vec<float> curSeedVec = seedsvecs.top();
  1200 + float curSeedMag = seedsmags.top();
1135 1201 seeds.pop();
1136 1202 seedsvecs.pop();
  1203 + seedsmags.pop();
1137 1204 // std::cout << "The current seed Vector is " << curSeedVec << std::endl;
1138 1205 setPosition(curSeed);
1139 1206 setDirection(curSeedVec);
1140 1207 cL.push_back(curSeed);
  1208 + cM.push_back(curSeedMag);
1141 1209 sk.createFromSelf(GL_SELECT);
1142 1210 traceLine(min_cost);
1143 1211  
1144 1212 sk.rev();
1145 1213 // std::cout << "reversed" << std::endl;
1146 1214 std::reverse(cL.begin(), cL.end());
  1215 + std::reverse(cM.begin(), cM.end());
1147 1216 setPosition(curSeed);
1148 1217 setDirection(-rev);
1149 1218 setMagnitude(16.0);
... ... @@ -1207,7 +1276,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1207 1276 break;
1208 1277 }
1209 1278 else {
1210   - cL.push_back(stim::vec<float>(p[0], p[1],p[2]));
  1279 + cL.push_back(stim::vec<float>(p[0], p[1],p[2]));//
1211 1280 sk.TexCoord(m[0]);
1212 1281 sk.Vertex(p[0], p[1], p[2]);
1213 1282 Bind(btexbufferID, bfboId, 27);
... ... @@ -1326,6 +1395,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1326 1395 clearCurrent()
1327 1396 {
1328 1397 cL.clear();
  1398 + cM.clear();
1329 1399 }
1330 1400  
1331 1401 void
... ... @@ -1335,7 +1405,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1335 1405 std::vector<stim::vec<float> > ce = in.first.centerline();
1336 1406 std::vector<stim::vec<float> > cm = in.first.centerlinemag();
1337 1407 //if the fiber is longer than 2 steps (the number it takes to diverge)
1338   - //if the value is 2, then there is a segfault in the ANN libraryt.
1339 1408 if(ce.size() > 3)
1340 1409 {
1341 1410 //if we did not hit a fiber
... ... @@ -1358,22 +1427,16 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1358 1427 spos[0] = spos[0]-sdir[0]*smag[0]/2.;
1359 1428 spos[1] = spos[1]-sdir[1]*smag[0]/2.;
1360 1429 spos[2] = spos[2]-sdir[2]*smag[0]/2.;
1361   - std::cout << (sdir).str() << std::endl;
1362 1430 int h = selectObject(spos, -sdir, smag[0]);
1363 1431 //did start with a fiber?
1364 1432 if(h != -1){
1365   - std::cout << "got here" << smag.str() << std::endl;
1366   - nt.addEdge(ce,cm,h, in.second);
  1433 + // std::cout << "got here double" << smag.str() << std::endl;
  1434 + nt.addEdge(ce,cm, h, in.second);
1367 1435 }
1368 1436 }
1369 1437 }
1370 1438 }
1371 1439  
1372   - stim::glnetwork<T>
1373   - getGLNetwork()
1374   - {
1375   - return nt;
1376   - }
1377 1440  
1378 1441 void
1379 1442 printSizes()
... ... @@ -1398,7 +1461,6 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1398 1461 // sk.createFromSelf(GL_SELECT);
1399 1462 nt.createFromSelf(GL_SELECT);
1400 1463  
1401   - std::vector<stim::vec<float> > cM;
1402 1464 cL.push_back(pos);
1403 1465 cM.push_back(mag);
1404 1466  
... ...