Commit 5e7c7581ec7673fafdceaa44b8b8bec1ee46c753
1 parent
a61d7195
Debugging build for testing of coordinate system alignments
Showing
3 changed files
with
91 additions
and
46 deletions
Show diff stats
stim/cuda/cost.h
... | ... | @@ -6,8 +6,9 @@ |
6 | 6 | #include "../visualization/colormap.h" |
7 | 7 | #include <sstream> |
8 | 8 | |
9 | -#define DIM_Y 10890 | |
10 | -#define DIM_X 20 | |
9 | +//#define | |
10 | +//#define DIM_Y 10890 | |
11 | +//#define DIM_X 20 | |
11 | 12 | typedef unsigned char uchar; |
12 | 13 | //surface<void, 2> texOut; ///// maybe just do a normal array instead of a surface. |
13 | 14 | //we may not need a surface at all. |
... | ... | @@ -58,7 +59,7 @@ void get_diff (float *result) |
58 | 59 | //cuPrintf("Hello"); |
59 | 60 | int x = threadIdx.x + blockIdx.x * blockDim.x; |
60 | 61 | int y = threadIdx.y + blockIdx.y * blockDim.y; |
61 | - int idx = y*DIM_X+x; | |
62 | + int idx = y*20+x; | |
62 | 63 | |
63 | 64 | //float valIn = tex2D(texIn, x, y); |
64 | 65 | float valIn = tex2D(texIn, x, y)/255.0; |
... | ... | @@ -70,7 +71,7 @@ void get_diff (float *result) |
70 | 71 | //float valIn = tex2D(texIn, x, y); |
71 | 72 | float valTemp = Template(x); |
72 | 73 | // result[idx] = (float) x/(blockDim.x*gridDim.x);//abs(x); |
73 | - result[idx] = abs(valIn-valTemp); | |
74 | + result[idx] = abs(valIn); | |
74 | 75 | // #if __CUDA_ARCH__>=200 |
75 | 76 | // printf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); |
76 | 77 | // #endif |
... | ... | @@ -79,7 +80,7 @@ void get_diff (float *result) |
79 | 80 | |
80 | 81 | |
81 | 82 | |
82 | -void initArray(cudaGraphicsResource_t src) | |
83 | +void initArray(cudaGraphicsResource_t src, int DIM_Y) | |
83 | 84 | { |
84 | 85 | //cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<uchar> (); |
85 | 86 | //cudaMallocArray(&result, &channelDesc, DIM_X, DIM_Y, 0); |
... | ... | @@ -96,7 +97,7 @@ void initArray(cudaGraphicsResource_t src) |
96 | 97 | HANDLE_ERROR( |
97 | 98 | cudaBindTextureToArray(texIn, srcArray) |
98 | 99 | ); |
99 | - cudaMalloc( (void**) &result, DIM_X*DIM_Y*sizeof(float)); | |
100 | + cudaMalloc( (void**) &result, 20*DIM_Y*sizeof(float)); | |
100 | 101 | checkCUDAerrors("Memory Allocation Issue 1"); |
101 | 102 | cudaMalloc((void **) &v_dif, 20*10*sizeof(float)); |
102 | 103 | checkCUDAerrors("Memory Allocation Issue 2"); |
... | ... | @@ -122,18 +123,18 @@ void cleanUP(cudaGraphicsResource_t src) |
122 | 123 | } |
123 | 124 | |
124 | 125 | extern "C" |
125 | -int get_cost(cudaGraphicsResource_t src, int inter) | |
126 | +int get_cost(cudaGraphicsResource_t src, int inter, int DIM_Y) | |
126 | 127 | { |
127 | - float output[1089]; | |
128 | + float output[DIM_Y]; | |
128 | 129 | float mini = 10000000000000000.0; |
129 | 130 | int idx; |
130 | 131 | stringstream name; |
131 | - initArray(src); | |
132 | - dim3 grid(20, 10890); | |
132 | + initArray(src, DIM_Y*10); | |
133 | + dim3 grid(20, DIM_Y*10); | |
133 | 134 | dim3 block(1, 1); |
134 | 135 | get_diff <<< grid, block >>> (result); |
135 | - stim::gpu2image<float>(result, "test.bmp", 20,10890,0,1); | |
136 | - for (int i = 0; i < 1089; i++){ | |
136 | + stim::gpu2image<float>(result, "test.bmp", 20,DIM_Y*10,0,1); | |
137 | + for (int i = 0; i < DIM_Y; i++){ | |
137 | 138 | output[i] = get_sum(result+(20*10*i)); |
138 | 139 | if(output[i] <= mini){ |
139 | 140 | mini = output[i]; | ... | ... |
stim/gl/gl_spider.h
... | ... | @@ -74,7 +74,9 @@ class gl_spider : public virtual gl_texture<T> |
74 | 74 | /* Method for finding the best scale for the spider. |
75 | 75 | changes the x, y, z size of the spider to minimize the cost |
76 | 76 | function. */ |
77 | + getSample(position, direction, magnitude); | |
77 | 78 | genTemplate(dirVectors, 0); |
79 | + int bets = getCost(); | |
78 | 80 | //getSample(position, direction, magnitude); |
79 | 81 | //int best = getCost(); |
80 | 82 | } |
... | ... | @@ -122,16 +124,16 @@ class gl_spider : public virtual gl_texture<T> |
122 | 124 | stim::vec<float>p2; |
123 | 125 | stim::vec<float>p3; |
124 | 126 | stim::vec<float>p4; |
125 | - std::cout << "hor" << std::endl; | |
127 | + //std::cout << "hor" << std::endl; | |
126 | 128 | p1 = hor.p(1,1); |
127 | - std::cout << p1 << std::endl; | |
129 | + //std::cout << p1 << std::endl; | |
128 | 130 | p2 = hor.p(1,0); |
129 | - std::cout << p2 << std::endl; | |
131 | + //std::cout << p2 << std::endl; | |
130 | 132 | p3 = hor.p(0,0); |
131 | - std::cout << p3 << std::endl; | |
133 | + //std::cout << p3 << std::endl; | |
132 | 134 | p4 = hor.p(0,1); |
133 | - std::cout << p4 << std::endl; | |
134 | - /* glBegin(GL_QUADS); | |
135 | + //std::cout << p4 << std::endl; | |
136 | + glBegin(GL_QUADS); | |
135 | 137 | glTexCoord3f( |
136 | 138 | // p1[0]/S[1], |
137 | 139 | // p1[1]/S[2], |
... | ... | @@ -141,7 +143,6 @@ class gl_spider : public virtual gl_texture<T> |
141 | 143 | p1[1], |
142 | 144 | p1[2] |
143 | 145 | ); |
144 | - CHECK_OPENGL_ERROR | |
145 | 146 | //glVertex2f(0.0,0.0); |
146 | 147 | glVertex2f(v_x,v_y); |
147 | 148 | glTexCoord3f( |
... | ... | @@ -175,17 +176,17 @@ class gl_spider : public virtual gl_texture<T> |
175 | 176 | //glVertex2f(0.0, 2.0); |
176 | 177 | glVertex2f(v_x, v_y+len); |
177 | 178 | glEnd(); |
178 | -*/ | |
179 | - std::cout << "ver" << std::endl; | |
179 | + | |
180 | + //std::cout << "ver" << std::endl; | |
180 | 181 | p1 = ver.p(1,1); |
181 | - std::cout << p1 << std::endl; | |
182 | + //std::cout << p1 << std::endl; | |
182 | 183 | p2 = ver.p(1,0); |
183 | - std::cout << p2 << std::endl; | |
184 | + //std::cout << p2 << std::endl; | |
184 | 185 | p3 = ver.p(0,0); |
185 | - std::cout << p3 << std::endl; | |
186 | + //std::cout << p3 << std::endl; | |
186 | 187 | p4 = ver.p(0,1); |
187 | - std::cout << p4 << std::endl; | |
188 | -/* glBegin(GL_QUADS); | |
188 | + //std::cout << p4 << std::endl; | |
189 | + glBegin(GL_QUADS); | |
189 | 190 | glTexCoord3f( |
190 | 191 | // p1[0]/S[1], |
191 | 192 | // p1[1]/S[2], |
... | ... | @@ -226,7 +227,8 @@ class gl_spider : public virtual gl_texture<T> |
226 | 227 | ); |
227 | 228 | //glVertex2f(1.0, 2.0); |
228 | 229 | glVertex2f(v_x+len, v_y+len); |
229 | - glEnd(); */ | |
230 | + glEnd(); | |
231 | + CHECK_OPENGL_ERROR | |
230 | 232 | } |
231 | 233 | |
232 | 234 | ///@param vector of stim::vec in that stores all of the samplable vectors. |
... | ... | @@ -241,6 +243,8 @@ class gl_spider : public virtual gl_texture<T> |
241 | 243 | { |
242 | 244 | float x = 0.0; |
243 | 245 | vec<float> Y(1.0,0.0,0.0); |
246 | + vec<float> pos(0.0,0.0,0.0); | |
247 | + vec<float> mag(1.0, 1.0, 1.0); | |
244 | 248 | switch(type) { |
245 | 249 | case 0: //Direction |
246 | 250 | Bind(); |
... | ... | @@ -249,16 +253,16 @@ class gl_spider : public virtual gl_texture<T> |
249 | 253 | if(cos(Y.dot(in[i]))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;} |
250 | 254 | else{Y[0] = 1.0; Y[1] = 0.0;} |
251 | 255 | |
252 | - hor = stim::rect<float>(magnitude, | |
253 | - position, in[i], | |
256 | + hor = stim::rect<float>(mag, | |
257 | + pos, in[i], | |
254 | 258 | ((Y.cross(in[i])).cross(in[i])).norm()); |
255 | - ver = stim::rect<float>(magnitude, | |
256 | - position, in[i], | |
259 | + ver = stim::rect<float>(mag, | |
260 | + pos, in[i], | |
257 | 261 | hor.n()); |
262 | + // std::cout<< (x+i*10.0) << std::endl; | |
258 | 263 | UpdateBuffer(x, x+i*10.0); |
259 | 264 | } |
260 | 265 | Unbind(); |
261 | - std::cout<< "Hmmm" << std::endl; | |
262 | 266 | break; |
263 | 267 | case 1: //Position |
264 | 268 | Bind(); |
... | ... | @@ -320,8 +324,11 @@ class gl_spider : public virtual gl_texture<T> |
320 | 324 | GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; |
321 | 325 | glDrawBuffers(1, DrawBuffers); |
322 | 326 | glBindTexture(GL_TEXTURE_2D, texbufferID); |
323 | - glClearColor(0,0,0,0); | |
327 | + glClearColor(1,1,1,1); | |
324 | 328 | glClear(GL_COLOR_BUFFER_BIT); |
329 | + glMatrixMode(GL_TEXTURE); | |
330 | + glLoadIdentity(); | |
331 | + getSample(position, direction, magnitude); | |
325 | 332 | glMatrixMode(GL_PROJECTION); |
326 | 333 | glLoadIdentity(); |
327 | 334 | glMatrixMode(GL_MODELVIEW); |
... | ... | @@ -330,6 +337,7 @@ class gl_spider : public virtual gl_texture<T> |
330 | 337 | gluOrtho2D(0.0,2.0*len,0.0,numSamples*len); |
331 | 338 | glEnable(GL_TEXTURE_3D); |
332 | 339 | glBindTexture(GL_TEXTURE_3D, texID); |
340 | + CHECK_OPENGL_ERROR | |
333 | 341 | } |
334 | 342 | |
335 | 343 | ///Method for Unbinding all of the texture resources |
... | ... | @@ -367,7 +375,7 @@ class gl_spider : public virtual gl_texture<T> |
367 | 375 | temp[2] = d_s[2]+dp*j; |
368 | 376 | |
369 | 377 | temp = (temp.sph2cart()).norm(); //back to cart |
370 | - std::cout << temp << std::endl; | |
378 | + //std::cout << temp << std::endl; | |
371 | 379 | dirVectors.push_back(temp); |
372 | 380 | } |
373 | 381 | } |
... | ... | @@ -459,7 +467,7 @@ class gl_spider : public virtual gl_texture<T> |
459 | 467 | getCost() |
460 | 468 | { |
461 | 469 | createResource(); |
462 | - int cost = get_cost(resource, iter); | |
470 | + int cost = get_cost(resource, iter, numSamples); | |
463 | 471 | destroyResource(); |
464 | 472 | iter++; |
465 | 473 | return cost; |
... | ... | @@ -477,8 +485,8 @@ class gl_spider : public virtual gl_texture<T> |
477 | 485 | setPosition(0.0,0.0,0.0); |
478 | 486 | setDirection(0.0,0.0,1.0); |
479 | 487 | setMagnitude(1.0); |
480 | - //numSamples = 1089; | |
481 | - numSamples = 9; | |
488 | + numSamples = 1089; | |
489 | + //numSamples = 9; | |
482 | 490 | std::cout << "I did this" <<std::endl; |
483 | 491 | } |
484 | 492 | gl_spider |
... | ... | @@ -511,11 +519,12 @@ class gl_spider : public virtual gl_texture<T> |
511 | 519 | GenerateFBO(20, numSamples*10); |
512 | 520 | //sampleDirection(); |
513 | 521 | genDirectionVectors(); |
514 | - CHECK_OPENGL_ERROR | |
515 | 522 | genPositionVectors(); |
516 | 523 | genMagnitudeVectors(); |
517 | 524 | gl_texture<T>::setDims(0.6, 0.6, 2.0); |
525 | + getSample(position, direction, magnitude); | |
518 | 526 | genTemplate(dirVectors, 0); |
527 | + std::cout << S[1] << ":" << S[2] << ":" << S[3] << std::endl; | |
519 | 528 | //gl_texture<T>::setDims(1.0, 1.0,1.0); |
520 | 529 | } |
521 | 530 | |
... | ... | @@ -575,17 +584,46 @@ class gl_spider : public virtual gl_texture<T> |
575 | 584 | |
576 | 585 | void getSample(vec<float> pos, vec<float> dir, vec<float> mag) |
577 | 586 | { |
578 | - Bind(); | |
587 | + //Bind(); | |
588 | + stim::vec<float>p1; | |
589 | + stim::vec<float>p2; | |
590 | + stim::vec<float>p3; | |
591 | + stim::vec<float>p4; | |
592 | + p1 = hor.p(1,1); | |
593 | + p2 = hor.p(1,0); | |
594 | + p3 = hor.p(0,0); | |
595 | + p4 = hor.p(0,1); | |
579 | 596 | glMatrixMode(GL_TEXTURE); |
580 | 597 | glLoadIdentity(); |
581 | - vec<float> temp = dir.sph2cart(); | |
598 | + //glScalef(0.005,0.005, 0.005); | |
582 | 599 | glScalef(mag[0], mag[1], mag[0]); |
583 | - //glRotatef(rotz, 0.0, 0.0, 1.0); | |
600 | + //glRotatef(30, 0.0, 0.0, 1.0); | |
584 | 601 | //glRotatef(roty, 0.0, 1.0, 0.0); |
585 | 602 | //glRotatef(rotx, 1.0, 0.0 ,0.0); |
586 | 603 | glTranslatef(pos[0], pos[1], pos[2]); |
587 | - glScalef(1/512/S[0], 1/512/S[1], 1/426/S[2]); | |
588 | - Unbind(); | |
604 | + glScalef(1/512/S[1], 1/512/S[2], 1/426/S[3]); | |
605 | + std::cout << "DEBUG: gl_spider::605" << std::endl; | |
606 | + std::cout << "pos: " << position << std::endl; | |
607 | + std::cout << "dir: " << direction << std::endl; | |
608 | + std::cout << "mag: " << magnitude << std::endl; | |
609 | + std::cout << "Before Transformation" << std::endl; | |
610 | + std::cout << p1 << ":" << p2 << ":" << p3 << ":" << p4 << std::endl; | |
611 | + std::cout << "After Transformation" << std::endl; | |
612 | + std::cout << "[" << (p1[0]+pos[0])/512/S[1] << ", " | |
613 | + <<(p1[1]+pos[1])/512/S[2] << ", " | |
614 | + <<(p1[2]+pos[2])/426/S[3] << "]" << ":" | |
615 | + << "[" << (p2[0]+pos[0])/512/S[1] << ", " | |
616 | + << (p2[1]+pos[1])/512/S[2] << ", " | |
617 | + << (p2[2]+pos[2])/426/S[3] << "]" << ":" | |
618 | + << "[" << (p3[0]+pos[0])/512/S[1] << ", " | |
619 | + << (p3[1]+pos[1])/512/S[2] << ", " | |
620 | + << (p3[2]+pos[2])/426/S[3] << "]" << ":" | |
621 | + << "[" << (p4[0]+pos[0])/512/S[1] << ", " | |
622 | + << (p4[1]+pos[1])/512/S[2] << ", " | |
623 | + << (p4[2]+pos[2])/426/S[3] << "]" << std::endl; | |
624 | + | |
625 | + //glMatrixMode(GL_MODELVIEW); | |
626 | + //Unbind(); | |
589 | 627 | } |
590 | 628 | |
591 | 629 | ///@param vector dir, the new direction. | ... | ... |
stim/gl/gl_texture.h
... | ... | @@ -156,11 +156,17 @@ class gl_texture : public virtual image_stack<T> |
156 | 156 | { |
157 | 157 | case GL_TEXTURE_3D: |
158 | 158 | glTexParameteri(texture_type, |
159 | - GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
159 | + GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); | |
160 | + // GL_REPEAT); | |
161 | + // GL_CLAMP_TO_EDGE); | |
160 | 162 | glTexParameteri(texture_type, |
161 | - GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
163 | + GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); | |
164 | + // GL_REPEAT); | |
165 | + // GL_CLAMP_TO_EDGE); | |
162 | 166 | glTexParameteri(texture_type, |
163 | - GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); | |
167 | + GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE); | |
168 | + // GL_REPEAT); | |
169 | + // GL_CLAMP_TO_EDGE); | |
164 | 170 | glTexImage3D(texture_type, |
165 | 171 | 0, |
166 | 172 | // GL_RGB16, | ... | ... |