From b3a386414300fd29dd08e3e76d0bd5fe48805eee Mon Sep 17 00:00:00 2001 From: David Date: Mon, 8 Feb 2016 23:29:36 -0600 Subject: [PATCH] added the ability to quickly render networks in OpenGL, renamed the bounding box class --- stim/biomodels/network.h | 5 +++++ stim/visualization/aabb.h | 72 ------------------------------------------------------------------------ stim/visualization/aaboundingbox.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/visualization/cylinder.h | 5 +++++ stim/visualization/gl_aabb.h | 60 ------------------------------------------------------------ stim/visualization/gl_aaboundingbox.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/visualization/gl_network.h | 16 +++++++++------- 7 files changed, 151 insertions(+), 139 deletions(-) delete mode 100644 stim/visualization/aabb.h create mode 100644 stim/visualization/aaboundingbox.h delete mode 100644 stim/visualization/gl_aabb.h create mode 100644 stim/visualization/gl_aaboundingbox.h diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index 06b0a63..29f4fe5 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -301,6 +301,11 @@ public: return R; //return the resulting network } + /// Returns the number of magnitude values stored in each edge. This should be uniform across the network. + unsigned nmags(){ + return E[0].nmags(); + } + }; //end stim::network class }; //end stim namespace diff --git a/stim/visualization/aabb.h b/stim/visualization/aabb.h deleted file mode 100644 index 119346f..0000000 --- a/stim/visualization/aabb.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef STIM_AABB -#define STIM_AABB - -namespace stim{ - - -/// This class describes a structure for an axis-aligned bounding box -template< typename T > -class aabb{ - -public: - bool set; //has the bounding box been set to include any points? - stim::vec A; //minimum point in the bounding box - stim::vec B; //maximum point in the bounding box - - aabb(){ //constructor generates an empty bounding box - set = false; - } - - - /// Test if a point is inside of the bounding box and returns true if it is. - - /// @param p is the point to be tested - bool test(stim::vec p){ - - for(unsigned d = 0; d < p.size(); p++){ //for each dimension - if(p[d] < A[d]) return false; //if the point is less than the minimum bound, return false - if(p[d] > B[d]) return false; //if the point is greater than the max bound, return false - } - return true; - } - - /// Expand the bounding box to include the specified point. - - /// @param p is the point to be included - void expand(stim::vec p){ - - if(!set){ //if the bounding box is empty, fill it with the current point - A = B = p; - set = true; - } - - for(unsigned d = 0; d < p.size(); d++){ //for each dimension - if(p[d] < A[d]) A[d] = p[d]; //expand the bounding box as necessary - if(p[d] > B[d]) B[d] = p[d]; - } - } - - /// Return the center point of the bounding box as a stim::vec - stim::vec center(){ - return (B + A) * 0.5; - } - - /// Return the size of the bounding box as a stim::vec - stim::vec size(){ - return (B - A); - } - - /// Generate a string for the bounding box - std::string str(){ - std::stringstream ss; - ss<"< +class aaboundingbox{ + +public: + bool set; //has the bounding box been set to include any points? + stim::vec A; //minimum point in the bounding box + stim::vec B; //maximum point in the bounding box + + aaboundingbox(){ //constructor generates an empty bounding box + set = false; + } + + + /// Test if a point is inside of the bounding box and returns true if it is. + + /// @param p is the point to be tested + bool test(stim::vec p){ + + for(unsigned d = 0; d < p.size(); p++){ //for each dimension + if(p[d] < A[d]) return false; //if the point is less than the minimum bound, return false + if(p[d] > B[d]) return false; //if the point is greater than the max bound, return false + } + return true; + } + + /// Expand the bounding box to include the specified point. + + /// @param p is the point to be included + void expand(stim::vec p){ + + if(!set){ //if the bounding box is empty, fill it with the current point + A = B = p; + set = true; + } + + for(unsigned d = 0; d < p.size(); d++){ //for each dimension + if(p[d] < A[d]) A[d] = p[d]; //expand the bounding box as necessary + if(p[d] > B[d]) B[d] = p[d]; + } + } + + /// Return the center point of the bounding box as a stim::vec + stim::vec center(){ + return (B + A) * 0.5; + } + + /// Return the size of the bounding box as a stim::vec + stim::vec size(){ + return (B - A); + } + + /// Generate a string for the bounding box + std::string str(){ + std::stringstream ss; + ss<"< -class gl_aabb : public aabb{ - -public: - - //default constructor - gl_aabb() : stim::aabb(){} - - //constructor takes an AABB - gl_aabb(stim::aabb b) : stim::aabb(b){} - - - /// 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); - 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(); - - //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(B[0], A[1], B[2]); - glEnd(); - - //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]); - glVertex3f(B[0], B[1], A[2]); - glVertex3f(B[0], A[1], A[2]); - glVertex3f(B[0], A[1], B[2]); - glVertex3f(A[0], A[1], B[2]); - glVertex3f(A[0], A[1], A[2]); - glEnd(); - - } - - -}; //end stim::gl_aabb - - -}; //end namespace stim - -#endif \ No newline at end of file diff --git a/stim/visualization/gl_aaboundingbox.h b/stim/visualization/gl_aaboundingbox.h new file mode 100644 index 0000000..de81ae8 --- /dev/null +++ b/stim/visualization/gl_aaboundingbox.h @@ -0,0 +1,60 @@ +#ifndef STIM_GL_AABB +#define STIM_GL_AABB + +#include +#include + +namespace stim{ + +template +class gl_aaboundingbox : public aaboundingbox{ + +public: + + //default constructor + gl_aaboundingbox() : stim::aaboundingbox(){} + + //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(){ + + //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(); + + //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(B[0], A[1], B[2]); + glEnd(); + + //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]); + glVertex3f(B[0], B[1], A[2]); + glVertex3f(B[0], A[1], A[2]); + glVertex3f(B[0], A[1], B[2]); + glVertex3f(A[0], A[1], B[2]); + glVertex3f(A[0], A[1], A[2]); + glEnd(); + + } + + +}; //end stim::gl_aabb + + +}; //end namespace stim + +#endif \ No newline at end of file diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index 48765b9..f1b357f 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -2,7 +2,7 @@ #define STIM_GL_NETWORK #include -#include "aabb.h" +#include namespace stim{ @@ -29,9 +29,9 @@ public: /// Fills the parameters with the minimum and maximum spatial positions in the network, /// specifying a bounding box for the network geometry - aabb boundingbox(){ + aaboundingbox boundingbox(){ - aabb bb; //create a bounding box + aaboundingbox bb; //create a bounding box //loop through every edge for(unsigned e = 0; e < E.size(); e++){ @@ -44,16 +44,18 @@ public: } /// Render the network centerline as a series of line strips. - void glCenterline(){ + + /// @param m specifies the magnitude value used as the vertex weight (radius, error, etc.) + void glCenterline(unsigned m = 0){ 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 for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network glBegin(GL_LINE_STRIP); - for(unsigned p = 0; p < E[e].size(); p++){ //for each point on that edge - glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); - glTexCoord1f(E[e].ri(p)); + for(unsigned p = 0; p < E[e].size(); p++){ //for each point on that edge + glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); //set the vertex position based on the current point + glTexCoord1f(E[e].ri(p, m)); //set the texture coordinate based on the specified magnitude index } glEnd(); } -- libgit2 0.21.4