Commit 8412027b75fcc9af8d583c934265fc39e1f5b078

Authored by David Mayerich
2 parents ff4ee63d 30b20d4f

Merge branch 'JACK' into 'master'

make it render better for both swc and obj files

add a new function in circle class in order to get a close circle

See merge request !25
stim/biomodels/network.h
@@ -144,7 +144,7 @@ protected: @@ -144,7 +144,7 @@ protected:
144 144
145 std::vector<edge> E; //list of edges 145 std::vector<edge> E; //list of edges
146 std::vector<vertex> V; //list of vertices. 146 std::vector<vertex> V; //list of vertices.
147 - std::vector<int> NT; //stores a list of neuronal type for each point in the centerline (will set value only when centerline is built from swc file) 147 + //std::vector<int> NT; //stores a list of neuronal type for each point in the centerline (will set value only when centerline is built from swc file)
148 148
149 public: 149 public:
150 150
@@ -396,11 +396,11 @@ public: @@ -396,11 +396,11 @@ public:
396 S.load(filename); // load the node information 396 S.load(filename); // load the node information
397 S.create_tree(); // link those node according to their linking relationships as a tree 397 S.create_tree(); // link those node according to their linking relationships as a tree
398 398
399 - NT.push_back(S.node[0].type); // set the neuronal_type value to the first vertex in the network 399 + //NT.push_back(S.node[0].type); // set the neuronal_type value to the first vertex in the network
400 std::vector<unsigned> id2vert; // this list stores the SWC vertex ID associated with each network vertex 400 std::vector<unsigned> id2vert; // this list stores the SWC vertex ID associated with each network vertex
401 unsigned i[2]; // temporary, IDs associated with the first and last points 401 unsigned i[2]; // temporary, IDs associated with the first and last points
402 for (unsigned int l = 1; l < S.numL(); l++) { // for every node starts from second one 402 for (unsigned int l = 1; l < S.numL(); l++) { // for every node starts from second one
403 - NT.push_back(S.node[l].type); 403 + //NT.push_back(S.node[l].type);
404 stim::centerline<T> c3(2); // every fiber contains two vertices 404 stim::centerline<T> c3(2); // every fiber contains two vertices
405 int p_idx = S.node[l].parent_idx - 1; // get the parent node loop idx of current node 405 int p_idx = S.node[l].parent_idx - 1; // get the parent node loop idx of current node
406 c3[0] = S.node[p_idx].point; // store the begin vertex 406 c3[0] = S.node[p_idx].point; // store the begin vertex
@@ -479,7 +479,7 @@ public: @@ -479,7 +479,7 @@ public:
479 stim::network<T> resample(T spacing){ 479 stim::network<T> resample(T spacing){
480 stim::network<T> n; //create a new network that will be an exact copy, with resampled fibers 480 stim::network<T> n; //create a new network that will be an exact copy, with resampled fibers
481 n.V = V; //copy all vertices 481 n.V = V; //copy all vertices
482 - n.NT = NT; //copy all the neuronal type information 482 + //n.NT = NT; //copy all the neuronal type information
483 n.E.resize(edges()); //allocate space for the edge list 483 n.E.resize(edges()); //allocate space for the edge list
484 484
485 //copy all fibers, resampling them in the process 485 //copy all fibers, resampling them in the process
@@ -820,7 +820,7 @@ public: @@ -820,7 +820,7 @@ public:
820 V[V.size() - 1].e[0].push_back((unsigned)E.size() - 1); // push second half edge to the outgoing of new vertex 820 V[V.size() - 1].e[0].push_back((unsigned)E.size() - 1); // push second half edge to the outgoing of new vertex
821 for(unsigned i = 0; i < V[tmp.v[1]].e[1].size(); i++) // find the incoming edge of original ending vertex 821 for(unsigned i = 0; i < V[tmp.v[1]].e[1].size(); i++) // find the incoming edge of original ending vertex
822 if(V[tmp.v[1]].e[1][i] == e) 822 if(V[tmp.v[1]].e[1][i] == e)
823 - V[tmp.v[1]].e[1][i] = (unsigned)V.size() - 1; 823 + V[tmp.v[1]].e[1][i] = (unsigned)E.size() - 1; // set to new edge
824 } 824 }
825 } 825 }
826 } 826 }
stim/math/circle.h
@@ -193,9 +193,20 @@ public: @@ -193,9 +193,20 @@ public:
193 result[i] = p(i * dt); //calculate a point on the edge of the circle 193 result[i] = p(i * dt); //calculate a point on the edge of the circle
194 return result; 194 return result;
195 } 195 }
196 -  
197 -  
198 196
  197 + ///returns a vector with the points on the initialized circle
  198 + ///connecting the points results in a circle
  199 + ///@param n: integer for the number of points representing the circle
  200 + ///the only difference between points and glpoints is that the first point appears twice in the returning lists
  201 + std::vector< stim::vec3<T> > glpoints(unsigned n) {
  202 + std::vector< stim::vec3<T> > result(n + 1);
  203 + float dt = stim::TAU / n;
  204 + for (unsigned i = 0; i < n; i++)
  205 + result[i] = p(i * dt);
  206 + result[n] = p(0); //close the circle!
  207 + return result;
  208 + }
  209 +
