diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index 3107256..438708f 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -55,7 +55,7 @@ public: //glFlush(); } - ///render the vertex as sphere + ///render the vertex as sphere based on glut build-in function ///@param x, y, z are the three coordinates of the center point ///@param radius is the radius of the sphere ///@param subdivisions is the slice/stride along/around z-axis @@ -66,6 +66,53 @@ public: glPopMatrix(); } + ///render the vertex as sphere based on transformation + ///@param x, y, z are the three coordinates of the center point + ///@param radius is the radius of the sphere + ///@param slice is the number of subdivisions around the z-axis + ///@param stack is the number of subdivisions along the z-axis + void renderBall(T x, T y, T z, T radius, T slice, T stack) { + T step_z = stim::PI / slice; // step angle along z-axis + T step_xy = 2 * stim::PI / stack; // step angle in xy-plane + T xx[4], yy[4], zz[4]; // store coordinates + + T angle_z = 0.0; // start angle + T angle_xy = 0.0; + + glBegin(GL_QUADS); + 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 + { + 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 + yy[0] = radius * std::sin(angle_z) * std::sin(angle_xy); + zz[0] = radius * std::cos(angle_z); + + xx[1] = radius * std::sin(angle_z + step_z) * std::cos(angle_xy); + yy[1] = radius * std::sin(angle_z + step_z) * std::sin(angle_xy); + zz[1] = radius * std::cos(angle_z + step_z); + + xx[2] = radius * std::sin(angle_z + step_z) * std::cos(angle_xy + step_xy); + yy[2] = radius * std::sin(angle_z + step_z) * std::sin(angle_xy + step_xy); + zz[2] = radius * std::cos(angle_z + step_z); + + xx[3] = radius * std::sin(angle_z) * std::cos(angle_xy + step_xy); + 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++) + { + glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane + } + } + } + glEnd(); + } + /// Render the network centerline as a series of line strips. /// glCenterline0 is for only one input void glCenterline0(){ @@ -145,7 +192,7 @@ public: unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex 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); + renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20, 20); } glEndList(); // end the display list } @@ -183,7 +230,7 @@ public: else { unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex } - renderBall(V[n][0], V[n][1], V[n][2], 2 * radius, 20); + renderBall(V[n][0], V[n][1], V[n][2], 2 * radius, 20, 20); } glEndList(); } @@ -236,11 +283,11 @@ public: size_t num_edge = V[v].e[0].size() + V[v].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); + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); } else { // if it is the terminal vertex glColor3f(0.6, 0.6, 0.6); // more white gray - renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20); + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); } } glEndList(); -- libgit2 0.21.4