Commit a9073ab59bbdfc104171dd7f6f3dae4675d941f0
1 parent
5b6c317a
glnetwork is under stim/visualization/
Showing
1 changed file
with
106 additions
and
0 deletions
Show diff stats
1 | +#ifndef STIM_GLNETWORK_H | ||
2 | +#define STIM_GLNETWORK_H | ||
3 | + | ||
4 | +#include <GL/glew.h> | ||
5 | +#include <GL/glut.h> | ||
6 | +#include "network.h" | ||
7 | +#include <stim/math/vector.h> | ||
8 | +#include <list> | ||
9 | +#include <ANN/ANN.h> | ||
10 | +#include "fiber.h" | ||
11 | + | ||
12 | + | ||
13 | +namespace stim | ||
14 | +{ | ||
15 | +template <typename T> | ||
16 | +class glnetwork : public virtual network<T> | ||
17 | +{ | ||
18 | +private: | ||
19 | + using stim::network<T>::E; | ||
20 | + | ||
21 | + GLuint dList; | ||
22 | + | ||
23 | + void init() | ||
24 | + { | ||
25 | + if(glIsList(dList)) | ||
26 | + glDeleteLists(dList, 1); | ||
27 | + dList = glGenLists(1); | ||
28 | + glListBase(dList); | ||
29 | + glMatrixMode(GL_PROJECTION); | ||
30 | + glLoadIdentity; | ||
31 | + glMatrixMode(GL_MODELVIEW); | ||
32 | + glLoadIdentity; | ||
33 | + } | ||
34 | + | ||
35 | + void | ||
36 | + Create(GLenum mode) | ||
37 | + { | ||
38 | + glNewList(dList, GL_COMPILE); | ||
39 | + glLineWidth(3.5); | ||
40 | + for(int i = 0; i < E.size(); i++) | ||
41 | + { | ||
42 | + if(mode == GL_SELECT) | ||
43 | + { | ||
44 | +// glLineWidth(3.5); | ||
45 | + glLoadName(i); | ||
46 | + } | ||
47 | + else{ | ||
48 | +// glLineWidth(1.0+1.0*i); | ||
49 | + } | ||
50 | + glColor3f(0.0, 1.0-0.05*i, i*0.05); | ||
51 | + std::vector<stim::vec<T> > line = getEdgeCenterLine(i); | ||
52 | + glBegin(GL_LINE_STRIP); | ||
53 | + for(int j = 0; j < line.size(); j++) | ||
54 | + { | ||
55 | + glVertex3f(line[j][0], | ||
56 | + line[j][1], | ||
57 | + line[j][2]); | ||
58 | + } | ||
59 | + glEnd(); | ||
60 | + } | ||
61 | + glEndList(); | ||
62 | +// CHECK_OPENGL_ERROR | ||
63 | + } | ||
64 | + | ||
65 | +public: | ||
66 | + using stim::network<T>::sizeE; | ||
67 | + using stim::network<T>::getEdgeCenterLine; | ||
68 | + glnetwork() | ||
69 | + { | ||
70 | + | ||
71 | + } | ||
72 | + | ||
73 | + void | ||
74 | + createFromSelf(GLenum mode = GL_RENDER) | ||
75 | + { | ||
76 | + init(); | ||
77 | + Create(mode); | ||
78 | + } | ||
79 | + | ||
80 | + void | ||
81 | + Render() | ||
82 | + { | ||
83 | + glCallList(dList); | ||
84 | +// CHECK_OPENGL_ERROR | ||
85 | + } | ||
86 | + | ||
87 | + void | ||
88 | + RenderLine(std::vector<stim::vec<T> > l) | ||
89 | + { | ||
90 | + glColor3f(0.5, 1.0, 0.5); | ||
91 | + glLineWidth(3.0); | ||
92 | + glBegin(GL_LINE_STRIP); | ||
93 | + for(int j = 0; j < l.size(); j++){ | ||
94 | + glVertex3f( | ||
95 | + l[j][0], | ||
96 | + l[j][1], | ||
97 | + l[j][2] | ||
98 | + ); | ||
99 | + } | ||
100 | + glEnd(); | ||
101 | + } | ||
102 | + | ||
103 | +}; | ||
104 | +} | ||
105 | + | ||
106 | +#endif |