Commit c8864f86cdf0a6e1966eb1f6d1cc99eaf3a92dff
1 parent
761ebaa9
fixed light relevant
Showing
1 changed file
with
62 additions
and
28 deletions
Show diff stats
stim/visualization/gl_network.h
@@ -45,10 +45,12 @@ public: | @@ -45,10 +45,12 @@ public: | ||
45 | 45 | ||
46 | ///render cylinder based on points from the top/bottom hat | 46 | ///render cylinder based on points from the top/bottom hat |
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, stim::vec3<T> n1, stim::vec3<T> n2) { |
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(); i++) { // for every point on the circle |
51 | + glNormal3f(n1[0], n1[1], n1[2]); | ||
51 | glVertex3f(C1[i][0], C1[i][1], C1[i][2]); | 52 | glVertex3f(C1[i][0], C1[i][1], C1[i][2]); |
53 | + glNormal3f(n2[0], n2[1], n2[2]); | ||
52 | glVertex3f(C2[i][0], C2[i][1], C2[i][2]); | 54 | glVertex3f(C2[i][0], C2[i][1], C2[i][2]); |
53 | } | 55 | } |
54 | glEnd(); | 56 | glEnd(); |
@@ -80,12 +82,10 @@ public: | @@ -80,12 +82,10 @@ public: | ||
80 | T angle_xy = 0.0; | 82 | T angle_xy = 0.0; |
81 | 83 | ||
82 | glBegin(GL_QUADS); | 84 | glBegin(GL_QUADS); |
83 | - for (unsigned i = 0; i < slice; i++) // around the z-axis | ||
84 | - { | 85 | + for (unsigned i = 0; i < slice; i++) { // around the z-axis |
85 | angle_z = i * step_z; // step step_z each time | 86 | angle_z = i * step_z; // step step_z each time |
86 | 87 | ||
87 | - for (unsigned j = 0; j < stack; j++) // along the z-axis | ||
88 | - { | 88 | + 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 | 89 | angle_xy = j * step_xy; // step step_xy each time, draw floor by floor |
90 | 90 | ||
91 | xx[0] = radius * std::sin(angle_z) * std::cos(angle_xy); // four vertices | 91 | xx[0] = radius * std::sin(angle_z) * std::cos(angle_xy); // four vertices |
@@ -104,8 +104,7 @@ public: | @@ -104,8 +104,7 @@ public: | ||
104 | yy[3] = radius * std::sin(angle_z) * std::sin(angle_xy + step_xy); | 104 | yy[3] = radius * std::sin(angle_z) * std::sin(angle_xy + step_xy); |
105 | zz[3] = radius * std::cos(angle_z); | 105 | zz[3] = radius * std::cos(angle_z); |
106 | 106 | ||
107 | - for (unsigned k = 0; k < 4; k++) | ||
108 | - { | 107 | + for (unsigned k = 0; k < 4; k++) { |
109 | glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane | 108 | glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane |
110 | } | 109 | } |
111 | } | 110 | } |
@@ -162,21 +161,23 @@ public: | @@ -162,21 +161,23 @@ public: | ||
162 | if (!glIsList(dlist)) { // if dlist isn't a display list, create it | 161 | if (!glIsList(dlist)) { // if dlist isn't a display list, create it |
163 | dlist = glGenLists(1); // generate a display list | 162 | dlist = glGenLists(1); // generate a display list |
164 | glNewList(dlist, GL_COMPILE); // start a new display list | 163 | 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 | 164 | 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 | 165 | 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); | 166 | stim::circle<T> C1 = E[e].circ(p - 1); |
170 | stim::circle<T> C2 = E[e].circ(p); | 167 | stim::circle<T> C2 = E[e].circ(p); |
171 | - C1.set_R(2*radius); // scale the circle to the same | 168 | + C1.set_R(2*radius); // re-scale the circle to the same |
172 | C2.set_R(2*radius); | 169 | C2.set_R(2*radius); |
173 | - std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); | 170 | + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20);// get 20 points on the circle plane |
174 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); | 171 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); |
172 | + stim::vec3<T> n1 = C1.n(); // get the normal vector | ||
173 | + stim::vec3<T> n2 = C2.n(); | ||
175 | glBegin(GL_QUAD_STRIP); | 174 | glBegin(GL_QUAD_STRIP); |
176 | for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) | 175 | for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) |
177 | glTexCoord1f(E[e].r(p - 1)); | 176 | glTexCoord1f(E[e].r(p - 1)); |
177 | + glNormal3f(n1[0], n1[1], n1[2]); // set normal vector for lighting | ||
178 | glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); | 178 | glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); |
179 | glTexCoord1f(E[e].r(p)); | 179 | glTexCoord1f(E[e].r(p)); |
180 | + glNormal3f(n2[0], n2[1], n2[2]); | ||
180 | glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); | 181 | glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); |
181 | } | 182 | } |
182 | glEnd(); | 183 | glEnd(); |
@@ -185,11 +186,17 @@ public: | @@ -185,11 +186,17 @@ public: | ||
185 | for (unsigned n = 0; n < V.size(); n++) { | 186 | 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 | 187 | 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 | 188 | 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 | 189 | + unsigned idx = V[n].e[0][0]; // find the index of first outgoing edge of that vertex |
190 | + stim::circle<T> C = E[idx].circ(0); | ||
191 | + stim::vec3<T> normal = C.n(); | ||
192 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
189 | glTexCoord1f(E[idx].r(0)); // bind the texture as metric of first point on that edge | 193 | glTexCoord1f(E[idx].r(0)); // bind the texture as metric of first point on that edge |
190 | } | 194 | } |
191 | else { | 195 | else { |
192 | unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex | 196 | unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex |
197 | + stim::circle<T> C = E[idx].circ(E[idx].size()-1); | ||
198 | + stim::vec3<T> normal = C.n(); | ||
199 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
193 | glTexCoord1f(E[idx].r(E[idx].size() - 1)); // bind the texture as metric of last point on that edge | 200 | glTexCoord1f(E[idx].r(E[idx].size() - 1)); // bind the texture as metric of last point on that edge |
194 | } | 201 | } |
195 | renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20, 20); | 202 | renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20, 20); |
@@ -247,51 +254,78 @@ public: | @@ -247,51 +254,78 @@ public: | ||
247 | glDeleteLists(dlist+2, 1); | 254 | glDeleteLists(dlist+2, 1); |
248 | if (!glIsList(dlist+2)) { // if dlist isn't a display list, create it | 255 | if (!glIsList(dlist+2)) { // if dlist isn't a display list, create it |
249 | glNewList(dlist+2, GL_COMPILE); // start a new display list | 256 | 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 | 257 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network |
253 | if (map[e] != unsigned(-1)) { | 258 | if (map[e] != unsigned(-1)) { |
254 | - if(I == 0) // if it is to render GT | 259 | + if (I == 0) { // if it is to render GT |
255 | glColor3f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2]); | 260 | glColor3f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2]); |
256 | - else // if it is to render T | 261 | + } |
262 | + else { // if it is to render T | ||
257 | glColor3f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2]); | 263 | glColor3f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2]); |
264 | + } | ||
258 | 265 | ||
259 | for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge | 266 | 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); | 267 | stim::circle<T> C1 = E[e].circ(p - 1); |
261 | stim::circle<T> C2 = E[e].circ(p); | 268 | stim::circle<T> C2 = E[e].circ(p); |
262 | - C1.set_R(2*radius); // scale the circle to the same | 269 | + C1.set_R(2*radius); // re-scale the circle to the same |
263 | C2.set_R(2*radius); | 270 | C2.set_R(2*radius); |
264 | std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); | 271 | std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); |
265 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); | 272 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); |
266 | - renderCylinder(Cp1, Cp2); | 273 | + stim::vec3<T> n1 = C1.n(); // get the normal vector |
274 | + stim::vec3<T> n2 = C2.n(); | ||
275 | + renderCylinder(Cp1, Cp2, n1, n2); | ||
267 | } | 276 | } |
268 | } | 277 | } |
269 | else { | 278 | 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 | 279 | + glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges |
280 | + 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); | 281 | stim::circle<T> C1 = E[e].circ(p - 1); |
273 | stim::circle<T> C2 = E[e].circ(p); | 282 | stim::circle<T> C2 = E[e].circ(p); |
274 | C1.set_R(2*radius); // scale the circle to the same | 283 | C1.set_R(2*radius); // scale the circle to the same |
275 | C2.set_R(2*radius); | 284 | C2.set_R(2*radius); |
276 | std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); | 285 | std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); |
277 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); | 286 | std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); |
278 | - renderCylinder(Cp1, Cp2); | 287 | + stim::vec3<T> n1 = C1.n(); // get the normal vector |
288 | + stim::vec3<T> n2 = C2.n(); | ||
289 | + renderCylinder(Cp1, Cp2, n1, n2); | ||
279 | } | 290 | } |
280 | } | 291 | } |
281 | } | 292 | } |
282 | - for (unsigned v = 0; v < V.size(); v++) { | ||
283 | - size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); | 293 | + for (unsigned n = 0; n < V.size(); n++) { |
294 | + 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 | 295 | 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); | 296 | + if (V[n].e[0].size() != 0) { |
297 | + unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex | ||
298 | + stim::circle<T> C = E[idx].circ(0); | ||
299 | + stim::vec3<T> normal = C.n(); | ||
300 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
301 | + } | ||
302 | + else { | ||
303 | + unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex | ||
304 | + stim::circle<T> C = E[idx].circ(E[idx].size() - 1); | ||
305 | + stim::vec3<T> normal = C.n(); | ||
306 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
307 | + } | ||
308 | + glColor3f(0.3, 0.3, 0.3); // gray | ||
309 | + renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20, 20); | ||
287 | } | 310 | } |
288 | else { // if it is the terminal vertex | 311 | else { // if it is the terminal vertex |
312 | + if (V[n].e[0].size() != 0) { | ||
313 | + unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex | ||
314 | + stim::circle<T> C = E[idx].circ(0); | ||
315 | + stim::vec3<T> normal = C.n(); | ||
316 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
317 | + } | ||
318 | + else { | ||
319 | + unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex | ||
320 | + stim::circle<T> C = E[idx].circ(E[idx].size() - 1); | ||
321 | + stim::vec3<T> normal = C.n(); | ||
322 | + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
323 | + } | ||
289 | glColor3f(0.6, 0.6, 0.6); // more white gray | 324 | 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); | 325 | + renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20, 20); |
291 | } | 326 | } |
292 | } | 327 | } |
293 | glEndList(); | 328 | glEndList(); |
294 | - glDisable(GL_COLOR_MATERIAL); | ||
295 | } | 329 | } |
296 | glCallList(dlist+2); | 330 | glCallList(dlist+2); |
297 | } | 331 | } |
@@ -319,7 +353,7 @@ public: | @@ -319,7 +353,7 @@ public: | ||
319 | glEnd(); | 353 | glEnd(); |
320 | } | 354 | } |
321 | else { | 355 | else { |
322 | - glColor3f(1.0, 1.0, 1.0); // white color | 356 | + glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges |
323 | glBegin(GL_LINE_STRIP); | 357 | glBegin(GL_LINE_STRIP); |
324 | for (unsigned p = 0; p < E[e].size(); p++) { | 358 | for (unsigned p = 0; p < E[e].size(); p++) { |
325 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); | 359 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); |