From 30b20d4f70ec82f20ac2c39e70977cae823b453d Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Thu, 12 Jan 2017 17:06:00 -0600 Subject: [PATCH] make it render better for both swc and obj files --- stim/biomodels/network.h | 10 +++++----- stim/math/circle.h | 15 +++++++++++++-- stim/visualization/gl_network.h | 164 ++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------- 3 files changed, 60 insertions(+), 129 deletions(-) diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index d1b33c0..97f34a1 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -144,7 +144,7 @@ protected: std::vector E; //list of edges std::vector V; //list of vertices. - std::vector NT; //stores a list of neuronal type for each point in the centerline (will set value only when centerline is built from swc file) + //std::vector NT; //stores a list of neuronal type for each point in the centerline (will set value only when centerline is built from swc file) public: @@ -396,11 +396,11 @@ public: S.load(filename); // load the node information S.create_tree(); // link those node according to their linking relationships as a tree - NT.push_back(S.node[0].type); // set the neuronal_type value to the first vertex in the network + //NT.push_back(S.node[0].type); // set the neuronal_type value to the first vertex in the network std::vector id2vert; // this list stores the SWC vertex ID associated with each network vertex unsigned i[2]; // temporary, IDs associated with the first and last points for (unsigned int l = 1; l < S.numL(); l++) { // for every node starts from second one - NT.push_back(S.node[l].type); + //NT.push_back(S.node[l].type); stim::centerline c3(2); // every fiber contains two vertices int p_idx = S.node[l].parent_idx - 1; // get the parent node loop idx of current node c3[0] = S.node[p_idx].point; // store the begin vertex @@ -479,7 +479,7 @@ public: stim::network resample(T spacing){ stim::network n; //create a new network that will be an exact copy, with resampled fibers n.V = V; //copy all vertices - n.NT = NT; //copy all the neuronal type information + //n.NT = NT; //copy all the neuronal type information n.E.resize(edges()); //allocate space for the edge list //copy all fibers, resampling them in the process @@ -820,7 +820,7 @@ public: V[V.size() - 1].e[0].push_back((unsigned)E.size() - 1); // push second half edge to the outgoing of new vertex for(unsigned i = 0; i < V[tmp.v[1]].e[1].size(); i++) // find the incoming edge of original ending vertex if(V[tmp.v[1]].e[1][i] == e) - V[tmp.v[1]].e[1][i] = (unsigned)V.size() - 1; + V[tmp.v[1]].e[1][i] = (unsigned)E.size() - 1; // set to new edge } } } diff --git a/stim/math/circle.h b/stim/math/circle.h index 7baaba7..9e94a0f 100644 --- a/stim/math/circle.h +++ b/stim/math/circle.h @@ -193,9 +193,20 @@ public: result[i] = p(i * dt); //calculate a point on the edge of the circle return result; } - - + ///returns a vector with the points on the initialized circle + ///connecting the points results in a circle + ///@param n: integer for the number of points representing the circle + ///the only difference between points and glpoints is that the first point appears twice in the returning lists + std::vector< stim::vec3 > glpoints(unsigned n) { + std::vector< stim::vec3 > result(n + 1); + float dt = stim::TAU / n; + for (unsigned i = 0; i < n; i++) + result[i] = p(i * dt); + result[n] = p(0); //close the circle! + return result; + } + std::string str() const { std::stringstream ss; diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index 0a7f172..2606354 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -87,7 +87,7 @@ public: /// 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() { + /*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 @@ -163,7 +163,7 @@ public: 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 @@ -188,7 +188,7 @@ public: ///render the network cylinder as a series of tubes ///colors are based on metric values - void glCylinder() { + 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 @@ -196,12 +196,12 @@ 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(10); // scale the circle to the same - C2.set_R(10); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); + C1.set_R(3*sigma); // scale the circle to the same + C2.set_R(3*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 + 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)); @@ -209,6 +209,18 @@ public: 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], 3*sigma, 20); + } glEndList(); //end the display list } glCallList(dlist); //render the display list @@ -218,53 +230,7 @@ public: ///@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) { - 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 - for (unsigned e = 0; e < E.size(); e++) { // for each edge in the network - if (map[e] != unsigned(-1)) { - glColor3f(colormap[e * 3 + 0], colormap[e * 3 + 1], colormap[e * 3 + 2]); - 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(10); // scale the circle to the same - C2.set_R(10); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); - renderCylinder(Cp1, Cp2); - } - } - else { - glColor3f(1.0f, 1.0f, 1.0f); // 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(10); // scale the circle to the same - C2.set_R(10); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); - renderCylinder(Cp1, Cp2); - } - } - } - for (unsigned v = 0; v < V.size(); v++) { - 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], 20, 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], 20, 20); - } - } - glEndList(); - } - glCallList(dlist1); - } - - void glRandColorCylinder1_swc(GLuint &dlist1, std::vector map, std::vector colormap) { + void glRandColorCylinder1(GLuint &dlist1, std::vector map, std::vector colormap, float sigma) { 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 @@ -274,10 +240,10 @@ 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(0.5); // scale the circle to the same - C2.set_R(0.5); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); + C1.set_R(3*sigma); // scale the circle to the same + C2.set_R(3*sigma); + std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + std::vector< stim::vec3 >Cp2 = C2.glpoints(20); renderCylinder(Cp1, Cp2); } } @@ -286,10 +252,10 @@ 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(0.5); // scale the circle to the same - C2.set_R(0.5); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); + C1.set_R(3*sigma); // scale the circle to the same + C2.set_R(3*sigma); + std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + std::vector< stim::vec3 >Cp2 = C2.glpoints(20); renderCylinder(Cp1, Cp2); } } @@ -298,11 +264,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], 1, 20); + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 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], 1, 20); + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20); } } glEndList(); @@ -314,53 +280,7 @@ 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) { - 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(10); // scale the circle to the same - C2.set_R(10); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); - renderCylinder(Cp1, Cp2); - } - } - 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(10); // scale the circle to the same - C2.set_R(10); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); - renderCylinder(Cp1, Cp2); - } - } - } - for (unsigned v = 0; v < V.size(); v++) { - 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], 20, 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], 20, 20); - } - } - glEndList(); - } - glCallList(dlist2); - } - - void glRandColorCylinder2_swc(GLuint &dlist2, std::vector map, std::vector colormap) { + void glRandColorCylinder2(GLuint &dlist2, std::vector map, std::vector colormap, float sigma) { if (!glIsList(dlist2)) { dlist2 = glGenLists(1); glNewList(dlist2, GL_COMPILE); @@ -370,10 +290,10 @@ public: 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(0.5); // scale the circle to the same - C2.set_R(0.5); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); + C1.set_R(3*sigma); // scale the circle to the same + C2.set_R(3*sigma); + std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + std::vector< stim::vec3 >Cp2 = C2.glpoints(20); renderCylinder(Cp1, Cp2); } } @@ -382,10 +302,10 @@ public: 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(0.5); // scale the circle to the same - C2.set_R(0.5); - std::vector< stim::vec3 >Cp1 = C1.points(20); - std::vector< stim::vec3 >Cp2 = C2.points(20); + C1.set_R(3*sigma); // scale the circle to the same + C2.set_R(3*sigma); + std::vector< stim::vec3 >Cp1 = C1.glpoints(20); + std::vector< stim::vec3 >Cp2 = C2.glpoints(20); renderCylinder(Cp1, Cp2); } } @@ -394,11 +314,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], 1, 20); + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 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], 1, 20); + renderBall(V[v][0], V[v][1], V[v][2], 6*sigma, 20); } } glEndList(); -- libgit2 0.21.4