Commit 385d2447fe1df96d07a60a6856c8189019445d32

Authored by Pavel Govyadinov
1 parent 5f81932b

Checkpoint: Converted the previous version of the code to a more seperable versi…

…on with each function doing a seperate job. Renamed the series of 'sample' methods and changed what they do. The vector arrays are now owned by the spider class, and the previously-named 'sample' functions fill in the arrays with vectors. Update() has been renamed into genTemplate and now maps from the TissueSpace to bufferSpace. Some new comments for the documentation
@@ -2,8 +2,6 @@ @@ -2,8 +2,6 @@
2 #include <cuda.h> 2 #include <cuda.h>
3 #include <cuda_runtime.h> 3 #include <cuda_runtime.h>
4 #include <cublas_v2.h> 4 #include <cublas_v2.h>
5 -//#include "cuPrintf.cu"  
6 -//#include "cuPrintf.cuh"  
7 #include <stdio.h> 5 #include <stdio.h>
8 #include "../visualization/colormap.h" 6 #include "../visualization/colormap.h"
9 #include <sstream> 7 #include <sstream>
@@ -11,9 +9,6 @@ @@ -11,9 +9,6 @@
11 #define DIM_Y 10890 9 #define DIM_Y 10890
12 #define DIM_X 20 10 #define DIM_X 20
13 typedef unsigned char uchar; 11 typedef unsigned char uchar;
14 -//surface<void, 2> texOut; ///// maybe just do a normal array instead of a surface.  
15 - //we may not need a surface at all.  
16 -//texture<float, cudaTextureType2D, cudaReadModeElementType> texTemplate  
17 texture<uchar, cudaTextureType2D, cudaReadModeElementType> texIn; 12 texture<uchar, cudaTextureType2D, cudaReadModeElementType> texIn;
18 float *result; 13 float *result;
19 float* v_dif; 14 float* v_dif;
@@ -66,11 +61,9 @@ void get_diff (float *result) @@ -66,11 +61,9 @@ void get_diff (float *result)
66 float valIn = tex2D(texIn, x, y)/255.0; 61 float valIn = tex2D(texIn, x, y)/255.0;
67 float valTemp = Template(x); 62 float valTemp = Template(x);
68 result[idx] = abs(valIn-valTemp); 63 result[idx] = abs(valIn-valTemp);
69 - //result[idx] = abs(valTemp);  
70 // #if __CUDA_ARCH__>=200 64 // #if __CUDA_ARCH__>=200
71 // printf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); 65 // printf("Value is : %f\n and the result is : %f\n", valIn, result[idx]);
72 // #endif 66 // #endif
73 - //cuPrintf("Value is : %f\n and the result is : %f\n", valIn, result[idx]);  
74 } 67 }
75 68
76 69
@@ -128,7 +121,6 @@ int get_cost(cudaGraphicsResource_t src, int inter) @@ -128,7 +121,6 @@ int get_cost(cudaGraphicsResource_t src, int inter)
128 initArray(src); 121 initArray(src);
129 dim3 grid(20, 10890); 122 dim3 grid(20, 10890);
130 dim3 block(1, 1); 123 dim3 block(1, 1);
131 - //texIn.normalized = 1;  
132 get_diff <<< grid, block >>> (result); 124 get_diff <<< grid, block >>> (result);
133 stim::gpu2image<float>(result, "test.bmp", 20,10890,0,1); 125 stim::gpu2image<float>(result, "test.bmp", 20,10890,0,1);
134 for (int i = 0; i < 1089; i++){ 126 for (int i = 0; i < 1089; i++){
@@ -136,19 +128,11 @@ int get_cost(cudaGraphicsResource_t src, int inter) @@ -136,19 +128,11 @@ int get_cost(cudaGraphicsResource_t src, int inter)
136 if(output[i] <= mini){ 128 if(output[i] <= mini){
137 mini = output[i]; 129 mini = output[i];
138 idx = i; 130 idx = i;
139 -// if(!testing)  
140 -  
141 -// testing = true;  
142 - } //float* out = (float*) malloc(sizeof(float)); 131 + }
143 } 132 }
144 name << "sample_" << inter << "_" << idx << ".bmp"; 133 name << "sample_" << inter << "_" << idx << ".bmp";
145 output[idx] = get_sum(result+(20*10*idx)); 134 output[idx] = get_sum(result+(20*10*idx));
146 stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1); 135 stim::gpu2image<float>(v_dif, name.str(), 20,10,0,1);
147 - std::cout << output[0] << std::endl;  
148 - std::cout << output[100] << std::endl;  
149 - std::cout << output[500] << std::endl;  
150 - std::cout << output[1000] << std::endl;  
151 - std::cout << idx << std::endl;  
152 cleanUP(src); 136 cleanUP(src);
153 return idx; 137 return idx;
154 } 138 }
stim/gl/gl_spider.h
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 #include "../math/rect.h" 14 #include "../math/rect.h"
15 #include "../cuda/cost.h" 15 #include "../cuda/cost.h"
16 #include "../cuda/glbind.h" 16 #include "../cuda/glbind.h"
  17 +#include <vector>
