Commit 8c4f5d849ffcac79284407ffc6bee29a3090bd7a

Authored by Pavel Govyadinov
1 parent 26aee9ed

fixed the issue with the seed points, fixed the issue with the no-terminating st…

…atement, this commit is still using ivote due to instability with the LaG version
stim/cuda/branch_detection.cuh
... ... @@ -101,7 +101,7 @@ find_branch(GLint texbufferID, GLenum texType, unsigned int x, unsigned int y)
101 101 unsigned int x_ds = (x + (x % 1 == 0 ? 0:1));
102 102 unsigned int y_ds = (y + (x % 1 == 0 ? 0:1));
103 103 unsigned int bytes_ds = sizeof(float) * x_ds * y_ds;
104   - unsigned int conn = 5;
  104 + unsigned int conn = 10;
105 105 float final_t = 200.0;
106 106 float* cpuTable = (float*) malloc(bytes_table);
107 107 float* cpuCenters = (float*) malloc(bytes_ds);
... ... @@ -111,7 +111,7 @@ find_branch(GLint texbufferID, GLenum texType, unsigned int x, unsigned int y)
111 111  
112 112  
113 113  
114   - test(texbufferID, texType, x, y);
  114 +// test(texbufferID, texType, x, y);
115 115 std::vector<stim::vec<float> > output;
116 116 initCuda(bytes_table, bytes_ds);
117 117  
... ... @@ -124,7 +124,7 @@ find_branch(GLint texbufferID, GLenum texType, unsigned int x, unsigned int y)
124 124 stim::cuda::tex_gaussian_blur2<float>(
125 125 gpuI, sigma, x, y, t.getTexture(), t.getArray()
126 126 );
127   - stim::gpu2image<float>(gpuI, "Blur.jpg", x,y , 0, 255);
  127 +// stim::gpu2image<float>(gpuI, "Blur.jpg", x,y , 0, 255);
128 128 // stim::gpu2image<float>(t.getArray(), "ORIGINAL.jpg", x,y , 0, 255);
129 129 cudaDeviceSynchronize();
130 130  
... ... @@ -149,24 +149,50 @@ find_branch(GLint texbufferID, GLenum texType, unsigned int x, unsigned int y)
149 149  
150 150 cudaDeviceSynchronize();
151 151 stim::cuda::gpu_local_max<float>(gpuCenters, gpuVote, final_t, conn, x, y);
152   - stim::gpu2image<float>(gpuCenters, "Centers.jpg", x, y, 0, 1);
  152 +// stim::gpu2image<float>(gpuCenters, "Centers.jpg", x, y, 0, 1);
153 153 cudaMemcpy(cpuCenters, gpuCenters, bytes_ds, cudaMemcpyDeviceToHost);
154   - stim::cpu2image<float>(cpuCenters, "CentersXPU.jpg", x, y, 0, 1);
155   - std::cout << pixels << " " << x << " " << y << std::endl;
156   - for(int i = 0; i < pixels; i++)
  154 +// stim::cpu2image<float>(cpuCenters, "CentersXPU.jpg", x, y, 0, 1);
  155 +// std::cerr << pixels << " " << x << " " << y << std::endl;
  156 +// std::cerr << "y is " << y << ", x is " << x << std::endl;
  157 +
  158 +// std::cout << "Before " << output.size() << std::endl;
  159 +
  160 + for(int i = 0; i < x; i++)
  161 + {
  162 + for(int j = 0; j < y; j++)
  163 + {
  164 + int idx = x*j+i;
  165 + if(cpuCenters[idx] != 0)
  166 + {
  167 + float x_v = (float) i;
  168 + float y_v = (float) j;
  169 + std::cout << x_v/x*360.0 << std::endl;
  170 + std::cout << y_v/y << std::endl;
  171 + output.push_back(stim::vec<float>((x_v/(float)x*360.0),
  172 + (y_v), y_v/8));
  173 + }
  174 +
  175 + }
  176 + }
  177 +
  178 +/* for(int i = 0; i < pixels; i++)
157 179 {
158 180 int ix = (i % x);
159 181 int iy = (i / x);
160   - if((cpuCenters[i] == 1))
  182 + if(cpuCenters[i] != 0)
161 183 {
162 184  
163 185 float x_v = (float) ix;
164 186 float y_v = (float) iy;
  187 + std::cout << x_v/x*360 << std::endl;
  188 + std::cout << y_v/y << std::endl;
165 189 output.push_back(stim::vec<float>((x_v/(float)x*360),
166 190 (y_v/(float)y), 0.0));
167 191  
168 192 }
169   - }
  193 + } */
  194 +
  195 +// std::cout << "After " << output.size() << std::endl;
