#ifndef STIM_GLOBJ_H #define STIM_GLOBJ_H #include #include #include #include namespace stim { /** This class uses the loading functionality of the obj class in order to * Assist with the visualization the segmented vessels. * Uses */ template class glObj : public virtual stim::obj { private: using stim::obj::L; using stim::obj::P; using stim::obj::F; // using stim::obj::numL(); // using std::vector::size; // using std::vector::at; GLuint dList; void init() { if(glIsList(dList)) glDeleteLists(dList, 1); dList = glGenLists(1); glListBase(dList); glMatrixMode(GL_PROJECTION); glLoadIdentity; glMatrixMode(GL_MODELVIEW); glLoadIdentity; } void Create(GLenum mode) { // GLuint selectBuf[2048]; // GLint hits; // glSelectBuffer(2048, selectBuf); int len = (int) stim::obj::numL(); std::vector< stim::vec > line; glNewList(dList, GL_COMPILE); // glColor3f(0.0, 1.0, 0.0); glLineWidth(3.5); for(int i = 0; i < len; i++){ line = stim::obj::getL_V(i); if(mode == GL_SELECT) { glLoadName(i); } glColor3f(0.0, 1.0, 0.05); //glColor3ub(rand()%255, rand()%255, rand()%255); glBegin(GL_LINE_STRIP); for(int j = 0; j < line.size(); j++){ glVertex3f( line[j][0], line[j][1], line[j][2] ); } glEnd(); } glEndList(); CHECK_OPENGL_ERROR } public: glObj() { } void createFromSelf(GLenum mode = GL_RENDER) { // glPopMatrix(); init(); Create(mode); // glPushMatrix(); } void createFromFile(std::string filename, GLenum mode = GL_RENDER) { stim::obj::load(filename); glPushMatrix(); //Safety Operation to avoid changing the current matrix. init(); Create(mode); glPopMatrix(); CHECK_OPENGL_ERROR } void Render() { glCallList(dList); CHECK_OPENGL_ERROR } void RenderLine(int i) { std::vector < stim::vec > line; int len = (int) stim::obj::numL(); line = stim::obj::getL_V(i); glColor3f(0.5, 1.0, 0.5); glLineWidth(3.0); glBegin(GL_LINE_STRIP); for(int j = 0; j < line.size(); j++){ glVertex3f( line[j][0], line[j][1], line[j][2] ); } glEnd(); } void RenderLine(std::vector< stim::vec > l) { glColor3f(0.5, 1.0, 0.5); glLineWidth(3.0); glBegin(GL_LINE_STRIP); for(int j = 0; j < l.size(); j++){ glVertex3f( l[j][0], l[j][1], l[j][2] ); } glEnd(); } }; } #endif