diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index 438708f..a08d5b8 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -45,10 +45,12 @@ public: ///render cylinder based on points from the top/bottom hat ///@param C1 set of points from one of the hat - void renderCylinder(std::vector< stim::vec3 > C1, std::vector< stim::vec3 > C2) { + void renderCylinder(std::vector< stim::vec3 > C1, std::vector< stim::vec3 > C2, stim::vec3 n1, stim::vec3 n2) { glBegin(GL_QUAD_STRIP); for (unsigned i = 0; i < C1.size(); i++) { // for every point on the circle + glNormal3f(n1[0], n1[1], n1[2]); glVertex3f(C1[i][0], C1[i][1], C1[i][2]); + glNormal3f(n2[0], n2[1], n2[2]); glVertex3f(C2[i][0], C2[i][1], C2[i][2]); } glEnd(); @@ -80,12 +82,10 @@ public: T angle_xy = 0.0; glBegin(GL_QUADS); - for (unsigned i = 0; i < slice; i++) // around the z-axis - { + for (unsigned i = 0; i < slice; i++) { // around the z-axis angle_z = i * step_z; // step step_z each time - for (unsigned j = 0; j < stack; j++) // along the z-axis - { + for (unsigned j = 0; j < stack; j++) { // along the z-axis angle_xy = j * step_xy; // step step_xy each time, draw floor by floor xx[0] = radius * std::sin(angle_z) * std::cos(angle_xy); // four vertices @@ -104,8 +104,7 @@ public: yy[3] = radius * std::sin(angle_z) * std::sin(angle_xy + step_xy); zz[3] = radius * std::cos(angle_z); - for (unsigned k = 0; k < 4; k++) - { + for (unsigned k = 0; k < 4; k++) { glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane } } @@ -162,21 +161,23 @@ public: if (!glIsList(dlist)) { // if dlist isn't a display list, create it dlist = glGenLists(1); // generate a display list glNewList(dlist, GL_COMPILE); // start a new display list - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge stim::circle C1 = E[e].circ(p - 1); stim::circle C2 = E[e].circ(p); - C1.set_R(2*radius); // scale the circle to the same + C1.set_R(2*radius); // re-scale the circle to the same C2.set_R(2*radius); - std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + std::vector< stim::vec3 >Cp1 = C1.glpoints(20);// get 20 points on the circle plane std::vector< stim::vec3 >Cp2 = C2.glpoints(20); + stim::vec3 n1 = C1.n(); // get the normal vector + stim::vec3 n2 = C2.n(); glBegin(GL_QUAD_STRIP); for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) glTexCoord1f(E[e].r(p - 1)); + glNormal3f(n1[0], n1[1], n1[2]); // set normal vector for lighting glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); glTexCoord1f(E[e].r(p)); + glNormal3f(n2[0], n2[1], n2[2]); glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); } glEnd(); @@ -185,11 +186,17 @@ public: for (unsigned n = 0; n < V.size(); n++) { size_t num = V[n].e[0].size(); // store the number of outgoing edge of that vertex if (num != 0) { // if it has outgoing edge - unsigned idx = V[n].e[0][0]; // find the index of first outgoing edge of that vertex + unsigned idx = V[n].e[0][0]; // find the index of first outgoing edge of that vertex + stim::circle C = E[idx].circ(0); + stim::vec3 normal = C.n(); + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector glTexCoord1f(E[idx].r(0)); // bind the texture as metric of first point on that edge } else { unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex + stim::circle C = E[idx].circ(E[idx].size()-1); + stim::vec3 normal = C.n(); + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector glTexCoord1f(E[idx].r(E[idx].size() - 1)); // bind the texture as metric of last point on that edge } renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20, 20); @@ -247,51 +254,78 @@ public: glDeleteLists(dlist+2, 1); if (!glIsList(dlist+2)) { // if dlist isn't a display list, create it glNewList(dlist+2, GL_COMPILE); // start a new display list - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network if (map[e] != unsigned(-1)) { - if(I == 0) // if it is to render GT + if (I == 0) { // if it is to render GT glColor3f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2]); - else // if it is to render T + } + else { // if it is to render T glColor3f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2]); + } for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge stim::circle C1 = E[e].circ(p - 1); stim::circle C2 = E[e].circ(p); - C1.set_R(2*radius); // scale the circle to the same + C1.set_R(2*radius); // re-scale the circle to the same C2.set_R(2*radius); std::vector< stim::vec3 >Cp1 = C1.glpoints(20); std::vector< stim::vec3 >Cp2 = C2.glpoints(20); - renderCylinder(Cp1, Cp2); + stim::vec3 n1 = C1.n(); // get the normal vector + stim::vec3 n2 = C2.n(); + renderCylinder(Cp1, Cp2, n1, n2); } } else { - glColor3f(1.0f, 1.0f, 1.0f); // white color for the un-mapping edges - for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge + glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges + for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge stim::circle C1 = E[e].circ(p - 1); stim::circle C2 = E[e].circ(p); C1.set_R(2*radius); // scale the circle to the same C2.set_R(2*radius); std::vector< stim::vec3 >Cp1 = C1.glpoints(20); std::vector< stim::vec3 >Cp2 = C2.glpoints(20); - renderCylinder(Cp1, Cp2); + stim::vec3 n1 = C1.n(); // get the normal vector + stim::vec3 n2 = C2.n(); + renderCylinder(Cp1, Cp2, n1, n2); } } } - for (unsigned v = 0; v < V.size(); v++) { - size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); + for (unsigned n = 0; n < V.size(); n++) { + size_t num_edge = V[n].e[0].size() + V[n].e[1].size(); if (num_edge > 1) { // if it is the joint vertex - glColor3f(0.3, 0.3, 0.3); // gray color - renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); + if (V[n].e[0].size() != 0) { + unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex + stim::circle C = E[idx].circ(0); + stim::vec3 normal = C.n(); + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector + } + else { + unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex + stim::circle C = E[idx].circ(E[idx].size() - 1); + stim::vec3 normal = C.n(); + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector + } + glColor3f(0.3, 0.3, 0.3); // gray + renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20, 20); } else { // if it is the terminal vertex + if (V[n].e[0].size() != 0) { + unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex + stim::circle C = E[idx].circ(0); + stim::vec3 normal = C.n(); + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector + } + else { + unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex + stim::circle C = E[idx].circ(E[idx].size() - 1); + stim::vec3 normal = C.n(); + glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector + } glColor3f(0.6, 0.6, 0.6); // more white gray - renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); + renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20, 20); } } glEndList(); - glDisable(GL_COLOR_MATERIAL); } glCallList(dlist+2); } @@ -319,7 +353,7 @@ public: glEnd(); } else { - glColor3f(1.0, 1.0, 1.0); // white color + glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges glBegin(GL_LINE_STRIP); for (unsigned p = 0; p < E[e].size(); p++) { glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); -- libgit2 0.21.4