170 196  
171 197  
172 198 t.UnmapCudaTexture();
... ...
stim/gl/gl_spider.h
... ... @@ -229,24 +229,49 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
229 229 DrawLongCylinder(n, l_template, l_square);
230 230 stim::cylinder<float> cyl(cL, cM);
231 231 std::vector< stim::vec<float> > result = find_branch(btexbufferID, GL_TEXTURE_2D, n*l_square, (cL.size()-1)*l_template);
  232 + stim::vec<float> size(S[0]*R[0], S[1]*R[1], S[2]*R[2]);
  233 + float pval;
232 234 // std::cerr << "the number of points is " << result.size() << std::endl;
233 235 if(!result.empty())
234 236 {
235 237 for(int i = 0; i < result.size(); i++)
236 238 {
237   - std::cout << "Testing "<< i << ": " << result[i][0] << ", " << result[i][1] << std::endl;
238   - stim::vec<float> v = cyl.surf(result[i][1], result[i][0]);
  239 + int id = result[i][2];
  240 + if(fmod(result[i][2], id) != 0 && id != 0)
  241 + {
  242 +
  243 + pval = ((cyl.getl(id+1)-cyl.getl(id))*
  244 + (fmod(result[i][2], id))+cyl.getl(id))/cyl.getl(cL.size()-1);
  245 +// std::cout << id << " " << cyl.getl(id) << " " << pval << " " << cyl.getl(cL.size()-1) << fmod(result[i][2], id) << std::endl;
  246 + }
  247 + else if(id == 0)
  248 + {
  249 + pval = (cyl.getl(id+1)*result[i][2])/cyl.getl(cL.size()-1);
  250 + }
  251 + else
  252 + {
  253 + pval = (cyl.getl(id)/cyl.getl(cL.size()-1));
  254 + }
  255 +// std::cout << "Testing "<< i << ": " << result[i][0] << ", " << result[i][1] << ", " << result[i][2] << std::endl;
  256 +// std::cout << "Testing " << pval << std::endl;
  257 + stim::vec<float> v = cyl.surf(pval, result[i][0]);
239 258 // std::cout << v[0] << " ," << v[1] << " ," << v[2] << std::endl;
240   - stim::vec<float> di = cyl.p(result[i][1]);
241   - std::cout << di[0] << " ," << di[1] << " ," << di[2] << std::endl;
242   - float rad = cyl.r(result[i][1]);
243   -// std::cout << rad << std::endl;
244   - setSeed(v);
245   - setSeedVec(stim::vec<float>(-di[0]+v[0], -di[1]+v[1], -di[2]+v[2]).norm());
246   - setSeedMag(cyl.r(result[i][1]));
  259 + stim::vec<float> di = cyl.p(pval);
  260 +// std::cout << di[0] << " ," << di[1] << " ," << di[2] << std::endl;
  261 + float rad = cyl.r(pval);
  262 + std::cout << rad << std::endl;
  263 + if(
  264 + !(v[0] > size[0] || v[1] > size[1]
  265 + || v[2] > size[2] || v[0] < 0
  266 + || v[1] < 0 || v[2] < 0))
  267 + {
  268 + setSeed(v);
  269 + setSeedVec((v-di).norm());
  270 + setSeedMag(rad);
  271 + }
247 272 }
248 273 }
249   - std::cout << "I ran the new branch detection" << std::endl;
  274 +// std::cout << "I ran the new branch detection" << std::endl;
