From 0311ab81ccc840968f323354738811bd1a1ee33e Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Thu, 25 Aug 2016 18:30:21 -0500 Subject: [PATCH] fixed some issues with std98 in filename, fixes to glObj, debugging code added, Cylinder now uses centerline --- stim/gl/gl_spider.h | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------- stim/math/circle.h | 10 +++++++++- stim/parser/filename.h | 4 ++-- stim/visualization/cylinder.h | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- stim/visualization/glObj.h | 6 +++--- stim/visualization/obj.h | 7 ------- 6 files changed, 206 insertions(+), 127 deletions(-) diff --git a/stim/gl/gl_spider.h b/stim/gl/gl_spider.h index 25efd24..ae942ba 100644 --- a/stim/gl/gl_spider.h +++ b/stim/gl/gl_spider.h @@ -24,7 +24,6 @@ #include #include #include -#include "../../../volume-spider/fiber.h" #include "../../../volume-spider/glnetwork.h" #include #include @@ -115,6 +114,7 @@ class gl_spider : public virtual gl_texture std::vector< stim::vec > cM; //Magnitude of line currently being traced. stim::glnetwork nt; //object for storing the network. + stim::glObj sk; stim::vec rev; //reverse vector; stim::camera camSel; @@ -228,51 +228,6 @@ class gl_spider : public virtual gl_texture } - ///subject to change. - ///finds branches. - ///depreciated - void - branchDetection() - { - setMatrix(); - glCallList(dList+3); - std::vector< stim::vec > result = find_branch( - btexbufferID, GL_TEXTURE_2D, 16, 216); - 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++) - { - stim::vec cylp( - 0.5 * cos(2*M_PI*(result[i][1])), - 0.5 * sin(2*M_PI*(result[i][1])), - result[i][0]-0.5, - 1.0); - cylp = cT*cylp; - - stim::vec3 vec( - cylp[0]*S[0]*R[0], - cylp[1]*S[1]*R[1], - cylp[2]*S[2]*R[2]); - 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(); - float seedm = m[0]; -// Uncomment for global run - if( - !(vec[0] > size[0] || vec[1] > size[1] - || vec[2] > size[2] || vec[0] < 0 - || vec[1] < 0 || vec[2] < 0)) - { - setSeed(vec); - setSeedVec(seeddir); - setSeedMag(seedm); - } - } - } - - } ///finds all the branches in the a given fiber. @@ -314,6 +269,8 @@ class gl_spider : public virtual gl_texture stim::vec3 v = cyl.surf(pval, result[i][0]); stim::vec3 di = cyl.p(pval); float rad = cyl.r(pval); + + std::cout << v << " " << di << " " << rad << std::endl; if( !(v[0] > size[0] || v[1] > size[1] || v[2] > size[2] || v[0] < 0 @@ -768,7 +725,7 @@ class gl_spider : public virtual gl_texture findOptimalScale(); Unbind(); Bind(btexbufferID, bfboID, 27); - branchDetection(); + branchDetection2(); Unbind(); return current_cost; } @@ -1297,7 +1254,7 @@ class gl_spider : public virtual gl_texture void saveNetwork(std::string name) { - stim::glObj sk; +/* stim::glObj sk; for(int i = 0; i < nt.sizeE(); i++) { std::vector > cm = nt.getEdgeCenterLineMag(i); @@ -1310,7 +1267,7 @@ class gl_spider : public virtual gl_texture } sk.End(); } - sk.save(name); +*/ sk.save(name); } ///Depreciated, but might be reused later() @@ -1318,7 +1275,7 @@ class gl_spider : public virtual gl_texture stim::glObj getNetwork() { - + return sk; } ///returns a COPY of the entire stim::glnetwork object. @@ -1387,14 +1344,14 @@ class gl_spider : public virtual gl_texture void MonteCarloDirectionVectors(int nSamples, float solidAngle = 2*M_PI) { - float PHI[2], Z[2], range; - PHI[0] = asin(solidAngle/2); - PHI[1] = asin(0); +// float PHI[2];//, Z[2];//, range; +// PHI[0] = asin(solidAngle/2); +// PHI[1] = asin(0); - Z[0] = cos(PHI[0]); - Z[1] = cos(PHI[1]); +// Z[0] = cos(PHI[0]); +// Z[1] = cos(PHI[1]); - range = Z[0] - Z[1]; +// range = Z[0] - Z[1]; std::vector > vecsUni; for(int i = 0; i < numSamplesPos; i++) @@ -1506,10 +1463,13 @@ class gl_spider : public virtual gl_texture setPosition(curSeed); setDirection(curSeedVec); setMagnitude(curSeedMag); + std::cout << "This was done" << std::endl; + findOptimalScale(); + // cL.push_back(curSeed); // cM.push_back(curSeedMag); // cD.push_back(curSeedMag); - pair, int> a = traceLine(p, m, min_cost); + traceLine(p, m, min_cost); } } @@ -1556,17 +1516,17 @@ class gl_spider : public virtual gl_texture ds[0], ds[1], ds[2], ups[0], ups[1], ups[2]); -// sk.Render(); - nt.Render(); + sk.Render(); +// nt.Render(); CHECK_OPENGL_ERROR -// glLoadName((int) sk.numL()); - glLoadName(nt.sizeE()); + glLoadName((int) sk.numL()); +// glLoadName(nt.sizeE()); -// sk.RenderLine(cL); - nt.RenderLine(cL); + sk.RenderLine(cL); +// nt.RenderLine(cL); // glPopName(); glFlush(); @@ -1615,8 +1575,9 @@ class gl_spider : public virtual gl_texture { cL.clear(); cM.clear(); - } + } +/* void addToNetwork(pair, int> in, stim::vec3 spos, stim::vec smag, stim::vec3 sdir) @@ -1664,13 +1625,23 @@ class gl_spider : public virtual gl_texture network_time += nt * 1000.0; #endif } +*/ + void + addToNetwork(std::vector > L, std::vector > M) + { + if(L.size() > 3) + { + sk.Begin(stim::OBJ_LINE); + for(int i = 0; i < L.size(); i++) + { + sk.TexCoord(M[i][0]); + sk.Vertex(L[i][0], L[i][1], L[i][2]); + } + sk.End(); -// void -// addToNetwork(pair, int> in, stim::vec3 spos, -// stim::vec smag, stim::vec3 sdir) -// { -// -// } + nt.addEdge(L,M); + } + } void @@ -1681,11 +1652,13 @@ class gl_spider : public virtual gl_texture } - std::pair, int > + void traceLine(stim::vec3 pos, stim::vec mag, int min_cost) { //starting (seed) position and magnitude. stim::vec3 spos = getPosition(); +// std::cout << "I did this" << std::endl; +// findOptimalScale(); stim::vec smag = getMagnitude(); stim::vec3 sdir = getDirection(); @@ -1693,8 +1666,8 @@ class gl_spider : public virtual gl_texture // sk.Begin(stim::OBJ_LINE); -// sk.createFromSelf(GL_SELECT); - nt.createFromSelf(GL_SELECT); + sk.createFromSelf(GL_SELECT); +// nt.createFromSelf(GL_SELECT); cL.push_back(pos); cM.push_back(mag); @@ -1712,10 +1685,8 @@ class gl_spider : public virtual gl_texture running = false; // sk.End(); branchDetection2(); - pair, int> a(stim::fiber (cL, cM), -1); - addToNetwork(a, spos, smag, sdir); -// std::cout << "the cost of " << cost << " > " << min_cost << std::endl; - return a; + addToNetwork(cL, cM); + std::cout << "the cost of " << cost << " > " << min_cost << std::endl; break; } else { //Have we found the edge of the map? @@ -1726,10 +1697,8 @@ class gl_spider : public virtual gl_texture { running = false; branchDetection2(); - pair, int> a(stim::fiber (cL, cM), -1); - addToNetwork(a, spos, smag, sdir); -// std::cout << "I hit and edge" << std::endl; - return a; + addToNetwork(cL, cM); + std::cout << "I hit and edge" << std::endl; break; } //If this is the first step in the trace, @@ -1744,10 +1713,8 @@ class gl_spider : public virtual gl_texture if(mag[0] > 75 || mag[0] < 1){ running = false; branchDetection2(); - pair, int> a(stim::fiber (cL, cM), -1); - addToNetwork(a, spos, smag, sdir); -// std::cout << "The templates are too big" << std::endl; - return a; + addToNetwork(cL, cM); + std::cout << "The templates are too big" << std::endl; break; } else @@ -1755,12 +1722,10 @@ class gl_spider : public virtual gl_texture h = selectObject(p, getDirection(), m[0]); //Have we hit something previously traced? if(h != -1){ -// std::cout << "I hit the fiber " << h << std::endl; + std::cout << "I hit the fiber " << h << std::endl; running = false; branchDetection2(); - pair, int> a(stim::fiber (cL, cM), h); - addToNetwork(a, spos, smag, sdir); - return a; + addToNetwork(cL, cM); break; } else { diff --git a/stim/math/circle.h b/stim/math/circle.h index 8a8c43c..423a9d3 100644 --- a/stim/math/circle.h +++ b/stim/math/circle.h @@ -48,9 +48,9 @@ public: CUDA_CALLABLE circle(T size, T z_pos = (T)0) : plane() { - init(); center(stim::vec3(0,0,z_pos)); scale(size); + init(); } ///create a rectangle from a center point, normal @@ -88,6 +88,7 @@ public: { init(); setU(u); +// U = u; center(c); normal(n); scale(s); @@ -174,6 +175,13 @@ public: return p(x,y); } + std::string str() const + { + std::stringstream ss; + ss << "(P=" << P.str() << ", N=" << N.str() << ", U=" << U.str() << ", Y=" << Y.str(); + return ss.str(); + } + }; } #endif diff --git a/stim/parser/filename.h b/stim/parser/filename.h index 0922d67..2225721 100644 --- a/stim/parser/filename.h +++ b/stim/parser/filename.h @@ -110,11 +110,11 @@ protected: unix_dir = unix_dir.substr(2, unix_dir.length()-2); //extract the directory structure } - if(unix_dir.front() == '/'){ //if there is a leading slash + if(unix_dir.at(0) == '/'){ //if there is a leading slash relative = false; //the path is not relative unix_dir = unix_dir.substr(1, unix_dir.length() - 1); //remove the slash } - if(unix_dir.back() == '/') + if(unix_dir.at(unix_dir.size()-1) == '/') unix_dir = unix_dir.substr(0, unix_dir.length() - 1); path = stim::parser::split(unix_dir, '/'); //split up the directory structure diff --git a/stim/visualization/cylinder.h b/stim/visualization/cylinder.h index d6dc68c..c52ee4d 100644 --- a/stim/visualization/cylinder.h +++ b/stim/visualization/cylinder.h @@ -2,19 +2,27 @@ #define STIM_CYLINDER_H #include #include -#include +#include namespace stim { template class cylinder + : public centerline { private: stim::circle s; //an arbitrary circle - std::vector > e; + std::vector > e; //an array of circles that store the centerline + + std::vector > norms; + std::vector > Us; std::vector > mags; std::vector< T > L; //length of the cylinder at each position. + + + using stim::centerline::c; + using stim::centerline::N; ///default init void @@ -23,6 +31,20 @@ class cylinder } + ///Calculate the physical length of the fiber at each point in the fiber. + void + calculateL() + { +/* L.resize(inP.size()); + T temp = (T)0; + L[0] = 0; + for(size_t i = 1; i < L.size(); i++) + { + temp += (inP[i-1] - inP[i]).len(); + L[i] = temp; + } +*/ } + ///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) @@ -31,6 +53,10 @@ class cylinder stim::vec3 v1; stim::vec3 v2; e.resize(inP.size()); + + norms.resize(inP.size()); + Us.resize(inP.size()); + if(inP.size() < 2) return; @@ -46,7 +72,9 @@ class cylinder stim::vec3 dr = (inP[1] - inP[0]).norm(); s = stim::circle(inP[0], inM[0][0], dr, stim::vec3(1,0,0)); + norms[0] = s.N; e[0] = s; + Us[0] = e[0].U; for(size_t i = 1; i < inP.size()-1; i++) { s.center(inP[i]); @@ -54,16 +82,24 @@ class cylinder v2 = (inP[i+1] - inP[i]).norm(); dr = (v1+v2).norm(); s.normal(dr); + + norms[i] = s.N; + s.scale(inM[i][0]/inM[i-1][0]); e[i] = s; + Us[i] = e[i].U; } int j = inP.size()-1; s.center(inP[j]); dr = (inP[j] - inP[j-1]).norm(); s.normal(dr); + + norms[j] = s.N; + s.scale(inM[j][0]/inM[j-1][0]); e[j] = s; + Us[j] = e[j].U; } ///returns the direction vector at point idx. @@ -72,18 +108,42 @@ class cylinder { if(idx == 0) { - return (e[idx+1].P - e[idx].P).norm(); + stim::vec3 temp( + c[idx+1][0]-c[idx][0], + c[idx+1][1]-c[idx][1], + c[idx+1][2]-c[idx][2] + ); +// return (e[idx+1].P - e[idx].P).norm(); + return (temp.norm()); } - else if(idx == e.size()-1) + else if(idx == N-1) { - return (e[idx].P - e[idx-1].P).norm(); + stim::vec3 temp( + c[idx][0]-c[idx+1][0], + c[idx][1]-c[idx+1][1], + c[idx][2]-c[idx+1][2] + ); + // return (e[idx].P - e[idx-1].P).norm(); + return (temp.norm()); } else { // return (e[idx+1].P - e[idx].P).norm(); - stim::vec3 v1 = (e[idx].P-e[idx-1].P).norm(); - stim::vec3 v2 = (e[idx+1].P-e[idx].P).norm(); - return (v1+v2).norm(); +// stim::vec3 v1 = (e[idx].P-e[idx-1].P).norm(); + stim::vec3 v1( + c[idx][0]-c[idx-1][0], + c[idx][1]-c[idx-1][1], + c[idx][2]-c[idx-1][2] + ); + +// stim::vec3 v2 = (e[idx+1].P-e[idx].P).norm(); + stim::vec3 v2( + c[idx+1][0]-c[idx][0], + c[idx+1][1]-c[idx][1], + c[idx+1][2]-c[idx][2] + ); + + return (v1.norm()+v2.norm()).norm(); } // return e[idx].N; @@ -92,14 +152,17 @@ class cylinder stim::vec3 d(T l, int idx) { - if(idx == 0 || idx == e.size()-1) + if(idx == 0 || idx == N-1) { - return e[idx].N; + return norms[idx]; +// return e[idx].N; } else { + T rat = (l-L[idx])/(L[idx+1]-L[idx]); - return( e[idx].N + (e[idx+1].N - e[idx].N)*rat); + return( norms[idx] + (norms[idx+1] - norms[idx])*rat); +// return( e[idx].N + (e[idx+1].N - e[idx].N)*rat); } } @@ -137,6 +200,7 @@ class cylinder public: ///default constructor cylinder() + // : centerline() { } @@ -144,14 +208,18 @@ 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 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) + : centerline(inP) + { init(inP, inM); } ///Constructor defines a cylinder with centerline inP and magnitudes of zero ///@param inP: Vector of stim vec3 composing the points of the centerline - cylinder(std::vector< stim::vec3 > inP){ + cylinder(std::vector< stim::vec3 > inP) + : centerline(inP) + { std::vector< stim::vec > inM; //create an array of arbitrary magnitudes stim::vec zero; @@ -164,7 +232,7 @@ class cylinder ///Returns the number of points on the cylinder centerline unsigned int size(){ - return e.size(); + return N; } @@ -180,9 +248,23 @@ class cylinder } T l = pvalue*L[L.size()-1]; int idx = findIdx(l); - T rat = (l-L[idx])/(L[idx+1]-L[idx]); - return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); - } + return (p(l,idx)); +/* T rat = (l-L[idx])/(L[idx+1]-L[idx]); + stim::vec3 v1( + c[idx][0], + c[idx][1], + c[idx][2] + ); + + stim::vec3 v2( + c[idx+1][0], + c[idx+1][1], + c[idx+1][2] + ); + +// return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); + return( v1 + (v2 - v1)*rat); +*/ } ///Returns a position vector at the given length into the fiber (based on the pvalue). ///Interpolates the radius along the line. @@ -192,7 +274,19 @@ class cylinder p(T l, int idx) { T rat = (l-L[idx])/(L[idx+1]-L[idx]); - return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); + stim::vec3 v1( + c[idx][0], + c[idx][1], + c[idx][2] + ); + + stim::vec3 v2( + c[idx+1][0], + c[idx+1][1], + c[idx+1][2] + ); +// return( e[idx].P + (e[idx+1].P-e[idx].P)*rat); + return( v1 + (v2-v1)*rat); // return( // return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); } @@ -209,8 +303,11 @@ class cylinder } T l = pvalue*L[L.size()-1]; int idx = findIdx(l); - return (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*((l-L[idx])/(L[idx+1]- L[idx]))); - } + return (r(l,idx)); +/* T rat = (l-L[idx])/(L[idx+1]-L[idx]); +// return (mags[idx][0] + (mags[idx+1][0]-mags[idx][0])*rat); + return (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*rat); +*/ } ///Returns a radius at the given length into the fiber (based on the pvalue). ///Interpolates the position along the line. @@ -220,7 +317,23 @@ class cylinder r(T l, int idx) { T rat = (l-L[idx])/(L[idx+1]-L[idx]); - return( e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*rat); + T v1 = (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*rat); + T v3 = (Us[idx].len() + (Us[idx+1].len() - Us[idx].len())*rat); + T v2 = (mags[idx][0] + (mags[idx+1][0]-mags[idx][0])*rat); +// std::cout << (float)v1 = (float) v2 << std::endl; + if(abs(v3 - v1) >= 10e-6) + { + std::cout << "-------------------------" << std::endl; + std::cout << e[idx].str() << std::endl << std::endl; + std::cout << Us[idx] << std::endl; + std::cout << (float)v1 - (float) v2 << std::endl; + std::cout << "failed" << std::endl; + } +// std::cout << e[idx].U.len() << " " << mags[idx][0] << std::endl; +// std::cout << v2 << std::endl; + return(v1); +// return (mags[idx][0] + (mags[idx+1][0]-mags[idx][0])*rat); + // ( } /// Returns the magnitude at the given index @@ -233,7 +346,7 @@ class cylinder /// Adds a new magnitude value to all points /// @param m is the starting value for the new magnitude void add_mag(T m = 0){ - for(unsigned int p = 0; p < e.size(); p++) + for(unsigned int p = 0; p < N; p++) mags[p].push_back(m); } @@ -279,8 +392,8 @@ class cylinder getPoints(int sides) { std::vector > > points; - points.resize(e.size()); - for(int i = 0; i < e.size(); i++) + points.resize(N); + for(int i = 0; i < N; i++) { points[i] = e[i].getPoints(sides); } @@ -319,7 +432,7 @@ class cylinder T len = L[0]; //allocate space for the segment length //for every consecutive point in the cylinder - for(unsigned p = 1; p < e.size(); p++){ + for(unsigned p = 1; p < N; p++){ //p1 = pos[p]; //get the position and magnitude for the next point m1 = mags[p][m]; diff --git a/stim/visualization/glObj.h b/stim/visualization/glObj.h index 9f66d6a..6751138 100644 --- a/stim/visualization/glObj.h +++ b/stim/visualization/glObj.h @@ -35,9 +35,9 @@ private: glListBase(dList); glMatrixMode(GL_PROJECTION); - glLoadIdentity; + glLoadIdentity(); glMatrixMode(GL_MODELVIEW); - glLoadIdentity; + glLoadIdentity(); } @@ -129,7 +129,7 @@ public: } void - RenderLine(std::vector< stim::vec > l) + RenderLine(std::vector< stim::vec3 > l) { glColor3f(0.5, 1.0, 0.5); glLineWidth(3.0); diff --git a/stim/visualization/obj.h b/stim/visualization/obj.h index 09e8a68..f3886db 100644 --- a/stim/visualization/obj.h +++ b/stim/visualization/obj.h @@ -322,13 +322,6 @@ protected: return OBJ_INVALID; } - //private method returns the vertex indices for a line - std::vector get_l_v(unsigned l){ - - - - } - public: /// Constructor loads a Wavefront OBJ file obj(std::string filename){ -- libgit2 0.21.4