199 std::string str() const 210 std::string str() const
200 { 211 {
201 std::stringstream ss; 212 std::stringstream ss;
stim/visualization/gl_network.h
@@ -87,7 +87,7 @@ public: @@ -87,7 +87,7 @@ public:
87 87
88 /// render the network centerline from swc file as a series of strips in different colors based on the neuronal type 88 /// render the network centerline from swc file as a series of strips in different colors based on the neuronal type
89 /// glCenterline0_swc is for only one input 89 /// glCenterline0_swc is for only one input
90 - void glCenterline0_swc() { 90 + /*void glCenterline0_swc() {
91 if (!glIsList(dlist)) { // if dlist isn't a display list, create it 91 if (!glIsList(dlist)) { // if dlist isn't a display list, create it
92 dlist = glGenLists(1); // generate a display list 92 dlist = glGenLists(1); // generate a display list
93 glNewList(dlist, GL_COMPILE); // start a new display list 93 glNewList(dlist, GL_COMPILE); // start a new display list
@@ -163,7 +163,7 @@ public: @@ -163,7 +163,7 @@ public:
163 glEndList(); //end the display list 163 glEndList(); //end the display list
164 } 164 }
165 glCallList(dlist); // render the display list 165 glCallList(dlist); // render the display list
166 - } 166 + }*/
167 167
168 ///render the network centerline as a series of line strips(when loading at least two networks, otherwise using glCenterline0()) 168 ///render the network centerline as a series of line strips(when loading at least two networks, otherwise using glCenterline0())
169 ///colors are based on metric values 169 ///colors are based on metric values
@@ -188,7 +188,7 @@ public: @@ -188,7 +188,7 @@ public:
188 188
189 ///render the network cylinder as a series of tubes 189 ///render the network cylinder as a series of tubes
190 ///colors are based on metric values 190 ///colors are based on metric values
191 - void glCylinder() { 191 + void glCylinder(float sigma) {
192 if (!glIsList(dlist)) { //if dlist isn't a display list, create it 192 if (!glIsList(dlist)) { //if dlist isn't a display list, create it
193 dlist = glGenLists(1); //generate a display list 193 dlist = glGenLists(1); //generate a display list
194 glNewList(dlist, GL_COMPILE); //start a new display list 194 glNewList(dlist, GL_COMPILE); //start a new display list
@@ -196,12 +196,12 @@ public: @@ -196,12 +196,12 @@ public:
196 for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge 196 for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge
197 stim::circle<T> C1 = E[e].circ(p - 1); 197 stim::circle<T> C1 = E[e].circ(p - 1);
198 stim::circle<T> C2 = E[e].circ(p); 198 stim::circle<T> C2 = E[e].circ(p);
199 - C1.set_R(10); // scale the circle to the same  
200 - C2.set_R(10);  
201 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
202 - std::vector< stim::vec3<T> >Cp2 = C2.points(20); 199 + C1.set_R(3*sigma); // scale the circle to the same
  200 + C2.set_R(3*sigma);
  201 + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20);
  202 + std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20);
203 glBegin(GL_QUAD_STRIP); 203 glBegin(GL_QUAD_STRIP);
204 - for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle 204 + for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle)
205 glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); 205 glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]);
206 glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); 206 glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]);
207 glTexCoord1f(E[e].r(p)); 207 glTexCoord1f(E[e].r(p));
@@ -209,6 +209,18 @@ public: @@ -209,6 +209,18 @@ public:
209 glEnd(); 209 glEnd();
210 } //set the texture coordinate based on the specified magnitude index 210 } //set the texture coordinate based on the specified magnitude index
211 } 211 }
  212 + for (unsigned n = 0; n < V.size(); n++) {
  213 + size_t num = V[n].e[0].size(); //store the number of outgoing edge of that vertex
  214 + if (num != 0) { //if it has outgoing edge
  215 + unsigned idx = V[n].e[0][0]; //find the index of first outgoing edge of that vertex
  216 + glTexCoord1f(E[idx].r(0)); //bind the texture as metric of first point on that edge
  217 + }
  218 + else {
  219 + unsigned idx = V[n].e[1][0]; //find the index of first incoming edge of that vertex
  220 + glTexCoord1f(E[idx].r(E[idx].size() - 1)); //bind the texture as metric of last point on that edge
  221 + }
  222 + renderBall(V[n][0], V[n][1], V[n][2], 3*sigma, 20);
  223 + }