250 275 }
251 276 }
252 277  
... ... @@ -1264,6 +1289,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1264 1289 glEndList();
1265 1290 }
1266 1291  
  1292 +///need to return the cylinder.
1267 1293 void
1268 1294 DrawLongCylinder(int n = 8, int l_template = 8,int l_square = 8)
1269 1295 {
... ... @@ -1590,6 +1616,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1590 1616 {
1591 1617 int cost = Step();
1592 1618 if (cost > min_cost){
  1619 + std::cout << "Cost Limit" << std::endl;
1593 1620 running = false;
1594 1621 sk.End();
1595 1622 branchDetection2();
... ... @@ -1604,6 +1631,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1604 1631 || pos[2] > size[2] || pos[0] < 0
1605 1632 || pos[1] < 0 || pos[2] < 0)
1606 1633 {
  1634 + std::cout << "Edge Limit" << std::endl;
1607 1635 // std::cout << "Found Edge" << std::endl;
1608 1636 running = false;
1609 1637 sk.End();
... ... @@ -1624,7 +1652,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1624 1652 //Has the template size gotten unreasonable?
1625 1653 mag = getMagnitude();
1626 1654 if(mag[0] > 75 || mag[0] < 1){
1627   -// std::cout << "Magnitude Limit" << std::endl;
  1655 + std::cout << "Magnitude Limit" << std::endl;
1628 1656 running = false;
1629 1657 sk.End();
1630 1658 branchDetection2();
... ... @@ -1638,6 +1666,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
1638 1666 h = selectObject(p, getDirection(), m[0]);
1639 1667 //Have we hit something previously traced?
1640 1668 if(h != -1){
  1669 + std::cout << "Hit Limit" << std::endl;
1641 1670 running = false;
1642 1671 sk.End();
1643 1672 branchDetection2();
... ...
stim/visualization/cylinder.h
... ... @@ -12,8 +12,7 @@ class cylinder
12 12 {
13 13 private:
14 14 stim::circle<T> s; //an arbitrary circle
15   - std::vector< stim::vec<T> > pos; //positions of the cylinder.
16   - std::vector< stim::vec<T> > mags; //radii at each position
  15 + std::vector<stim::circle<T> > e;
17 16 std::vector< T > L; //length of the cylinder at each position.
18 17  
19 18 ///default init
... ... @@ -27,18 +26,44 @@ class cylinder
27 26 void
28 27 init(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM)
29 28 {
30   - pos = inP;
31   - mags = inM;
  29 +// pos = inP;
  30 +// mags = inM;
  31 + stim::vec<float> v1;
  32 + stim::vec<float> v2;
  33 + e.resize(inP.size());
  34 + if(inP.size() < 2)
  35 + return;
32 36  
33 37 //calculate each L.
34   - L.resize(pos.size());
  38 + L.resize(inP.size());
35 39 T temp = (T)0;
36 40 L[0] = 0;
37 41 for(int i = 1; i < L.size(); i++)
38 42 {
39   - temp += (pos[i-1] - pos[i]).len();
  43 + temp += (inP[i-1] - inP[i]).len();
40 44 L[i] = temp;
41 45 }
  46 +
  47 + stim::vec<T> dr = (inP[1] - inP[0]).norm();
  48 + s = stim::circle<T>(inP[0], inM[0][0], dr, stim::vec<T>(1,0,0));
  49 + e[0] = s;
  50 + for(int i = 1; i < inP.size()-1; i++)
  51 + {
  52 + s.center(inP[i]);
  53 + v1 = (inP[i] - inP[i-1]).norm();
  54 + v2 = (inP[i+1] - inP[i]).norm();
  55 + dr = (v1+v2).norm();
  56 + s.normal(dr);
  57 + s.scale(inM[i][0]/inM[i-1][0]);
  58 + e[i] = s;
  59 + }
  60 +
  61 + int j = inP.size()-1;
  62 + s.center(inP[j]);
  63 + dr = (inP[j] - inP[j-1]).norm();
  64 + s.normal(dr);
  65 + s.scale(inM[j][0]/inM[j-1][0]);
  66 + e[j] = s;
42 67 }
43 68  
44 69 ///returns the direction vector at point idx.
... ... @@ -47,33 +72,38 @@ class cylinder
47 72 {
48 73 if(idx == 0)
49 74 {
50   - return (pos[idx+1] - pos[idx]).norm();
  75 + return (e[idx+1].P - e[idx].P).norm();
51 76 }
52   - else if(idx == pos.size()-1)
  77 + else if(idx == e.size()-1)
53 78 {
54   - return (pos[idx] - pos[idx-1]).norm();
  79 + return (e[idx].P - e[idx-1].P).norm();
55 80 }
56 81 else
57 82 {
58   - stim::vec<float> v1 = (pos[idx]-pos[idx-1]).norm();
59   - stim::vec<float> v2 = (pos[idx+1]-pos[idx]).norm();
  83 +// return (e[idx+1].P - e[idx].P).norm();
  84 + stim::vec<float> v1 = (e[idx].P-e[idx-1].P).norm();
  85 + stim::vec<float> v2 = (e[idx+1].P-e[idx].P).norm();
60 86 return (v1+v2).norm();
61   - }
62   -
  87 + }
  88 + // return e[idx].N;
  89 +
63 90 }
64 91  
65   - ///returns the total length of the line at index j.
66   - T
67   - getl(int j)
  92 + stim::vec<T>
  93 + d(T l, int idx)
68 94 {
69   - T temp = (T) 0;
70   - for(int i = 0; i < j; ++i)
  95 + if(idx == 0 || idx == e.size()-1)
71 96 {
72   - temp += (pos[i] - pos[i+1]).len();
73   - L[i] = temp;
  97 + return e[idx].N;
74 98 }
  99 + else
  100 + {
  101 + T rat = (l-L[idx])/(L[idx+1]-L[idx]);
  102 + return( e[idx].N + (e[idx+1].N - e[idx].N)*rat);
  103 + }
75 104 }
76 105  
  106 +
77 107 ///finds the index of the point closest to the length l on the lower bound.
78 108 ///binary search.
79 109 int
... ... @@ -82,26 +112,22 @@ class cylinder
82 112 unsigned int i = L.size()/2;
83 113 unsigned int max = L.size()-1;
84 114 unsigned int min = 0;
85   -// std::cerr << "Index initially: " << i << std::endl;
86   -// std::cerr << "l initially: " << l << std::endl;
87 115 while(i > 0 && i < L.size()-1)
88 116 {
89   -// std::cerr << "L[i] = " << L[i] << " i= " << i << " maxval= " << L.size()-1 << std::endl;
  117 +// std::cerr << "Trying " << i << std::endl;
  118 +// std::cerr << "l is " << l << ", L[" << i << "]" << L[i] << std::endl;
90 119 if(l < L[i])
91 120 {
92 121 max = i;
93   -// std::cerr << l << " < " << L[i] << "so max is set to " << i << " and the new i is " << min+(max-min)/2 << std::endl;
94 122 i = min+(max-min)/2;
95 123 }
96 124 else if(L[i] <= l && L[i+1] >= l)
97 125 {
98   -// std::cerr << L[i] << " < " << l << " < " << L[i+1] << std::endl;
99 126 break;
100 127 }
101 128 else
102 129 {
103 130 min = i;
104   -// std::cerr << l << " > " << L[i] << "so min is set to " << i << " and the new i is " << min+(max-min)/2 << std::endl;
105 131 i = min+(max-min)/2;
106 132 }
107 133 }
... ... @@ -137,7 +163,7 @@ class cylinder
137 163 T l = pvalue*L[L.size()-1];
138 164 int idx = findIdx(l);
139 165 T rat = (l-L[idx])/(L[idx+1]-L[idx]);
140   - return( pos[idx] + (pos[idx+1]-pos[idx])*rat);
  166 + return( e[idx].P + (e[idx+1].P-e[idx].P)*rat);
141 167 }
142 168  
143 169 ///Returns a position vector at the given length into the fiber (based on the pvalue).
... ... @@ -148,7 +174,7 @@ class cylinder
148 174 p(T l, int idx)
149 175 {
150 176 T rat = (l-L[idx])/(L[idx+1]-L[idx]);
151   - return( pos[idx] + (pos[idx+1]-pos[idx])*rat);
  177 + return( e[idx].P + (e[idx+1].P-e[idx].P)*rat);
152 178 // return(
153 179 // return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
154 180 }
... ... @@ -163,7 +189,7 @@ class cylinder
163 189 return;
164 190 T l = pvalue*L[L.size()-1];
165 191 int idx = findIdx(l);
166   - return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])))[0];
  192 + return (e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*((l-L[idx])/(L[idx+1]- L[idx])));
