From 10654a1f993ec09f8270dfd9a7f934d9294fd475 Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Tue, 2 Feb 2016 18:41:13 -0600 Subject: [PATCH] added the necessary methods to circle and cylinder classes in order to merge those with network --- stim/visualization/cylinder.h | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- stim/visualization/glnetwork.h | 5 +++-- 2 files changed, 95 insertions(+), 5 deletions(-) diff --git a/stim/visualization/cylinder.h b/stim/visualization/cylinder.h index 50cc1d1..cd00daf 100644 --- a/stim/visualization/cylinder.h +++ b/stim/visualization/cylinder.h @@ -14,20 +14,63 @@ class cylinder stim::circle s; std::vector< stim::vec > pos; std::vector< stim::vec > mags; + std::vector< T > L; void init() { - + } void - init(std::vector > &inP, std::vector > &inM) + init(std::vector > inP, std::vector > inM) { pos = inP; mags = inM; + L.resize(pos.size()-1); + for(int i = 0; i < L.size; i++) + { + L[i] += (pos[i] - pos[i+1]).len(); + } } + stim::vec + d(int idx) + { + return (pos[idx] - pos[idx+1]).norm(); + + } + + T + getl(int j) + { + for(int i = 0; i < j-1; ++i) + { + L += (pos[i] -pos[i+1]).len(); + } + } + + int + findIdx(T l) + { + int i = pos.size()/2; + while(1) + { + if(L[i] < l) + { + i = i/2; + } + else if(L[i] < l && L[i+1] > l) + { + break; + } + else + { + i = i+i/2; + } + } + return i; + } public: cylinder() @@ -39,11 +82,57 @@ class cylinder ///The higher the number of sides, the more rectangeles compose the surface of the cylinder. ///@param inP: Vector of stim vecs 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); } + + ///Returns a position vector at the given p-value (p value ranges from 0 to 1). + stim::vec + p(T pvalue) + { + T l = pvalue*L[L.size()-1]; + int idx = findIdx(l); + return pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])); + } + + stim::vec + p(T l, int idx) + { + return pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])); + } + + ///Returns a radius at the given p-value (p value ranges from 0 to 1). + T + r(T pvalue) + { + T l = pvalue*L[L.size()-1]; + int idx = findIdx(l); + return mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])); + { + + T + r(T l, int idx) + { + return mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])); + { + + + ///returns the position of the point with a given pvalue and theta on the surface + ///in x, y, z coordinates. Theta is in degrees from 0 to 360 + stim::vec + surf(T pvalue, T theta) + { + T l = pvalue*L[L.size()-1]; + int idx = findIdx(l); + stim::vec ps = p(l, idx); + T m = r(l, idx); + stim::vec dr = d(idx); + s = stim::circle(ps, m, dr); + return(s.p(theta)); + } + std::vector > > getPoints(int sides) { diff --git a/stim/visualization/glnetwork.h b/stim/visualization/glnetwork.h index 418fdbd..26813c5 100644 --- a/stim/visualization/glnetwork.h +++ b/stim/visualization/glnetwork.h @@ -107,11 +107,12 @@ private: glDisable(GL_BLEND); glColor4f(1.0, 0.0, 1.0, 1.0); + glLineWidth(2.0); glBegin(GL_LINES); glVertex3f(p[i][j][0], p[i][j][1], p[i][j][2]); glVertex3f(p[i][j+1][0], p[i][j+1][1], p[i][j+1][2]); - glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2]); - glVertex3f(p[i+1][j+1][0], p[i+1][j+1][1], p[i+1][j+1][2] ); + glVertex3f(p[i][j][0], p[i][j][1], p[i][j][2]); + glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2] ); glEnd(); } -- libgit2 0.21.4