diff --git a/stim/gl/gl_spider.h b/stim/gl/gl_spider.h index 02772c6..717692b 100644 --- a/stim/gl/gl_spider.h +++ b/stim/gl/gl_spider.h @@ -7,13 +7,14 @@ #include #include #include -#include "stim/gl/gl_texture.h" -#include "stim/visualization/camera.h" -#include "stim/gl/error.h" -#include "stim/math/vector.h" -#include "stim/math/rect.h" -#include "stim/math/matrix.h" -#include "stim/cuda/spider_cost.cuh" +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -48,15 +49,15 @@ class gl_spider : public virtual gl_texture private: // - stim::vec p; //vector designating the position of the spider. - stim::vec d; //vector designating the orientation of the spider + stim::vec3 p; //vector designating the position of the spider. + stim::vec3 d; //vector designating the orientation of the spider //always a unit vector. - stim::vec m; //magnitude of the spider vector. + stim::vec3 m; //magnitude of the spider vector. //mag[0] = length. //mag[1] = width. - std::vector > dV; //A list of all the direction vectors. - std::vector > pV; //A list of all the position vectors. - std::vector > mV; //A list of all the size vectors. + std::vector > dV; //A list of all the direction vectors. + std::vector > pV; //A list of all the position vectors. + std::vector > mV; //A list of all the size vectors. stim::matrix cT; //current Transformation matrix //From tissue space to texture space. @@ -88,21 +89,21 @@ class gl_spider : public virtual gl_texture //Tracing variables. - std::stack< stim::vec > seeds; //seed positions. - std::stack< stim::vec > seedsvecs; //seed directions. + std::stack< stim::vec3 > seeds; //seed positions. + std::stack< stim::vec3 > seedsvecs; //seed directions. std::stack< float > seedsmags; //seed magnitudes. - std::vector< stim::vec > cL; //Positions of line currently being traced. - std::vector< stim::vec > cD; //Direction of line currently being traced. + std::vector< stim::vec3 > cL; //Positions of line currently being traced. + std::vector< stim::vec3 > cD; //Direction of line currently being traced. std::vector< stim::vec > cM; //Magnitude of line currently being traced. stim::glnetwork nt; //object for storing the network. stim::vec rev; //reverse vector; stim::camera camSel; - stim::vec ps; - stim::vec ups; - stim::vec ds; + stim::vec3 ps; + stim::vec3 ups; + stim::vec3 ds; static const float t_length = 16.0; @@ -188,7 +189,7 @@ class gl_spider : public virtual gl_texture glCallList(dList+3); std::vector< stim::vec > result = find_branch( btexbufferID, GL_TEXTURE_2D, 16, 216); - stim::vec size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); + stim::vec3 size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); if(!result.empty()) { for(int i = 1; i < result.size(); i++) @@ -200,11 +201,11 @@ class gl_spider : public virtual gl_texture 1.0); cylp = cT*cylp; - stim::vec vec( + stim::vec3 vec( cylp[0]*S[0]*R[0], cylp[1]*S[1]*R[1], cylp[2]*S[2]*R[2]); - stim::vec seeddir(-p[0] + cylp[0]*S[0]*R[0], + stim::vec3 seeddir(-p[0] + cylp[0]*S[0]*R[0], -p[1] + cylp[1]*S[1]*R[1], -p[2] + cylp[2]*S[2]*R[2]); seeddir = seeddir.norm(); @@ -236,7 +237,7 @@ class gl_spider : public virtual gl_texture DrawLongCylinder(n, l_template, l_square); stim::cylinder cyl(cL, cM); std::vector< stim::vec > result = find_branch(btexbufferID, GL_TEXTURE_2D, n*l_square, (cL.size()-1)*l_template); - stim::vec size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); + stim::vec3 size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); float pval; if(!result.empty()) { @@ -257,8 +258,8 @@ class gl_spider : public virtual gl_texture { pval = (cyl.getl(id)/cyl.getl(cL.size()-1)); } - stim::vec v = cyl.surf(pval, result[i][0]); - stim::vec di = cyl.p(pval); + stim::vec3 v = cyl.surf(pval, result[i][0]); + stim::vec3 di = cyl.p(pval); float rad = cyl.r(pval); if( !(v[0] > size[0] || v[1] > size[1] @@ -287,15 +288,15 @@ class gl_spider : public virtual gl_texture return cos(2.0*atan(1.0)*u2)*sqrt(-1.0*log(u1)); } - stim::vec uniformRandVector() + stim::vec3 uniformRandVector() { - stim::vec r(uniformRandom(), uniformRandom(), 1.0); + stim::vec3 r(uniformRandom(), uniformRandom(), 1.0); return r; } - stim::vec normalRandVector() + stim::vec3 normalRandVector() { - stim::vec r(normalRandom(), normalRandom(), 1.0); + stim::vec3 r(normalRandom(), normalRandom(), 1.0); return r; } @@ -339,10 +340,10 @@ class gl_spider : public virtual gl_texture float z, theta, phi; - std::vector > vecsUni; + std::vector > vecsUni; for(int i = 0; i < numSamplesPos; i++) { - stim::vec a(uniformRandom()*0.8, uniformRandom()*0.8, 0.0); + stim::vec3 a(uniformRandom()*0.8, uniformRandom()*0.8, 0.0); a[0] = a[0]-0.4; a[1] = a[1]-0.4; vecsUni.push_back(a); @@ -369,10 +370,10 @@ class gl_spider : public virtual gl_texture { //Set up the vectors necessary for Rectangle creation. - vec Y(1.0,0.0,0.0); //orthogonal vec. - vec pos(0.0,0.0,0.0); - vec mag(1.0, 1.0, 1.0); - vec dir(0.0, 0.0, 1.0); + stim::vec3 Y(1.0,0.0,0.0); //orthogonal vec. + stim::vec3 pos(0.0,0.0,0.0); + stim::vec3 mag(1.0, 1.0, 1.0); + stim::vec3 dir(0.0, 0.0, 1.0); float PHI[2], Z[2], range; PHI[0] = solidAngle/2; @@ -390,8 +391,8 @@ class gl_spider : public virtual gl_texture z = uniformRandom()*range + Z[1]; theta = uniformRandom()*2*M_PI; phi = acos(z); - stim::vec sph(1, theta, phi); - stim::vec cart = sph.sph2cart(); + stim::vec3 sph(1, theta, phi); + stim::vec3 cart = sph.sph2cart(); dV.push_back(cart); if(cos(Y.dot(cart)) < 0.087) { @@ -420,16 +421,16 @@ class gl_spider : public virtual gl_texture genPositionVectors(float delta = 0.4) { //Set up the vectors necessary for Rectangle creation. - vec Y(1.0,0.0,0.0); //orthogonal vec. - vec pos(0.0,0.0,0.0); - vec mag(1.0, 1.0, 1.0); - vec dir(0.0, 0.0, 1.0); + stim::vec3 Y(1.0,0.0,0.0); //orthogonal vec. + stim::vec3 pos(0.0,0.0,0.0); + stim::vec3 mag(1.0, 1.0, 1.0); + stim::vec3 dir(0.0, 0.0, 1.0); //Set up the variable necessary for vector creation. glNewList(dList+1, GL_COMPILE); for(int i = 0; i < numSamplesPos; i++) { - stim::vec temp = uniformRandVector(); + stim::vec3 temp = uniformRandVector(); temp = temp*delta*2.0 - delta/2.0; temp[2] = 0.0; pV.push_back(temp); @@ -456,10 +457,10 @@ class gl_spider : public virtual gl_texture { //Set up the vectors necessary for Rectangle creation. - vec Y(1.0, 0.0, 0.0); //orthogonal vec. - vec pos(0.0, 0.0, 0.0); - vec mag(1.0, 1.0, 1.0); - vec dir(0.0, 0.0, 1.0); + stim::vec3 Y(1.0, 0.0, 0.0); //orthogonal vec. + stim::vec3 pos(0.0, 0.0, 0.0); + stim::vec3 mag(1.0, 1.0, 1.0); + stim::vec3 dir(0.0, 0.0, 1.0); //Set up the variable necessary for vector creation. int dim = (sqrt(numSamplesMag)-1)/2; @@ -467,7 +468,7 @@ class gl_spider : public virtual gl_texture float max = 1.0+delta; float step = (max-min)/(numSamplesMag-1); float factor; - vec temp(0.0,0.0,0.0); + stim::vec3 temp(0.0,0.0,0.0); glNewList(dList+2, GL_COMPILE); for(int i = 0; i < numSamplesMag; i++){ @@ -495,10 +496,10 @@ class gl_spider : public virtual gl_texture void UpdateBuffer(float v_x, float v_y) { - stim::vecp1; - stim::vecp2; - stim::vecp3; - stim::vecp4; + stim::vec3p1; + stim::vec3p2; + stim::vec3p3; + stim::vec3p4; p1 = hor.p(1,1); p2 = hor.p(1,0); p3 = hor.p(0,0); @@ -712,10 +713,6 @@ class gl_spider : public virtual gl_texture Bind(GLuint &textureID, GLuint &framebufferID, int nSamples, float len = 8.0) { -// std::cout << glGetIntegerv(GL_MAX_TEXTURE_SIZE) << std::endl; - GLint max; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); -// std::cout << max << std::endl; glBindFramebuffer(GL_FRAMEBUFFER, framebufferID);//set up GL buffer glFramebufferTexture2D( GL_FRAMEBUFFER, @@ -727,8 +724,6 @@ class gl_spider : public virtual gl_texture GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, DrawBuffers); glBindTexture(GL_TEXTURE_2D, textureID); -// glClearColor(1,1,1,1); -// glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); @@ -837,10 +832,6 @@ class gl_spider : public virtual gl_texture initCuda() { stim::cudaSetDevice(); - MonteCarloDirectionVectors(500); - //GLint max; - //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); - //std::cout << max << std::endl; } //horizonal rectangle forming the spider. @@ -869,11 +860,11 @@ class gl_spider : public virtual gl_texture (int samples = 1089, int samplespos = 441,int samplesmag = 144) { // std::cout << "I ran this constructor" << std::endl; - p = vec(0.0, 0.0, 0.0); - d = vec(0.0, 0.0, 1.0); - m = vec(1.0, 1.0); - S = vec(1.0, 1.0, 1.0); - R = vec(1.0, 1.0, 1.0); + p = stim::vec3(0.0, 0.0, 0.0); + d = stim::vec3(0.0, 0.0, 1.0); + m = stim::vec(1.0, 1.0); + S = stim::vec3(1.0, 1.0, 1.0); + R = stim::vec3(1.0, 1.0, 1.0); // std::cout << samples << std::endl; numSamples = samples; // std::cout << numSamples << std::endl; @@ -894,11 +885,11 @@ class gl_spider : public virtual gl_texture (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 = 441, int numsamplesmag =144) { - p = vec(pos_x, pos_y, pos_z); - d = vec(dir_x, dir_y, dir_z); - m = vec(mag_x, mag_x, mag_x); - S = vec(1.0,1.0,1.0); - R = vec(1.0,1.0,1.0); + p = stim::vec3(pos_x, pos_y, pos_z); + d = stim::vec3(dir_x, dir_y, dir_z); + m = stim::vec(mag_x, mag_x, mag_x); + S = stim::vec3(1.0,1.0,1.0); + R = stim::vec3(1.0,1.0,1.0); numSamples = numsamples; numSamplesPos = numsamplespos; numSamplesMag = numsamplesmag; @@ -910,13 +901,13 @@ 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 = 441, int samplesMag = 144) + (stim::vec3 pos, stim::vec3 dir, float mag, int samples = 1089, int samplesPos = 441, int samplesMag = 144) { p = pos; d = dir; m = vec(mag, mag, mag); - S = vec(1.0,1.0,1.0); - R = vec(1.0,1.0,1.0); + S = vec3(1.0,1.0,1.0); + R = vec3(1.0,1.0,1.0); numSamples = samples; numSamplesPos = samplesPos; numSamplesMag = samplesMag; @@ -978,14 +969,14 @@ class gl_spider : public virtual gl_texture //-----------------------------ACCESS METHODS-------------------------------// //--------------------------------------------------------------------------// ///Returns the p vector. - vec + vec3 getPosition() { return p; } ///Returns the d vector. - vec + vec3 getDirection() { return d; @@ -1001,7 +992,7 @@ class gl_spider : public virtual gl_texture ///@param stim::vec pos, the new p. ///Sets the p vector to input vector pos. void - setPosition(vec pos) + setPosition(stim::vec3 pos) { p = pos; } @@ -1021,7 +1012,7 @@ class gl_spider : public virtual gl_texture ///@param stim::vec dir, the new d. ///Sets the d vector to input vector dir. void - setDirection(vec dir) + setDirection(stim::vec3 dir) { d = dir; } @@ -1041,7 +1032,7 @@ class gl_spider : public virtual gl_texture ///@param stim::vec dir, the new d. ///Sets the m vector to the input vector mag. void - setMagnitude(vec mag) + setMagnitude(stim::vec mag) { m[0] = mag[0]; m[1] = mag[0]; @@ -1071,7 +1062,7 @@ class gl_spider : public virtual gl_texture ///@param stim::vec Dims, voxel size. ///Sets the voxel sizes in each direction. necessary for non-standard data. void - setDims(stim::vec Dims) + setDims(stim::vec3 Dims) { S = Dims; } @@ -1091,7 +1082,7 @@ class gl_spider : public virtual gl_texture ///@param stim::vec Dims, size of the volume. ///Sets the data volume sizes in each direction. void - setSize(stim::vec Siz) + setSize(stim::vec3 Siz) { S = Siz; } @@ -1125,7 +1116,7 @@ class gl_spider : public virtual gl_texture ///Adds a seed to the seed list. ///Assumes that the coordinates passes are in tissue space. void - setSeed(stim::vec pos) + setSeed(stim::vec3 pos) { seeds.push(pos); } @@ -1133,7 +1124,7 @@ class gl_spider : public virtual gl_texture ///@param stim::vec dir, the direction of the seed to be added. ///Adds a seed to the seed directions list. void - setSeedVec(stim::vec dir) + setSeedVec(stim::vec3 dir) { seedsvecs.push(dir); } @@ -1173,18 +1164,18 @@ class gl_spider : public virtual gl_texture } ///Method to get the top of the seed positions stack. - stim::vec + stim::vec3 getLastSeed() { - stim::vec tp = seeds.top(); + stim::vec3 tp = seeds.top(); return tp; } ///Method to get the top of the seed direction stack. - stim::vec + stim::vec3 getLastSeedVec() { - stim::vec tp = seedsvecs.top(); + stim::vec3 tp = seedsvecs.top(); return tp; } @@ -1206,7 +1197,7 @@ class gl_spider : public virtual gl_texture } ///returns the seeds position stack. - std::stack > + std::stack > getSeeds() { return seeds; @@ -1252,7 +1243,7 @@ class gl_spider : public virtual gl_texture for(int i = 0; i < nt.sizeE(); i++) { std::vector > cm = nt.getEdgeCenterLineMag(i); - std::vector > ce = nt.getEdgeCenterLine(i); + std::vector > ce = nt.getEdgeCenterLine(i); sk.Begin(stim::OBJ_LINE); for(int j = 0; j < ce.size(); j++) { @@ -1269,7 +1260,7 @@ class gl_spider : public virtual gl_texture stim::glObj getNetwork() { -// return sk; + } ///returns a COPY of the entire stim::glnetwork object. @@ -1295,7 +1286,7 @@ class gl_spider : public virtual gl_texture void Update() { - vec Y(1.0,0.0,0.0); + vec3 Y(1.0,0.0,0.0); if(cos(Y.dot(d))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;} hor = stim::rect(m, p, d.norm(), @@ -1389,7 +1380,7 @@ class gl_spider : public virtual gl_texture GenerateFBO(n*l_square, cylLen*l_template, btexbufferID, bfboID); Bind(btexbufferID, bfboID, cylLen, l_template*l_square/2.0); stim::cylinder cyl(cL, cM); - std::vector > > p = cyl.getPoints(n); + std::vector > > p = cyl.getPoints(n); for(int i = 0; i < p.size()-1; i++) ///number of circles { for(int j = 0; j < p[0].size()-1; j++) ///points in the circle @@ -1418,11 +1409,10 @@ class gl_spider : public virtual gl_texture void trace(int min_cost) { -// rev = stim::vec(0.0,0.0,1.0); bool sEmpty = true; float lastmag = 16.0;; - stim::vec curSeed; - stim::vec curSeedVec; + stim::vec3 curSeed; + stim::vec3 curSeedVec; float curSeedMag; while(!Empty()) { @@ -1448,7 +1438,7 @@ class gl_spider : public virtual gl_texture } int - selectObject(stim::vec loc, stim::vec dir, float mag) + selectObject(stim::vec3 loc, stim::vec3 dir, float mag) { //Define the varibles and turn on Selection Mode @@ -1554,10 +1544,10 @@ class gl_spider : public virtual gl_texture } void - addToNetwork(pair, int> in, stim::vec spos, - stim::vec smag, stim::vec sdir) + addToNetwork(pair, int> in, stim::vec3 spos, + stim::vec smag, stim::vec3 sdir) { - std::vector > ce = in.first.centerline(); + std::vector > ce = in.first.centerline(); std::vector > cm = in.first.centerlinemag(); //if the fiber is longer than 2 steps (the number it takes to diverge) if(ce.size() > 3) @@ -1602,12 +1592,12 @@ class gl_spider : public virtual gl_texture } std::pair, int > - traceLine(stim::vec pos, stim::vec mag, int min_cost) + traceLine(stim::vec3 pos, stim::vec mag, int min_cost) { //starting (seed) position and magnitude. - stim::vec spos = getPosition(); + stim::vec3 spos = getPosition(); stim::vec smag = getMagnitude(); - stim::vec sdir = getDirection(); + stim::vec3 sdir = getDirection(); Bind(); // sk.Begin(stim::OBJ_LINE); @@ -1624,7 +1614,7 @@ class gl_spider : public virtual gl_texture int h; bool started = false; bool running = true; - stim::vec size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); + stim::vec3 size(S[0]*R[0], S[1]*R[1], S[2]*R[2]); while(running) { int cost = Step(); @@ -1684,7 +1674,7 @@ class gl_spider : public virtual gl_texture break; } else { - cL.push_back(stim::vec(p[0], p[1],p[2])); + cL.push_back(stim::vec3(p[0], p[1],p[2])); cM.push_back(stim::vec(m[0], m[0])); // Bind(btexbufferID, bfboID, 27); Unbind(); diff --git a/stim/math/vec3.h b/stim/math/vec3.h index f5cedd2..3cc2efc 100644 --- a/stim/math/vec3.h +++ b/stim/math/vec3.h @@ -37,10 +37,14 @@ public: } //access an element using an index - CUDA_CALLABLE T& operator[](int idx){ + CUDA_CALLABLE T& operator[](size_t idx){ return ptr[idx]; } + CUDA_CALLABLE T* data(){ + return ptr; + } + /// Casting operator. Creates a new vector with a new type U. template< typename U > CUDA_CALLABLE operator vec3(){ @@ -249,4 +253,4 @@ std::ostream& operator<<(std::ostream& os, stim::vec3 const& rhs){ return os; } -#endif \ No newline at end of file +#endif diff --git a/stim/math/vector.h b/stim/math/vector.h index 0e28aa3..02cfcd2 100644 --- a/stim/math/vector.h +++ b/stim/math/vector.h @@ -74,6 +74,13 @@ struct vec : public std::vector at(i) = other[i]; } } + + vec( vec3& other){ + resize(3); //resize the current vector to match the copy + for(size_t i=0; i<3; i++){ //copy each element + at(i) = other[i]; + } + } //I'm not sure what these were doing here. //Keep them now, we'll worry about it later. @@ -328,15 +335,16 @@ struct vec : public std::vector return *this; } - /// Cast to a vec3 - operator stim::vec3(){ - stim::vec3 r; - size_t N = std::min(size(), 3); - for(size_t i = 0; i < N; i++) - r[i] = at(i); - return r; - } - + /// Cast to a vec3 + operator stim::vec3(){ + stim::vec3 r; + size_t N = std::min(size(), 3); + for(size_t i = 0; i < N; i++) + r[i] = at(i); + return r; + } + + /// Casting and assignment template vec & operator=(vec rhs){ @@ -347,6 +355,16 @@ struct vec : public std::vector at(i) = rhs[i]; return *this; } + + /// Assign a vec = vec3 + template + vec & operator=(vec3 rhs) + { + resize(3); + for(size_t i=0; i<3; i++) + at(i) = rhs[i]; + return *this; + } /// Unary minus (returns the negative of the vector) vec operator-() const{ diff --git a/stim/visualization/cylinder.h b/stim/visualization/cylinder.h index a7b8662..6dec73b 100644 --- a/stim/visualization/cylinder.h +++ b/stim/visualization/cylinder.h @@ -23,7 +23,7 @@ class cylinder } - ///inits the cylinder from a list of points (inP) and radii (inM) + ///inits the cylinder from a list of points (std::vector of stim::vec3 --inP) and radii (inM) void init(std::vector > inP, std::vector > inM) { @@ -142,14 +142,15 @@ class cylinder } ///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder. - ///@param inP: Vector of stim vecs composing the points of the centerline. + ///@param inP: Vector of stim vec3 composing the points of the centerline. ///@param inM: Vector of stim vecs composing the radii of the centerline. - cylinder(std::vector > inP, std::vector > inM){ + cylinder(std::vector > inP, std::vector > inM){ init(inP, inM); } + ///Constructor defines a cylinder with centerline inP and magnitudes of zero - ///@param inP: Vector of stim vecs composing the points of the centerline + ///@param inP: Vector of stim vec3 composing the points of the centerline cylinder(std::vector< stim::vec3 > inP){ std::vector< stim::vec > inM; //create an array of arbitrary magnitudes @@ -160,7 +161,6 @@ class cylinder init(inP, inM); } - ///Returns the number of points on the cylinder centerline unsigned int size(){ -- libgit2 0.21.4