17 18
18 #include <iostream> 19 #include <iostream>
19 #include <fstream> 20 #include <fstream>
@@ -33,8 +34,11 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -33,8 +34,11 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
33 stim::vec<float> magnitude; //magnitude of the direction vector. 34 stim::vec<float> magnitude; //magnitude of the direction vector.
34 //mag[0] = length. 35 //mag[0] = length.
35 //mag[1] = width. 36 //mag[1] = width.
  37 + std::vector<stim::vec<float> > dirVectors;
  38 + std::vector<stim::vec<float> > posVectors;
  39 + std::vector<stim::vec<float> > magVectors;
36 using gl_texture<T>::texID; 40 using gl_texture<T>::texID;
37 - //using image_stack<T>::S; 41 + using gl_texture<T>::S;
38 cudaArray* c_Array; 42 cudaArray* c_Array;
39 //void** devPtr; 43 //void** devPtr;
40 //size_t size; 44 //size_t size;
@@ -49,6 +53,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -49,6 +53,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
49 /* Method for finding the best direction for the spider. 53 /* Method for finding the best direction for the spider.
50 Not sure if necessary since the next position for the spider 54 Not sure if necessary since the next position for the spider
51 will be at direction * magnitude. */ 55 will be at direction * magnitude. */
  56 + genTemplate(posVectors, 1);
  57 + int best = getCost();
52 } 58 }
53 59
54 void 60 void
@@ -57,20 +63,20 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -57,20 +63,20 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
57 /* Method for finding the best scale for the spider. 63 /* Method for finding the best scale for the spider.
58 changes the x, y, z size of the spider to minimize the cost 64 changes the x, y, z size of the spider to minimize the cost
59 function. */ 65 function. */
  66 + genTemplate(magVectors, 1);
  67 + int best = getCost();
60 } 68 }
61 69
62 void 70 void
63 - Evaluate()  
64 - {  
65 - /* Uses uniform sampler2D in order to take a difference between  
66 - the colors of two textures. 1st texture is the spider template,  
67 - the 2nd is the location of the spider's overlap with the  
68 - gl_template  
69 -  
70 - does the spider need to track it's location? Prob not since  
71 - position can be set with gl_texture coordinates */  
72 - 71 + findOptimalDirection()
  72 + {
  73 + /* Method for finding the best scale for the spider.
  74 + changes the x, y, z size of the spider to minimize the cost
  75 + function. */
  76 + genTemplate(dirVectors, 1);
  77 + int best = getCost();
73 } 78 }
  79 +
