Commit 385d2447fe1df96d07a60a6856c8189019445d32
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
Showing
5 changed files
with
220 additions
and
201 deletions
Show diff stats
stim/cuda/cost.h
... | ... | @@ -2,8 +2,6 @@ |
2 | 2 | #include <cuda.h> |
3 | 3 | #include <cuda_runtime.h> |
4 | 4 | #include <cublas_v2.h> |
5 | -//#include "cuPrintf.cu" | |
6 | -//#include "cuPrintf.cuh" | |
7 | 5 | #include <stdio.h> |
8 | 6 | #include "../visualization/colormap.h" |
9 | 7 | #include <sstream> |
... | ... | @@ -11,9 +9,6 @@ |
11 | 9 | #define DIM_Y 10890 |
12 | 10 | #define DIM_X 20 |
13 | 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 | 12 | texture<uchar, cudaTextureType2D, cudaReadModeElementType> texIn; |
18 | 13 | float *result; |
19 | 14 | float* v_dif; |
... | ... | @@ -66,11 +61,9 @@ void get_diff (float *result) |
66 | 61 | float valIn = tex2D(texIn, x, y)/255.0; |
67 | 62 | float valTemp = Template(x); |
68 | 63 | result[idx] = abs(valIn-valTemp); |
69 | - //result[idx] = abs(valTemp); | |
70 | 64 | // #if __CUDA_ARCH__>=200 |
71 | 65 | // printf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); |
72 | 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 | 121 | initArray(src); |
129 | 122 | dim3 grid(20, 10890); |
130 | 123 | dim3 block(1, 1); |
131 | - //texIn.normalized = 1; | |
132 | 124 | get_diff <<< grid, block >>> (result); |
133 | 125 | stim::gpu2image<float>(result, "test.bmp", 20,10890,0,1); |
134 | 126 | for (int i = 0; i < 1089; i++){ |
... | ... | @@ -136,19 +128,11 @@ int get_cost(cudaGraphicsResource_t src, int inter) |
136 | 128 | if(output[i] <= mini){ |
137 | 129 | mini = output[i]; |
138 | 130 | idx = i; |
139 | -// if(!testing) | |
140 | - | |
141 | -// testing = true; | |
142 | - } //float* out = (float*) malloc(sizeof(float)); | |
131 | + } | |
143 | 132 | } |
144 | 133 | name << "sample_" << inter << "_" << idx << ".bmp"; |
145 | 134 | output[idx] = get_sum(result+(20*10*idx)); |
146 | 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 | 136 | cleanUP(src); |
153 | 137 | return idx; |
154 | 138 | } | ... | ... |
stim/gl/gl_spider.h
... | ... | @@ -14,6 +14,7 @@ |
14 | 14 | #include "../math/rect.h" |
15 | 15 | #include "../cuda/cost.h" |
16 | 16 | #include "../cuda/glbind.h" |
17 | +#include <vector> | |
17 | 18 | |
18 | 19 | #include <iostream> |
19 | 20 | #include <fstream> |
... | ... | @@ -33,8 +34,11 @@ class gl_spider : public virtual gl_texture<T> |
33 | 34 | stim::vec<float> magnitude; //magnitude of the direction vector. |
34 | 35 | //mag[0] = length. |
35 | 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 | 40 | using gl_texture<T>::texID; |
37 | - //using image_stack<T>::S; | |
41 | + using gl_texture<T>::S; | |
38 | 42 | cudaArray* c_Array; |
39 | 43 | //void** devPtr; |
40 | 44 | //size_t size; |
... | ... | @@ -49,6 +53,8 @@ class gl_spider : public virtual gl_texture<T> |
49 | 53 | /* Method for finding the best direction for the spider. |
50 | 54 | Not sure if necessary since the next position for the spider |
51 | 55 | will be at direction * magnitude. */ |
56 | + genTemplate(posVectors, 1); | |
57 | + int best = getCost(); | |
52 | 58 | } |
53 | 59 | |
54 | 60 | void |
... | ... | @@ -57,20 +63,20 @@ class gl_spider : public virtual gl_texture<T> |
57 | 63 | /* Method for finding the best scale for the spider. |
58 | 64 | changes the x, y, z size of the spider to minimize the cost |
59 | 65 | function. */ |
66 | + genTemplate(magVectors, 1); | |
67 | + int best = getCost(); | |
60 | 68 | } |
61 | 69 | |
62 | 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 | 81 | void |
76 | 82 | Optimize() |
... | ... | @@ -120,6 +126,10 @@ class gl_spider : public virtual gl_texture<T> |
120 | 126 | p4 = hor.p(0,1); |
121 | 127 | glBegin(GL_QUADS); |
122 | 128 | glTexCoord3f( |
129 | + // p1[0]/S[1], | |
130 | + // p1[1]/S[2], | |
131 | + // p1[2]/S[3] | |
132 | + // ); | |
123 | 133 | p1[0], |
124 | 134 | p1[1], |
125 | 135 | p1[2] |
... | ... | @@ -127,6 +137,9 @@ class gl_spider : public virtual gl_texture<T> |
127 | 137 | //glVertex2f(0.0,0.0); |
128 | 138 | glVertex2f(v_x,v_y); |
129 | 139 | glTexCoord3f( |
140 | + // p2[0]/S[1], | |
141 | + // p2[1]/S[2], | |
142 | + // p2[2]/S[3] | |
130 | 143 | p2[0], |
131 | 144 | p2[1], |
132 | 145 | p2[2] |
... | ... | @@ -134,6 +147,9 @@ class gl_spider : public virtual gl_texture<T> |
134 | 147 | //glVertex2f(1.0, 0.0); |
135 | 148 | glVertex2f(v_x+len, v_y); |
136 | 149 | glTexCoord3f( |
150 | + // p2[0]/S[1], | |
151 | + // p2[1]/S[2], | |
152 | + // p2[2]/S[3] | |
137 | 153 | p3[0], |
138 | 154 | p3[1], |
139 | 155 | p3[2] |
... | ... | @@ -141,6 +157,9 @@ class gl_spider : public virtual gl_texture<T> |
141 | 157 | //glVertex2f(1.0, 2.0); |
142 | 158 | glVertex2f(v_x+len, v_y+len); |
143 | 159 | glTexCoord3f( |
160 | + // p4[0]/S[1], | |
161 | + // p4[1]/S[2], | |
162 | + // p4[2]/S[3] | |
144 | 163 | p4[0], |
145 | 164 | p4[1], |
146 | 165 | p4[2] |
... | ... | @@ -154,6 +173,9 @@ class gl_spider : public virtual gl_texture<T> |
154 | 173 | p4 = ver.p(0,1); |
155 | 174 | glBegin(GL_QUADS); |
156 | 175 | glTexCoord3f( |
176 | + // p1[0]/S[1], | |
177 | + // p1[1]/S[2], | |
178 | + // p1[2]/S[3] | |
157 | 179 | p1[0], |
158 | 180 | p1[1], |
159 | 181 | p1[2] |
... | ... | @@ -161,6 +183,9 @@ class gl_spider : public virtual gl_texture<T> |
161 | 183 | //glVertex2f(1.0, 0.0); |
162 | 184 | glVertex2f(v_x+len, v_y); |
163 | 185 | glTexCoord3f( |
186 | + // p2[0]/S[1], | |
187 | + // p2[1]/S[2], | |
188 | + // p2[2]/S[3] | |
164 | 189 | p2[0], |
165 | 190 | p2[1], |
166 | 191 | p2[2] |
... | ... | @@ -168,6 +193,9 @@ class gl_spider : public virtual gl_texture<T> |
168 | 193 | //glVertex2f(2.0, 0.0); |
169 | 194 | glVertex2f(v_x+2*len, v_y); |
170 | 195 | glTexCoord3f( |
196 | + // p3[0]/S[1], | |
197 | + // p3[1]/S[2], | |
198 | + // p3[2]/S[3] | |
171 | 199 | p3[0], |
172 | 200 | p3[1], |
173 | 201 | p3[2] |
... | ... | @@ -175,6 +203,9 @@ class gl_spider : public virtual gl_texture<T> |
175 | 203 | //glVertex2f(2.0, 2.0); |
176 | 204 | glVertex2f(v_x+2*len, v_y+len); |
177 | 205 | glTexCoord3f( |
206 | + // p4[0]/S[1], | |
207 | + // p4[1]/S[2], | |
208 | + // p4[2]/S[3] | |
178 | 209 | p4[0], |
179 | 210 | p4[1], |
180 | 211 | p4[2] |
... | ... | @@ -185,35 +216,60 @@ class gl_spider : public virtual gl_texture<T> |
185 | 216 | } |
186 | 217 | |
187 | 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 | 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 | 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 | 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 | 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 | 267 | default: |
212 | 268 | std::cout << "unknown case have been passed" |
213 | 269 | << std::endl; |
214 | 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<T> |
247 | 303 | glBindTexture(GL_TEXTURE_3D, texID); |
248 | 304 | } |
249 | 305 | |
306 | + /* | |
307 | + Method for Unbinding all of the texture resources | |
308 | + */ | |
250 | 309 | void |
251 | 310 | Unbind() |
252 | 311 | { |
... | ... | @@ -256,83 +315,46 @@ class gl_spider : public virtual gl_texture<T> |
256 | 315 | glBindFramebuffer(GL_FRAMEBUFFER,0); |
257 | 316 | glBindTexture(GL_TEXTURE_2D, 0); |
258 | 317 | } |
318 | + | |
259 | 319 | /* |
260 | 320 | Method for populating the buffer with the sampled texture. |
261 | 321 | usually uses the default direction vector and then |
262 | 322 | */ |
263 | 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 | 327 | vec<float> d_s = direction.cart2sph(); |
328 | + dirVectors.resize(1089); | |
272 | 329 | vec<float> temp; |
273 | 330 | int dim = (sqrt(numSamples)-1)/2; |
274 | - //std::cout << dim << std::endl; | |
275 | - float y_0 = 0.0; | |
276 | 331 | float p0 = M_PI/3; |
277 | 332 | float dt = solidAngle/(1.0 * dim); |
278 | 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 | 335 | for(int i = -dim; i <= dim; i++){ |
289 | 336 | for(int j = -dim; j <= dim; j++){ |
290 | 337 | //Create linear index |
291 | - idx = (i+dim)*(dim*2+1) + (j+dim); | |
292 | - | |
338 | + | |
293 | 339 | temp[0] = d_s[0]; //rotate vector |
294 | 340 | temp[1] = d_s[1]+dt*i; |
295 | 341 | temp[2] = d_s[2]+dp*j; |
296 | 342 | |
297 | 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 | 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 | 353 | vec<float> temp; |
330 | 354 | int dim = (sqrt(numSamples)-1)/2; |
331 | - float y_0 = 0.0; //location of the first sample in the buffer | |
332 | 355 | stim::rect<float> samplingPlane = |
333 | 356 | stim::rect<float>(magnitude[0]*delta, position, direction); |
334 | 357 | float step = 1.0/(dim); |
335 | - Bind(); | |
336 | 358 | //Loop over the samples, keeping the original position sample |
337 | 359 | //in the center of the resulting texture. |
338 | 360 | |
... | ... | @@ -340,52 +362,34 @@ class gl_spider : public virtual gl_texture<T> |
340 | 362 | for(int i = -dim; i <= dim; i++){ |
341 | 363 | for(int j = -dim; j <= dim; j++){ |
342 | 364 | //Create linear index |
343 | - idx = (i+dim)*(dim*2+1) + (j+dim); | |
344 | 365 | |
345 | 366 | temp = samplingPlane.p( |
346 | 367 | 0.5+step*i, |
347 | 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 | 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 | 379 | int dim = (sqrt(numSamples)-1)/2; |
370 | - float y_0 = 0.0; //location of the first sample in the buffer | |
371 | 380 | float min = 1.0-delta; |
372 | 381 | float max = 1.0+delta; |
373 | 382 | float step = (max-min)/(numSamples-1); |
374 | 383 | float factor; |
375 | 384 | vec<float> temp; |
376 | - Bind(); | |
377 | 385 | |
378 | 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<T> |
433 | 437 | stim::rect<float> hor; |
434 | 438 | stim::rect<float> ver; |
435 | 439 | |
436 | - //Default Constructor | |
440 | + ///Default Constructor | |
437 | 441 | gl_spider |
438 | 442 | () |
439 | 443 | { |
440 | 444 | setPosition(0.0,0.0,0.0); |
441 | 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 | 450 | gl_spider |
447 | 451 | (float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z, |
448 | 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 | 462 | void |
458 | 463 | attachSpider(GLuint id, int numSamples = 1089) |
459 | 464 | { |
460 | 465 | texID = id; |
461 | 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 | 474 | void |
467 | 475 | Update() |
468 | 476 | { |
... | ... | @@ -475,35 +483,39 @@ class gl_spider : public virtual gl_texture<T> |
475 | 483 | hor.n()); |
476 | 484 | } |
477 | 485 | |
478 | - //Returns the position vector. | |
486 | + ///Returns the position vector. | |
479 | 487 | vec<float> |
480 | 488 | getPosition() |
481 | 489 | { |
482 | 490 | return position; |
483 | 491 | } |
484 | 492 | |
485 | - //Returns the direction vector. | |
493 | + ///Returns the direction vector. | |
486 | 494 | vec<float> |
487 | 495 | getDirection() |
488 | 496 | { |
489 | 497 | return direction; |
490 | 498 | } |
491 | 499 | |
492 | - //Returns the magnitude vector. | |
500 | + ///Returns the magnitude vector. | |
493 | 501 | vec<float> |
494 | 502 | getMagnitude() |
495 | 503 | { |
496 | 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 | 509 | void |
501 | 510 | setPosition(vec<float> pos) |
502 | 511 | { |
503 | 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 | 519 | void |
508 | 520 | setPosition(float x, float y, float z) |
509 | 521 | { |
... | ... | @@ -513,14 +525,18 @@ class gl_spider : public virtual gl_texture<T> |
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 | 530 | void |
518 | 531 | setDirection(vec<float> dir) |
519 | 532 | { |
520 | 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 | 540 | void |
525 | 541 | setDirection(float x, float y, float z) |
526 | 542 | { |
... | ... | @@ -528,8 +544,9 @@ class gl_spider : public virtual gl_texture<T> |
528 | 544 | direction[1] = y; |
529 | 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 | 550 | void |
534 | 551 | setMagnitude(vec<float> mag) |
535 | 552 | { |
... | ... | @@ -537,6 +554,8 @@ class gl_spider : public virtual gl_texture<T> |
537 | 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 | 559 | void |
541 | 560 | setMagnitude(float mag) |
542 | 561 | { |
... | ... | @@ -544,7 +563,7 @@ class gl_spider : public virtual gl_texture<T> |
544 | 563 | magnitude[1] = mag; |
545 | 564 | } |
546 | 565 | |
547 | - //temporary method for visualization. | |
566 | + ///temporary method for visualization. | |
548 | 567 | GLuint |
549 | 568 | getFB() |
550 | 569 | { |
... | ... | @@ -564,9 +583,9 @@ class gl_spider : public virtual gl_texture<T> |
564 | 583 | /* Method for finding the best direction for the spider. |
565 | 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 | 591 | /* Method for initializing the cuda devices, necessary only | ... | ... |
stim/gl/gl_texture.h
... | ... | @@ -31,13 +31,10 @@ template<typename T> |
31 | 31 | class gl_texture : public virtual image_stack<T> |
32 | 32 | { |
33 | 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 | 39 | void |
43 | 40 | setTextureType() |
... | ... | @@ -54,28 +51,22 @@ class gl_texture : public virtual image_stack<T> |
54 | 51 | GLuint texID; //OpenGL object |
55 | 52 | GLenum texture_type; //1D, 2D, 3D |
56 | 53 | using image_stack<T>::R; |
54 | + using image_stack<T>::S; | |
57 | 55 | using image_stack<T>::ptr; |
58 | 56 | using image_stack<T>::samples; |
59 | 57 | |
60 | 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 | 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 | 71 | gl_texture(std::string file_path) |
81 | 72 | { |
... | ... | @@ -84,13 +75,34 @@ class gl_texture : public virtual image_stack<T> |
84 | 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 | 107 | void |
96 | 108 | setPath(std::string file_path) |
... | ... | @@ -100,12 +112,9 @@ class gl_texture : public virtual image_stack<T> |
100 | 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 | 119 | std::string |
111 | 120 | getPath() |
... | ... | @@ -113,27 +122,20 @@ class gl_texture : public virtual image_stack<T> |
113 | 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 | 130 | GLuint |
125 | 131 | getTexture() |
126 | 132 | { |
127 | 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 | 139 | //TO DO :::: 1D textures |
138 | 140 | //TO DO:::add methods for handling the cases of T |
139 | 141 | // and convert them to GL equivalent. |
... | ... | @@ -154,11 +156,11 @@ class gl_texture : public virtual image_stack<T> |
154 | 156 | { |
155 | 157 | case GL_TEXTURE_3D: |
156 | 158 | glTexParameteri(texture_type, |
157 | - GL_TEXTURE_WRAP_S, GL_REPEAT); | |
159 | + GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
158 | 160 | glTexParameteri(texture_type, |
159 | - GL_TEXTURE_WRAP_T, GL_REPEAT); | |
161 | + GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
160 | 162 | glTexParameteri(texture_type, |
161 | - GL_TEXTURE_WRAP_R, GL_REPEAT); | |
163 | + GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); | |
162 | 164 | glTexImage3D(texture_type, |
163 | 165 | 0, |
164 | 166 | // GL_RGB16, |
... | ... | @@ -190,15 +192,8 @@ class gl_texture : public virtual image_stack<T> |
190 | 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 | 198 | T* |
204 | 199 | getData() | ... | ... |
stim/grids/grid.h
... | ... | @@ -21,6 +21,7 @@ class grid{ |
21 | 21 | protected: |
22 | 22 | |
23 | 23 | stim::vec<unsigned long, D> R; //elements in each dimension |
24 | + stim::vec<float, D> S; | |
24 | 25 | T* ptr; //pointer to the data (on the GPU or CPU) |
25 | 26 | |
26 | 27 | ///Return the total number of values in the binary file |
... | ... | @@ -63,6 +64,12 @@ public: |
63 | 64 | init(); |
64 | 65 | } |
65 | 66 | |
67 | + void | |
68 | + setDim(stim::vec<float, D> s) | |
69 | + { | |
70 | + S = s; | |
71 | + } | |
72 | + | |
66 | 73 | ///Constructor used to specify the grid size as a set of parameters |
67 | 74 | |
68 | 75 | /// @param X0... is a list of values describing the grid size along each dimension |
... | ... | @@ -156,6 +163,7 @@ public: |
156 | 163 | ptr[p] = value; |
157 | 164 | } |
158 | 165 | |
166 | + | |
159 | 167 | ///Outputs grid data as a string |
160 | 168 | std::string str(){ |
161 | 169 | ... | ... |
stim/grids/image_stack.h
... | ... | @@ -17,6 +17,7 @@ class image_stack : public virtual stim::grid<T, 4>{ |
17 | 17 | enum image_type {stimAuto, stimMono, stimRGB, stimRGBA}; |
18 | 18 | |
19 | 19 | protected: |
20 | + using stim::grid<T, 4>::S; | |
20 | 21 | using stim::grid<T, 4>::R; |
21 | 22 | using stim::grid<T, 4>::ptr; |
22 | 23 | using stim::grid<T, 4>::samples; |
... | ... | @@ -83,7 +84,19 @@ public: |
83 | 84 | |
84 | 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 | 100 | ///Saves the entire stack to a set of images |
88 | 101 | |
89 | 102 | /// @param file_mask is the mask describing how the file names will be saved (ex. image????.bmp) | ... | ... |