a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
1
2
3
4
5
6
|
#ifndef STIM_GLNETWORK_H
#define STIM_GLNETWORK_H
#include <GL/glew.h>
#include <GL/glut.h>
#include "network.h"
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
7
|
#include <stim/visualization/cylinder.h>
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <stim/math/vector.h>
#include <list>
#include <ANN/ANN.h>
#include "fiber.h"
namespace stim
{
template <typename T>
class glnetwork : public virtual network<T>
{
private:
using stim::network<T>::E;
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
22
23
|
GLuint dList; ///displaylist for the lines.
GLuint cList; ///displaylist for the cylinders.
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
24
25
26
|
void init()
{
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
27
28
|
///clear lists if there is data in them.
///adding points may create errors or uncessary duplicate points.
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
29
30
|
if(glIsList(dList))
glDeleteLists(dList, 1);
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
31
32
33
34
35
36
|
if(glIsList(cList))
glDeleteLists(cList, 1);
dList = glGenLists(1); ///create the lists
cList = glGenLists(1);
///set up the Line list.
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
37
38
39
40
41
|
glListBase(dList);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
42
43
44
45
46
47
48
|
///set up the cylinder List.
glListBase(cList);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
49
50
51
|
}
void
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
52
|
Create(GLenum mode, int sides = 8)
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
53
|
{
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
54
|
glListBase(dList);
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
glNewList(dList, GL_COMPILE);
glLineWidth(3.5);
for(int i = 0; i < E.size(); i++)
{
if(mode == GL_SELECT)
{
// glLineWidth(3.5);
glLoadName(i);
}
else{
// glLineWidth(1.0+1.0*i);
}
glColor3f(0.0, 1.0-0.05*i, i*0.05);
std::vector<stim::vec<T> > line = getEdgeCenterLine(i);
glBegin(GL_LINE_STRIP);
for(int j = 0; j < line.size(); j++)
{
glVertex3f(line[j][0],
line[j][1],
line[j][2]);
}
glEnd();
}
glEndList();
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
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
|
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<stim::vec<T> > line = getEdgeCenterLine(i);
std::vector<stim::vec<T> > linemag = getEdgeCenterLineMag(i);
stim::cylinder<T> cyl(line, linemag);
std::vector<std::vector<stim::vec<T > > > 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);
|
10654a1f
Pavel Govyadinov
added the necessa...
|
110
|
glLineWidth(2.0);
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
111
112
113
|
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]);
|
10654a1f
Pavel Govyadinov
added the necessa...
|
114
115
|
glVertex3f(p[i][j][0], p[i][j][1], p[i][j][2]);
glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2] );
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
116
117
118
119
120
121
122
123
124
|
glEnd();
}
}
}
glEndList();
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
125
126
127
128
129
130
|
// CHECK_OPENGL_ERROR
}
public:
using stim::network<T>::sizeE;
using stim::network<T>::getEdgeCenterLine;
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
131
|
using stim::network<T>::getEdgeCenterLineMag;
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
132
133
134
135
136
137
|
glnetwork()
{
}
void
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
138
|
createFromSelf(GLenum mode = GL_RENDER, int sides = 8)
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
139
140
|
{
init();
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
141
|
Create(mode, sides);
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
142
143
144
145
146
147
148
149
150
151
|
}
void
Render()
{
glCallList(dList);
// CHECK_OPENGL_ERROR
}
void
|
1bdf7c1e
Pavel Govyadinov
extended the glne...
|
152
153
154
155
156
157
158
|
RenderCylinders()
{
glCallList(cList);
// CHECK_OPENGL_ERROR
}
void
|
a9073ab5
Pavel Govyadinov
glnetwork is unde...
|
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
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
|