diff --git a/stim/gl/gl_spider.h b/stim/gl/gl_spider.h index 7c5d5d5..e02412d 100644 --- a/stim/gl/gl_spider.h +++ b/stim/gl/gl_spider.h @@ -1,4 +1,4 @@ -#ifndef STIM_GL_SPIDER_H + #ifndef STIM_GL_SPIDER_H #define STIM_GL_SPIDER_H //#include @@ -138,7 +138,9 @@ class gl_spider // : public virtual gl_texture stim::cuda::cuda_texture t_pos; //cuda_texture object used as an interface between OpenGL and cuda for position vectors. stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. stim::cuda::cuda_texture t_len; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. - + + int last_fiber; //variable that tracks the last fiber hit during tracing. -1 if no fiber was hit. + #ifdef DEBUG stringstream name; @@ -1145,8 +1147,8 @@ class gl_spider // : public virtual gl_texture out[3] = temp[2]; } #ifdef DEBUG - std::cout << "out is " << out << std::endl; - std::cout << "when rotating from " << from << " to " << dir << std::endl; +// std::cout << "out is " << out << std::endl; +// std::cout << "when rotating from " << from << " to " << dir << std::endl; #endif return out; } @@ -1316,20 +1318,20 @@ class gl_spider // : public virtual gl_texture void saveNetwork(std::string name) { -/* stim::glObj sk; + stim::glObj sk1; for(int i = 0; i < nt.sizeE(); i++) { - std::vector > cm = nt.getEdgeCenterLineMag(i); + std::vector cm = nt.getEdgeCenterLineMag(i); std::vector > ce = nt.getEdgeCenterLine(i); sk.Begin(stim::OBJ_LINE); for(int j = 0; j < ce.size(); j++) { - sk.TexCoord(cm[j][0]); - sk.Vertex(ce[j][0], ce[j][1], ce[j][2]); + sk1.TexCoord(cm[j]); + sk1.Vertex(ce[j][0], ce[j][1], ce[j][2]); } - sk.End(); + sk1.End(); } -*/ sk.save(name); + sk1.save(name); } ///Depreciated, but might be reused later() @@ -1517,9 +1519,6 @@ class gl_spider // : public virtual gl_texture while(!Empty()) { //clear the currently traced line and start a new one. - cL.clear(); - cM.clear(); - cD.clear(); curSeed = seeds.top(); curSeedVec = seedsvecs.top(); curSeedMag = seedsmags.top(); @@ -1539,9 +1538,9 @@ class gl_spider // : public virtual gl_texture // findOptimalDirection(); // Unbind(); //THIS IS EXPERIMENTAL - Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); - findOptimalRadius(); - Unbind(); +// Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); +// findOptimalRadius(); +// Unbind(); //THIS IS EXPERIMENTAL // cL.push_back(curSeed); @@ -1593,17 +1592,17 @@ class gl_spider // : public virtual gl_texture ds[0], ds[1], ds[2], ups[0], ups[1], ups[2]); ///Set the look at distance - sk.Render(); ///Render the network -// nt.Render(); +// sk.Render(); ///Render the network + nt.Render(); CHECK_OPENGL_ERROR - glLoadName((int) sk.numL()); ///Load all the names -// glLoadName(nt.sizeE()); +// glLoadName((int) sk.numL()); ///Load all the names + glLoadName(nt.sizeE()); - sk.RenderLine(cL); ///Render the current line. -// nt.RenderLine(cL); +// sk.RenderLine(cL); ///Render the current line. + nt.RenderLine(cL); // glPopName(); glFlush(); ///Flush the buffer @@ -1654,55 +1653,51 @@ class gl_spider // : public virtual gl_texture cM.clear(); } -/* + void - addToNetwork(pair, int> in, stim::vec3 spos, - stim::vec smag, stim::vec3 sdir) + addToNetwork(std::vector > L, std::vector M, stim::vec3 spos, stim::vec3 sdir, float smag) { - #ifdef TIMING - double s = std::clock(); - #endif - - std::vector > ce = in.first.centerline(); - std::vector > cm = in.first.centerlinemag(); //if the fiber is longer than 2 steps (the number it takes to diverge) - if(ce.size() > 3) + if(L.size() > 3) { //if we did not hit a fiber - if(in.second == -1) + if(last_fiber == -1) { - spos[0] = spos[0]-sdir[0]*smag[0]/2.; - spos[1] = spos[1]-sdir[1]*smag[0]/2.; - spos[2] = spos[2]-sdir[2]*smag[0]/2.; - int h = selectObject(spos, -sdir, smag[0]); + spos[0] = spos[0]-sdir[0]*smag; + spos[1] = spos[1]-sdir[1]*smag; + spos[2] = spos[2]-sdir[2]*smag; + int h = selectObject(spos, -sdir, smag); //did we start with a fiber? if(h != -1 && h < nt.sizeE()) - nt.addEdge(ce, cm, h, -1); + nt.addEdge(L, M, h, -1); else - nt.addEdge(ce, cm, -1, -1); + nt.addEdge(L, M, -1, -1); } //if we hit a fiber? - else if(in.second != -1) + else if(last_fiber != -1) { - nt.addEdge(ce,cm,-1, in.second); - spos[0] = spos[0]-sdir[0]*smag[0]/2.; - spos[1] = spos[1]-sdir[1]*smag[0]/2.; - spos[2] = spos[2]-sdir[2]*smag[0]/2.; - int h = selectObject(spos, -sdir, smag[0]); + nt.addEdge(L, M, -1, last_fiber); + spos[0] = spos[0]-sdir[0]*smag; + spos[1] = spos[1]-sdir[1]*smag; + spos[2] = spos[2]-sdir[2]*smag; + int h = selectObject(spos, -sdir, smag); //did start with a fiber? if(h != -1 && h < nt.sizeE()){ // std::cout << "got here double" << smag.str() << std::endl; - nt.addEdge(ce,cm, h, in.second); - } else { nt.addEdge(ce,cm, -1, -1);} + nt.addEdge(L, M, h, last_fiber); + } + else + { + nt.addEdge(L, M, -1, -1); + } } } - #ifdef TIMING - double nt = (std::clock() - s) / (double) CLOCKS_PER_SEC; - network_time += nt * 1000.0; + #ifdef DEBUG + iter++; #endif } -*/ +/* void addToNetwork(std::vector > L, std::vector M) { @@ -1722,7 +1717,7 @@ class gl_spider // : public virtual gl_texture #endif } } - +*/ void printSizes() @@ -1735,22 +1730,31 @@ class gl_spider // : public virtual gl_texture traceLine(stim::vec3 pos, float mag, int min_cost) { //starting (seed) position and magnitude. + last_fiber = -1; + cL.clear(); + cM.clear(); + cD.clear(); + stim::vec3 spos = getPosition(); + stim::vec3 sdir = getDirection(); float smag = getMagnitude(); - stim::vec3 sdir = getDirection(); -// Bind(); -// sk.Begin(stim::OBJ_LINE); + setPosition(pos); + setMagnitude(mag); + cL.push_back(p); + cD.push_back(d); + cM.push_back(m); +// stim::vec3 spos = getPosition(); +// float smag = getMagnitude(); +// stim::vec3 sdir = getDirection(); - sk.createFromSelf(GL_SELECT); -// nt.createFromSelf(GL_SELECT); +// Bind(); +// sk.Begin(stim::OBJ_LINE); - cL.push_back(pos); - cM.push_back(mag); -// setPosition(pos); -// setMagnitude(mag); + //sk.createFromSelf(GL_SELECT); + nt.createFromSelf(GL_SELECT); int h; bool started = false; bool running = true; @@ -1761,7 +1765,7 @@ class gl_spider // : public virtual gl_texture if (cost > min_cost){ running = false; branchDetection2(); - addToNetwork(cL, cM); + addToNetwork(cL, cM, spos, sdir, smag); #ifdef DEBUG std::cerr << "the cost of " << cost << " > " << min_cost << std::endl; #endif @@ -1769,13 +1773,14 @@ class gl_spider // : public virtual gl_texture } else { //Have we found the edge of the map? pos = getPosition(); - if(pos[0] > size[0] || pos[1] > size[1] - || pos[2] > size[2] || pos[0] < 0 - || pos[1] < 0 || pos[2] < 0) + if(p[0] > size[0] || p[1] > size[1] + || p[2] > size[2] || p[0] < 0 + || p[1] < 0 || p[2] < 0) { running = false; branchDetection2(); - addToNetwork(cL, cM); + // addToNetwork(cL, cM); + addToNetwork(cL, cM, spos, sdir, smag); #ifdef DEBUG std::cerr << "I hit and edge" << std::endl; #endif @@ -1790,10 +1795,11 @@ class gl_spider // : public virtual gl_texture } //Has the template size gotten unreasonable? mag = getMagnitude(); - if(mag > 75 || mag < 1){ + if(m > 75 || m < 1){ running = false; branchDetection2(); - addToNetwork(cL, cM); + // addToNetwork(cL, cM); + addToNetwork(cL, cM, spos, sdir, smag); #ifdef DEBUG std::cerr << "The templates are too big" << std::endl; #endif @@ -1807,13 +1813,16 @@ class gl_spider // : public virtual gl_texture #ifdef DEBUG std::cerr << "I hit the fiber " << h << std::endl; #endif + last_fiber = h; running = false; branchDetection2(); - addToNetwork(cL, cM); + // addToNetwork(cL, cM); + addToNetwork(cL, cM, spos, sdir, smag); break; } else { - cL.push_back(stim::vec3(p[0], p[1],p[2])); + cL.push_back(p); + cD.push_back(d); cM.push_back(m); // Unbind(); CHECK_OPENGL_ERROR -- libgit2 0.21.4