From b7624d0db6675e2701f34201679d62635a7b2286 Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Wed, 8 Feb 2017 15:15:24 -0600 Subject: [PATCH] add function to help microfluidics project --- stim/biomodels/network.h | 32 ++++++++++++++++++++++++++++++-- stim/visualization/gl_aaboundingbox.h | 48 ++++++++++++++++++++++++------------------------ stim/visualization/gl_network.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 26 deletions(-) diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index ca6a1df..bde6683 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -175,21 +175,49 @@ public: return E[e].r(i); } + ///Returns the average radius of specific edge + T get_average_R(unsigned e) { + T result = 0.0; + unsigned n = E[e].size(); + for (unsigned p = 0; p < n; p++) + result += E[e].r(p); + + return (T)result / n; + } + ///Returns the length of current edge T get_L(unsigned e) { return E[e].length(); } ///Returns the start vertex of current edge - size_t get_SP(unsigned e) { + size_t get_start_vertex(unsigned e) { return E[e].v[0]; } ///Returns the end vertex of current edge - size_t get_EP(unsigned e) { + size_t get_end_vertex(unsigned e) { return E[e].v[1]; } + ///Returns one vertex + stim::vec3 get_vertex(unsigned i) { + return V[i]; + } + + ///Returns the boundary vertices' indices + std::vector get_boundary_vertex() { + std::vector result; + + for (unsigned v = 0; v < V.size(); v++) { + if (V[v].e[0].size() + V[v].e[1].size() == 1) { // boundary vertex + result.push_back(v); + } + } + + return result; + } + //scale the network by some constant value // I don't think these work?????? /*std::vector operator*(T s){ diff --git a/stim/visualization/gl_aaboundingbox.h b/stim/visualization/gl_aaboundingbox.h index 3e3b0b6..6796446 100644 --- a/stim/visualization/gl_aaboundingbox.h +++ b/stim/visualization/gl_aaboundingbox.h @@ -4,44 +4,44 @@ #include #include -namespace stim{ +namespace stim { -template -class gl_aaboundingbox : public aaboundingbox{ + template + class gl_aaboundingbox : public aaboundingbox { -public: + public: - using stim::aaboundingbox::A; - using stim::aaboundingbox::B; + using stim::aaboundingbox::A; + using stim::aaboundingbox::B; - //default constructor - gl_aaboundingbox() : stim::aaboundingbox(){} + //default constructor + gl_aaboundingbox() : stim::aaboundingbox() {} - //constructor takes an AABB - gl_aaboundingbox(stim::aaboundingbox b) : stim::aaboundingbox(b){} + //constructor takes an AABB + gl_aaboundingbox(stim::aaboundingbox b) : stim::aaboundingbox(b) {} - /// Specifies vertices of the bounding box using CW winding. Use GL_LINE_LOOP for wireframe or GL_QUADS for a solid. - void glWire(){ + /// Specifies vertices of the bounding box using CW winding. Use GL_LINE_LOOP for wireframe or GL_QUADS for a solid. + void glWire() { - //front plane (in A[2]) - glBegin(GL_LINE_LOOP); + //front plane (in A[2]) + glBegin(GL_LINE_LOOP); glVertex3f(A[0], A[1], A[2]); glVertex3f(A[0], B[1], A[2]); glVertex3f(B[0], B[1], A[2]); glVertex3f(B[0], A[1], A[2]); - glEnd(); + glEnd(); - //back plane (in B[2]) - glBegin(GL_LINE_LOOP); + //back plane (in B[2]) + glBegin(GL_LINE_LOOP); glVertex3f(B[0], B[1], B[2]); glVertex3f(A[0], B[1], B[2]); - glVertex3f(A[0], A[1], B[2]); + glVertex3f(A[0], A[1], B[2]); glVertex3f(B[0], A[1], B[2]); - glEnd(); + glEnd(); - //fill out the rest of the lines to connect the two faces - glBegin(GL_LINES); + //fill out the rest of the lines to connect the two faces + glBegin(GL_LINES); glVertex3f(A[0], B[1], A[2]); glVertex3f(A[0], B[1], B[2]); glVertex3f(B[0], B[1], B[2]); @@ -50,12 +50,12 @@ public: glVertex3f(B[0], A[1], B[2]); glVertex3f(A[0], A[1], B[2]); glVertex3f(A[0], A[1], A[2]); - glEnd(); + glEnd(); - } + } -}; //end stim::gl_aabb + }; //end stim::gl_aabb }; //end namespace stim diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index e337e74..ea751af 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -155,6 +155,39 @@ public: glCallList(dlist); //render the display list } + ///render the network cylinder as a series of tubes(when only one network loaded) + void glCylinder0() { + + if (!glIsList(dlist)) { // if dlist isn't a display list, create it + dlist = glGenLists(1); // generate a display list + glNewList(dlist, GL_COMPILE); // start a new display list + T radius = 0.0; + for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network + radius = get_average_R(e) / get_average_R(0); // calculate the radius + for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge + stim::circle C1 = E[e].circ(p - 1); + stim::circle C2 = E[e].circ(p); + C1.set_R(2 * radius); // re-scale the circle to the same + C2.set_R(2 * radius); + std::vector< stim::vec3 > Cp1 = C1.glpoints(20);// get 20 points on the circle plane + std::vector< stim::vec3 > Cp2 = C2.glpoints(20); + glBegin(GL_QUAD_STRIP); + for (unsigned i = 0; i < Cp1.size(); i++) { + glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); + glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); + } + glEnd(); + } // set the texture coordinate based on the specified magnitude index + } + for (unsigned n = 0; n < V.size(); n++) { + size_t num = V[n].e[0].size(); // store the number of outgoing edge of that vertex + renderBall(V[n][0], V[n][1], V[n][2], 2 * radius, 20); + } + glEndList(); // end the display list + } + glCallList(dlist); // render the display list + } + ///render the network cylinder as a series of tubes ///colors are based on metric values void glCylinder(float sigma, float radius) { -- libgit2 0.21.4