00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "gpu_area.h"
00032
00033
00035 texture<float, 2, cudaReadModeElementType> d_integralTex;
00036
00037 namespace asrl {
00038
00039 cudaError_t texturize_integral_image_c(cudaArray* intImg)
00040 {
00041
00042 d_integralTex.addressMode[0] = cudaAddressModeClamp;
00043 d_integralTex.addressMode[1] = cudaAddressModeClamp;
00044 d_integralTex.filterMode = cudaFilterModeLinear;
00045 d_integralTex.normalized = false;
00046
00047
00048 cudaError_t err = cudaBindTextureToArray(d_integralTex, intImg);
00049
00050 return err;
00051 }
00052
00053
00054 cudaError_t fh_untexturizeIntegral_c()
00055 {
00056 cudaError_t err = cudaUnbindTexture(d_integralTex);
00057
00058 return err;
00059 }
00060
00061
00089 __device__ float iiAreaLookupCDHalfWH(float cx, float cy, float halfWidth, float halfHeight)
00090 {
00091 float result = 0.f;
00092
00093
00094 result += tex2D(d_integralTex, cx - halfWidth, cy - halfHeight);
00095
00096 result -= tex2D(d_integralTex, cx + halfWidth, cy - halfHeight);
00097
00098 result -= tex2D(d_integralTex, cx - halfWidth, cy + halfHeight);
00099
00100 result += tex2D(d_integralTex, cx + halfWidth, cy + halfHeight);
00101
00102 return result;
00103 }
00104
00132 __device__ float iiAreaLookupCD(float cx, float cy, float width, float height)
00133 {
00134 return iiAreaLookupCDHalfWH(cx,cy,width*0.5f,height*0.5f);
00135 }
00136
00146 __global__ void iiAreaLookupCDKernel(float * d_result, float cx, float cy, float width, float height)
00147 {
00148 d_result[0] = iiAreaLookupCD(cx,cy,width,height);
00149 }
00150
00151
00152 void run_iiAreaLookupCDKernel(dim3 grid, dim3 threads, float * d_result, float cx, float cy, float width, float height)
00153 {
00154 iiAreaLookupCDKernel<<< grid, threads >>>(d_result, cx, cy, width, height);
00155 }
00156 }
00157