167 193 }
168 194  
169 195 ///Returns a radius at the given length into the fiber (based on the pvalue).
... ... @@ -174,7 +200,7 @@ class cylinder
174 200 r(T l, int idx)
175 201 {
176 202 T rat = (l-L[idx])/(L[idx+1]-L[idx]);
177   - return( mags[idx] + (mags[idx+1]-mags[idx])*rat)[0];
  203 + return( e[idx].U.len() + (e[idx+1].U.len() - e[idx].U.len())*rat);
178 204 // return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])))[0];
179 205 }
180 206  
... ... @@ -197,8 +223,10 @@ class cylinder
197 223 // std::cerr << "Index: " << idx << std::endl;
198 224 stim::vec<T> ps = p(l, idx);
199 225 T m = r(l, idx);
200   - stim::vec<T> dr = d(idx);
201   - s = stim::circle<T>(ps, m, dr, stim::vec<T>(1,0,0));
  226 + s = e[idx];
  227 + s.center(ps);
  228 + s.normal(d(l, idx));
  229 + s.scale(m/e[idx].U.len());
202 230 return(s.p(theta));
203 231 }
204 232 }
... ... @@ -208,29 +236,13 @@ class cylinder
208 236 std::vector<std::vector<vec<T> > >
209 237 getPoints(int sides)
210 238 {
211   - if(pos.size() < 2)
  239 + std::vector<std::vector <vec<T> > > points;
  240 + points.resize(e.size());
  241 + for(int i = 0; i < e.size(); i++)
212 242 {
213   - return;
214   - } else {
215   - std::vector<std::vector <vec<T> > > points;
216   - points.resize(pos.size());
217   - stim::vec<T> dr = (pos[1] - pos[0]).norm();
218   - s = stim::circle<T>(pos[0], mags[0][0], dr, stim::vec<T>(1,0,0));
219   - points[0] = s.getPoints(sides);
220   - for(int i = 1; i < pos.size(); i++)
221   - {
222   - dr = d(i);
223   -// dr = (pos[i-1] - pos[i]).norm();
224   -
225   -// s = stim::circle<T>(pos[i], mags[i][0], dr, stim::vec<T>(1,0,0));
226   - s.center(pos[i]);
227   - s.normal(dr);
228   -// s.scale(mags[i][0]/mags[i-1][0], mags[i][0]/mags[i-1][0]);
229   - s.scale(mags[i][0]/mags[i-1][0]);
230   - points[i] = s.getPoints(sides);
231   - }
232   - return points;
  243 + points[i] = e[i].getPoints(sides);
233 244 }
  245 + return points;
234 246 }
235 247  
236 248 void
... ... @@ -238,6 +250,13 @@ class cylinder
238 250 {
239 251 std::cout << d(idx) << std::endl;
240 252 }
  253 +
  254 + ///returns the total length of the line at index j.
  255 + T
  256 + getl(int j)
  257 + {
  258 + return (L[j]);
  259 + }
241 260  
242 261 };
243 262  
... ...