diff --git a/stim/gl/gl_spider.h b/stim/gl/gl_spider.h index 4217c71..3ffb4f8 100644 --- a/stim/gl/gl_spider.h +++ b/stim/gl/gl_spider.h @@ -140,11 +140,12 @@ class gl_spider : public virtual gl_texture setMatrix(); //create the transformation matrix. glCallList(dList+1); //move the templates to p, d, m. int best = getCost(ptexbufferID, numSamplesPos); //find min cost. + std::cerr << best << std::endl; stim::vec next( //find next position. - pV[best][0], - pV[best][1], - pV[best][2], - 1); + pV[best][0], + pV[best][1], + pV[best][2], + 1); next = cT*next; //find next position. setPosition( next[0]*S[0]*R[0], @@ -727,7 +728,7 @@ class gl_spider : public virtual gl_texture ///Best results if samples is can create a perfect root. ///Default Constructor gl_spider - (int samples = 1089, int samplespos = 400,int samplesmag = 144) + (int samples = 1089, int samplespos = 441,int samplesmag = 144) { p = vec(0.0, 0.0, 0.0); d = vec(0.0, 0.0, 1.0); @@ -750,7 +751,7 @@ class gl_spider : public virtual gl_texture ///@param int samples, number of templates this spider is going to use. gl_spider (float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z, - float mag_x, int numsamples = 1089, int numsamplespos = 400, int numsamplesmag =144) + float mag_x, int numsamples = 1089, int numsamplespos = 441, int numsamplesmag =144) { p = vec(pos_x, pos_y, pos_z); d = vec(dir_x, dir_y, dir_z); @@ -768,7 +769,7 @@ class gl_spider : public virtual gl_texture ///@param float mag, size of the vector. ///@param int samples, number of templates this spider is going to use. gl_spider - (stim::vec pos, stim::vec dir, float mag, int samples = 1089, int samplesPos = 400, int samplesMag = 144) + (stim::vec pos, stim::vec dir, float mag, int samples = 1089, int samplesPos = 441, int samplesMag = 144) { p = pos; d = dir; @@ -815,13 +816,13 @@ class gl_spider : public virtual gl_texture glListBase(dList); Bind(texbufferID, fboID, numSamples); genDirectionVectors(5*M_PI/4); -// Unbind(); - Bind(ptexbufferID, bfboID, numSamplesPos); + Unbind(); + Bind(ptexbufferID, pfboID, numSamplesPos); genPositionVectors(); -// Unbind(); + Unbind(); Bind(mtexbufferID, mfboID, numSamplesMag); genMagnitudeVectors(); -// Unbind(); + Unbind(); Bind(btexbufferID, bfboID, 27); DrawCylinder(); Unbind(); @@ -1150,13 +1151,13 @@ class gl_spider : public virtual gl_texture start = std::clock(); #endif findOptimalDirection(); - //Unbind(); + Unbind(); Bind(ptexbufferID, pfboID, numSamplesPos); findOptimalPosition(); - //Unbind(); + Unbind(); Bind(mtexbufferID, mfboID, numSamplesMag); findOptimalScale(); - //Unbind(); + Unbind(); CHECK_OPENGL_ERROR #ifdef TESTING @@ -1566,7 +1567,9 @@ class gl_spider : public virtual gl_texture } else { cL.push_back(stim::vec(p[0], p[1],p[2])); - cM.push_back(m[0]); + cM.push_back(stim::vec(m[0], m[0])); +// cM.push_back(m[0]); + sk.TexCoord(m[0]); sk.Vertex(p[0], p[1], p[2]); Bind(btexbufferID, bfboID, 27); diff --git a/stim/math/plane.h b/stim/math/plane.h index b009cad..d839265 100644 --- a/stim/math/plane.h +++ b/stim/math/plane.h @@ -1,179 +1,26 @@ -#ifndef RTS_PLANE_H -#define RTS_PLANE_H - -#include -#include -#include "rts/cuda/callable.h" - - -namespace stim{ -template class plane; -} - -template -CUDA_CALLABLE stim::plane operator-(stim::plane v); - -namespace stim{ - -template -class plane{ - - //a plane is defined by a point and a normal - -private: - - vec P; //point on the plane - vec N; //plane normal - - CUDA_CALLABLE void init(){ - P = vec(0, 0, 0); - N = vec(0, 0, 1); - } - - -public: - - //default constructor - CUDA_CALLABLE plane(){ - init(); - } +#ifndef STIM_PLANE_H +#define STIM_PLANE_H + +namespace stim +{ +template class plane +{ + private: + stim::vec P; + stim::vec N; + + CUDA_CALLABLE void init() + { + P = stim::vec(0, 0, 0); + N = stim::vec(0, 0, 1); + } + + public: - CUDA_CALLABLE plane(vec n, vec p = vec(0, 0, 0)){ - P = p; - N = n.norm(); - } - - CUDA_CALLABLE plane(T z_pos){ - init(); - P[2] = z_pos; - } - - //create a plane from three points (a triangle) - CUDA_CALLABLE plane(vec a, vec b, vec c){ - P = c; - N = (c - a).cross(b - a); - if(N.len() == 0) //handle the degenerate case when two vectors are the same, N = 0 - N = 0; - else - N = N.norm(); - } - - template< typename U > - CUDA_CALLABLE operator plane(){ - - plane result(N, P); - return result; - } - - CUDA_CALLABLE vec norm(){ - return N; - } - - CUDA_CALLABLE vec p(){ - return P; - } - - //flip the plane front-to-back - CUDA_CALLABLE plane flip(){ - plane result = *this; - result.N = -result.N; - return result; - } - - //determines how a vector v intersects the plane (1 = intersects front, 0 = within plane, -1 = intersects back) - CUDA_CALLABLE int face(vec v){ + CUDA_CALLABLE plane() + { + init(); + } - T dprod = v.dot(N); //get the dot product between v and N - - //conditional returns the appropriate value - if(dprod < 0) - return 1; - else if(dprod > 0) - return -1; - else - return 0; - } - - //determine on which side of the plane a point lies (1 = front, 0 = on the plane, -1 = back) - CUDA_CALLABLE int side(vec p){ - - vec v = p - P; //get the vector from P to the query point p - - return face(v); - } - - //compute the component of v that is perpendicular to the plane - CUDA_CALLABLE vec perpendicular(vec v){ - return N * v.dot(N); - } - - //compute the projection of v in the plane - CUDA_CALLABLE vec parallel(vec v){ - return v - perpendicular(v); - } - - CUDA_CALLABLE void decompose(vec v, vec& para, vec& perp){ - perp = N * v.dot(N); - para = v - perp; - } - - //get both the parallel and perpendicular components of a vector v w.r.t. the plane - CUDA_CALLABLE void project(vec v, vec &v_par, vec &v_perp){ - - v_perp = v.dot(N); - v_par = v - v_perp; - } - - //compute the reflection of v off of the plane - CUDA_CALLABLE vec reflect(vec v){ - - //compute the reflection using N_prime as the plane normal - vec par = parallel(v); - vec r = (-v) + par * 2; - - /*std::cout<<"----------------REFLECT-----------------------------"< operator-() - { - rts::plane p = *this; - - //negate the normal vector - p.N = -p.N; - - return p; - } - - //output a string - std::string str(){ - std::stringstream ss; - ss<<"P: "< operator- <> (rts::plane v); - - - -}; - } - -//arithmetic operators - -//negative operator flips the plane (front to back) -//template - - - - #endif diff --git a/stim/math/rect.h b/stim/math/rect.h index 9767f26..336a3ac 100644 --- a/stim/math/rect.h +++ b/stim/math/rect.h @@ -38,31 +38,17 @@ private: } - CUDA_CALLABLE void normal(vec n){ //orient the rectangle along the specified normal - - n = n.norm(); //normalize, just in case - vec n_current = X.cross(Y).norm(); //compute the current normal - quaternion q; //create a quaternion - q.CreateRotation(n_current, n); //initialize a rotation from n_current to n - - //apply the quaternion to the vectors and position - X = q.toMatrix3() * X; - Y = q.toMatrix3() * Y; - } - - CUDA_CALLABLE void init(){ - C = vec(0, 0, 0); - X = vec(1, 0, 0); - Y = vec(0, 1, 0); - } public: + ///base constructor. CUDA_CALLABLE rect(){ init(); } - //create a rectangle given a size and position + ///create a rectangle given a size and position in Z space. + ///@param size: size of the rectangle in ND space. + ///@param z_pos z coordinate of the rectangle. CUDA_CALLABLE rect(T size, T z_pos = (T)0){ init(); //use the default setup scale(size); //scale the rectangle @@ -70,13 +56,30 @@ public: } - //create a rectangle from a center point, normal, and size + ///create a rectangle from a center point, normal + ///@param c: x,y,z location of the center. + ///@param n: x,y,z direction of the normal. CUDA_CALLABLE rect(vec c, vec n = vec(0, 0, 1)){ init(); //start with the default setting C = c; normal(n); //orient } + ///create a rectangle from a center point, normal, and size + ///@param c: x,y,z location of the center. + ///@param s: size of the rectangle. + ///@param n: x,y,z direction of the normal. + CUDA_CALLABLE rect(vec c, T s, vec n = vec(0, 0, 1)){ + init(); //start with the default setting + C = c; + scale(s); + normal(n); //orient + } + + ///creates a rectangle from a centerpoint and an X and Y direction vectors. + ///@param center: x,y,z location of the center. + ///@param directionX: u,v,w direction of the X vector. + ///@param directionY: u,v,w direction of the Y vector. CUDA_CALLABLE rect(vec center, vec directionX, vec directionY ) { C = center; @@ -84,6 +87,11 @@ public: Y = directionY; } + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors. + ///@param size of the rectangle in ND space. + ///@param center: x,y,z location of the center. + ///@param directionX: u,v,w direction of the X vector. + ///@param directionY: u,v,w direction of the Y vector. CUDA_CALLABLE rect(T size, vec center, vec directionX, vec directionY ) { C = center; @@ -91,7 +99,12 @@ public: Y = directionY; scale(size); } - + + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors. + ///@param size of the rectangle in ND space, size[0] = size in X, size[1] = size in Y. + ///@param center: x,y,z location of the center. + ///@param directionX: u,v,w direction of the X vector. + ///@param directionY: u,v,w direction of the Y vector. CUDA_CALLABLE rect(vec size, vec center, vec directionX, vec directionY ) { C = center; @@ -99,12 +112,36 @@ public: Y = directionY; scale(size[0], size[1]); } - + + ///scales a rectangle in ND space. + ///@param factor1: size of the scale in the X-direction. + ///@param factor2: size of the scale in the Y-direction. CUDA_CALLABLE void scale(T factor1, T factor2){ X *= factor1; Y *= factor2; } + ///@param n; vector with the normal. + ///Orients the rectangle along the normal n. + CUDA_CALLABLE void normal(vec n){ //orient the rectangle along the specified normal + + n = n.norm(); //normalize, just in case + vec n_current = X.cross(Y).norm(); //compute the current normal + quaternion q; //create a quaternion + q.CreateRotation(n_current, n); //initialize a rotation from n_current to n + + //apply the quaternion to the vectors and position + X = q.toMatrix3() * X; + Y = q.toMatrix3() * Y; + } + + ///general init method that sets a general rectangle. + CUDA_CALLABLE void init(){ + C = vec(0, 0, 0); + X = vec(1, 0, 0); + Y = vec(0, 1, 0); + } + //boolean comparison bool operator==(const rect & rhs) { @@ -151,7 +188,7 @@ public: } - //scales the rectangle by a value rhs + ///multiplication operator scales the rectangle by a value rhs. CUDA_CALLABLE rect operator*(T rhs) { //scales the plane by a scalar value @@ -164,7 +201,8 @@ public: } - //computes the distance between the specified point and this rectangle + ///computes the distance between the specified point and this rectangle. + ///@param p: x, y, z coordinates of the point to calculate distance to. CUDA_CALLABLE T dist(vec p) { //compute the distance between a point and this rect @@ -185,6 +223,13 @@ public: return d1; } + CUDA_CALLABLE T center(vec p) + { + C = p; + } + + ///Returns the maximum distance of the rectangle from a point p to the sides of the rectangle. + ///@param p: x, y, z point. CUDA_CALLABLE T dist_max(vec p) { vec A = C - X * (T)0.5 - Y * (T)0.5; -- libgit2 0.21.4