Commit 10654a1f993ec09f8270dfd9a7f934d9294fd475
1 parent
1bdf7c1e
added the necessary methods to circle and cylinder classes in order to merge those with network
Showing
2 changed files
with
95 additions
and
5 deletions
Show diff stats
stim/visualization/cylinder.h
... | ... | @@ -14,20 +14,63 @@ class cylinder |
14 | 14 | stim::circle<T> s; |
15 | 15 | std::vector< stim::vec<T> > pos; |
16 | 16 | std::vector< stim::vec<T> > mags; |
17 | + std::vector< T > L; | |
17 | 18 | |
18 | 19 | void |
19 | 20 | init() |
20 | 21 | { |
21 | - | |
22 | + | |
22 | 23 | } |
23 | 24 | |
24 | 25 | void |
25 | - init(std::vector<stim::vec<T> > &inP, std::vector<stim::vec<T> > &inM) | |
26 | + init(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM) | |
26 | 27 | { |
27 | 28 | pos = inP; |
28 | 29 | mags = inM; |
30 | + L.resize(pos.size()-1); | |
31 | + for(int i = 0; i < L.size; i++) | |
32 | + { | |
33 | + L[i] += (pos[i] - pos[i+1]).len(); | |
34 | + } | |
29 | 35 | } |
30 | 36 | |
37 | + stim::vec<T> | |
38 | + d(int idx) | |
39 | + { | |
40 | + return (pos[idx] - pos[idx+1]).norm(); | |
41 | + | |
42 | + } | |
43 | + | |
44 | + T | |
45 | + getl(int j) | |
46 | + { | |
47 | + for(int i = 0; i < j-1; ++i) | |
48 | + { | |
49 | + L += (pos[i] -pos[i+1]).len(); | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + int | |
54 | + findIdx(T l) | |
55 | + { | |
56 | + int i = pos.size()/2; | |
57 | + while(1) | |
58 | + { | |
59 | + if(L[i] < l) | |
60 | + { | |
61 | + i = i/2; | |
62 | + } | |
63 | + else if(L[i] < l && L[i+1] > l) | |
64 | + { | |
65 | + break; | |
66 | + } | |
67 | + else | |
68 | + { | |
69 | + i = i+i/2; | |
70 | + } | |
71 | + } | |
72 | + return i; | |
73 | + } | |
31 | 74 | |
32 | 75 | public: |
33 | 76 | cylinder() |
... | ... | @@ -39,11 +82,57 @@ class cylinder |
39 | 82 | ///The higher the number of sides, the more rectangeles compose the surface of the cylinder. |
40 | 83 | ///@param inP: Vector of stim vecs composing the points of the centerline. |
41 | 84 | ///@param inM: Vector of stim vecs composing the radii of the centerline. |
42 | - cylinder(std::vector<stim::vec<T> > &inP, std::vector<stim::vec<T> > &inM) | |
85 | + cylinder(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM) | |
43 | 86 | { |
44 | 87 | init(inP, inM); |
45 | 88 | } |
46 | 89 | |
90 | + | |
91 | + ///Returns a position vector at the given p-value (p value ranges from 0 to 1). | |
92 | + stim::vec<T> | |
93 | + p(T pvalue) | |
94 | + { | |
95 | + T l = pvalue*L[L.size()-1]; | |
96 | + int idx = findIdx(l); | |
97 | + return pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])); | |
98 | + } | |
99 | + | |
100 | + stim::vec<T> | |
101 | + p(T l, int idx) | |
102 | + { | |
103 | + return pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])); | |
104 | + } | |
105 | + | |
106 | + ///Returns a radius at the given p-value (p value ranges from 0 to 1). | |
107 | + T | |
108 | + r(T pvalue) | |
109 | + { | |
110 | + T l = pvalue*L[L.size()-1]; | |
111 | + int idx = findIdx(l); | |
112 | + return mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])); | |
113 | + { | |
114 | + | |
115 | + T | |
116 | + r(T l, int idx) | |
117 | + { | |
118 | + return mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])); | |
119 | + { | |
120 | + | |
121 | + | |
122 | + ///returns the position of the point with a given pvalue and theta on the surface | |
123 | + ///in x, y, z coordinates. Theta is in degrees from 0 to 360 | |
124 | + stim::vec<T> | |
125 | + surf(T pvalue, T theta) | |
126 | + { | |
127 | + T l = pvalue*L[L.size()-1]; | |
128 | + int idx = findIdx(l); | |
129 | + stim::vec<T> ps = p(l, idx); | |
130 | + T m = r(l, idx); | |
131 | + stim::vec<T> dr = d(idx); | |
132 | + s = stim::circle<T>(ps, m, dr); | |
133 | + return(s.p(theta)); | |
134 | + } | |
135 | + | |
47 | 136 | std::vector<std::vector<vec<T> > > |
48 | 137 | getPoints(int sides) |
49 | 138 | { | ... | ... |
stim/visualization/glnetwork.h
... | ... | @@ -107,11 +107,12 @@ private: |
107 | 107 | glDisable(GL_BLEND); |
108 | 108 | |
109 | 109 | glColor4f(1.0, 0.0, 1.0, 1.0); |
110 | + glLineWidth(2.0); | |
110 | 111 | glBegin(GL_LINES); |
111 | 112 | glVertex3f(p[i][j][0], p[i][j][1], p[i][j][2]); |
112 | 113 | glVertex3f(p[i][j+1][0], p[i][j+1][1], p[i][j+1][2]); |
113 | - glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2]); | |
114 | - glVertex3f(p[i+1][j+1][0], p[i+1][j+1][1], p[i+1][j+1][2] ); | |
114 | + glVertex3f(p[i][j][0], p[i][j][1], p[i][j][2]); | |
115 | + glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2] ); | |
115 | 116 | glEnd(); |
116 | 117 | } |
117 | 118 | ... | ... |