Commit 9f3f0602e8e8103738a19ef0ad1562c150fad6ca
Merge branch 'JACK' into 'master'
fixed light relevant See merge request !28
Showing
1 changed file
with
83 additions
and
29 deletions
Show diff stats
stim/visualization/gl_network.h
@@ -47,12 +47,30 @@ public: | @@ -47,12 +47,30 @@ public: | ||
47 | ///@param C1 set of points from one of the hat | 47 | ///@param C1 set of points from one of the hat |
48 | void renderCylinder(std::vector< stim::vec3<T> > C1, std::vector< stim::vec3<T> > C2) { | 48 | void renderCylinder(std::vector< stim::vec3<T> > C1, std::vector< stim::vec3<T> > C2) { |
49 | glBegin(GL_QUAD_STRIP); | 49 | glBegin(GL_QUAD_STRIP); |
50 | - for (unsigned i = 0; i < C1.size(); i++) { // for every point on the circle | 50 | + for (unsigned i = 0; i < C1.size() - 1; i++) { // for every point on the circle |
51 | + stim::vec3<T> v1; | ||
52 | + stim::vec3<T> v2; | ||
53 | + stim::vec3<T> v3; | ||
54 | + stim::vec3<T> v4; | ||
55 | + | ||
56 | + v1 = C2[i + 1] - C1[i + 1]; | ||
57 | + v2 = C1[i] - C1[i + 1]; | ||
58 | + v3 = C1[i] - C2[i]; | ||
59 | + v4 = C2[i + 1] - C2[i]; | ||
60 | + | ||
61 | + stim::vec3<T> n1 = v1.cross(v2); | ||
62 | + stim::vec3<T> n2 = v3.cross(v4); | ||
63 | + stim::vec3<T> normal = n1 + n2; | ||
64 | + normal = normal.norm(); | ||
51 | glVertex3f(C1[i][0], C1[i][1], C1[i][2]); | 65 | glVertex3f(C1[i][0], C1[i][1], C1[i][2]); |
52 | glVertex3f(C2[i][0], C2[i][1], C2[i][2]); | 66 | glVertex3f(C2[i][0], C2[i][1], C2[i][2]); |
67 | + glNormal3f(normal[0], normal[1], normal[2]); // set normal vector for lighting | ||
68 | + //glNormal3f(n1[0], n1[1], n1[2]); | ||
69 | + //glVertex3f(C1[i][0], C1[i][1], C1[i][2]); | ||
70 | + //glNormal3f(n2[0], n2[1], n2[2]); | ||
71 | + //glVertex3f(C2[i][0], C2[i][1], C2[i][2]); | ||
53 | } | 72 | } |
54 | glEnd(); | 73 | glEnd(); |
55 | - //glFlush(); | ||
56 | } | 74 | } |
57 | 75 | ||
58 | ///render the vertex as sphere based on glut build-in function | 76 | ///render the vertex as sphere based on glut build-in function |
@@ -80,12 +98,10 @@ public: | @@ -80,12 +98,10 @@ public: | ||
80 | T angle_xy = 0.0; | 98 | T angle_xy = 0.0; |
81 | 99 | ||
82 | glBegin(GL_QUADS); | 100 | glBegin(GL_QUADS); |
83 | - for (unsigned i = 0; i < slice; i++) // around the z-axis | ||
84 | - { | 101 | + for (unsigned i = 0; i < slice; i++) { // around the z-axis |
85 | angle_z = i * step_z; // step step_z each time | 102 | angle_z = i * step_z; // step step_z each time |
86 | 103 | ||
87 | - for (unsigned j = 0; j < stack; j++) // along the z-axis | ||
88 | - { | 104 | + for (unsigned j = 0; j < stack; j++) { // along the z-axis |
89 | angle_xy = j * step_xy; // step step_xy each time, draw floor by floor | 105 | angle_xy = j * step_xy; // step step_xy each time, draw floor by floor |
90 | 106 | ||
91 | xx[0] = radius * std::sin(angle_z) * std::cos(angle_xy); // four vertices | 107 | xx[0] = radius * std::sin(angle_z) * std::cos(angle_xy); // four vertices |
@@ -104,8 +120,8 @@ public: | @@ -104,8 +120,8 @@ public: | ||
104 | yy[3] = radius * std::sin(angle_z) * std::sin(angle_xy + step_xy); | 120 | yy[3] = radius * std::sin(angle_z) * std::sin(angle_xy + step_xy); |
105 | zz[3] = radius * std::cos(angle_z); | 121 | zz[3] = radius * std::cos(angle_z); |
106 | 122 | ||
107 | - for (unsigned k = 0; k < 4; k++) | ||
108 | - { | 123 | + |
124 | + for (unsigned k = 0; k < 4; k++) { | ||
109 | glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane | 125 | glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane |
110 | } | 126 | } |
111 | } | 127 | } |
@@ -162,30 +178,51 @@ public: | @@ -162,30 +178,51 @@ public: | ||
162 | if (!glIsList(dlist)) { // if dlist isn't a display list, create it | 178 | if (!glIsList(dlist)) { // if dlist isn't a display list, create it |
163 | dlist = glGenLists(1); // generate a display list | 179 | dlist = glGenLists(1); // generate a display list |
164 | glNewList(dlist, GL_COMPILE); // start a new display list | 180 | glNewList(dlist, GL_COMPILE); // start a new display list |
165 | - glEnable(GL_COLOR_MATERIAL); | ||
166 | - glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); | ||
167 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network | 181 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network |
168 | for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge | 182 | for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge |
169 | stim::circle<T> C1 = E[e].circ(p - 1); | 183 | stim::circle<T> C1 = E[e].circ(p - 1); |
170 | stim::circle<T> C2 = E[e].circ(p); | 184 | stim::circle<T> C2 = E[e].circ(p); |
171 | - C1.set_R(2*radius); // scale the circle to the same | 185 | + C1.set_R(2*radius); // re-scale the circle to the same |
172 | C2.set_R(2*radius); | 186 | C2.set_R(2*radius); |
173 | - std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); | ||
174 | - std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); | 187 | + std::vector< stim::vec3<T> > Cp1 = C1.glpoints(20);// get 20 points on the circle plane |
188 | + std::vector< stim::vec3<T> > Cp2 = C2.glpoints(20); | ||
175 | glBegin(GL_QUAD_STRIP); | 189 | glBegin(GL_QUAD_STRIP); |
176 | - for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) | 190 | + for (unsigned i = 0; i < Cp1.size() - 1; i++) { |
191 | + stim::vec3<T> v1; | ||
192 | + stim::vec3<T> v2; | ||
193 | + stim::vec3<T> v3; | ||
194 | + stim::vec3<T> v4; | ||
195 | + v1 = Cp2[i + 1] - Cp1[i + 1]; | ||
196 | + v2 = Cp1[i] - Cp1[i + 1]; | ||
197 | + v3 = Cp1[i] - Cp2[i]; | ||
198 | + v4 = Cp2[i + 1] - Cp2[i]; | ||
199 | + | ||
200 | + stim::vec3<T> n1 = v1.cross(v2); | ||
201 | + stim::vec3<T> n2 = v3.cross(v4); | ||
202 | + stim::vec3<T> normal = n1; | ||
203 | + normal = normal.norm(); | ||
204 | + | ||
177 | glTexCoord1f(E[e].r(p - 1)); | 205 | glTexCoord1f(E[e].r(p - 1)); |
178 | glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); | 206 | glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); |
179 | glTexCoord1f(E[e].r(p)); | 207 | glTexCoord1f(E[e].r(p)); |
180 | glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); | 208 | glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); |
209 | + glNormal3f(normal[0], normal[1], normal[2]); // set normal vector for lighting | ||
181 | } | 210 | } |
211 | + //for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) | ||
212 | + // glTexCoord1f(E[e].r(p - 1)); | ||
213 | + // glNormal3f(n1[0], n1[1], n1[2]); // set normal vector for lighting | ||
214 | + // glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); | ||
215 | + // glTexCoord1f(E[e].r(p)); | ||
216 | + // glNormal3f(n2[0], n2[1], n2[2]); | ||
217 | + // glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); | ||
218 | + //} | ||
182 | glEnd(); | 219 | glEnd(); |
183 | } // set the texture coordinate based on the specified magnitude index | 220 | } // set the texture coordinate based on the specified magnitude index |
184 | } | 221 | } |
185 | for (unsigned n = 0; n < V.size(); n++) { | 222 | for (unsigned n = 0; n < V.size(); n++) { |
186 | size_t num = V[n].e[0].size(); // store the number of outgoing edge of that vertex | 223 | size_t num = V[n].e[0].size(); // store the number of outgoing edge of that vertex |
187 | if (num != 0) { // if it has outgoing edge | 224 | if (num != 0) { // if it has outgoing edge |
188 | - unsigned idx = V[n].e[0][0]; // find the index of first outgoing edge of that vertex | 225 | + unsigned idx = V[n].e[0][0]; // find the index of first outgoing edge of that vertex |
189 | glTexCoord1f(E[idx].r(0)); // bind the texture as metric of first point on that edge | 226 | glTexCoord1f(E[idx].r(0)); // bind the texture as metric of first point on that edge |
190 | } | 227 | } |
191 | else { | 228 | else { |
@@ -247,19 +284,19 @@ public: | @@ -247,19 +284,19 @@ public: | ||
247 | glDeleteLists(dlist+2, 1); | 284 | glDeleteLists(dlist+2, 1); |
248 | if (!glIsList(dlist+2)) { // if dlist isn't a display list, create it | 285 | if (!glIsList(dlist+2)) { // if dlist isn't a display list, create it |
249 | glNewList(dlist+2, GL_COMPILE); // start a new display list | 286 | glNewList(dlist+2, GL_COMPILE); // start a new display list |
250 | - glEnable(GL_COLOR_MATERIAL); | ||
251 | - glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); | ||
252 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network | 287 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network |
253 | if (map[e] != unsigned(-1)) { | 288 | if (map[e] != unsigned(-1)) { |
254 | - if(I == 0) // if it is to render GT | 289 | + if (I == 0) { // if it is to render GT |
255 | glColor3f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2]); | 290 | glColor3f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2]); |
256 | - else // if it is to render T | 291 | + } |
292 | + else { // if it is to render T | ||
257 | glColor3f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2]); | 293 | glColor3f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2]); |
294 | + } | ||
258 | 295 | ||
259 | for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge | 296 | for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge |
260 | stim::circle<T> C1 = E[e].circ(p - 1); | 297 | stim::circle<T> C1 = E[e].circ(p - 1); |
261 | stim::circle<T> C2 = E[e].circ(p); | 298 | stim::circle<T> C2 = E[e].circ(p); |
262 | - C1.set_R(2*radius); // scale the circle to the same | 299 | + C1.set_R(2*radius); // re-scale the circle to the same |
263 | C2.set_R(2*radius); | 300 | C2.set_R(2*radius); |
264 | std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); | 301 | std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); |
265 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); | 302 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); |
@@ -267,8 +304,8 @@ public: | @@ -267,8 +304,8 @@ public: | ||
267 | } | 304 | } |
268 | } | 305 | } |
269 | else { | 306 | else { |
270 | - glColor3f(1.0f, 1.0f, 1.0f); // white color for the un-mapping edges | ||
271 | - for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge | 307 | + glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges |
308 | + for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge | ||
272 | stim::circle<T> C1 = E[e].circ(p - 1); | 309 | stim::circle<T> C1 = E[e].circ(p - 1); |
273 | stim::circle<T> C2 = E[e].circ(p); | 310 | stim::circle<T> C2 = E[e].circ(p); |
274 | C1.set_R(2*radius); // scale the circle to the same | 311 | C1.set_R(2*radius); // scale the circle to the same |
@@ -279,19 +316,36 @@ public: | @@ -279,19 +316,36 @@ public: | ||
279 | } | 316 | } |
280 | } | 317 | } |
281 | } | 318 | } |
282 | - for (unsigned v = 0; v < V.size(); v++) { | ||
283 | - size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); | 319 | + for (unsigned n = 0; n < V.size(); n++) { |
320 | + size_t num_edge = V[n].e[0].size() + V[n].e[1].size(); | ||
284 | if (num_edge > 1) { // if it is the joint vertex | 321 | if (num_edge > 1) { // if it is the joint vertex |
285 | - glColor3f(0.3, 0.3, 0.3); // gray color | ||
286 | - renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); | 322 | + if (V[n].e[0].size() != 0) { |
323 | + unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex | ||
324 | + stim::circle<T> C = E[idx].circ(0); | ||
325 | + stim::vec3<T> normal = C.n(); | ||
326 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
327 | + } | ||
328 | + else { | ||
329 | + unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex | ||
330 | + stim::circle<T> C = E[idx].circ(E[idx].size() - 1); | ||
331 | + stim::vec3<T> normal = C.n(); | ||
332 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
333 | + } | ||
334 | + glColor3f(0.3, 0.3, 0.3); // gray | ||
335 | + renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20, 20); | ||
287 | } | 336 | } |
288 | else { // if it is the terminal vertex | 337 | else { // if it is the terminal vertex |
338 | + if (V[n].e[0].size() != 0) { | ||
339 | + unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex | ||
340 | + } | ||
341 | + else { | ||
342 | + unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex | ||
343 | + } | ||
289 | glColor3f(0.6, 0.6, 0.6); // more white gray | 344 | glColor3f(0.6, 0.6, 0.6); // more white gray |
290 | - renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); | 345 | + renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20, 20); |
291 | } | 346 | } |
292 | } | 347 | } |
293 | glEndList(); | 348 | glEndList(); |
294 | - glDisable(GL_COLOR_MATERIAL); | ||
295 | } | 349 | } |
296 | glCallList(dlist+2); | 350 | glCallList(dlist+2); |
297 | } | 351 | } |
@@ -319,7 +373,7 @@ public: | @@ -319,7 +373,7 @@ public: | ||
319 | glEnd(); | 373 | glEnd(); |
320 | } | 374 | } |
321 | else { | 375 | else { |
322 | - glColor3f(1.0, 1.0, 1.0); // white color | 376 | + glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges |
323 | glBegin(GL_LINE_STRIP); | 377 | glBegin(GL_LINE_STRIP); |
324 | for (unsigned p = 0; p < E[e].size(); p++) { | 378 | for (unsigned p = 0; p < E[e].size(); p++) { |
325 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); | 379 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); |