Commit b7624d0db6675e2701f34201679d62635a7b2286
1 parent
00a7e339
add function to help microfluidics project
Showing
3 changed files
with
87 additions
and
26 deletions
Show diff stats
stim/biomodels/network.h
... | ... | @@ -175,21 +175,49 @@ public: |
175 | 175 | return E[e].r(i); |
176 | 176 | } |
177 | 177 | |
178 | + ///Returns the average radius of specific edge | |
179 | + T get_average_R(unsigned e) { | |
180 | + T result = 0.0; | |
181 | + unsigned n = E[e].size(); | |
182 | + for (unsigned p = 0; p < n; p++) | |
183 | + result += E[e].r(p); | |
184 | + | |
185 | + return (T)result / n; | |
186 | + } | |
187 | + | |
178 | 188 | ///Returns the length of current edge |
179 | 189 | T get_L(unsigned e) { |
180 | 190 | return E[e].length(); |
181 | 191 | } |
182 | 192 | |
183 | 193 | ///Returns the start vertex of current edge |
184 | - size_t get_SP(unsigned e) { | |
194 | + size_t get_start_vertex(unsigned e) { | |
185 | 195 | return E[e].v[0]; |
186 | 196 | } |
187 | 197 | |
188 | 198 | ///Returns the end vertex of current edge |
189 | - size_t get_EP(unsigned e) { | |
199 | + size_t get_end_vertex(unsigned e) { | |
190 | 200 | return E[e].v[1]; |
191 | 201 | } |
192 | 202 | |
203 | + ///Returns one vertex | |
204 | + stim::vec3<T> get_vertex(unsigned i) { | |
205 | + return V[i]; | |
206 | + } | |
207 | + | |
208 | + ///Returns the boundary vertices' indices | |
209 | + std::vector<unsigned> get_boundary_vertex() { | |
210 | + std::vector<unsigned> result; | |
211 | + | |
212 | + for (unsigned v = 0; v < V.size(); v++) { | |
213 | + if (V[v].e[0].size() + V[v].e[1].size() == 1) { // boundary vertex | |
214 | + result.push_back(v); | |
215 | + } | |
216 | + } | |
217 | + | |
218 | + return result; | |
219 | + } | |
220 | + | |
193 | 221 | //scale the network by some constant value |
194 | 222 | // I don't think these work?????? |
195 | 223 | /*std::vector<vertex> operator*(T s){ | ... | ... |
stim/visualization/gl_aaboundingbox.h
... | ... | @@ -4,44 +4,44 @@ |
4 | 4 | #include <stim/visualization/aaboundingbox.h> |
5 | 5 | #include <GL/gl.h> |
6 | 6 | |
7 | -namespace stim{ | |
7 | +namespace stim { | |
8 | 8 | |
9 | -template <typename T> | |
10 | -class gl_aaboundingbox : public aaboundingbox<T>{ | |
9 | + template <typename T> | |
10 | + class gl_aaboundingbox : public aaboundingbox<T> { | |
11 | 11 | |
12 | -public: | |
12 | + public: | |
13 | 13 | |
14 | - using stim::aaboundingbox<T>::A; | |
15 | - using stim::aaboundingbox<T>::B; | |
14 | + using stim::aaboundingbox<T>::A; | |
15 | + using stim::aaboundingbox<T>::B; | |
16 | 16 | |
17 | - //default constructor | |
18 | - gl_aaboundingbox() : stim::aaboundingbox<T>(){} | |
17 | + //default constructor | |
18 | + gl_aaboundingbox() : stim::aaboundingbox<T>() {} | |
19 | 19 | |
20 | - //constructor takes an AABB | |
21 | - gl_aaboundingbox(stim::aaboundingbox<T> b) : stim::aaboundingbox<T>(b){} | |
20 | + //constructor takes an AABB | |
21 | + gl_aaboundingbox(stim::aaboundingbox<T> b) : stim::aaboundingbox<T>(b) {} | |
22 | 22 | |
23 | 23 | |
24 | - /// Specifies vertices of the bounding box using CW winding. Use GL_LINE_LOOP for wireframe or GL_QUADS for a solid. | |
25 | - void glWire(){ | |
24 | + /// Specifies vertices of the bounding box using CW winding. Use GL_LINE_LOOP for wireframe or GL_QUADS for a solid. | |
25 | + void glWire() { | |
26 | 26 | |
27 | - //front plane (in A[2]) | |
28 | - glBegin(GL_LINE_LOOP); | |
27 | + //front plane (in A[2]) | |
28 | + glBegin(GL_LINE_LOOP); | |
29 | 29 | glVertex3f(A[0], A[1], A[2]); |
30 | 30 | glVertex3f(A[0], B[1], A[2]); |
31 | 31 | glVertex3f(B[0], B[1], A[2]); |
32 | 32 | glVertex3f(B[0], A[1], A[2]); |
33 | - glEnd(); | |
33 | + glEnd(); | |
34 | 34 | |
35 | - //back plane (in B[2]) | |
36 | - glBegin(GL_LINE_LOOP); | |
35 | + //back plane (in B[2]) | |
36 | + glBegin(GL_LINE_LOOP); | |
37 | 37 | glVertex3f(B[0], B[1], B[2]); |
38 | 38 | glVertex3f(A[0], B[1], B[2]); |
39 | - glVertex3f(A[0], A[1], B[2]); | |
39 | + glVertex3f(A[0], A[1], B[2]); | |
40 | 40 | glVertex3f(B[0], A[1], B[2]); |
41 | - glEnd(); | |
41 | + glEnd(); | |
42 | 42 | |
43 | - //fill out the rest of the lines to connect the two faces | |
44 | - glBegin(GL_LINES); | |
43 | + //fill out the rest of the lines to connect the two faces | |
44 | + glBegin(GL_LINES); | |
45 | 45 | glVertex3f(A[0], B[1], A[2]); |
46 | 46 | glVertex3f(A[0], B[1], B[2]); |
47 | 47 | glVertex3f(B[0], B[1], B[2]); |
... | ... | @@ -50,12 +50,12 @@ public: |
50 | 50 | glVertex3f(B[0], A[1], B[2]); |
51 | 51 | glVertex3f(A[0], A[1], B[2]); |
52 | 52 | glVertex3f(A[0], A[1], A[2]); |
53 | - glEnd(); | |
53 | + glEnd(); | |
54 | 54 | |
55 | - } | |
55 | + } | |
56 | 56 | |
57 | 57 | |
58 | -}; //end stim::gl_aabb | |
58 | + }; //end stim::gl_aabb | |
59 | 59 | |
60 | 60 | |
61 | 61 | }; //end namespace stim | ... | ... |
stim/visualization/gl_network.h
... | ... | @@ -155,6 +155,39 @@ public: |
155 | 155 | glCallList(dlist); //render the display list |
156 | 156 | } |
157 | 157 | |
158 | + ///render the network cylinder as a series of tubes(when only one network loaded) | |
159 | + void glCylinder0() { | |
160 | + | |
161 | + if (!glIsList(dlist)) { // if dlist isn't a display list, create it | |
162 | + dlist = glGenLists(1); // generate a display list | |
163 | + glNewList(dlist, GL_COMPILE); // start a new display list | |
164 | + T radius = 0.0; | |
165 | + for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network | |
166 | + radius = get_average_R(e) / get_average_R(0); // calculate the radius | |
167 | + for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge | |
168 | + stim::circle<T> C1 = E[e].circ(p - 1); | |
169 | + stim::circle<T> C2 = E[e].circ(p); | |
170 | + C1.set_R(2 * radius); // re-scale the circle to the same | |
171 | + C2.set_R(2 * radius); | |
172 | + std::vector< stim::vec3<T> > Cp1 = C1.glpoints(20);// get 20 points on the circle plane | |
173 | + std::vector< stim::vec3<T> > Cp2 = C2.glpoints(20); | |
174 | + glBegin(GL_QUAD_STRIP); | |
175 | + for (unsigned i = 0; i < Cp1.size(); i++) { | |
176 | + glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); | |
177 | + glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); | |
178 | + } | |
179 | + glEnd(); | |
180 | + } // set the texture coordinate based on the specified magnitude index | |
181 | + } | |
182 | + for (unsigned n = 0; n < V.size(); n++) { | |
183 | + size_t num = V[n].e[0].size(); // store the number of outgoing edge of that vertex | |
184 | + renderBall(V[n][0], V[n][1], V[n][2], 2 * radius, 20); | |
185 | + } | |
186 | + glEndList(); // end the display list | |
187 | + } | |
188 | + glCallList(dlist); // render the display list | |
189 | + } | |
190 | + | |
158 | 191 | ///render the network cylinder as a series of tubes |
159 | 192 | ///colors are based on metric values |
160 | 193 | void glCylinder(float sigma, float radius) { | ... | ... |