From 26e84a59a4e13b042d90b2d9f1e0d31695856917 Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Mon, 30 Jan 2017 14:37:14 -0600 Subject: [PATCH] add adjacency_matrix and new way to see information from loaded network --- stim/biomodels/network.h | 25 +++++++++++++++++++++++++ stim/visualization/gl_network.h | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- 2 files changed, 118 insertions(+), 34 deletions(-) diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index 8b804b4..f3f01d1 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -466,6 +466,31 @@ public: } } + /// Get adjacency matrix of the network + std::vector< typename std::vector > get_adj_mat() { + + unsigned n = V.size(); // get the number of vertices in the networks + + std::vector< typename std::vector > result(n, std::vector(n, 0)); // initialize every entry in the matrix to be 0 + result.resize(n); // resize rows + for (unsigned i = 0; i < n; i++) + result[i].resize(n); // resize columns + + for (unsigned i = 0; i < n; i++) { // for every vertex + unsigned num_out = V[i].e[0].size(); // number of outgoing edges of current vertex + if (num_out != 0) { + for (unsigned j = 0; j < num_out; j++) { + int edge_idx = V[i].e[0][j]; // get the jth out-going edge index of current vertex + int vertex_idx = E[edge_idx].v[1]; // get the ending vertex of specific out-going edge + result[i][vertex_idx] = 1; // can simply set to 1 if it is simple-graph + result[vertex_idx][i] = 1; // symmetric + } + } + } + + return result; + } + /// Output the network as a string std::string str(){ diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index cb987f4..e337e74 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -210,9 +210,9 @@ public: void glAdjointCylinder(float sigma, float radius) { if (radius != sigma) // if render radius was changed by user, create a new display list - glDeleteLists(dlist+4, 1); - if (!glIsList(dlist+4)) { - glNewList(dlist+4, GL_COMPILE); + glDeleteLists(dlist + 4, 1); + if (!glIsList(dlist + 4)) { + glNewList(dlist + 4, GL_COMPILE); for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge stim::circle C1 = E[e].circ(p - 1); @@ -241,7 +241,7 @@ public: } glEndList(); } - glCallList(dlist+4); + glCallList(dlist + 4); } ///render the network cylinder as series of tubes @@ -251,9 +251,9 @@ public: void glRandColorCylinder(int I, std::vector map, std::vector colormap, float sigma, float radius) { if (radius != sigma) // if render radius was changed by user, create a new display list - glDeleteLists(dlist+2, 1); - if (!glIsList(dlist+2)) { // if dlist isn't a display list, create it - glNewList(dlist+2, GL_COMPILE); // start a new display list + glDeleteLists(dlist + 2, 1); + if (!glIsList(dlist + 2)) { // if dlist isn't a display list, create it + glNewList(dlist + 2, GL_COMPILE); // start a new display list for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network if (map[e] != unsigned(-1)) { if (I == 0) { // if it is to render GT @@ -274,7 +274,7 @@ public: } } else { - glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges + glColor3f(1.0, 1.0, 1.0); // white color for the un-mapping edges for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge stim::circle C1 = E[e].circ(p - 1); stim::circle C2 = E[e].circ(p); @@ -289,46 +289,26 @@ public: for (unsigned n = 0; n < V.size(); n++) { size_t num_edge = V[n].e[0].size() + V[n].e[1].size(); if (num_edge > 1) { // if it is the joint vertex - if (V[n].e[0].size() != 0) { - unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex - stim::circle C = E[idx].circ(0); - stim::vec3 normal = C.n(); - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector - } - else { - unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex - stim::circle C = E[idx].circ(E[idx].size() - 1); - stim::vec3 normal = C.n(); - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector - } glColor3f(0.3, 0.3, 0.3); // gray renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20); } else { // if it is the terminal vertex - if (V[n].e[0].size() != 0) { - unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex - } - else { - unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex - } glColor3f(0.6, 0.6, 0.6); // more white gray renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20); } } glEndList(); } - glCallList(dlist+2); + glCallList(dlist + 2); } ///render the network centerline as a series of line strips in random different color ///@param I is a indicator: 0 -> GT, 1 -> T - ///@param dlist1 is the display list ///@param map is the mapping relationship between two networks ///@param colormap is the random generated color set for render - void glRandColorCenterline(int I, GLuint &dlist1, std::vector map, std::vector colormap) { - if (!glIsList(dlist1)) { - dlist1 = glGenLists(1); - glNewList(dlist1, GL_COMPILE); + void glRandColorCenterline(int I, std::vector map, std::vector colormap) { + if (!glIsList(dlist + 2)) { + glNewList(dlist + 2, GL_COMPILE); for (unsigned e = 0; e < E.size(); e++) { if (map[e] != unsigned(-1)) { // if it has corresponding edge in another network if (I == 0) // if it is to render GT @@ -343,7 +323,7 @@ public: glEnd(); } else { - glColor3f(0.2, 0.0, 0.0); // red color for the un-mapping edges + glColor3f(1.0, 1.0, 1.0); // white color for the un-mapping edges glBegin(GL_LINE_STRIP); for (unsigned p = 0; p < E[e].size(); p++) { glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); @@ -353,7 +333,86 @@ public: } glEndList(); } - glCallList(dlist1); + glCallList(dlist + 2); + } + + void glAdjointCenterline() { + if (!glIsList(dlist + 4)) { + glNewList(dlist + 4, GL_COMPILE); + for (unsigned e = 0; e < E.size(); e++) { //for each edge in the network + + glBegin(GL_LINE_STRIP); + for (unsigned p = 0; p < E[e].size(); p++) { //for each point on that edge + glVertex3f(E[e][p][0], E[e][p][1], E[e][p][2]); //set the vertex position based on the current point + glTexCoord1f(E[e].r(p)); //set the texture coordinate based on the specified magnitude index + } + glEnd(); + } + glEndList(); + } + glCallList(dlist + 4); + } + + // highlight the difference part + void glDifferenceCylinder(int I, std::vector map, std::vector colormap, float sigma, float radius) { + + if (radius != sigma) // if render radius was changed by user, create a new display list + glDeleteLists(dlist + 6, 1); + if (!glIsList(dlist + 6)) { // if dlist isn't a display list, create it + glNewList(dlist + 6, GL_COMPILE); // start a new display list + for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network + if (map[e] != unsigned(-1)) { + glEnable(GL_BLEND); //enable color blend + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function + glDisable(GL_DEPTH_TEST); //should disable depth + + if (I == 0) { // if it is to render GT + glColor4f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2], 0.1); + } + else { // if it is to render T + glColor4f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2], 0.1); + } + + for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge + stim::circle C1 = E[e].circ(p - 1); + stim::circle C2 = E[e].circ(p); + C1.set_R(2 * radius); // re-scale the circle to the same + C2.set_R(2 * radius); + std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + std::vector< stim::vec3 >Cp2 = C2.glpoints(20); + renderCylinder(Cp1, Cp2, E[e][p - 1], E[e][p]); + } + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + } + else { + glColor3f(1.0, 1.0, 1.0); // white color for the un-mapping edges + for (unsigned p = 1; p < E[e].size(); p++) {// for each point on that edge + stim::circle C1 = E[e].circ(p - 1); + stim::circle C2 = E[e].circ(p); + C1.set_R(2 * radius); // scale the circle to the same + C2.set_R(2 * radius); + std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + std::vector< stim::vec3 >Cp2 = C2.glpoints(20); + renderCylinder(Cp1, Cp2, E[e][p - 1], E[e][p]); + } + } + } + for (unsigned n = 0; n < V.size(); n++) { + + size_t num_edge = V[n].e[0].size() + V[n].e[1].size(); + if (num_edge > 1) { // if it is the joint vertex + glColor4f(0.3, 0.3, 0.3, 0.1); // gray + renderBall(V[n][0], V[n][1], V[n][2], 3 * radius, 20); + } + else { // if it is the terminal vertex + glColor4f(0.6, 0.6, 0.6, 0.1); // more white gray + renderBall(V[n][0], V[n][1], V[n][2], 3 * radius, 20); + } + } + glEndList(); + } + glCallList(dlist + 6); } //void glRandColorCenterlineGT(GLuint &dlist1, std::vector map, std::vector colormap){ -- libgit2 0.21.4