Commit fac43319abb6213f2376a1bc993728d86eb8f30d

Authored by Pavel Govyadinov
1 parent af825cb9

Changed the position vector creation method to use a circle instead of square an…

…d added cyl2cart and cart2cyl functions to vec3
stim/gl/gl_spider.h
... ... @@ -419,12 +419,16 @@ class gl_spider // : public virtual gl_texture<T>
419 419 ver = stim::rect<float>(mag, ///generate anoth er rectangle that's perpendicular the first but parallel to the cart vector.
420 420 pos, dir,
421 421 hor.n());
  422 + ///The first vector is always in the center.
422 423 UpdateBuffer(0.0, 0.0+0*n_pixels);
423 424 for(int i = 1; i < numSamplesPos; i++) ///for the number of position samples
424 425 {
425 426 stim::vec3<float> temp = uniformRandVector(); ///generate a random point on a plane.
426   - temp = temp*delta*2.0 - delta; ///scale the point and center it around 0.0
  427 + temp[0] = temp[0]*delta;
  428 + temp[1] = temp[1]*2*stim::PI;
  429 +
427 430 temp[2] = 0.0;
  431 + temp = temp.cyl2cart();
428 432 pV.push_back(temp); ///save the point for further use.
429 433 hor = stim::rect<float>(mag, ///generate a rectangle with the new vector as a normal.
430 434 temp, dir,
... ... @@ -878,7 +882,7 @@ class gl_spider // : public virtual gl_texture&lt;T&gt;
878 882 iter_dir = 0;
879 883 iter_siz = 0;
880 884 #endif
881   - stepsize = 3.0;
  885 + stepsize = 10.0;
882 886 n_pixels = 16.0;
883 887  
884 888 srand(100);
... ...
stim/gl/gl_texture.h
... ... @@ -64,7 +64,7 @@ class gl_texture : public virtual image_stack&lt;T, F&gt;
64 64 case 4:
65 65 return GL_RGBA;
66 66 default:
67   - std::cout<<"Error in stim::gl_texture - unable to guess texture format based on number of channels ("<<R[4]<<")"<<std::endl;
  67 + std::cout<<"Error in stim::gl_texture - unable to guess texture format based on number of channels" << std::endl;
68 68 exit(1);
69 69 }
70 70 }
... ... @@ -236,7 +236,7 @@ class gl_texture : public virtual image_stack&lt;T, F&gt;
236 236 if(texID == 0) generate_texture(); //generate the texture if it doesn't already exist
237 237 else{
238 238 std::cout<<"Texture has already been attached to a context."<<std::endl;
239   - exit(1);
  239 + //exit(1); Why do we need to quit if it's attached. print the message and continue.
240 240 }
241 241 }
242 242  
... ...
stim/math/vec3.h
... ... @@ -80,6 +80,15 @@ public:
80 80 return sph;
81 81 }
82 82  
  83 + CUDA_CALLABLE vec3<T> cart2cyl() const{
  84 + vec3<T> cyl;
  85 + cyl.ptr[0] = sqrt(pow(ptr[0],2) + pow(ptr[1],2));
  86 + cyl.ptr[1] = atan(ptr[1]/ptr[0]);
  87 + cyl.ptr[2] = ptr[2];
  88 +
  89 + return cyl;
  90 + }
  91 +
83 92 /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi])
84 93 CUDA_CALLABLE vec3<T> sph2cart() const{
85 94 vec3<T> cart;
... ... @@ -90,6 +99,16 @@ public:
90 99 return cart;
91 100 }
92 101  
  102 + /// Convert the vector from cylindrical to cart coordinates (r, theta, z -> x, y, z where theta = [0, 2*pi])
  103 + CUDA_CALLABLE vec3<T> cyl2cart() const{
  104 + vec3<T> cart;
  105 + cart.ptr[0] = ptr[0] * std::cos(ptr[1]);
  106 + cart.ptr[1] = ptr[0] * std::sin(ptr[1]);
  107 + cart.ptr[2] = ptr[2];
  108 +
  109 + return cart;
  110 + }
  111 +
93 112 /// Computes the normalized vector (where each coordinate is divided by the L2 norm)
94 113 CUDA_CALLABLE vec3<T> norm() const{
95 114 vec3<T> result;
... ...