Commit b019bc5e8aaac9845d926bcf1b8b11237bc6174e
1 parent
7a615d7e
add function to render a tube around the centerline
Showing
1 changed file
with
53 additions
and
1 deletions
Show diff stats
stim/visualization/gl_network.h
... | ... | @@ -43,6 +43,36 @@ public: |
43 | 43 | return bb; //return the bounding box |
44 | 44 | } |
45 | 45 | |
46 | + void renderCylinder(T x1, T y1, T z1, T x2, T y2, T z2, T radius, int subdivisions) { | |
47 | + T dx = x2 - x1; | |
48 | + T dy = y2 - y1; | |
49 | + T dz = z2 - z1; | |
50 | + /// handle the degenerate case with an approximation | |
51 | + if (dz == 0) | |
52 | + dz = .00000001; | |
53 | + T d = sqrt(dx*dx + dy*dy + dz*dz); // distance between two points = length/height | |
54 | + T ax = 57.2957795*acos(dz / d); // 180°/pi | |
55 | + if (dz < 0.0) | |
56 | + ax = -ax; | |
57 | + T rx = -dy*dz; | |
58 | + T ry = dx*dz; | |
59 | + | |
60 | + glPushMatrix(); | |
61 | + glTranslatef(x1, y1, z1); | |
62 | + glRotatef(ax, rx, ry, 0.0); | |
63 | + | |
64 | + glutSolidCylinder(radius, d, subdivisions, 1); | |
65 | + glPopMatrix(); | |
66 | + } | |
67 | + | |
68 | + void renderBall(T x, T y, T z, T radius, int subdivisions) { | |
69 | + glPushMatrix(); | |
70 | + glTranslatef(x, y, z); | |
71 | + glutSolidSphere(radius, subdivisions, subdivisions); | |
72 | + glPopMatrix(); | |
73 | + } | |
74 | + | |
75 | + | |
46 | 76 | /// Render the network centerline as a series of line strips. |
47 | 77 | /// glCenterline0 is for only one input |
48 | 78 | void glCenterline0(){ |
... | ... | @@ -66,7 +96,7 @@ public: |
66 | 96 | void glCenterline(){ |
67 | 97 | |
68 | 98 | if(!glIsList(dlist)){ //if dlist isn't a display list, create it |
69 | - dlist = glGenLists(3); //generate a display list | |
99 | + dlist = glGenLists(1); //generate a display list | |
70 | 100 | glNewList(dlist, GL_COMPILE); //start a new display list |
71 | 101 | for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network |
72 | 102 | //unsigned errormag_id = E[e].nmags() - 1; |
... | ... | @@ -84,6 +114,7 @@ public: |
84 | 114 | |
85 | 115 | void glRandColorCenterlineGT(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap){ |
86 | 116 | if(!glIsList(dlist1)){ |
117 | + dlist1 = glGenLists(1); | |
87 | 118 | glNewList(dlist1, GL_COMPILE); |
88 | 119 | for(unsigned e = 0; e < E.size(); e++){ |
89 | 120 | if(map[e] != unsigned(-1)){ |
... | ... | @@ -93,6 +124,9 @@ public: |
93 | 124 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); |
94 | 125 | } |
95 | 126 | glEnd(); |
127 | + for (unsigned p = 0; p < E[e].size() - 1; p++) { | |
128 | + renderCylinder(E[e][p][0], E[e][p][1], E[e][p][2], E[e][p + 1][0], E[e][p + 1][1], E[e][p + 1][2], 10, 20); | |
129 | + } | |
96 | 130 | } |
97 | 131 | else{ |
98 | 132 | glColor3f(1.0, 1.0, 1.0); |
... | ... | @@ -103,6 +137,13 @@ public: |
103 | 137 | glEnd(); |
104 | 138 | } |
105 | 139 | } |
140 | + for (unsigned v = 0; v < V.size(); v++) { | |
141 | + size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); | |
142 | + if (num_edge > 1) { | |
143 | + glColor3f(0.3, 0.3, 0.3); // gray color for vertex | |
144 | + renderBall(V[v][0], V[v][1], V[v][2], 20, 20); | |
145 | + } | |
146 | + } | |
106 | 147 | glEndList(); |
107 | 148 | } |
108 | 149 | glCallList(dlist1); |
... | ... | @@ -110,6 +151,7 @@ public: |
110 | 151 | |
111 | 152 | void glRandColorCenterlineT(GLuint &dlist2, std::vector<unsigned> map, std::vector<T> colormap){ |
112 | 153 | if(!glIsList(dlist2)){ |
154 | + dlist2 = glGenLists(1); | |
113 | 155 | glNewList(dlist2, GL_COMPILE); |
114 | 156 | for(unsigned e = 0; e < E.size(); e++){ |
115 | 157 | if(map[e] != unsigned(-1)){ |
... | ... | @@ -119,6 +161,9 @@ public: |
119 | 161 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); |
120 | 162 | } |
121 | 163 | glEnd(); |
164 | + for (unsigned p = 0; p < E[e].size() - 1; p++) { | |
165 | + renderCylinder(E[e][p][0], E[e][p][1], E[e][p][2], E[e][p + 1][0], E[e][p + 1][1], E[e][p + 1][2], 10, 20); | |
166 | + } | |
122 | 167 | } |
123 | 168 | else{ |
124 | 169 | glColor3f(1.0, 1.0, 1.0); |
... | ... | @@ -129,6 +174,13 @@ public: |
129 | 174 | glEnd(); |
130 | 175 | } |
131 | 176 | } |
177 | + for (unsigned v = 0; v < V.size(); v++) { | |
178 | + size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); | |
179 | + if (num_edge > 1) { | |
180 | + glColor3f(0.3, 0.3, 0.3); // gray color for vertex | |
181 | + renderBall(V[v][0], V[v][1], V[v][2], 20, 20); | |
182 | + } | |
183 | + } | |
132 | 184 | glEndList(); |
133 | 185 | } |
134 | 186 | glCallList(dlist2); | ... | ... |