glObj.h
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef STIM_GLOBJ_H
#define STIM_GLOBJ_H
#include <GL/glew.h>
#include <GL/glut.h>
#include <stim/math/vector.h>
#include <stim/visualization/obj.h>
namespace stim
{
/** This class uses the loading functionality of the obj class in order to
* Assist with the visualization the segmented vessels.
* Uses
*/
template <typename T>
class glObj : public virtual stim::obj<T>
{
private:
using stim::obj<T>::L;
using stim::obj<T>::P;
using stim::obj<T>::F;
// using stim::obj<T>::numL();
// using std::vector<T>::size;
// using std::vector<T>::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<T>::numL();
std::vector< stim::vec<float> > 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<T>::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<T>::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<T> > line;
int len = (int) stim::obj<T>::numL();
line = stim::obj<T>::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<T> > 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