Commit 91e2e1ec404c6a308d14e4ba85fdeae0e22ba2ea
1 parent
1657f19c
went to a better way of using the dynamic network
Showing
1 changed file
with
79 additions
and
70 deletions
Show diff stats
stim/gl/gl_spider.h
1 | -#ifndef STIM_GL_SPIDER_H | 1 | + #ifndef STIM_GL_SPIDER_H |
2 | #define STIM_GL_SPIDER_H | 2 | #define STIM_GL_SPIDER_H |
3 | 3 | ||
4 | //#include <GL/glew.h> | 4 | //#include <GL/glew.h> |
@@ -138,7 +138,9 @@ class gl_spider // : public virtual gl_texture<T> | @@ -138,7 +138,9 @@ class gl_spider // : public virtual gl_texture<T> | ||
138 | stim::cuda::cuda_texture t_pos; //cuda_texture object used as an interface between OpenGL and cuda for position vectors. | 138 | stim::cuda::cuda_texture t_pos; //cuda_texture object used as an interface between OpenGL and cuda for position vectors. |
139 | stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. | 139 | stim::cuda::cuda_texture t_mag; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. |
140 | stim::cuda::cuda_texture t_len; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. | 140 | stim::cuda::cuda_texture t_len; //cuda_texture object used as an interface between OpenGL and cuda for size vectors. |
141 | - | 141 | + |
142 | + int last_fiber; //variable that tracks the last fiber hit during tracing. -1 if no fiber was hit. | ||
143 | + | ||
142 | 144 | ||
143 | #ifdef DEBUG | 145 | #ifdef DEBUG |
144 | stringstream name; | 146 | stringstream name; |
@@ -1145,8 +1147,8 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1145,8 +1147,8 @@ class gl_spider // : public virtual gl_texture<T> | ||
1145 | out[3] = temp[2]; | 1147 | out[3] = temp[2]; |
1146 | } | 1148 | } |
1147 | #ifdef DEBUG | 1149 | #ifdef DEBUG |
1148 | - std::cout << "out is " << out << std::endl; | ||
1149 | - std::cout << "when rotating from " << from << " to " << dir << std::endl; | 1150 | +// std::cout << "out is " << out << std::endl; |
1151 | +// std::cout << "when rotating from " << from << " to " << dir << std::endl; | ||
1150 | #endif | 1152 | #endif |
1151 | return out; | 1153 | return out; |
1152 | } | 1154 | } |
@@ -1316,20 +1318,20 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1316,20 +1318,20 @@ class gl_spider // : public virtual gl_texture<T> | ||
1316 | void | 1318 | void |
1317 | saveNetwork(std::string name) | 1319 | saveNetwork(std::string name) |
1318 | { | 1320 | { |
1319 | -/* stim::glObj<float> sk; | 1321 | + stim::glObj<float> sk1; |
1320 | for(int i = 0; i < nt.sizeE(); i++) | 1322 | for(int i = 0; i < nt.sizeE(); i++) |
1321 | { | 1323 | { |
1322 | - std::vector<stim::vec< float > > cm = nt.getEdgeCenterLineMag(i); | 1324 | + std::vector<float> cm = nt.getEdgeCenterLineMag(i); |
1323 | std::vector<stim::vec3< float > > ce = nt.getEdgeCenterLine(i); | 1325 | std::vector<stim::vec3< float > > ce = nt.getEdgeCenterLine(i); |
1324 | sk.Begin(stim::OBJ_LINE); | 1326 | sk.Begin(stim::OBJ_LINE); |
1325 | for(int j = 0; j < ce.size(); j++) | 1327 | for(int j = 0; j < ce.size(); j++) |
1326 | { | 1328 | { |
1327 | - sk.TexCoord(cm[j][0]); | ||
1328 | - sk.Vertex(ce[j][0], ce[j][1], ce[j][2]); | 1329 | + sk1.TexCoord(cm[j]); |
1330 | + sk1.Vertex(ce[j][0], ce[j][1], ce[j][2]); | ||
1329 | } | 1331 | } |
1330 | - sk.End(); | 1332 | + sk1.End(); |
1331 | } | 1333 | } |
1332 | -*/ sk.save(name); | 1334 | + sk1.save(name); |
1333 | } | 1335 | } |
1334 | 1336 | ||
1335 | ///Depreciated, but might be reused later() | 1337 | ///Depreciated, but might be reused later() |
@@ -1517,9 +1519,6 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1517,9 +1519,6 @@ class gl_spider // : public virtual gl_texture<T> | ||
1517 | while(!Empty()) | 1519 | while(!Empty()) |
1518 | { | 1520 | { |
1519 | //clear the currently traced line and start a new one. | 1521 | //clear the currently traced line and start a new one. |
1520 | - cL.clear(); | ||
1521 | - cM.clear(); | ||
1522 | - cD.clear(); | ||
1523 | curSeed = seeds.top(); | 1522 | curSeed = seeds.top(); |
1524 | curSeedVec = seedsvecs.top(); | 1523 | curSeedVec = seedsvecs.top(); |
1525 | curSeedMag = seedsmags.top(); | 1524 | curSeedMag = seedsmags.top(); |
@@ -1539,9 +1538,9 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1539,9 +1538,9 @@ class gl_spider // : public virtual gl_texture<T> | ||
1539 | // findOptimalDirection(); | 1538 | // findOptimalDirection(); |
1540 | // Unbind(); | 1539 | // Unbind(); |
1541 | //THIS IS EXPERIMENTAL | 1540 | //THIS IS EXPERIMENTAL |
1542 | - Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); | ||
1543 | - findOptimalRadius(); | ||
1544 | - Unbind(); | 1541 | +// Bind(radius_texID, radius_buffID, numSamplesMag, n_pixels); |
1542 | +// findOptimalRadius(); | ||
1543 | +// Unbind(); | ||
1545 | //THIS IS EXPERIMENTAL | 1544 | //THIS IS EXPERIMENTAL |
1546 | 1545 | ||
1547 | // cL.push_back(curSeed); | 1546 | // cL.push_back(curSeed); |
@@ -1593,17 +1592,17 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1593,17 +1592,17 @@ class gl_spider // : public virtual gl_texture<T> | ||
1593 | ds[0], ds[1], ds[2], | 1592 | ds[0], ds[1], ds[2], |
1594 | ups[0], ups[1], ups[2]); | 1593 | ups[0], ups[1], ups[2]); |
1595 | ///Set the look at distance | 1594 | ///Set the look at distance |
1596 | - sk.Render(); ///Render the network | ||
1597 | -// nt.Render(); | 1595 | +// sk.Render(); ///Render the network |
1596 | + nt.Render(); | ||
1598 | 1597 | ||
1599 | CHECK_OPENGL_ERROR | 1598 | CHECK_OPENGL_ERROR |
1600 | 1599 | ||
1601 | 1600 | ||
1602 | - glLoadName((int) sk.numL()); ///Load all the names | ||
1603 | -// glLoadName(nt.sizeE()); | 1601 | +// glLoadName((int) sk.numL()); ///Load all the names |
1602 | + glLoadName(nt.sizeE()); | ||
1604 | 1603 | ||
1605 | - sk.RenderLine(cL); ///Render the current line. | ||
1606 | -// nt.RenderLine(cL); | 1604 | +// sk.RenderLine(cL); ///Render the current line. |
1605 | + nt.RenderLine(cL); | ||
1607 | 1606 | ||
1608 | // glPopName(); | 1607 | // glPopName(); |
1609 | glFlush(); ///Flush the buffer | 1608 | glFlush(); ///Flush the buffer |
@@ -1654,55 +1653,51 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1654,55 +1653,51 @@ class gl_spider // : public virtual gl_texture<T> | ||
1654 | cM.clear(); | 1653 | cM.clear(); |
1655 | } | 1654 | } |
1656 | 1655 | ||
1657 | -/* | 1656 | + |
1658 | void | 1657 | void |
1659 | - addToNetwork(pair<stim::fiber<float>, int> in, stim::vec3<float> spos, | ||
1660 | - stim::vec<float> smag, stim::vec3<float> sdir) | 1658 | + addToNetwork(std::vector<stim::vec3<float> > L, std::vector<float > M, stim::vec3<float> spos, stim::vec3<float> sdir, float smag) |
1661 | { | 1659 | { |
1662 | - #ifdef TIMING | ||
1663 | - double s = std::clock(); | ||
1664 | - #endif | ||
1665 | - | ||
1666 | - std::vector<stim::vec3<float> > ce = in.first.centerline(); | ||
1667 | - std::vector<stim::vec<float> > cm = in.first.centerlinemag(); | ||
1668 | //if the fiber is longer than 2 steps (the number it takes to diverge) | 1660 | //if the fiber is longer than 2 steps (the number it takes to diverge) |
1669 | - if(ce.size() > 3) | 1661 | + if(L.size() > 3) |
1670 | { | 1662 | { |
1671 | //if we did not hit a fiber | 1663 | //if we did not hit a fiber |
1672 | - if(in.second == -1) | 1664 | + if(last_fiber == -1) |
1673 | { | 1665 | { |
1674 | - spos[0] = spos[0]-sdir[0]*smag[0]/2.; | ||
1675 | - spos[1] = spos[1]-sdir[1]*smag[0]/2.; | ||
1676 | - spos[2] = spos[2]-sdir[2]*smag[0]/2.; | ||
1677 | - int h = selectObject(spos, -sdir, smag[0]); | 1666 | + spos[0] = spos[0]-sdir[0]*smag; |
1667 | + spos[1] = spos[1]-sdir[1]*smag; | ||
1668 | + spos[2] = spos[2]-sdir[2]*smag; | ||
1669 | + int h = selectObject(spos, -sdir, smag); | ||
1678 | //did we start with a fiber? | 1670 | //did we start with a fiber? |
1679 | if(h != -1 && h < nt.sizeE()) | 1671 | if(h != -1 && h < nt.sizeE()) |
1680 | - nt.addEdge(ce, cm, h, -1); | 1672 | + nt.addEdge(L, M, h, -1); |
1681 | else | 1673 | else |
1682 | - nt.addEdge(ce, cm, -1, -1); | 1674 | + nt.addEdge(L, M, -1, -1); |
1683 | } | 1675 | } |
1684 | //if we hit a fiber? | 1676 | //if we hit a fiber? |
1685 | - else if(in.second != -1) | 1677 | + else if(last_fiber != -1) |
1686 | { | 1678 | { |
1687 | - nt.addEdge(ce,cm,-1, in.second); | ||
1688 | - spos[0] = spos[0]-sdir[0]*smag[0]/2.; | ||
1689 | - spos[1] = spos[1]-sdir[1]*smag[0]/2.; | ||
1690 | - spos[2] = spos[2]-sdir[2]*smag[0]/2.; | ||
1691 | - int h = selectObject(spos, -sdir, smag[0]); | 1679 | + nt.addEdge(L, M, -1, last_fiber); |
1680 | + spos[0] = spos[0]-sdir[0]*smag; | ||
1681 | + spos[1] = spos[1]-sdir[1]*smag; | ||
1682 | + spos[2] = spos[2]-sdir[2]*smag; | ||
1683 | + int h = selectObject(spos, -sdir, smag); | ||
1692 | //did start with a fiber? | 1684 | //did start with a fiber? |
1693 | if(h != -1 && h < nt.sizeE()){ | 1685 | if(h != -1 && h < nt.sizeE()){ |
1694 | // std::cout << "got here double" << smag.str() << std::endl; | 1686 | // std::cout << "got here double" << smag.str() << std::endl; |
1695 | - nt.addEdge(ce,cm, h, in.second); | ||
1696 | - } else { nt.addEdge(ce,cm, -1, -1);} | 1687 | + nt.addEdge(L, M, h, last_fiber); |
1688 | + } | ||
1689 | + else | ||
1690 | + { | ||
1691 | + nt.addEdge(L, M, -1, -1); | ||
1692 | + } | ||
1697 | } | 1693 | } |
1698 | } | 1694 | } |
1699 | 1695 | ||
1700 | - #ifdef TIMING | ||
1701 | - double nt = (std::clock() - s) / (double) CLOCKS_PER_SEC; | ||
1702 | - network_time += nt * 1000.0; | 1696 | + #ifdef DEBUG |
1697 | + iter++; | ||
1703 | #endif | 1698 | #endif |
1704 | } | 1699 | } |
1705 | -*/ | 1700 | +/* |
1706 | void | 1701 | void |
1707 | addToNetwork(std::vector<stim::vec3<float> > L, std::vector<float > M) | 1702 | addToNetwork(std::vector<stim::vec3<float> > L, std::vector<float > M) |
1708 | { | 1703 | { |
@@ -1722,7 +1717,7 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1722,7 +1717,7 @@ class gl_spider // : public virtual gl_texture<T> | ||
1722 | #endif | 1717 | #endif |
1723 | } | 1718 | } |
1724 | } | 1719 | } |
1725 | - | 1720 | +*/ |
1726 | 1721 | ||
1727 | void | 1722 | void |
1728 | printSizes() | 1723 | printSizes() |
@@ -1735,22 +1730,31 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1735,22 +1730,31 @@ class gl_spider // : public virtual gl_texture<T> | ||
1735 | traceLine(stim::vec3<float> pos, float mag, int min_cost) | 1730 | traceLine(stim::vec3<float> pos, float mag, int min_cost) |
1736 | { | 1731 | { |
1737 | //starting (seed) position and magnitude. | 1732 | //starting (seed) position and magnitude. |
1733 | + last_fiber = -1; | ||
1734 | + cL.clear(); | ||
1735 | + cM.clear(); | ||
1736 | + cD.clear(); | ||
1737 | + | ||
1738 | stim::vec3<float> spos = getPosition(); | 1738 | stim::vec3<float> spos = getPosition(); |
1739 | + stim::vec3<float> sdir = getDirection(); | ||
1739 | float smag = getMagnitude(); | 1740 | float smag = getMagnitude(); |
1740 | - stim::vec3<float> sdir = getDirection(); | ||
1741 | 1741 | ||
1742 | -// Bind(); | ||
1743 | -// sk.Begin(stim::OBJ_LINE); | 1742 | + setPosition(pos); |
1743 | + setMagnitude(mag); | ||
1744 | 1744 | ||
1745 | + cL.push_back(p); | ||
1746 | + cD.push_back(d); | ||
1747 | + cM.push_back(m); | ||
1748 | +// stim::vec3<float> spos = getPosition(); | ||
1749 | +// float smag = getMagnitude(); | ||
1750 | +// stim::vec3<float> sdir = getDirection(); | ||
1745 | 1751 | ||
1746 | - sk.createFromSelf(GL_SELECT); | ||
1747 | -// nt.createFromSelf(GL_SELECT); | 1752 | +// Bind(); |
1753 | +// sk.Begin(stim::OBJ_LINE); | ||
1748 | 1754 | ||
1749 | - cL.push_back(pos); | ||
1750 | - cM.push_back(mag); | ||
1751 | 1755 | ||
1752 | -// setPosition(pos); | ||
1753 | -// setMagnitude(mag); | 1756 | + //sk.createFromSelf(GL_SELECT); |
1757 | + nt.createFromSelf(GL_SELECT); | ||
1754 | int h; | 1758 | int h; |
1755 | bool started = false; | 1759 | bool started = false; |
1756 | bool running = true; | 1760 | bool running = true; |
@@ -1761,7 +1765,7 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1761,7 +1765,7 @@ class gl_spider // : public virtual gl_texture<T> | ||
1761 | if (cost > min_cost){ | 1765 | if (cost > min_cost){ |
1762 | running = false; | 1766 | running = false; |
1763 | branchDetection2(); | 1767 | branchDetection2(); |
1764 | - addToNetwork(cL, cM); | 1768 | + addToNetwork(cL, cM, spos, sdir, smag); |
1765 | #ifdef DEBUG | 1769 | #ifdef DEBUG |
1766 | std::cerr << "the cost of " << cost << " > " << min_cost << std::endl; | 1770 | std::cerr << "the cost of " << cost << " > " << min_cost << std::endl; |
1767 | #endif | 1771 | #endif |
@@ -1769,13 +1773,14 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1769,13 +1773,14 @@ class gl_spider // : public virtual gl_texture<T> | ||
1769 | } else { | 1773 | } else { |
1770 | //Have we found the edge of the map? | 1774 | //Have we found the edge of the map? |
1771 | pos = getPosition(); | 1775 | pos = getPosition(); |
1772 | - if(pos[0] > size[0] || pos[1] > size[1] | ||
1773 | - || pos[2] > size[2] || pos[0] < 0 | ||
1774 | - || pos[1] < 0 || pos[2] < 0) | 1776 | + if(p[0] > size[0] || p[1] > size[1] |
1777 | + || p[2] > size[2] || p[0] < 0 | ||
1778 | + || p[1] < 0 || p[2] < 0) | ||
1775 | { | 1779 | { |
1776 | running = false; | 1780 | running = false; |
1777 | branchDetection2(); | 1781 | branchDetection2(); |
1778 | - addToNetwork(cL, cM); | 1782 | + // addToNetwork(cL, cM); |
1783 | + addToNetwork(cL, cM, spos, sdir, smag); | ||
1779 | #ifdef DEBUG | 1784 | #ifdef DEBUG |
1780 | std::cerr << "I hit and edge" << std::endl; | 1785 | std::cerr << "I hit and edge" << std::endl; |
1781 | #endif | 1786 | #endif |
@@ -1790,10 +1795,11 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1790,10 +1795,11 @@ class gl_spider // : public virtual gl_texture<T> | ||
1790 | } | 1795 | } |
1791 | //Has the template size gotten unreasonable? | 1796 | //Has the template size gotten unreasonable? |
1792 | mag = getMagnitude(); | 1797 | mag = getMagnitude(); |
1793 | - if(mag > 75 || mag < 1){ | 1798 | + if(m > 75 || m < 1){ |
1794 | running = false; | 1799 | running = false; |
1795 | branchDetection2(); | 1800 | branchDetection2(); |
1796 | - addToNetwork(cL, cM); | 1801 | + // addToNetwork(cL, cM); |
1802 | + addToNetwork(cL, cM, spos, sdir, smag); | ||
1797 | #ifdef DEBUG | 1803 | #ifdef DEBUG |
1798 | std::cerr << "The templates are too big" << std::endl; | 1804 | std::cerr << "The templates are too big" << std::endl; |
1799 | #endif | 1805 | #endif |
@@ -1807,13 +1813,16 @@ class gl_spider // : public virtual gl_texture<T> | @@ -1807,13 +1813,16 @@ class gl_spider // : public virtual gl_texture<T> | ||
1807 | #ifdef DEBUG | 1813 | #ifdef DEBUG |
1808 | std::cerr << "I hit the fiber " << h << std::endl; | 1814 | std::cerr << "I hit the fiber " << h << std::endl; |
1809 | #endif | 1815 | #endif |
1816 | + last_fiber = h; | ||
1810 | running = false; | 1817 | running = false; |
1811 | branchDetection2(); | 1818 | branchDetection2(); |
1812 | - addToNetwork(cL, cM); | 1819 | + // addToNetwork(cL, cM); |
1820 | + addToNetwork(cL, cM, spos, sdir, smag); | ||
1813 | break; | 1821 | break; |
1814 | } | 1822 | } |
1815 | else { | 1823 | else { |
1816 | - cL.push_back(stim::vec3<float>(p[0], p[1],p[2])); | 1824 | + cL.push_back(p); |
1825 | + cD.push_back(d); | ||
1817 | cM.push_back(m); | 1826 | cM.push_back(m); |
1818 | // Unbind(); | 1827 | // Unbind(); |
1819 | CHECK_OPENGL_ERROR | 1828 | CHECK_OPENGL_ERROR |