Commit 26e84a59a4e13b042d90b2d9f1e0d31695856917
1 parent
16e854e8
add adjacency_matrix and new way to see information from loaded network
Showing
2 changed files
with
118 additions
and
34 deletions
Show diff stats
stim/biomodels/network.h
@@ -466,6 +466,31 @@ public: | @@ -466,6 +466,31 @@ public: | ||
466 | } | 466 | } |
467 | } | 467 | } |
468 | 468 | ||
469 | + /// Get adjacency matrix of the network | ||
470 | + std::vector< typename std::vector<int> > get_adj_mat() { | ||
471 | + | ||
472 | + unsigned n = V.size(); // get the number of vertices in the networks | ||
473 | + | ||
474 | + std::vector< typename std::vector<int> > result(n, std::vector<int>(n, 0)); // initialize every entry in the matrix to be 0 | ||
475 | + result.resize(n); // resize rows | ||
476 | + for (unsigned i = 0; i < n; i++) | ||
477 | + result[i].resize(n); // resize columns | ||
478 | + | ||
479 | + for (unsigned i = 0; i < n; i++) { // for every vertex | ||
480 | + unsigned num_out = V[i].e[0].size(); // number of outgoing edges of current vertex | ||
481 | + if (num_out != 0) { | ||
482 | + for (unsigned j = 0; j < num_out; j++) { | ||
483 | + int edge_idx = V[i].e[0][j]; // get the jth out-going edge index of current vertex | ||
484 | + int vertex_idx = E[edge_idx].v[1]; // get the ending vertex of specific out-going edge | ||
485 | + result[i][vertex_idx] = 1; // can simply set to 1 if it is simple-graph | ||
486 | + result[vertex_idx][i] = 1; // symmetric | ||
487 | + } | ||
488 | + } | ||
489 | + } | ||
490 | + | ||
491 | + return result; | ||
492 | + } | ||
493 | + | ||
469 | /// Output the network as a string | 494 | /// Output the network as a string |
470 | std::string str(){ | 495 | std::string str(){ |
471 | 496 |
stim/visualization/gl_network.h
@@ -210,9 +210,9 @@ public: | @@ -210,9 +210,9 @@ public: | ||
210 | void glAdjointCylinder(float sigma, float radius) { | 210 | void glAdjointCylinder(float sigma, float radius) { |
211 | 211 | ||
212 | if (radius != sigma) // if render radius was changed by user, create a new display list | 212 | if (radius != sigma) // if render radius was changed by user, create a new display list |
213 | - glDeleteLists(dlist+4, 1); | ||
214 | - if (!glIsList(dlist+4)) { | ||
215 | - glNewList(dlist+4, GL_COMPILE); | 213 | + glDeleteLists(dlist + 4, 1); |
214 | + if (!glIsList(dlist + 4)) { | ||
215 | + glNewList(dlist + 4, GL_COMPILE); | ||
216 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network | 216 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network |
217 | for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge | 217 | for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge |
218 | stim::circle<T> C1 = E[e].circ(p - 1); | 218 | stim::circle<T> C1 = E[e].circ(p - 1); |
@@ -241,7 +241,7 @@ public: | @@ -241,7 +241,7 @@ public: | ||
241 | } | 241 | } |
242 | glEndList(); | 242 | glEndList(); |
243 | } | 243 | } |
244 | - glCallList(dlist+4); | 244 | + glCallList(dlist + 4); |
245 | } | 245 | } |
246 | 246 | ||
247 | ///render the network cylinder as series of tubes | 247 | ///render the network cylinder as series of tubes |
@@ -251,9 +251,9 @@ public: | @@ -251,9 +251,9 @@ public: | ||
251 | void glRandColorCylinder(int I, std::vector<unsigned> map, std::vector<T> colormap, float sigma, float radius) { | 251 | void glRandColorCylinder(int I, std::vector<unsigned> map, std::vector<T> colormap, float sigma, float radius) { |
252 | 252 | ||
253 | if (radius != sigma) // if render radius was changed by user, create a new display list | 253 | if (radius != sigma) // if render radius was changed by user, create a new display list |
254 | - glDeleteLists(dlist+2, 1); | ||
255 | - if (!glIsList(dlist+2)) { // if dlist isn't a display list, create it | ||
256 | - glNewList(dlist+2, GL_COMPILE); // start a new display list | 254 | + glDeleteLists(dlist + 2, 1); |
255 | + if (!glIsList(dlist + 2)) { // if dlist isn't a display list, create it | ||
256 | + glNewList(dlist + 2, GL_COMPILE); // start a new display list | ||
257 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network | 257 | for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network |
258 | if (map[e] != unsigned(-1)) { | 258 | if (map[e] != unsigned(-1)) { |
259 | if (I == 0) { // if it is to render GT | 259 | if (I == 0) { // if it is to render GT |
@@ -274,7 +274,7 @@ public: | @@ -274,7 +274,7 @@ public: | ||
274 | } | 274 | } |
275 | } | 275 | } |
276 | else { | 276 | else { |
277 | - glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges | 277 | + glColor3f(1.0, 1.0, 1.0); // white color for the un-mapping edges |
278 | for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge | 278 | for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge |
279 | stim::circle<T> C1 = E[e].circ(p - 1); | 279 | stim::circle<T> C1 = E[e].circ(p - 1); |
280 | stim::circle<T> C2 = E[e].circ(p); | 280 | stim::circle<T> C2 = E[e].circ(p); |
@@ -289,46 +289,26 @@ public: | @@ -289,46 +289,26 @@ public: | ||
289 | for (unsigned n = 0; n < V.size(); n++) { | 289 | for (unsigned n = 0; n < V.size(); n++) { |
290 | size_t num_edge = V[n].e[0].size() + V[n].e[1].size(); | 290 | size_t num_edge = V[n].e[0].size() + V[n].e[1].size(); |
291 | if (num_edge > 1) { // if it is the joint vertex | 291 | if (num_edge > 1) { // if it is the joint vertex |
292 | - if (V[n].e[0].size() != 0) { | ||
293 | - unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex | ||
294 | - stim::circle<T> C = E[idx].circ(0); | ||
295 | - stim::vec3<T> normal = C.n(); | ||
296 | - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
297 | - } | ||
298 | - else { | ||
299 | - unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex | ||
300 | - stim::circle<T> C = E[idx].circ(E[idx].size() - 1); | ||
301 | - stim::vec3<T> normal = C.n(); | ||
302 | - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector | ||
303 | - } | ||
304 | glColor3f(0.3, 0.3, 0.3); // gray | 292 | glColor3f(0.3, 0.3, 0.3); // gray |
305 | renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20); | 293 | renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20); |
306 | } | 294 | } |
307 | else { // if it is the terminal vertex | 295 | else { // if it is the terminal vertex |
308 | - if (V[n].e[0].size() != 0) { | ||
309 | - unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex | ||
310 | - } | ||
311 | - else { | ||
312 | - unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex | ||
313 | - } | ||
314 | glColor3f(0.6, 0.6, 0.6); // more white gray | 296 | glColor3f(0.6, 0.6, 0.6); // more white gray |
315 | renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20); | 297 | renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20); |
316 | } | 298 | } |
317 | } | 299 | } |
318 | glEndList(); | 300 | glEndList(); |
319 | } | 301 | } |
320 | - glCallList(dlist+2); | 302 | + glCallList(dlist + 2); |
321 | } | 303 | } |
322 | 304 | ||
323 | ///render the network centerline as a series of line strips in random different color | 305 | ///render the network centerline as a series of line strips in random different color |
324 | ///@param I is a indicator: 0 -> GT, 1 -> T | 306 | ///@param I is a indicator: 0 -> GT, 1 -> T |
325 | - ///@param dlist1 is the display list | ||
326 | ///@param map is the mapping relationship between two networks | 307 | ///@param map is the mapping relationship between two networks |
327 | ///@param colormap is the random generated color set for render | 308 | ///@param colormap is the random generated color set for render |
328 | - void glRandColorCenterline(int I, GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap) { | ||
329 | - if (!glIsList(dlist1)) { | ||
330 | - dlist1 = glGenLists(1); | ||
331 | - glNewList(dlist1, GL_COMPILE); | 309 | + void glRandColorCenterline(int I, std::vector<unsigned> map, std::vector<T> colormap) { |
310 | + if (!glIsList(dlist + 2)) { | ||
311 | + glNewList(dlist + 2, GL_COMPILE); | ||
332 | for (unsigned e = 0; e < E.size(); e++) { | 312 | for (unsigned e = 0; e < E.size(); e++) { |
333 | if (map[e] != unsigned(-1)) { // if it has corresponding edge in another network | 313 | if (map[e] != unsigned(-1)) { // if it has corresponding edge in another network |
334 | if (I == 0) // if it is to render GT | 314 | if (I == 0) // if it is to render GT |
@@ -343,7 +323,7 @@ public: | @@ -343,7 +323,7 @@ public: | ||
343 | glEnd(); | 323 | glEnd(); |
344 | } | 324 | } |
345 | else { | 325 | else { |
346 | - glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges | 326 | + glColor3f(1.0, 1.0, 1.0); // white color for the un-mapping edges |
347 | glBegin(GL_LINE_STRIP); | 327 | glBegin(GL_LINE_STRIP); |
348 | for (unsigned p = 0; p < E[e].size(); p++) { | 328 | for (unsigned p = 0; p < E[e].size(); p++) { |
349 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); | 329 | glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); |
@@ -353,7 +333,86 @@ public: | @@ -353,7 +333,86 @@ public: | ||
353 | } | 333 | } |
354 | glEndList(); | 334 | glEndList(); |
355 | } | 335 | } |
356 | - glCallList(dlist1); | 336 | + glCallList(dlist + 2); |
337 | + } | ||
338 | + | ||
339 | + void glAdjointCenterline() { | ||
340 | + if (!glIsList(dlist + 4)) { | ||
341 | + glNewList(dlist + 4, GL_COMPILE); | ||
342 | + for (unsigned e = 0; e < E.size(); e++) { //for each edge in the network | ||
343 | + | ||
344 | + glBegin(GL_LINE_STRIP); | ||
345 | + for (unsigned p = 0; p < E[e].size(); p++) { //for each point on that edge | ||
346 | + glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); //set the vertex position based on the current point | ||
347 | + glTexCoord1f(E[e].r(p)); //set the texture coordinate based on the specified magnitude index | ||
348 | + } | ||
349 | + glEnd(); | ||
350 | + } | ||
351 | + glEndList(); | ||
352 | + } | ||
353 | + glCallList(dlist + 4); | ||
354 | + } | ||
355 | + | ||
356 | + // highlight the difference part | ||
357 | + void glDifferenceCylinder(int I, std::vector<unsigned> map, std::vector<T> colormap, float sigma, float radius) { | ||
358 | + | ||
359 | + if (radius != sigma) // if render radius was changed by user, create a new display list | ||
360 | + glDeleteLists(dlist + 6, 1); | ||
361 | + if (!glIsList(dlist + 6)) { // if dlist isn't a display list, create it | ||
362 | + glNewList(dlist + 6, GL_COMPILE); // start a new display list | ||
363 | + for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network | ||
364 | + if (map[e] != unsigned(-1)) { | ||
365 | + glEnable(GL_BLEND); //enable color blend | ||
366 | + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function | ||
367 | + glDisable(GL_DEPTH_TEST); //should disable depth | ||
368 | + | ||
369 | + if (I == 0) { // if it is to render GT | ||
370 | + glColor4f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2], 0.1); | ||
371 | + } | ||
372 | + else { // if it is to render T | ||
373 | + glColor4f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2], 0.1); | ||
374 | + } | ||
375 | + | ||
376 | + for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge | ||
377 | + stim::circle<T> C1 = E[e].circ(p - 1); | ||
378 | + stim::circle<T> C2 = E[e].circ(p); | ||
379 | + C1.set_R(2 * radius); // re-scale the circle to the same | ||
380 | + C2.set_R(2 * radius); | ||
381 | + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); | ||
382 | + std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); | ||
383 | + renderCylinder(Cp1, Cp2, E[e][p - 1], E[e][p]); | ||
384 | + } | ||
385 | + glDisable(GL_BLEND); | ||
386 | + glEnable(GL_DEPTH_TEST); | ||
387 | + } | ||
388 | + else { | ||
389 | + glColor3f(1.0, 1.0, 1.0); // white color for the un-mapping edges | ||
390 | + for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge | ||
391 | + stim::circle<T> C1 = E[e].circ(p - 1); | ||
392 | + stim::circle<T> C2 = E[e].circ(p); | ||
393 | + C1.set_R(2 * radius); // scale the circle to the same | ||
394 | + C2.set_R(2 * radius); | ||
395 | + std::vector< stim::vec3<T> >Cp1 = C1.glpoints(20); | ||
396 | + std::vector< stim::vec3<T> >Cp2 = C2.glpoints(20); | ||
397 | + renderCylinder(Cp1, Cp2, E[e][p - 1], E[e][p]); | ||
398 | + } | ||
399 | + } | ||
400 | + } | ||
401 | + for (unsigned n = 0; n < V.size(); n++) { | ||
402 | + | ||
403 | + size_t num_edge = V[n].e[0].size() + V[n].e[1].size(); | ||
404 | + if (num_edge > 1) { // if it is the joint vertex | ||
405 | + glColor4f(0.3, 0.3, 0.3, 0.1); // gray | ||
406 | + renderBall(V[n][0], V[n][1], V[n][2], 3 * radius, 20); | ||
407 | + } | ||
408 | + else { // if it is the terminal vertex | ||
409 | + glColor4f(0.6, 0.6, 0.6, 0.1); // more white gray | ||
410 | + renderBall(V[n][0], V[n][1], V[n][2], 3 * radius, 20); | ||
411 | + } | ||
412 | + } | ||
413 | + glEndList(); | ||
414 | + } | ||
415 | + glCallList(dlist + 6); | ||
357 | } | 416 | } |
358 | 417 | ||
359 | //void glRandColorCenterlineGT(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap){ | 418 | //void glRandColorCenterlineGT(GLuint &dlist1, std::vector<unsigned> map, std::vector<T> colormap){ |