212 glEndList(); //end the display list 224 glEndList(); //end the display list
213 } 225 }
214 glCallList(dlist); //render the display list 226 glCallList(dlist); //render the display list
@@ -218,53 +230,7 @@ public: @@ -218,53 +230,7 @@ public:
218 ///@param dlist1 is the display list 230 ///@param dlist1 is the display list
219 ///@param map is the mapping relationship between two networks 231 ///@param map is the mapping relationship between two networks
220 ///@param colormap is the random generated color set for render 232 ///@param colormap is the random generated color set for render
221 - void glRandColorCylinder1(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap) {  
222 - if (!glIsList(dlist1)) { // if dlist1 isn't a display list, create it  
223 - dlist1 = glGenLists(1); // generate a display list  
224 - glNewList(dlist1, GL_COMPILE); // start a new display list  
225 - for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network  
226 - if (map[e] != unsigned(-1)) {  
227 - glColor3f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2]);  
228 - for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge  
229 - stim::circle<T> C1 = E[e].circ(p - 1);  
230 - stim::circle<T> C2 = E[e].circ(p);  
231 - C1.set_R(10); // scale the circle to the same  
232 - C2.set_R(10);  
233 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
234 - std::vector< stim::vec3<T> >Cp2 = C2.points(20);  
235 - renderCylinder(Cp1, Cp2);  
236 - }  
237 - }  
238 - else {  
239 - glColor3f(1.0f, 1.0f, 1.0f); // white color for the un-mapping edges  
240 - for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge  
241 - stim::circle<T> C1 = E[e].circ(p - 1);  
242 - stim::circle<T> C2 = E[e].circ(p);  
243 - C1.set_R(10); // scale the circle to the same  
244 - C2.set_R(10);  
245 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
246 - std::vector< stim::vec3<T> >Cp2 = C2.points(20);  
247 - renderCylinder(Cp1, Cp2);  
248 - }  
249 - }  
250 - }  
251 - for (unsigned v = 0; v < V.size(); v++) {  
252 - size_t num_edge = V[v].e[0].size() + V[v].e[1].size();  
253 - if (num_edge > 1) { // if it is the joint vertex  
254 - glColor3f(0.3, 0.3, 0.3); // gray color  
255 - renderBall(V[v][0], V[v][1], V[v][2], 20, 20);  
256 - }  
257 - else { // if it is the terminal vertex  
258 - glColor3f(0.6, 0.6, 0.6); // more white gray  
259 - renderBall(V[v][0], V[v][1], V[v][2], 20, 20);  
260 - }  
261 - }  
262 - glEndList();  
263 - }  
264 - glCallList(dlist1);  
265 - }  
266 -  
267 - void glRandColorCylinder1_swc(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap) { 233 + void glRandColorCylinder1(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap, float sigma) {
268 if (!glIsList(dlist1)) { // if dlist1 isn't a display list, create it 234 if (!glIsList(dlist1)) { // if dlist1 isn't a display list, create it
269 dlist1 = glGenLists(1); // generate a display list 235 dlist1 = glGenLists(1); // generate a display list
270 glNewList(dlist1, GL_COMPILE); // start a new display list 236 glNewList(dlist1, GL_COMPILE); // start a new display list
@@ -274,10 +240,10 @@ public: @@ -274,10 +240,10 @@ public:
274 for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge 240 for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge
275 stim::circle<T> C1 = E[e].circ(p - 1); 241 stim::circle<T> C1 = E[e].circ(p - 1);
276 stim::circle<T> C2 = E[e].circ(p); 242 stim::circle<T> C2 = E[e].circ(p);
277 - C1.set_R(0.5); // scale the circle to the same  
278 - C2.set_R(0.5);  
279 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
280 - std::vector< stim::vec3<T> >Cp2 = C2.points(20); 243 + C1.set_R(3*sigma); // scale the circle to the same
  244 + C2.set_R(3*sigma);
  245 + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20);
  246 + std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20);
281 renderCylinder(Cp1, Cp2); 247 renderCylinder(Cp1, Cp2);
282 } 248 }
283 } 249 }
@@ -286,10 +252,10 @@ public: @@ -286,10 +252,10 @@ public:
286 for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge 252 for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge
287 stim::circle<T> C1 = E[e].circ(p - 1); 253 stim::circle<T> C1 = E[e].circ(p - 1);
288 stim::circle<T> C2 = E[e].circ(p); 254 stim::circle<T> C2 = E[e].circ(p);
289 - C1.set_R(0.5); // scale the circle to the same  
290 - C2.set_R(0.5);  
291 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
292 - std::vector< stim::vec3<T> >Cp2 = C2.points(20); 255 + C1.set_R(3*sigma); // scale the circle to the same
  256 + C2.set_R(3*sigma);
  257 + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20);
  258 + std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20);
