Commit 90f833711e610aed864bec575686f0e51e936a73
Merged branch JACK into master
Showing
1 changed file
with
53 additions
and
1 deletions
Show diff stats
stim/visualization/gl_network.h
@@ -43,6 +43,36 @@ public: | @@ -43,6 +43,36 @@ public: | ||
43 | return bb; //return the bounding box | 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 | /// Render the network centerline as a series of line strips. | 76 | /// Render the network centerline as a series of line strips. |
47 | /// glCenterline0 is for only one input | 77 | /// glCenterline0 is for only one input |
48 | void glCenterline0(){ | 78 | void glCenterline0(){ |
@@ -66,7 +96,7 @@ public: | @@ -66,7 +96,7 @@ public: | ||
66 | void glCenterline(){ | 96 | void glCenterline(){ |
67 | 97 | ||
68 | if(!glIsList(dlist)){ //if dlist isn't a display list, create it | 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 | glNewList(dlist, GL_COMPILE); //start a new display list | 100 | glNewList(dlist, GL_COMPILE); //start a new display list |
71 | for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network | 101 | for(unsigned e = 0; e < E.size(); e++){ //for each edge in the network |
72 | //unsigned errormag_id = E[e].nmags() - 1; | 102 | //unsigned errormag_id = E[e].nmags() - 1; |
@@ -84,6 +114,7 @@ public: | @@ -84,6 +114,7 @@ public: | ||
84 | 114 | ||
85 | void glRandColorCenterlineGT(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap){ | 115 | void glRandColorCenterlineGT(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap){ |
86 | if(!glIsList(dlist1)){ | 116 | if(!glIsList(dlist1)){ |
117 | + dlist1 = glGenLists(1); | ||
87 | glNewList(dlist1, GL_COMPILE); | 118 | glNewList(dlist1, GL_COMPILE); |
88 | for(unsigned e = 0; e < E.size(); e++){ | 119 | for(unsigned e = 0; e < E.size(); e++){ |
89 | if(map[e] != unsigned(-1)){ | 120 | if(map[e] != unsigned(-1)){ |
@@ -93,6 +124,9 @@ public: | @@ -93,6 +124,9 @@ public: | ||
93 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); | 124 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); |
94 | } | 125 | } |
95 | glEnd(); | 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 | else{ | 131 | else{ |
98 | glColor3f(1.0, 1.0, 1.0); | 132 | glColor3f(1.0, 1.0, 1.0); |
@@ -103,6 +137,13 @@ public: | @@ -103,6 +137,13 @@ public: | ||
103 | glEnd(); | 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 | glEndList(); | 147 | glEndList(); |
107 | } | 148 | } |
108 | glCallList(dlist1); | 149 | glCallList(dlist1); |
@@ -110,6 +151,7 @@ public: | @@ -110,6 +151,7 @@ public: | ||
110 | 151 | ||
111 | void glRandColorCenterlineT(GLuint &dlist2, std::vector<unsigned> map, std::vector<T> colormap){ | 152 | void glRandColorCenterlineT(GLuint &dlist2, std::vector<unsigned> map, std::vector<T> colormap){ |
112 | if(!glIsList(dlist2)){ | 153 | if(!glIsList(dlist2)){ |
154 | + dlist2 = glGenLists(1); | ||
113 | glNewList(dlist2, GL_COMPILE); | 155 | glNewList(dlist2, GL_COMPILE); |
114 | for(unsigned e = 0; e < E.size(); e++){ | 156 | for(unsigned e = 0; e < E.size(); e++){ |
115 | if(map[e] != unsigned(-1)){ | 157 | if(map[e] != unsigned(-1)){ |
@@ -119,6 +161,9 @@ public: | @@ -119,6 +161,9 @@ public: | ||
119 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); | 161 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); |
120 | } | 162 | } |
121 | glEnd(); | 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 | else{ | 168 | else{ |
124 | glColor3f(1.0, 1.0, 1.0); | 169 | glColor3f(1.0, 1.0, 1.0); |
@@ -129,6 +174,13 @@ public: | @@ -129,6 +174,13 @@ public: | ||
129 | glEnd(); | 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 | glEndList(); | 184 | glEndList(); |
133 | } | 185 | } |
134 | glCallList(dlist2); | 186 | glCallList(dlist2); |