Commit 2df16996ceaf47335cca5459ad72020c69c384f3
1 parent
2b28db3e
add a new way to draw vertex as sphere instead of using GLUT build-in function
Showing
1 changed file
with
52 additions
and
5 deletions
Show diff stats
stim/visualization/gl_network.h
... | ... | @@ -55,7 +55,7 @@ public: |
55 | 55 | //glFlush(); |
56 | 56 | } |
57 | 57 | |
58 | - ///render the vertex as sphere | |
58 | + ///render the vertex as sphere based on glut build-in function | |
59 | 59 | ///@param x, y, z are the three coordinates of the center point |
60 | 60 | ///@param radius is the radius of the sphere |
61 | 61 | ///@param subdivisions is the slice/stride along/around z-axis |
... | ... | @@ -66,6 +66,53 @@ public: |
66 | 66 | glPopMatrix(); |
67 | 67 | } |
68 | 68 | |
69 | + ///render the vertex as sphere based on transformation | |
70 | + ///@param x, y, z are the three coordinates of the center point | |
71 | + ///@param radius is the radius of the sphere | |
72 | + ///@param slice is the number of subdivisions around the z-axis | |
73 | + ///@param stack is the number of subdivisions along the z-axis | |
74 | + void renderBall(T x, T y, T z, T radius, T slice, T stack) { | |
75 | + T step_z = stim::PI / slice; // step angle along z-axis | |
76 | + T step_xy = 2 * stim::PI / stack; // step angle in xy-plane | |
77 | + T xx[4], yy[4], zz[4]; // store coordinates | |
78 | + | |
79 | + T angle_z = 0.0; // start angle | |
80 | + T angle_xy = 0.0; | |
81 | + | |
82 | + glBegin(GL_QUADS); | |
83 | + for (unsigned i = 0; i < slice; i++) // around the z-axis | |
84 | + { | |
85 | + angle_z = i * step_z; // step step_z each time | |
86 | + | |
87 | + for (unsigned j = 0; j < stack; j++) // along the z-axis | |
88 | + { | |
89 | + angle_xy = j * step_xy; // step step_xy each time, draw floor by floor | |
90 | + | |
91 | + xx[0] = radius * std::sin(angle_z) * std::cos(angle_xy); // four vertices | |
92 | + yy[0] = radius * std::sin(angle_z) * std::sin(angle_xy); | |
93 | + zz[0] = radius * std::cos(angle_z); | |
94 | + | |
95 | + xx[1] = radius * std::sin(angle_z + step_z) * std::cos(angle_xy); | |
96 | + yy[1] = radius * std::sin(angle_z + step_z) * std::sin(angle_xy); | |
97 | + zz[1] = radius * std::cos(angle_z + step_z); | |
98 | + | |
99 | + xx[2] = radius * std::sin(angle_z + step_z) * std::cos(angle_xy + step_xy); | |
100 | + yy[2] = radius * std::sin(angle_z + step_z) * std::sin(angle_xy + step_xy); | |
101 | + zz[2] = radius * std::cos(angle_z + step_z); | |
102 | + | |
103 | + xx[3] = radius * std::sin(angle_z) * std::cos(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); | |
106 | + | |
107 | + for (unsigned k = 0; k < 4; k++) | |
108 | + { | |
109 | + glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane | |
110 | + } | |
111 | + } | |
112 | + } | |
113 | + glEnd(); | |
114 | + } | |
115 | + | |
69 | 116 | /// Render the network centerline as a series of line strips. |
70 | 117 | /// glCenterline0 is for only one input |
71 | 118 | void glCenterline0(){ |
... | ... | @@ -145,7 +192,7 @@ public: |
145 | 192 | unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex |
146 | 193 | glTexCoord1f(E[idx].r(E[idx].size() - 1)); // bind the texture as metric of last point on that edge |
147 | 194 | } |
148 | - renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20); | |
195 | + renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20, 20); | |
149 | 196 | } |
150 | 197 | glEndList(); // end the display list |
151 | 198 | } |
... | ... | @@ -183,7 +230,7 @@ public: |
183 | 230 | else { |
184 | 231 | unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex |
185 | 232 | } |
186 | - renderBall(V[n][0], V[n][1], V[n][2], 2 * radius, 20); | |
233 | + renderBall(V[n][0], V[n][1], V[n][2], 2 * radius, 20, 20); | |
187 | 234 | } |
188 | 235 | glEndList(); |
189 | 236 | } |
... | ... | @@ -236,11 +283,11 @@ public: |
236 | 283 | size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); |
237 | 284 | if (num_edge > 1) { // if it is the joint vertex |
238 | 285 | glColor3f(0.3, 0.3, 0.3); // gray color |
239 | - renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20); | |
286 | + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); | |
240 | 287 | } |
241 | 288 | else { // if it is the terminal vertex |
242 | 289 | glColor3f(0.6, 0.6, 0.6); // more white gray |
243 | - renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20); | |
290 | + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20, 20); | |
244 | 291 | } |
245 | 292 | } |
246 | 293 | glEndList(); | ... | ... |