diff --git a/cuda/cost.h b/cuda/cost.h index fd8a121..1389074 100644 --- a/cuda/cost.h +++ b/cuda/cost.h @@ -61,17 +61,12 @@ void get_diff (float *result) int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; int idx = y*DIM_X+x; - //idx = x*DIM_Y+y; - //int idx = x*DIM_X+y; - //uchar4 color = tex2D(texIn, x, y); - //float3 tempcolor = make_float3(color.x, color.y, color.z); - //float valIn = tempcolor.x + tempcolor.y + tempcolor.z; - float valIn = tex2D(texIn, x, y)/255.0; + float valIn = tex2D(texIn, x, y); + //float valIn = tex2D(texIn, x, y)/255.0; float valTemp = Template(x); - result[idx] = abs(valIn-valTemp); - //-valTemp; -// - valTemp; + //result[idx] = abs(valIn-valTemp); + result[idx] = abs(valIn); // #if __CUDA_ARCH__>=200 // printf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); // #endif diff --git a/gl/gl_spider.h b/gl/gl_spider.h index d1c65be..101af5c 100644 --- a/gl/gl_spider.h +++ b/gl/gl_spider.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "gl_texture.h" #include "../visualization/camera.h" #include "./error.h" @@ -130,8 +131,9 @@ class gl_spider : public virtual gl_texture attachSpider(GLuint id) { texID = id; - GenerateFBO(400,200); - Update(); + GenerateFBO(800,400); + // Update(); + generateVectorField(direction, 75.0); } void @@ -146,7 +148,42 @@ class gl_spider : public virtual gl_texture hor.n()); UpdateBuffer(); } + + void + Update(float v_x, float v_y, vec dir, float dim) + { + vec Y(1.0,0.0,0.0); + if(cos(Y.dot(dir))< 0.087){ + Y[0] = 0.0; Y[1] = 1.0;} + hor = stim::rect(magnitude, position, dir.norm(), + ((Y.cross(dir)).cross(dir)).norm()); + ver = stim::rect(magnitude, position, dir.norm(), + hor.n()); + UpdateBuffer(v_x, v_y, dim); + } + stim::vec + toSpherical(vec in) + { + vec out; + out[0] = sqrt(pow(in[0],2) + pow(in[1],2) + pow(in[2],2)); + out[1] = atan(in[1]/in[0]); + out[2] = acos(in[2]/out[0]); + return out; + } + + stim::vec + toCartesian(vec in) + { + vec out; + out[0] = cos(in[1])*sin(in[2]); + out[1] = sin(in[1])*sin(in[2]); + out[2] = cos(in[2]); + return out; + } + + + vec getPosition() { @@ -312,14 +349,145 @@ class gl_spider : public virtual gl_texture ); glVertex2f(1.0, 2.0); glEnd(); - //glClearColor(1,1,1,1); + glBindTexture(GL_TEXTURE_3D, 0); + glDisable(GL_TEXTURE_3D); + glBindFramebuffer(GL_FRAMEBUFFER,0); + glBindTexture(GL_TEXTURE_2D, 0); + } + + void + UpdateBuffer(float v_x, float v_y, float len) + { + std::cout << v_x << "," << v_y << std::endl; + //float len = dim; + stim::vecp1; + stim::vecp2; + stim::vecp3; + stim::vecp4; + glBindFramebuffer(GL_FRAMEBUFFER, fboID); + glFramebufferTexture2D( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, + texbufferID, + 0); + glBindFramebuffer(GL_FRAMEBUFFER, fboID); + GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; + glDrawBuffers(1, DrawBuffers); + glBindTexture(GL_TEXTURE_2D, texbufferID); + //glClearColor(0,0,0,0); //glClear(GL_COLOR_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0,0,800,400); + gluOrtho2D(0.0,8.0,0.0,4.0); + glEnable(GL_TEXTURE_3D); + glBindTexture(GL_TEXTURE_3D, texID); + p1 = hor.p(1,1); + p2 = hor.p(1,0); + p3 = hor.p(0,0); + p4 = hor.p(0,1); + glBegin(GL_QUADS); + glTexCoord3f( + p1[0], + p1[1], + p1[2] + ); + //glVertex2f(0.0,0.0); + glVertex2f(v_x,v_y); + glTexCoord3f( + p2[0], + p2[1], + p2[2] + ); + //glVertex2f(1.0, 0.0); + glVertex2f(v_x+len, v_y); + glTexCoord3f( + p3[0], + p3[1], + p3[2] + ); + //glVertex2f(1.0, 2.0); + glVertex2f(v_x+len, v_y+len); + glTexCoord3f( + p4[0], + p4[1], + p4[2] + ); + //glVertex2f(0.0, 2.0); + glVertex2f(v_x, v_y+len); + glEnd(); + p1 = ver.p(1,1); + p2 = ver.p(1,0); + p3 = ver.p(0,0); + p4 = ver.p(0,1); + glBegin(GL_QUADS); + glTexCoord3f( + p1[0], + p1[1], + p1[2] + ); + //glVertex2f(1.0, 0.0); + glVertex2f(v_x+len, v_y); + glTexCoord3f( + p2[0], + p2[1], + p2[2] + ); + //glVertex2f(2.0, 0.0); + glVertex2f(v_x+2*len, v_y); + glTexCoord3f( + p3[0], + p3[1], + p3[2] + ); + //glVertex2f(2.0, 2.0); + glVertex2f(v_x+2*len, v_y+len); + glTexCoord3f( + p4[0], + p4[1], + p4[2] + ); + //glVertex2f(1.0, 2.0); + glVertex2f(v_x+len, v_y+len); + glEnd(); glBindTexture(GL_TEXTURE_3D, 0); glDisable(GL_TEXTURE_3D); glBindFramebuffer(GL_FRAMEBUFFER,0); glBindTexture(GL_TEXTURE_2D, 0); } - + + void + generateVectorField(stim::vec d, float dim) + { + vec d_s = toSpherical(d); + vec temp; + float Dim = (float) dim; + float y_0 = 0.0; + float x_0 = 0.0; + float len = 4.0/(2.0*Dim+1.0); + float t0 = M_PI/2; + float p0 = M_PI/3; + float dt = 2.0*t0/Dim; + float dp = 2.0*p0/Dim; + for(int i = -dim; i <= dim; i++){ + for(int j = -dim; j <= dim; j++){ + //field[i+dim][j+dim][0] = d[0]; + //field[i+dim][j+dim][1] = d[1]+dt*i; + //field[i+dim][j+dim][2] = d[2]+dp*j; + temp[0] = 1; + temp[1] = d_s[1]+dt*i; + temp[2] = d_s[2]+dp*j; + temp = toCartesian(temp); + std::cout << i <<"," << j << std::endl; + Update(x_0+2.0*(i+dim)*len, y_0+(j+dim)*len, temp, len); + } + } + + } + void GenerateFBO(unsigned int width, unsigned int height) @@ -345,40 +513,7 @@ class gl_spider : public virtual gl_texture void initCuda() { - /* cudaDeviceProp prop; - int device; - memset( &prop, 0, sizeof(cudaDeviceProp) ); - prop.major = 1; - prop.minor = 0; - HANDLE_ERROR( cudaChooseDevice (&device, &prop ) ); - HANDLE_ERROR( cudaGetDeviceProperties(&prop, device)); - printf(" device number: %d\n", device); - printf(" device name: %s\n", prop.name); - printf(" device maxTexture3D: %d %d %d\n", prop.maxTexture3D[0] ,prop.maxTexture3D[0], prop.maxTexture3D[2]) ; - HANDLE_ERROR( cudaGLSetGLDevice (device)); */ - //stim::cudaSetDevice(); -/* HANDLE_ERROR( - cudaGraphicsMapResources(1, &resource, 0) - ); - HANDLE_ERROR( - cudaGraphicsResourceGetMappedPointer( - &devPtr, - size, - resource)); - HANDLE_ERROR( - cudaGraphicsSubResourceGetMappedArray( - &c_Array, - resource, - 0,0) - ); - HANDLE_ERROR( - cudaBindTextureToArray(fboID, c_Array) - ); - HANDLE_ERROR( - cudaGraphicsUnmapResources(1, &resource, 0) - ); - //need to move the constants to video memory. -*/ + stim::cudaSetDevice(); } void @@ -392,9 +527,6 @@ class gl_spider : public virtual gl_texture //CU_GRAPHICS_REGISTER_FLAGS_NONE) cudaGraphicsMapFlagsReadOnly) ); - //HANDLE_ERROR( - // cudaGraphicsMapResources(1, &resource) - //); } void @@ -403,11 +535,9 @@ class gl_spider : public virtual gl_texture HANDLE_ERROR( cudaGraphicsUnregisterResource(resource) ); - //HANDLE_ERROR( - // cudaGraphicsUnmapResources(1,&resource) - //); } + float getCost() { -- libgit2 0.21.4