cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
1
2
3
|
#ifndef STIM_GLOBJ_H
#define STIM_GLOBJ_H
|
98eecaa9
David Mayerich
VS and win32 updates
|
4
|
//#include <GL/glew.h>
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
5
6
|
#include <GL/glut.h>
#include <stim/math/vector.h>
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
7
|
#include <stim/visualization/obj.h>
|
b50c840e
David Mayerich
eliminated ANN fr...
|
8
|
#include <stim/gl/error.h>
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
9
10
11
12
13
14
15
16
|
namespace stim
{
/** This class uses the loading functionality of the obj class in order to
* Assist with the visualization the segmented vessels.
* Uses
*/
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
17
18
|
template <typename T>
class glObj : public virtual stim::obj<T>
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
19
20
21
22
23
|
{
private:
using stim::obj<T>::L;
using stim::obj<T>::P;
using stim::obj<T>::F;
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
24
25
26
|
// using stim::obj<T>::numL();
// using std::vector<T>::size;
// using std::vector<T>::at;
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
27
28
29
30
|
GLuint dList;
void
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
31
|
init()
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
32
|
{
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
33
34
|
if(glIsList(dList))
glDeleteLists(dList, 1);
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
35
|
dList = glGenLists(1);
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
36
|
glListBase(dList);
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
37
|
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
38
|
glMatrixMode(GL_PROJECTION);
|
0311ab81
Pavel Govyadinov
fixed some issues...
|
39
|
glLoadIdentity();
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
40
|
glMatrixMode(GL_MODELVIEW);
|
0311ab81
Pavel Govyadinov
fixed some issues...
|
41
|
glLoadIdentity();
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
42
43
44
45
|
}
void
|
1657f19c
Pavel Govyadinov
fixed selective v...
|
46
|
Create(GLenum mode, bool blend = false, float opacity = 1.0)
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
47
|
{
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
48
|
|
18cb8a07
Pavel Govyadinov
changed the wrong...
|
49
50
51
52
53
|
if(blend)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
54
|
int len = (int) stim::obj<T>::numL();
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
55
56
|
std::vector< stim::vec<float> > line;
glNewList(dList, GL_COMPILE);
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
57
|
glLineWidth(3.5);
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
58
|
for(int i = 0; i < len; i++){
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
59
|
line = stim::obj<T>::getL_V(i);
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
60
61
62
63
|
if(mode == GL_SELECT)
{
glLoadName(i);
}
|
acc30a5e
Pavel Govyadinov
Added the ability...
|
64
|
if(blend == false)
|
1657f19c
Pavel Govyadinov
fixed selective v...
|
65
|
{
|
acc30a5e
Pavel Govyadinov
Added the ability...
|
66
|
glColor3f(0.0, 1.0, 0.05);
|
1657f19c
Pavel Govyadinov
fixed selective v...
|
67
68
|
}
else
|
acc30a5e
Pavel Govyadinov
Added the ability...
|
69
70
|
{
glColor4f(50.0/256.0,205.0/256.0, 50.0/256.0, opacity); ///Dark Green.
|
1657f19c
Pavel Govyadinov
fixed selective v...
|
71
|
}
|
1306fd96
Pavel Govyadinov
minor bug fixes i...
|
72
|
//glColor3ub(rand()%255, rand()%255, rand()%255);
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
73
|
glBegin(GL_LINE_STRIP);
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
74
|
for(int j = 0; j < line.size(); j++){
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
75
|
glVertex3f(
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
76
77
78
79
80
81
82
|
line[j][0],
line[j][1],
line[j][2]
);
}
glEnd();
}
|
18cb8a07
Pavel Govyadinov
changed the wrong...
|
83
84
|
if(blend)
glDisable(GL_BLEND);
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
85
|
glEndList();
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
86
|
CHECK_OPENGL_ERROR
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
87
88
|
}
|
1657f19c
Pavel Govyadinov
fixed selective v...
|
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
|
///Method for drawing selectively opaque things.
void
Create(GLenum mode, stim::vec3<float> point)
{
float l, opacity;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
int len = (int) stim::obj<T>::numL();
std::vector< stim::vec<float> > line;
glNewList(dList, GL_COMPILE);
glLineWidth(3.5);
for(int i = 0; i < len; i++){
line = stim::obj<T>::getL_V(i);
if(mode == GL_SELECT)
{
glLoadName(i);
}
glBegin(GL_LINE_STRIP);
for(int j = 0; j < line.size(); j++){
l = sqrt(pow((point[0] - line[j][0]),2) + pow((point[1] - line[j][1]),2) + pow((point[2] - line[j][2]),2));
if(l < 10)
{
opacity = 1.0;
} else if( l > 40) {
opacity = 0.0;
} else {
opacity = l*(-1.0/30.0) + 4.0/3.0;
}
glColor4f(50.0/256.0,205.0/256.0, 50.0/256.0, opacity); ///Dark Green.
glVertex3f(
line[j][0],
line[j][1],
line[j][2]
);
}
glEnd();
}
glDisable(GL_BLEND);
glEndList();
CHECK_OPENGL_ERROR
}
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
134
|
public:
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
135
|
glObj()
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
136
|
{
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
137
138
139
140
|
}
void
|
acc30a5e
Pavel Govyadinov
Added the ability...
|
141
142
143
144
145
146
147
148
|
createFromSelf(GLenum mode = GL_RENDER, bool blend = false, float opacity = 1.0)
{
// glPopMatrix();
init();
Create(mode, blend, opacity);
// glPushMatrix();
}
|
518258d3
Pavel Govyadinov
minor bug fixes
|
149
150
|
void
createFromSelf(stim::vec3<float> point, GLenum mode = GL_RENDER)
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
151
152
|
{
// glPopMatrix();
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
153
|
init();
|
1657f19c
Pavel Govyadinov
fixed selective v...
|
154
|
Create(mode, point);
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
155
156
157
158
|
// glPushMatrix();
}
void
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
159
|
createFromFile(std::string filename, GLenum mode = GL_RENDER)
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
160
161
162
163
|
{
stim::obj<T>::load(filename);
glPushMatrix(); //Safety Operation to avoid changing the current matrix.
init();
|
84eff8b1
Pavel Govyadinov
Merged only the n...
|
164
|
Create(mode);
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
165
166
|
glPopMatrix();
CHECK_OPENGL_ERROR
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
167
168
169
170
|
}
void
|
acc30a5e
Pavel Govyadinov
Added the ability...
|
171
|
Render(bool blend = false)
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
172
|
{
|
acc30a5e
Pavel Govyadinov
Added the ability...
|
173
174
175
176
177
|
if(blend)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
178
|
glCallList(dList);
|
acc30a5e
Pavel Govyadinov
Added the ability...
|
179
180
|
if(blend)
glDisable(GL_BLEND);
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
181
|
CHECK_OPENGL_ERROR
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
182
183
|
}
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
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
|
0311ab81
Pavel Govyadinov
fixed some issues...
|
204
|
RenderLine(std::vector< stim::vec3<T> > l)
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
{
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();
}
};
|
cce7daf9
Pavel Govyadinov
added glObj.h to ...
|
220
|
}
|
14b500f9
Pavel Govyadinov
minor bug fixes
|
221
|
#endif
|