74 80
75 void 81 void
76 Optimize() 82 Optimize()
@@ -120,6 +126,10 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -120,6 +126,10 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
120 p4 = hor.p(0,1); 126 p4 = hor.p(0,1);
121 glBegin(GL_QUADS); 127 glBegin(GL_QUADS);
122 glTexCoord3f( 128 glTexCoord3f(
  129 + // p1[0]/S[1],
  130 + // p1[1]/S[2],
  131 + // p1[2]/S[3]
  132 + // );
123 p1[0], 133 p1[0],
124 p1[1], 134 p1[1],
125 p1[2] 135 p1[2]
@@ -127,6 +137,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -127,6 +137,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
127 //glVertex2f(0.0,0.0); 137 //glVertex2f(0.0,0.0);
128 glVertex2f(v_x,v_y); 138 glVertex2f(v_x,v_y);
129 glTexCoord3f( 139 glTexCoord3f(
  140 + // p2[0]/S[1],
  141 + // p2[1]/S[2],
  142 + // p2[2]/S[3]
130 p2[0], 143 p2[0],
131 p2[1], 144 p2[1],
132 p2[2] 145 p2[2]
@@ -134,6 +147,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -134,6 +147,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
134 //glVertex2f(1.0, 0.0); 147 //glVertex2f(1.0, 0.0);
135 glVertex2f(v_x+len, v_y); 148 glVertex2f(v_x+len, v_y);
136 glTexCoord3f( 149 glTexCoord3f(
  150 + // p2[0]/S[1],
  151 + // p2[1]/S[2],
  152 + // p2[2]/S[3]
137 p3[0], 153 p3[0],
138 p3[1], 154 p3[1],
139 p3[2] 155 p3[2]
@@ -141,6 +157,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -141,6 +157,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
141 //glVertex2f(1.0, 2.0); 157 //glVertex2f(1.0, 2.0);
142 glVertex2f(v_x+len, v_y+len); 158 glVertex2f(v_x+len, v_y+len);
143 glTexCoord3f( 159 glTexCoord3f(
  160 + // p4[0]/S[1],
  161 + // p4[1]/S[2],
  162 + // p4[2]/S[3]
144 p4[0], 163 p4[0],
145 p4[1], 164 p4[1],
146 p4[2] 165 p4[2]
@@ -154,6 +173,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -154,6 +173,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
154 p4 = ver.p(0,1); 173 p4 = ver.p(0,1);
155 glBegin(GL_QUADS); 174 glBegin(GL_QUADS);
156 glTexCoord3f( 175 glTexCoord3f(
  176 + // p1[0]/S[1],
  177 + // p1[1]/S[2],
  178 + // p1[2]/S[3]
157 p1[0], 179 p1[0],
158 p1[1], 180 p1[1],
159 p1[2] 181 p1[2]
@@ -161,6 +183,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -161,6 +183,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
161 //glVertex2f(1.0, 0.0); 183 //glVertex2f(1.0, 0.0);
162 glVertex2f(v_x+len, v_y); 184 glVertex2f(v_x+len, v_y);
163 glTexCoord3f( 185 glTexCoord3f(
  186 + // p2[0]/S[1],
  187 + // p2[1]/S[2],
  188 + // p2[2]/S[3]
164 p2[0], 189 p2[0],
165 p2[1], 190 p2[1],
166 p2[2] 191 p2[2]
@@ -168,6 +193,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -168,6 +193,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
168 //glVertex2f(2.0, 0.0); 193 //glVertex2f(2.0, 0.0);
169 glVertex2f(v_x+2*len, v_y); 194 glVertex2f(v_x+2*len, v_y);
170 glTexCoord3f( 195 glTexCoord3f(
  196 + // p3[0]/S[1],
  197 + // p3[1]/S[2],
  198 + // p3[2]/S[3]
171 p3[0], 199 p3[0],
172 p3[1], 200 p3[1],
173 p3[2] 201 p3[2]
@@ -175,6 +203,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -175,6 +203,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
175 //glVertex2f(2.0, 2.0); 203 //glVertex2f(2.0, 2.0);
176 glVertex2f(v_x+2*len, v_y+len); 204 glVertex2f(v_x+2*len, v_y+len);
177 glTexCoord3f( 205 glTexCoord3f(
  206 + // p4[0]/S[1],
  207 + // p4[1]/S[2],
  208 + // p4[2]/S[3]
178 p4[0], 209 p4[0],
179 p4[1], 210 p4[1],
180 p4[2] 211 p4[2]
@@ -185,35 +216,60 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -185,35 +216,60 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
185 } 216 }
186 217
187 void 218 void
188 - UpdatePlanes(float v_x, float v_y, vec<float> vctr, int type = 0) 219 + genTemplate(std::vector<stim::vec<float> > in, int type = 0)
189 { 220 {
  221 + float x = 0.0;
190 vec<float> Y(1.0,0.0,0.0); 222 vec<float> Y(1.0,0.0,0.0);
191 - if(cos(Y.dot(vctr))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;} 223 + Bind();
192 switch(type) { 224 switch(type) {
193 - case 0:  
194 - hor = stim::rect<float>(magnitude, position, vctr.norm(),  
195 - ((Y.cross(vctr)).cross(vctr)).norm());  
196 - ver = stim::rect<float>(magnitude, position, vctr.norm(),  
197 - hor.n()); 225 + case 0: //Direction
  226 + for(int i = 0; i < in.size(); i++)
  227 + {
  228 + if(cos(Y.dot(in[i]))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;}
  229 + else{Y[0] = 1.0; Y[1] = 0.0;}
  230 +
  231 + hor = stim::rect<float>(magnitude,
  232 + position, in[i],
  233 + ((Y.cross(in[i])).cross(in[i])).norm());
  234 + ver = stim::rect<float>(magnitude,
  235 + position, in[i],
  236 + hor.n());
  237 + UpdateBuffer(x, x+i*10.0);
  238 + }
198 break; 239 break;
199 - case 1:  
200 - hor = stim::rect<float>(magnitude, vctr, direction,  
201 - ((Y.cross(direction)).cross(direction)).norm());  
202 - ver = stim::rect<float>(magnitude, vctr, direction,  
203 - hor.n()); 240 + case 1: //Position
  241 + if(cos(Y.dot(direction))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;}
  242 + else{Y[0] = 1.0; Y[1] = 0.0;}
  243 +
  244 + for(int i = 0; i < in.size(); i++)
  245 + {
  246 + hor = stim::rect<float>(magnitude, in[i], direction,
  247 + ((Y.cross(direction)).cross(direction))
  248 + .norm());
  249 + ver = stim::rect<float>(magnitude, in[i], direction,
  250 + hor.n());
  251 + UpdateBuffer(x, x+i*10.0);
  252 + }
204 break; 253 break;
205 - case 2:  
206 - hor = stim::rect<float>(vctr, position, direction,  
207 - ((Y.cross(direction)).cross(direction)).norm());  
208 - ver = stim::rect<float>(vctr, position, direction,  
209 - hor.n());  
210 - break; 254 + case 2: //Scale
  255 + if(cos(Y.dot(direction))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;}
  256 + else{Y[0] = 1.0; Y[1] = 0.0;}
  257 +
  258 + for(int i = 0; i < in.size(); i++)
  259 + {
  260 + hor = stim::rect<float>(in[i], position, direction,
  261 + ((Y.cross(direction)).cross(direction))
  262 + .norm());
  263 + ver = stim::rect<float>(in[i], position, direction,
  264 + hor.n());
  265 + }
  266 + break;
211 default: 267 default:
212 std::cout << "unknown case have been passed" 268 std::cout << "unknown case have been passed"
213 << std::endl; 269 << std::endl;
214 break; 270 break;
215 } 271 }
216 - UpdateBuffer(v_x, v_y); 272 + Unbind();
217 } 273 }
218 274
219 /* 275 /*
@@ -247,6 +303,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -247,6 +303,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
247 glBindTexture(GL_TEXTURE_3D, texID); 303 glBindTexture(GL_TEXTURE_3D, texID);
248 } 304 }
249 305
  306 + /*
  307 + Method for Unbinding all of the texture resources
  308 + */
250 void 309 void
251 Unbind() 310 Unbind()
252 { 311 {
@@ -256,83 +315,46 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -256,83 +315,46 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
256 glBindFramebuffer(GL_FRAMEBUFFER,0); 315 glBindFramebuffer(GL_FRAMEBUFFER,0);
257 glBindTexture(GL_TEXTURE_2D, 0); 316 glBindTexture(GL_TEXTURE_2D, 0);
258 } 317 }
  318 +
259 /* 319 /*
260 Method for populating the buffer with the sampled texture. 320 Method for populating the buffer with the sampled texture.
261 usually uses the default direction vector and then 321 usually uses the default direction vector and then
262 */ 322 */
263 void 323 void
264 - sampleDirection(int numSamples = 1089, float solidAngle = M_PI) 324 + genDirectionVectors(int numSamples = 1089, float solidAngle = M_PI/1.5)
265 { 325 {
266 326
267 - //ofstream file;  
268 - //file.open("samples.txt", std::ios_base::app);  
269 - float samples[numSamples][3]; //Set up the variables  
270 - //necessary for sample generation  
271 vec<float> d_s = direction.cart2sph(); 327 vec<float> d_s = direction.cart2sph();
  328 + dirVectors.resize(1089);
272 vec<float> temp; 329 vec<float> temp;
273 int dim = (sqrt(numSamples)-1)/2; 330 int dim = (sqrt(numSamples)-1)/2;
274 - //std::cout << dim << std::endl;  
275 - float y_0 = 0.0;  
276 float p0 = M_PI/3; 331 float p0 = M_PI/3;
277 float dt = solidAngle/(1.0 * dim); 332 float dt = solidAngle/(1.0 * dim);
278 float dp = p0/(1.0*dim); 333 float dp = p0/(1.0*dim);
279 334
280 - Bind();  
281 - //file << "Step: Direction" << "\n";  
282 - //file << "iteration: " << iter << "\n";  
283 - //file << "starting pos and dir:" << "[" << position[0] << "," <<position[1] << "," << position[2] << "]" << ":" << "[" << direction[0] << "," << direction[1] << "," << direction[2] << "]\n";  
284 - //Loop over the samples such that the original orientation is in the  
285 - //center of the resulting texture index (544)  
286 - //file << position[0] << "," <<position[1] << "," << position[2] << "\n";  
287 - int idx;  
288 for(int i = -dim; i <= dim; i++){ 335 for(int i = -dim; i <= dim; i++){
289 for(int j = -dim; j <= dim; j++){ 336 for(int j = -dim; j <= dim; j++){
290 //Create linear index 337 //Create linear index
291 - idx = (i+dim)*(dim*2+1) + (j+dim);  
292 - 338 +
293 temp[0] = d_s[0]; //rotate vector 339 temp[0] = d_s[0]; //rotate vector
294 temp[1] = d_s[1]+dt*i; 340 temp[1] = d_s[1]+dt*i;
295 temp[2] = d_s[2]+dp*j; 341 temp[2] = d_s[2]+dp*j;
296 342
297 temp = (temp.sph2cart()).norm(); //back to cart 343 temp = (temp.sph2cart()).norm(); //back to cart
298 - samples[idx][0] = temp[0]; //save sample vector  
299 - samples[idx][1] = temp[1];  
300 - samples[idx][2] = temp[2];  
301 -  
302 - // file << idx << ":" <<"[" << samples[idx][0] << "," << samples[idx][1] << "," << samples[idx][2] << "]" << "\n";  
303 -  
304 - UpdatePlanes(0.0, y_0+(idx)*10, temp); 344 + dirVectors.push_back(temp);
305 } 345 }
306 } 346 }
307 - Unbind();  
308 - int nxt = getCost();  
309 - stim::vec<float> next(samples[nxt][0], samples[nxt][1], samples[nxt][2]);  
310 - //next[0] = samples[nxt][0];  
311 - //next[1] = samples[nxt][1];  
312 - //next[2] = samples[nxt][2];  
313 - next.norm();  
314 - //file << "next direction" << "[" << next[0] << "," << next[1] << "," << next[2] << "]\n\n";  
315 - setPosition(position[0] + next[0]*magnitude[0]/2,  
316 - position[1]+next[1]*magnitude[0]/2,  
317 - position[2]+next[2]*magnitude[0]/2);  
318 - setDirection(next[0], next[1], next[2]);  
319 - //file.close();  
320 - setDirection(next);  
321 - //file << "ending pos and dir:" << "[" << position[0] << "," <<position[1] << "," << position[2] << "]" << ":" << "[" << direction[0] << "," << direction[1] << "," << direction[2] << "]\n";  
322 } 347 }
323 348
324 void 349 void
325 - samplePosition(int numSamples = 1089, float delta = 0.2) 350 + genPositionVectors(int numSamples = 1089, float delta = 0.2)
326 { 351 {
327 352
328 - float samples[numSamples][3]; //Set up the variables  
329 vec<float> temp; 353 vec<float> temp;
330 int dim = (sqrt(numSamples)-1)/2; 354 int dim = (sqrt(numSamples)-1)/2;
331 - float y_0 = 0.0; //location of the first sample in the buffer  
332 stim::rect<float> samplingPlane = 355 stim::rect<float> samplingPlane =
333 stim::rect<float>(magnitude[0]*delta, position, direction); 356 stim::rect<float>(magnitude[0]*delta, position, direction);
334 float step = 1.0/(dim); 357 float step = 1.0/(dim);
335 - Bind();  
336 //Loop over the samples, keeping the original position sample 358 //Loop over the samples, keeping the original position sample
337 //in the center of the resulting texture. 359 //in the center of the resulting texture.
338 360
@@ -340,52 +362,34 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -340,52 +362,34 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
340 for(int i = -dim; i <= dim; i++){ 362 for(int i = -dim; i <= dim; i++){
341 for(int j = -dim; j <= dim; j++){ 363 for(int j = -dim; j <= dim; j++){
342 //Create linear index 364 //Create linear index
343 - idx = (i+dim)*(dim*2+1) + (j+dim);  
344 365
345 temp = samplingPlane.p( 366 temp = samplingPlane.p(
346 0.5+step*i, 367 0.5+step*i,
347 0.5+step*j 368 0.5+step*j
348 ); 369 );
349 -  
350 - samples[idx][0] = temp[0]; //save sample vector  
351 - samples[idx][1] = temp[1];  
352 - samples[idx][2] = temp[2];  
353 -  
354 - UpdatePlanes(0.0, y_0+(idx)*10, temp, 1); 370 + dirVectors.push_back(temp);
355 } 371 }
356 } 372 }
357 - Unbind();  
358 - int nxt = getCost();  
359 - setPosition(samples[nxt][0], samples[nxt][1], samples[nxt][2]);  
360 } 373 }
361 374
362 void 375 void
363 - sampleMagnitude(int numSamples = 1089, float delta = 0.5) 376 + genMagnitudeVectors(int numSamples = 1089, float delta = 0.5)
364 { 377 {
365 378
366 - ofstream file;  
367 - file.open("samples.txt", std::ios_base::app);  
368 - float samples[numSamples]; //Set up the variables  
369 int dim = (sqrt(numSamples)-1)/2; 379 int dim = (sqrt(numSamples)-1)/2;
370 - float y_0 = 0.0; //location of the first sample in the buffer  
371 float min = 1.0-delta; 380 float min = 1.0-delta;
372 float max = 1.0+delta; 381 float max = 1.0+delta;
373 float step = (max-min)/(numSamples-1); 382 float step = (max-min)/(numSamples-1);
374 float factor; 383 float factor;
375 vec<float> temp; 384 vec<float> temp;
376 - Bind();  
377 385
378 for(int i = 0; i < numSamples; i++){ 386 for(int i = 0; i < numSamples; i++){
379 - //Create linear index  
380 - factor = (min+step*i)*magnitude[0];  
381 - samples[i] = factor; //save sample vector  
382 - stim::vec<float> temp(factor);  
383 - UpdatePlanes(0.0, y_0+(i)*10, temp, 2); 387 + //Create linear index
  388 + factor = (min+step*i)*magnitude[0];
  389 + temp[0] = factor;
  390 + temp[1] = factor;
  391 + magVectors.push_back(temp);
384 } 392 }
385 - Unbind();  
386 - int nxt = getCost();  
387 - setMagnitude(samples[nxt]);  
388 - file << position[0] << "," <<position[1] << "," << position[2] << "\n";  
389 } 393 }
390 394
391 //--------------------------------------------------------------------------// 395 //--------------------------------------------------------------------------//
@@ -433,36 +437,40 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -433,36 +437,40 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
433 stim::rect<float> hor; 437 stim::rect<float> hor;
434 stim::rect<float> ver; 438 stim::rect<float> ver;
435 439
436 - //Default Constructor 440 + ///Default Constructor
437 gl_spider 441 gl_spider
438 () 442 ()
439 { 443 {
440 setPosition(0.0,0.0,0.0); 444 setPosition(0.0,0.0,0.0);
441 setDirection(0.0,0.0,1.0); 445 setDirection(0.0,0.0,1.0);
442 - setMagnitude(0.03); 446 + setMagnitude(1.0);
443 } 447 }
444 448
445 - //temporary constructor for convenience, will be removed in further updates. 449 + ///temporary constructor for convenience, will be removed in further updates.
446 gl_spider 450 gl_spider
447 (float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z, 451 (float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z,
448 float mag_x) 452 float mag_x)
449 { 453 {
450 - setPosition(pos_x, pos_y, pos_z);  
451 - setDirection(dir_x, dir_y, dir_z);  
452 - setMagnitude(mag_x);  
453 - }  
454 -  
455 - //Attached the spider to the texture with the given GLuint ID.  
456 - //Samples in the default direction acting as the init method. 454 + //setPosition(pos_x, pos_y, pos_z);
  455 + //setDirection(dir_x, dir_y, dir_z);
  456 + //setMagnitude(mag_x);
  457 + }
  458 + ///@param GLuint id texture that is going to be sampled.
  459 + ///@param numSamples number of samples per operation.
  460 + ///Attached the spider to the texture with the given GLuint ID.
  461 + ///Samples in the default direction acting as the init method.
457 void 462 void
458 attachSpider(GLuint id, int numSamples = 1089) 463 attachSpider(GLuint id, int numSamples = 1089)
459 { 464 {
460 texID = id; 465 texID = id;
461 GenerateFBO(20, numSamples*10); 466 GenerateFBO(20, numSamples*10);
462 - sampleDirection(); 467 + //sampleDirection();
  468 + genDirectionVectors();
  469 + gl_texture<T>::setDims(0.6, 0.6, 1.0);
  470 + //gl_texture<T>::setDims(1.0, 1.0,1.0);
463 } 471 }
464 472
465 - //temporary Method necessary for visualization and testing. 473 + ///temporary Method necessary for visualization and testing.
466 void 474 void
467 Update() 475 Update()
468 { 476 {
@@ -475,35 +483,39 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -475,35 +483,39 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
475 hor.n()); 483 hor.n());
476 } 484 }
477 485
478 - //Returns the position vector. 486 + ///Returns the position vector.
479 vec<float> 487 vec<float>
480 getPosition() 488 getPosition()
481 { 489 {
482 return position; 490 return position;
483 } 491 }
484 492
485 - //Returns the direction vector. 493 + ///Returns the direction vector.
486 vec<float> 494 vec<float>
487 getDirection() 495 getDirection()
488 { 496 {
489 return direction; 497 return direction;
490 } 498 }
491 499
492 - //Returns the magnitude vector. 500 + ///Returns the magnitude vector.
493 vec<float> 501 vec<float>
494 getMagnitude() 502 getMagnitude()
495 { 503 {
496 return magnitude; 504 return magnitude;
497 } 505 }
498 506
499 - //Sets the position vector to input vector pos 507 + ///@param vector pos, the new position.
  508 + ///Sets the position vector to input vector pos.
500 void 509 void
501 setPosition(vec<float> pos) 510 setPosition(vec<float> pos)
502 { 511 {
503 position = pos; 512 position = pos;
504 } 513 }
505 -  
506 - //Sets the position vector to the input float coordinates x,y,z 514 +
  515 + ///@param x x-coordinate.
  516 + ///@param y y-coordinate.
  517 + ///@param z z-coordinate.
  518 + ///Sets the position vector to the input float coordinates x,y,z.
507 void 519 void
508 setPosition(float x, float y, float z) 520 setPosition(float x, float y, float z)
509 { 521 {
@@ -513,14 +525,18 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -513,14 +525,18 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
513 } 525 }
514 526
515 527
516 - //Sets the direction vector to input vector dir 528 + ///@param vector dir, the new direction.
  529 + ///Sets the direction vector to input vector dir.
517 void 530 void
518 setDirection(vec<float> dir) 531 setDirection(vec<float> dir)
519 { 532 {
520 direction = dir; 533 direction = dir;
521 } 534 }
522 535
523 - //Sets the direction vector to the input float coordinates x,y,z 536 + ///@param x x-coordinate.
  537 + ///@param y y-coordinate.
  538 + ///@param z z-coordinate.
  539 + ///Sets the direction vector to the input float coordinates x,y,z.
524 void 540 void
525 setDirection(float x, float y, float z) 541 setDirection(float x, float y, float z)
526 { 542 {
@@ -528,8 +544,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -528,8 +544,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
528 direction[1] = y; 544 direction[1] = y;
529 direction[2] = z; 545 direction[2] = z;
530 } 546 }
531 -  
532 - //Sets the magnitude vector to the input vector mag. 547 +
  548 + ///@param vector dir, the new direction.
  549 + ///Sets the magnitude vector to the input vector mag.
533 void 550 void
534 setMagnitude(vec<float> mag) 551 setMagnitude(vec<float> mag)
535 { 552 {
@@ -537,6 +554,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -537,6 +554,8 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
537 magnitude[1] = mag[0]; 554 magnitude[1] = mag[0];
538 } 555 }
539 556
  557 + ///@param mag size of the sampled region.
  558 + ///Sets the magnitude vector to the input mag for both templates.
540 void 559 void
541 setMagnitude(float mag) 560 setMagnitude(float mag)
542 { 561 {
@@ -544,7 +563,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -544,7 +563,7 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
544 magnitude[1] = mag; 563 magnitude[1] = mag;
545 } 564 }
546 565
547 - //temporary method for visualization. 566 + ///temporary method for visualization.
548 GLuint 567 GLuint
549 getFB() 568 getFB()
550 { 569 {
@@ -564,9 +583,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt; @@ -564,9 +583,9 @@ class gl_spider : public virtual gl_texture&lt;T&gt;
564 /* Method for finding the best direction for the spider. 583 /* Method for finding the best direction for the spider.
565 Uses the camera to rotate. Then Calls Evaluate to find new cost. 584 Uses the camera to rotate. Then Calls Evaluate to find new cost.
566 */ 585 */
567 - sampleDirection();  
568 - samplePosition();  
569 - sampleMagnitude(); 586 + //sampleDirection();
  587 + //samplePosition();
  588 + //sampleMagnitude();
570 } 589 }
571 590
572 /* Method for initializing the cuda devices, necessary only 591 /* Method for initializing the cuda devices, necessary only
stim/gl/gl_texture.h
@@ -31,13 +31,10 @@ template&lt;typename T&gt; @@ -31,13 +31,10 @@ template&lt;typename T&gt;
31 class gl_texture : public virtual image_stack<T> 31 class gl_texture : public virtual image_stack<T>
32 { 32 {
33 private: 33 private:
34 - /*  
35 - Method: setTextureType  
36 - Inputs:  
37 - Outputs:  
38 - Sets the internal texture_type, based on the data  
39 - size. Either 3D, 2D, 1D textures.  
40 - */ 34 +
  35 + ///Method: setTextureType
  36 + /// Sets the internal texture_type, based on the data
  37 + /// size. Either 3D, 2D, 1D textures.
41 38
42 void 39 void
43 setTextureType() 40 setTextureType()
@@ -54,28 +51,22 @@ class gl_texture : public virtual image_stack&lt;T&gt; @@ -54,28 +51,22 @@ class gl_texture : public virtual image_stack&lt;T&gt;
54 GLuint texID; //OpenGL object 51 GLuint texID; //OpenGL object
55 GLenum texture_type; //1D, 2D, 3D 52 GLenum texture_type; //1D, 2D, 3D
56 using image_stack<T>::R; 53 using image_stack<T>::R;
  54 + using image_stack<T>::S;
57 using image_stack<T>::ptr; 55 using image_stack<T>::ptr;
58 using image_stack<T>::samples; 56 using image_stack<T>::samples;
59 57
60 public: 58 public:
61 59
62 - /*  
63 - Method: Basic Constructor  
64 - Inputs:  
65 - Outputs:  
66 - Creates an instance of the gl_texture object.  
67 - */ 60 + ///Method: Basic Constructor
  61 + /// Creates an instance of the gl_texture object.
68 gl_texture() 62 gl_texture()
69 { 63 {
70 64
71 } 65 }
72 66
73 - /*  
74 - Method: Path Constructor  
75 - Inputs: string file_path  
76 - Outputs:  
77 - Creates an instance of the gl_texture object with a path to the data.  
78 - */ 67 + ///Method: Path Constructor
  68 + ///@param string file_path path to the directory with the files.
  69 + /// Creates an instance of the gl_texture object with a path to the data.
79 70
80 gl_texture(std::string file_path) 71 gl_texture(std::string file_path)
81 { 72 {
@@ -84,13 +75,34 @@ class gl_texture : public virtual image_stack&lt;T&gt; @@ -84,13 +75,34 @@ class gl_texture : public virtual image_stack&lt;T&gt;
84 setTextureType(); 75 setTextureType();
85 } 76 }
86 77
87 - /*  
88 - Method: setPath  
89 - Inputs:string file_Path  
90 - Outputs:  
91 - sets the protected path variable of an instance of the gl_texture class  
92 - to the method input.  
93 - */ 78 +
  79 + ///Method:setDims
  80 + ///@param x size of the voxel in x direction
  81 + ///@param y size of the voxel in y direction
  82 + ///@param z size of the voxel in z direction
  83 + /// Sets the dimenstions of the voxels.
  84 + void
  85 + setDims(float x, float y, float z)
  86 + {
  87 + S[1] = x;
  88 + S[2] = y;
  89 + S[3] = z;
  90 + }
  91 +
  92 + ///Method:getDims
  93 + /// get the dimenstions of the voxels.
  94 +
  95 + vec<float>
  96 + getDims()
  97 + {
  98 + vec<float> dims(S[1], S[2], S[3]);
  99 + return dims;
  100 + }
  101 +
  102 + ///Method:setPath
  103 + ///@param file_Path location of the directory with the files
  104 + /// Sets the path and calls the loader on that path.
  105 +
94 106
95 void 107 void
96 setPath(std::string file_path) 108 setPath(std::string file_path)
@@ -100,12 +112,9 @@ class gl_texture : public virtual image_stack&lt;T&gt; @@ -100,12 +112,9 @@ class gl_texture : public virtual image_stack&lt;T&gt;
100 setTextureType(); 112 setTextureType();
101 } 113 }
102 114
103 - /*  
104 - Method: getPath  
105 - Inputs:  
106 - Outputs: string path  
107 - Returns the path associated with an instance of the gl_texture class.  
108 - */ 115 + ///Method: getPath
  116 + ///Outputs: string path
  117 + /// Returns the path associated with an instance of the gl_texture class.
109 118
110 std::string 119 std::string
111 getPath() 120 getPath()
@@ -113,27 +122,20 @@ class gl_texture : public virtual image_stack&lt;T&gt; @@ -113,27 +122,20 @@ class gl_texture : public virtual image_stack&lt;T&gt;
113 return path; 122 return path;
114 } 123 }
115 124
116 - /*  
117 - Method: getTexture  
118 - Inputs:  
119 - Outputs: GLuint texID  
120 - Returns the id of the texture create by/associated with the  
121 - instance of the gl_texture class.  
122 - */ 125 + ///Method: getTexture
  126 + ///Outputs: GLuint texID
  127 + /// Returns the id of the texture create by/associated with the
  128 + /// instance of the gl_texture class.
123 129
124 GLuint 130 GLuint
125 getTexture() 131 getTexture()
126 { 132 {
127 return texID; 133 return texID;
128 } 134 }
129 -  
130 - /*  
131 - Method: createTexture  
132 - Inputs:  
133 - Outputs:  
134 - Creates a texture and from the data located at <path> and  
135 - assigns that texture to texID  
136 - */ 135 +
  136 + ///Method: createTexture
  137 + /// Creates a texture and from the loaded data and
  138 + /// assigns that texture to texID
137 //TO DO :::: 1D textures 139 //TO DO :::: 1D textures
138 //TO DO:::add methods for handling the cases of T 140 //TO DO:::add methods for handling the cases of T
139 // and convert them to GL equivalent. 141 // and convert them to GL equivalent.
@@ -154,11 +156,11 @@ class gl_texture : public virtual image_stack&lt;T&gt; @@ -154,11 +156,11 @@ class gl_texture : public virtual image_stack&lt;T&gt;
154 { 156 {
155 case GL_TEXTURE_3D: 157 case GL_TEXTURE_3D:
156 glTexParameteri(texture_type, 158 glTexParameteri(texture_type,
157 - GL_TEXTURE_WRAP_S, GL_REPEAT); 159 + GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
158 glTexParameteri(texture_type, 160 glTexParameteri(texture_type,
159 - GL_TEXTURE_WRAP_T, GL_REPEAT); 161 + GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
160 glTexParameteri(texture_type, 162 glTexParameteri(texture_type,
161 - GL_TEXTURE_WRAP_R, GL_REPEAT); 163 + GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
162 glTexImage3D(texture_type, 164 glTexImage3D(texture_type,
163 0, 165 0,
164 // GL_RGB16, 166 // GL_RGB16,
@@ -190,15 +192,8 @@ class gl_texture : public virtual image_stack&lt;T&gt; @@ -190,15 +192,8 @@ class gl_texture : public virtual image_stack&lt;T&gt;
190 break; 192 break;
191 } 193 }
192 } 194 }
193 - /*  
194 - Temporary methods for debugging and testing are below.  
195 - Self-explanatory.  
196 - */  
197 - stim::vec<unsigned long,4>  
198 - getDims()  
199 - {  
200 - return R;  
201 - } 195 + ///Temporary methods for debugging and testing are below.
  196 + ///Self-explanatory.
202 197
203 T* 198 T*
204 getData() 199 getData()
@@ -21,6 +21,7 @@ class grid{ @@ -21,6 +21,7 @@ class grid{
21 protected: 21 protected:
22 22
23 stim::vec<unsigned long, D> R; //elements in each dimension 23 stim::vec<unsigned long, D> R; //elements in each dimension
  24 + stim::vec<float, D> S;
24 T* ptr; //pointer to the data (on the GPU or CPU) 25 T* ptr; //pointer to the data (on the GPU or CPU)
25 26
26 ///Return the total number of values in the binary file 27 ///Return the total number of values in the binary file
@@ -63,6 +64,12 @@ public: @@ -63,6 +64,12 @@ public:
63 init(); 64 init();
64 } 65 }
65 66
  67 + void
  68 + setDim(stim::vec<float, D> s)
  69 + {
  70 + S = s;
  71 + }
  72 +
66 ///Constructor used to specify the grid size as a set of parameters 73 ///Constructor used to specify the grid size as a set of parameters
67 74
68 /// @param X0... is a list of values describing the grid size along each dimension 75 /// @param X0... is a list of values describing the grid size along each dimension
@@ -156,6 +163,7 @@ public: @@ -156,6 +163,7 @@ public:
156 ptr[p] = value; 163 ptr[p] = value;
157 } 164 }
158 165
  166 +
159 ///Outputs grid data as a string 167 ///Outputs grid data as a string
160 std::string str(){ 168 std::string str(){
161 169
stim/grids/image_stack.h
@@ -17,6 +17,7 @@ class image_stack : public virtual stim::grid&lt;T, 4&gt;{ @@ -17,6 +17,7 @@ class image_stack : public virtual stim::grid&lt;T, 4&gt;{
17 enum image_type {stimAuto, stimMono, stimRGB, stimRGBA}; 17 enum image_type {stimAuto, stimMono, stimRGB, stimRGBA};
18 18
19 protected: 19 protected:
  20 + using stim::grid<T, 4>::S;
20 using stim::grid<T, 4>::R; 21 using stim::grid<T, 4>::R;
21 using stim::grid<T, 4>::ptr; 22 using stim::grid<T, 4>::ptr;
22 using stim::grid<T, 4>::samples; 23 using stim::grid<T, 4>::samples;
@@ -83,7 +84,19 @@ public: @@ -83,7 +84,19 @@ public:
83 84
84 I.save(file_name); 85 I.save(file_name);
85 } 86 }
86 - 87 + ///Sets the dimensions of the image in each direction
  88 + ///Voxel-size.
  89 + /// @param x size in the x direction
  90 + /// @param y size in the y direction
  91 + /// @param z size in the z direction
  92 + void
  93 + set_dim(float x, float y, float z)
  94 + {
  95 + S[0] = 1;
  96 + S[1] = x;
  97 + S[2] = y;
  98 + S[3] = z;
  99 + }
87 ///Saves the entire stack to a set of images 100 ///Saves the entire stack to a set of images
88 101
89 /// @param file_mask is the mask describing how the file names will be saved (ex. image????.bmp) 102 /// @param file_mask is the mask describing how the file names will be saved (ex. image????.bmp)