293 renderCylinder(Cp1, Cp2); 259 renderCylinder(Cp1, Cp2);
294 } 260 }
295 } 261 }
@@ -298,11 +264,11 @@ public: @@ -298,11 +264,11 @@ public:
298 size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); 264 size_t num_edge = V[v].e[0].size() + V[v].e[1].size();
299 if (num_edge > 1) { // if it is the joint vertex 265 if (num_edge > 1) { // if it is the joint vertex
300 glColor3f(0.3, 0.3, 0.3); // gray color 266 glColor3f(0.3, 0.3, 0.3); // gray color
301 - renderBall(V[v][0], V[v][1], V[v][2], 1, 20); 267 + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20);
302 } 268 }
303 else { // if it is the terminal vertex 269 else { // if it is the terminal vertex
304 glColor3f(0.6, 0.6, 0.6); // more white gray 270 glColor3f(0.6, 0.6, 0.6); // more white gray
305 - renderBall(V[v][0], V[v][1], V[v][2], 1, 20); 271 + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20);
306 } 272 }
307 } 273 }
308 glEndList(); 274 glEndList();
@@ -314,53 +280,7 @@ public: @@ -314,53 +280,7 @@ public:
314 ///@param dlist2 is the display list 280 ///@param dlist2 is the display list
315 ///@param map is the mapping relationship between two networks 281 ///@param map is the mapping relationship between two networks
316 ///@param colormap is the random generated color set for render 282 ///@param colormap is the random generated color set for render
317 - void glRandColorCylinder2(GLuint &dlist2, std::vector<unsigned> map, std::vector<T> colormap) {  
318 - if (!glIsList(dlist2)) {  
319 - dlist2 = glGenLists(1);  
320 - glNewList(dlist2, GL_COMPILE);  
321 - for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network  
322 - if (map[e] != unsigned(-1)) {  
323 - glColor3f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2]);  
324 - for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge  
325 - stim::circle<T> C1 = E[e].circ(p);  
326 - stim::circle<T> C2 = E[e].circ(p + 1);  
327 - C1.set_R(10); // scale the circle to the same  
328 - C2.set_R(10);  
329 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
330 - std::vector< stim::vec3<T> >Cp2 = C2.points(20);  
331 - renderCylinder(Cp1, Cp2);  
332 - }  
333 - }  
334 - else {  
335 - glColor3f(1.0f, 1.0f, 1.0f); // white color for the un-mapping edges  
336 - for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge  
337 - stim::circle<T> C1 = E[e].circ(p);  
338 - stim::circle<T> C2 = E[e].circ(p + 1);  
339 - C1.set_R(10); // scale the circle to the same  
340 - C2.set_R(10);  
341 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
342 - std::vector< stim::vec3<T> >Cp2 = C2.points(20);  
343 - renderCylinder(Cp1, Cp2);  
344 - }  
345 - }  
346 - }  
347 - for (unsigned v = 0; v < V.size(); v++) {  
348 - size_t num_edge = V[v].e[0].size() + V[v].e[1].size();  
349 - if (num_edge > 1) { // if it is the joint vertex  
350 - glColor3f(0.3, 0.3, 0.3); // gray color  
351 - renderBall(V[v][0], V[v][1], V[v][2], 20, 20);  
352 - }  
353 - else { // if it is the terminal vertex  
354 - glColor3f(0.6, 0.6, 0.6); // more white gray  
355 - renderBall(V[v][0], V[v][1], V[v][2], 20, 20);  
356 - }  
357 - }  
358 - glEndList();  
359 - }  
360 - glCallList(dlist2);  
361 - }  
362 -  
363 - void glRandColorCylinder2_swc(GLuint &dlist2, std::vector<unsigned> map, std::vector<T> colormap) { 283 + void glRandColorCylinder2(GLuint &dlist2, std::vector<unsigned> map, std::vector<T> colormap, float sigma) {
364 if (!glIsList(dlist2)) { 284 if (!glIsList(dlist2)) {
365 dlist2 = glGenLists(1); 285 dlist2 = glGenLists(1);
366 glNewList(dlist2, GL_COMPILE); 286 glNewList(dlist2, GL_COMPILE);
@@ -370,10 +290,10 @@ public: @@ -370,10 +290,10 @@ public:
370 for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge 290 for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge
371 stim::circle<T> C1 = E[e].circ(p); 291 stim::circle<T> C1 = E[e].circ(p);
372 stim::circle<T> C2 = E[e].circ(p + 1); 292 stim::circle<T> C2 = E[e].circ(p + 1);
373 - C1.set_R(0.5); // scale the circle to the same  
374 - C2.set_R(0.5);  
375 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
376 - std::vector< stim::vec3<T> >Cp2 = C2.points(20); 293 + C1.set_R(3*sigma); // scale the circle to the same
  294 + C2.set_R(3*sigma);
  295 + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20);
  296 + std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20);
377 renderCylinder(Cp1, Cp2); 297 renderCylinder(Cp1, Cp2);
378 } 298 }
379 } 299 }
@@ -382,10 +302,10 @@ public: @@ -382,10 +302,10 @@ public:
382 for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge 302 for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge
383 stim::circle<T> C1 = E[e].circ(p); 303 stim::circle<T> C1 = E[e].circ(p);
384 stim::circle<T> C2 = E[e].circ(p + 1); 304 stim::circle<T> C2 = E[e].circ(p + 1);
385 - C1.set_R(0.5); // scale the circle to the same  
386 - C2.set_R(0.5);  
387 - std::vector< stim::vec3<T> >Cp1 = C1.points(20);  
388 - std::vector< stim::vec3<T> >Cp2 = C2.points(20); 305 + C1.set_R(3*sigma); // scale the circle to the same
  306 + C2.set_R(3*sigma);
  307 + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20);
  308 + std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20);
389 renderCylinder(Cp1, Cp2); 309 renderCylinder(Cp1, Cp2);
390 } 310 }
391 } 311 }
@@ -394,11 +314,11 @@ public: @@ -394,11 +314,11 @@ public:
394 size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); 314 size_t num_edge = V[v].e[0].size() + V[v].e[1].size();
395 if (num_edge > 1) { // if it is the joint vertex 315 if (num_edge > 1) { // if it is the joint vertex
396 glColor3f(0.3, 0.3, 0.3); // gray color 316 glColor3f(0.3, 0.3, 0.3); // gray color
397 - renderBall(V[v][0], V[v][1], V[v][2], 1, 20); 317 + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20);
398 } 318 }
399 else { // if it is the terminal vertex 319 else { // if it is the terminal vertex
400 glColor3f(0.6, 0.6, 0.6); // more white gray 320 glColor3f(0.6, 0.6, 0.6); // more white gray
401 - renderBall(V[v][0], V[v][1], V[v][2], 1, 20); 321 + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20);
402 } 322 }
403 } 323 }
404 glEndList(); 324 glEndList();