Commit 1bdf7c1ed2283171b8f2bcd3426e66fc33b7aa01
1 parent
a9073ab5
extended the glnetwork.h class to use cylinders and render a cylinder network as…
… well as a line network, note that the includes need to be fixed once the network.h class is complete
Showing
1 changed file
with
75 additions
and
5 deletions
Show diff stats
stim/visualization/glnetwork.h
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | #include <GL/glew.h> |
5 | 5 | #include <GL/glut.h> |
6 | 6 | #include "network.h" |
7 | +#include <stim/visualization/cylinder.h> | |
7 | 8 | #include <stim/math/vector.h> |
8 | 9 | #include <list> |
9 | 10 | #include <ANN/ANN.h> |
... | ... | @@ -18,23 +19,39 @@ class glnetwork : public virtual network<T> |
18 | 19 | private: |
19 | 20 | using stim::network<T>::E; |
20 | 21 | |
21 | - GLuint dList; | |
22 | + GLuint dList; ///displaylist for the lines. | |
23 | + GLuint cList; ///displaylist for the cylinders. | |
22 | 24 | |
23 | 25 | void init() |
24 | 26 | { |
27 | + ///clear lists if there is data in them. | |
28 | + ///adding points may create errors or uncessary duplicate points. | |
25 | 29 | if(glIsList(dList)) |
26 | 30 | glDeleteLists(dList, 1); |
27 | - dList = glGenLists(1); | |
31 | + if(glIsList(cList)) | |
32 | + glDeleteLists(cList, 1); | |
33 | + dList = glGenLists(1); ///create the lists | |
34 | + cList = glGenLists(1); | |
35 | + | |
36 | + ///set up the Line list. | |
28 | 37 | glListBase(dList); |
29 | 38 | glMatrixMode(GL_PROJECTION); |
30 | 39 | glLoadIdentity; |
31 | 40 | glMatrixMode(GL_MODELVIEW); |
32 | 41 | glLoadIdentity; |
42 | + | |
43 | + ///set up the cylinder List. | |
44 | + glListBase(cList); | |
45 | + glMatrixMode(GL_PROJECTION); | |
46 | + glLoadIdentity; | |
47 | + glMatrixMode(GL_MODELVIEW); | |
48 | + glLoadIdentity; | |
33 | 49 | } |
34 | 50 | |
35 | 51 | void |
36 | - Create(GLenum mode) | |
52 | + Create(GLenum mode, int sides = 8) | |
37 | 53 | { |
54 | + glListBase(dList); | |
38 | 55 | glNewList(dList, GL_COMPILE); |
39 | 56 | glLineWidth(3.5); |
40 | 57 | for(int i = 0; i < E.size(); i++) |
... | ... | @@ -59,22 +76,68 @@ private: |
59 | 76 | glEnd(); |
60 | 77 | } |
61 | 78 | glEndList(); |
79 | + | |
80 | + glListBase(cList); | |
81 | + glNewList(cList, GL_COMPILE); | |
82 | + | |
83 | + for(int i = 0; i < E.size(); i++) | |
84 | + { | |
85 | + if(mode == GL_SELECT) | |
86 | + { | |
87 | + glLoadName(i); | |
88 | + } | |
89 | + glColor3f(1.0, 1.0, 0.0); | |
90 | + std::vector<stim::vec<T> > line = getEdgeCenterLine(i); | |
91 | + std::vector<stim::vec<T> > linemag = getEdgeCenterLineMag(i); | |
92 | + stim::cylinder<T> cyl(line, linemag); | |
93 | + std::vector<std::vector<stim::vec<T > > > p = cyl.getPoints(sides); | |
94 | + for(int i = 0; i < p.size()-1; i++) | |
95 | + { | |
96 | + for(int j = 0; j < p[0].size()-1; j++) | |
97 | + { | |
98 | + glColor4f(1.0, 1.0, 0.0, 0.5); | |
99 | + glEnable(GL_BLEND); | |
100 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
101 | + glBegin(GL_QUADS); | |
102 | + glVertex3f(p[i][j][0], p[i][j][1], p[i][j][2]); | |
103 | + glVertex3f(p[i][j+1][0], p[i][j+1][1], p[i][j+1][2]); | |
104 | + glVertex3f(p[i+1][j+1][0], p[i+1][j+1][1], p[i+1][j+1][2] ); | |
105 | + glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2]); | |
106 | + glEnd(); | |
107 | + glDisable(GL_BLEND); | |
108 | + | |
109 | + glColor4f(1.0, 0.0, 1.0, 1.0); | |
110 | + glBegin(GL_LINES); | |
111 | + glVertex3f(p[i][j][0], p[i][j][1], p[i][j][2]); | |
112 | + glVertex3f(p[i][j+1][0], p[i][j+1][1], p[i][j+1][2]); | |
113 | + glVertex3f(p[i+1][j][0], p[i+1][j][1], p[i+1][j][2]); | |
114 | + glVertex3f(p[i+1][j+1][0], p[i+1][j+1][1], p[i+1][j+1][2] ); | |
115 | + glEnd(); | |
116 | + } | |
117 | + | |
118 | + } | |
119 | + | |
120 | + | |
121 | + | |
122 | + } | |
123 | + glEndList(); | |
62 | 124 | // CHECK_OPENGL_ERROR |
63 | 125 | } |
64 | 126 | |
65 | 127 | public: |
66 | 128 | using stim::network<T>::sizeE; |
67 | 129 | using stim::network<T>::getEdgeCenterLine; |
130 | + using stim::network<T>::getEdgeCenterLineMag; | |
68 | 131 | glnetwork() |
69 | 132 | { |
70 | 133 | |
71 | 134 | } |
72 | 135 | |
73 | 136 | void |
74 | - createFromSelf(GLenum mode = GL_RENDER) | |
137 | + createFromSelf(GLenum mode = GL_RENDER, int sides = 8) | |
75 | 138 | { |
76 | 139 | init(); |
77 | - Create(mode); | |
140 | + Create(mode, sides); | |
78 | 141 | } |
79 | 142 | |
80 | 143 | void |
... | ... | @@ -85,6 +148,13 @@ public: |
85 | 148 | } |
86 | 149 | |
87 | 150 | void |
151 | + RenderCylinders() | |
152 | + { | |
153 | + glCallList(cList); | |
154 | +// CHECK_OPENGL_ERROR | |
155 | + } | |
156 | + | |
157 | + void | |
88 | 158 | RenderLine(std::vector<stim::vec<T> > l) |
89 | 159 | { |
90 | 160 | glColor3f(0.5, 1.0, 0.5); | ... | ... |