From 1bdf7c1ed2283171b8f2bcd3426e66fc33b7aa01 Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Mon, 1 Feb 2016 17:12:06 -0600 Subject: [PATCH] extended the glnetwork.h class to use cylinders and render a cylinder network as well as a line network, note that the includes need to be fixed once the network.h class is complete --- stim/visualization/glnetwork.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/stim/visualization/glnetwork.h b/stim/visualization/glnetwork.h index 5f5d8eb..418fdbd 100644 --- a/stim/visualization/glnetwork.h +++ b/stim/visualization/glnetwork.h @@ -4,6 +4,7 @@ #include #include #include "network.h" +#include #include #include #include @@ -18,23 +19,39 @@ class glnetwork : public virtual network private: using stim::network::E; - GLuint dList; + GLuint dList; ///displaylist for the lines. + GLuint cList; ///displaylist for the cylinders. void init() { + ///clear lists if there is data in them. + ///adding points may create errors or uncessary duplicate points. if(glIsList(dList)) glDeleteLists(dList, 1); - dList = glGenLists(1); + if(glIsList(cList)) + glDeleteLists(cList, 1); + dList = glGenLists(1); ///create the lists + cList = glGenLists(1); + + ///set up the Line list. glListBase(dList); glMatrixMode(GL_PROJECTION); glLoadIdentity; glMatrixMode(GL_MODELVIEW); glLoadIdentity; + + ///set up the cylinder List. + glListBase(cList); + glMatrixMode(GL_PROJECTION); + glLoadIdentity; + glMatrixMode(GL_MODELVIEW); + glLoadIdentity; } void - Create(GLenum mode) + Create(GLenum mode, int sides = 8) { + glListBase(dList); glNewList(dList, GL_COMPILE); glLineWidth(3.5); for(int i = 0; i < E.size(); i++) @@ -59,22 +76,68 @@ private: glEnd(); } glEndList(); + + glListBase(cList); + glNewList(cList, GL_COMPILE); + + for(int i = 0; i < E.size(); i++) + { + if(mode == GL_SELECT) + { + glLoadName(i); + } + glColor3f(1.0, 1.0, 0.0); + std::vector > line = getEdgeCenterLine(i); + std::vector > linemag = getEdgeCenterLineMag(i); + stim::cylinder cyl(line, linemag); + std::vector > > p = cyl.getPoints(sides); + for(int i = 0; i < p.size()-1; i++) + { + for(int j = 0; j < p[0].size()-1; j++) + { + glColor4f(1.0, 1.0, 0.0, 0.5); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBegin(GL_QUADS); + 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+1][0], p[i+1][j+1][1], p[i+1][j+1][2] ); + glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2]); + glEnd(); + glDisable(GL_BLEND); + + glColor4f(1.0, 0.0, 1.0, 1.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] ); + glEnd(); + } + + } + + + + } + glEndList(); // CHECK_OPENGL_ERROR } public: using stim::network::sizeE; using stim::network::getEdgeCenterLine; + using stim::network::getEdgeCenterLineMag; glnetwork() { } void - createFromSelf(GLenum mode = GL_RENDER) + createFromSelf(GLenum mode = GL_RENDER, int sides = 8) { init(); - Create(mode); + Create(mode, sides); } void @@ -85,6 +148,13 @@ public: } void + RenderCylinders() + { + glCallList(cList); +// CHECK_OPENGL_ERROR + } + + void RenderLine(std::vector > l) { glColor3f(0.5, 1.0, 0.5); -- libgit2 0.21.4