From 46a9cc269055e91eff7777a51fb55a83f4b3b57c Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Fri, 13 Jan 2017 14:05:57 -0600 Subject: [PATCH] fix minor errors in getting circle at specific point --- stim/biomodels/centerline.h | 2 +- stim/visualization/gl_network.h | 284 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------- 2 files changed, 168 insertions(+), 118 deletions(-) diff --git a/stim/biomodels/centerline.h b/stim/biomodels/centerline.h index 136aab7..1aa7563 100644 --- a/stim/biomodels/centerline.h +++ b/stim/biomodels/centerline.h @@ -22,7 +22,7 @@ protected: if (size() <= 1) return vec3(0, 0, 0); //if there is insufficient information to calculate the direction, return a null vector if (size() == 2) return (at(1) - at(0)).norm(); //if there are only two points, the direction vector at both is the direction of the line segment if (i == 0) return (at(1) - at(0)).norm(); //the first direction vector is oriented towards the first line segment - if (i == size() - 1) return at(size() - 1) - at(size() - 2); //the last direction vector is oriented towards the last line segment + if (i == size() - 1) return (at(size() - 1) - at(size() - 2)).norm(); //the last direction vector is oriented towards the last line segment //all other direction vectors are the average direction of the two joined line segments vec3 a = at(i) - at(i - 1); diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index 2606354..d2ddbd7 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -85,86 +85,6 @@ public: glCallList(dlist); // render the display list } - /// render the network centerline from swc file as a series of strips in different colors based on the neuronal type - /// glCenterline0_swc is for only one input - /*void glCenterline0_swc() { - if (!glIsList(dlist)) { // if dlist isn't a display list, create it - dlist = glGenLists(1); // generate a display list - glNewList(dlist, GL_COMPILE); // start a new display list - for (unsigned e = 0; e < E.size(); e++) { - int type = NT[e]; // get the neuronal type - switch (type) { - case 0: - glColor3f(1.0f, 1.0f, 1.0f); // white for undefined - 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]); - } - glEnd(); - break; - case 1: - glColor3f(1.0f, 0.0f, 0.0f); // red for soma - 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]); - } - glEnd(); - break; - case 2: - glColor3f(1.0f, 0.5f, 0.0f); // orange for axon - 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]); - } - glEnd(); - break; - case 3: - glColor3f(1.0f, 1.0f, 0.0f); // yellow for undefined - 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]); - } - glEnd(); - break; - case 4: - glColor3f(0.0f, 1.0f, 0.0f); // green for undefined - 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]); - } - glEnd(); - break; - case 5: - glColor3f(0.0f, 1.0f, 1.0f); // verdant for undefined - 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]); - } - glEnd(); - break; - case 6: - glColor3f(0.0f, 0.0f, 1.0f); // blue for undefined - 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]); - } - glEnd(); - break; - case 7: - glColor3f(0.5f, 0.0f, 1.0f); // purple for undefined - 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]); - } - glEnd(); - break; - } - } - glEndList(); //end the display list - } - glCallList(dlist); // render the display list - }*/ - ///render the network centerline as a series of line strips(when loading at least two networks, otherwise using glCenterline0()) ///colors are based on metric values void glCenterline(){ @@ -188,16 +108,19 @@ public: ///render the network cylinder as a series of tubes ///colors are based on metric values - void glCylinder(float sigma) { - if (!glIsList(dlist)) { //if dlist isn't a display list, create it - dlist = glGenLists(1); //generate a display list - glNewList(dlist, GL_COMPILE); //start a new display list - for (unsigned e = 0; e < E.size(); e++) { //for each edge in the network + void glCylinder(float sigma, float radius) { + + if (radius != sigma) // if render radius was changed by user, create a new display list + glDeleteLists(dlist, 1); + if (!glIsList(dlist)) { // if dlist isn't a display list, create it + dlist = glGenLists(1); // generate a display list + glNewList(dlist, GL_COMPILE); // start a new display list + 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); stim::circle C2 = E[e].circ(p); - C1.set_R(3*sigma); // scale the circle to the same - C2.set_R(3*sigma); + 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); glBegin(GL_QUAD_STRIP); @@ -207,30 +130,33 @@ public: glTexCoord1f(E[e].r(p)); } glEnd(); - } //set the texture coordinate based on the specified magnitude index + } // set the texture coordinate based on the specified magnitude index } for (unsigned n = 0; n < V.size(); n++) { - size_t num = V[n].e[0].size(); //store the number of outgoing edge of that vertex - if (num != 0) { //if it has outgoing edge - unsigned idx = V[n].e[0][0]; //find the index of first outgoing edge of that vertex - glTexCoord1f(E[idx].r(0)); //bind the texture as metric of first point on that edge + size_t num = V[n].e[0].size(); // store the number of outgoing edge of that vertex + if (num != 0) { // if it has outgoing edge + unsigned idx = V[n].e[0][0]; // find the index of first outgoing edge of that vertex + glTexCoord1f(E[idx].r(0)); // bind the texture as metric of first point on that edge } else { - unsigned idx = V[n].e[1][0]; //find the index of first incoming edge of that vertex - glTexCoord1f(E[idx].r(E[idx].size() - 1)); //bind the texture as metric of last point on that edge + unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex + glTexCoord1f(E[idx].r(E[idx].size() - 1)); // bind the texture as metric of last point on that edge } - renderBall(V[n][0], V[n][1], V[n][2], 3*sigma, 20); + renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20); } - glEndList(); //end the display list + glEndList(); // end the display list } - glCallList(dlist); //render the display list + glCallList(dlist); // render the display list } ///render the GT network cylinder as series of tubes ///@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 glRandColorCylinder1(GLuint &dlist1, std::vector map, std::vector colormap, float sigma) { + void glRandColorCylinder1(GLuint &dlist1, 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(dlist1, 1); if (!glIsList(dlist1)) { // if dlist1 isn't a display list, create it dlist1 = glGenLists(1); // generate a display list glNewList(dlist1, GL_COMPILE); // start a new display list @@ -240,8 +166,8 @@ public: 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(3*sigma); // scale the circle to the same - C2.set_R(3*sigma); + 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); @@ -252,8 +178,8 @@ public: 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(3*sigma); // scale the circle to the same - C2.set_R(3*sigma); + 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); @@ -264,11 +190,11 @@ public: size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); if (num_edge > 1) { // if it is the joint vertex glColor3f(0.3, 0.3, 0.3); // gray color - renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20); + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20); } else { // if it is the terminal vertex glColor3f(0.6, 0.6, 0.6); // more white gray - renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20); + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20); } } glEndList(); @@ -280,18 +206,21 @@ public: ///@param dlist2 is the display list ///@param map is the mapping relationship between two networks ///@param colormap is the random generated color set for render - void glRandColorCylinder2(GLuint &dlist2, std::vector map, std::vector colormap, float sigma) { + void glRandColorCylinder2(GLuint &dlist2, 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(dlist2, 1); if (!glIsList(dlist2)) { dlist2 = glGenLists(1); glNewList(dlist2, GL_COMPILE); for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network if (map[e] != unsigned(-1)) { glColor3f(colormap[map[e] * 3 + 0], colormap[map[e] * 3 + 1], colormap[map[e] * 3 + 2]); - for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge - stim::circle C1 = E[e].circ(p); - stim::circle C2 = E[e].circ(p + 1); - C1.set_R(3*sigma); // scale the circle to the same - C2.set_R(3*sigma); + for (unsigned p = 1; p < E[e].size(); p++) { // for each point on that edge(except last one) + 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); @@ -299,11 +228,11 @@ public: } else { glColor3f(1.0f, 1.0f, 1.0f); // white color for the un-mapping edges - for (unsigned p = 0; p < E[e].size() - 1; p++) {// for each point on that edge - stim::circle C1 = E[e].circ(p); - stim::circle C2 = E[e].circ(p + 1); - C1.set_R(3*sigma); // scale the circle to the same - C2.set_R(3*sigma); + 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); @@ -314,11 +243,11 @@ public: size_t num_edge = V[v].e[0].size() + V[v].e[1].size(); if (num_edge > 1) { // if it is the joint vertex glColor3f(0.3, 0.3, 0.3); // gray color - renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20); + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20); } else { // if it is the terminal vertex glColor3f(0.6, 0.6, 0.6); // more white gray - renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20); + renderBall(V[v][0], V[v][1], V[v][2], 3*radius, 20); } } glEndList(); @@ -485,6 +414,127 @@ public: // glPopMatrix(); //} + + /// render the network centerline from swc file as a series of strips in different colors based on the neuronal type + /// glCenterline0_swc is for only one input + /*void glCenterline0_swc() { + if (!glIsList(dlist)) { // if dlist isn't a display list, create it + dlist = glGenLists(1); // generate a display list + glNewList(dlist, GL_COMPILE); // start a new display list + for (unsigned e = 0; e < E.size(); e++) { + int type = NT[e]; // get the neuronal type + switch (type) { + case 0: + glColor3f(1.0f, 1.0f, 1.0f); // white for undefined + 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]); + } + glEnd(); + break; + case 1: + glColor3f(1.0f, 0.0f, 0.0f); // red for soma + 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]); + } + glEnd(); + break; + case 2: + glColor3f(1.0f, 0.5f, 0.0f); // orange for axon + 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]); + } + glEnd(); + break; + case 3: + glColor3f(1.0f, 1.0f, 0.0f); // yellow for undefined + 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]); + } + glEnd(); + break; + case 4: + glColor3f(0.0f, 1.0f, 0.0f); // green for undefined + 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]); + } + glEnd(); + break; + case 5: + glColor3f(0.0f, 1.0f, 1.0f); // verdant for undefined + 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]); + } + glEnd(); + break; + case 6: + glColor3f(0.0f, 0.0f, 1.0f); // blue for undefined + 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]); + } + glEnd(); + break; + case 7: + glColor3f(0.5f, 0.0f, 1.0f); // purple for undefined + 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]); + } + glEnd(); + break; + } + } + glEndList(); //end the display list + } + glCallList(dlist); // render the display list + }*/ + + ///render the network cylinder as a series of tubes + ///colors are based on metric values + //void glCylinder(float sigma) { + // if (!glIsList(dlist)) { //if dlist isn't a display list, create it + // dlist = glGenLists(1); //generate a display list + // glNewList(dlist, GL_COMPILE); //start a new display list + // for (unsigned e = 0; e < E.size(); e++) { //for each edge in the network + // for (unsigned p = 1; p < E[e].size() - 1; 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.5*sigma); // scale the circle to the same + // C2.set_R(2.5*sigma); + // std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + // std::vector< stim::vec3 >Cp2 = C2.glpoints(20); + // glBegin(GL_QUAD_STRIP); + // for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) + // glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); + // glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); + // glTexCoord1f(E[e].r(p)); + // } + // glEnd(); + // } //set the texture coordinate based on the specified magnitude index + // } + // for (unsigned n = 0; n < V.size(); n++) { + // size_t num = V[n].e[0].size(); //store the number of outgoing edge of that vertex + // if (num != 0) { //if it has outgoing edge + // unsigned idx = V[n].e[0][0]; //find the index of first outgoing edge of that vertex + // glTexCoord1f(E[idx].r(0)); //bind the texture as metric of first point on that edge + // } + // else { + // unsigned idx = V[n].e[1][0]; //find the index of first incoming edge of that vertex + // glTexCoord1f(E[idx].r(E[idx].size() - 1)); //bind the texture as metric of last point on that edge + // } + // renderBall(V[n][0], V[n][1], V[n][2], 2.5*sigma, 20); + // } + // glEndList(); //end the display list + // } + // glCallList(dlist); //render the display list + //} + }; //end stim::gl_network class }; //end stim namespace -- libgit2 0.21.4