CUDA_interpolation.h

Go to the documentation of this file.
00001 #ifndef __CUDA_INTERPOLATION_H__
00002 #define __CUDA_INTERPOLATION_H__
00003 
00004 template <typename T> class CUDAkernel_Interpolate_NearestNaighbor
00005 {
00006 public:
00007     __device__ float operator()(const void* SourceData, const int3& VolumeSize, const float3& Pos)
00008     {
00009         return ((T*)SourceData)[(int)(__float2int_rn(Pos.z)*VolumeSize.x*VolumeSize.y + 
00010             __float2int_rn(Pos.y)*VolumeSize.x +
00011             __float2int_rn(Pos.x))];
00012     }
00013 };
00014 
00015 
00016 
00017 template <typename T> class CUDAkernel_Interpolate_Trilinear
00018 {
00019 public:
00020     __device__ float operator()(const void* SourceData, const int3& VolumeSize, const float3& Pos)
00021     {
00022         float posX = Pos.x - __float2int_rd(Pos.x);
00023         float posY = Pos.y - __float2int_rd(Pos.y);
00024         float posZ = Pos.z - __float2int_rd(Pos.z);
00025 
00026         int base = __float2int_rd((Pos.z)) * VolumeSize.x * VolumeSize.y + 
00027             __float2int_rd((Pos.y)) * VolumeSize.x +
00028             __float2int_rd((Pos.x));
00029 
00030         return interpolater(posX, posY, posZ,
00031             ((T*)SourceData)[base],
00032             ((T*)SourceData)[(int)(base + VolumeSize.x * VolumeSize.y)],
00033             ((T*)SourceData)[(int)(base + VolumeSize.x)],
00034             ((T*)SourceData)[(int)(base + VolumeSize.x * VolumeSize.y + VolumeSize.x)],
00035             ((T*)SourceData)[(int)(base + 1)],
00036             ((T*)SourceData)[(int)(base + VolumeSize.x * VolumeSize.y + 1)],
00037             ((T*)SourceData)[(int)(base + VolumeSize.x + 1)],
00038             ((T*)SourceData)[(int)(base + VolumeSize.x * VolumeSize.y + VolumeSize.x + 1)]);
00039     }
00040 private:
00041 __device__ T interpolater(float posX, float posY, float posZ,
00042                          T val1, T val2, T val3, T val4,
00043                          T val5, T val6, T val7, T val8)
00044 {
00045     float revX = 1-posX;
00046     float revY = 1-posY;
00047     float revZ = 1-posZ;
00048 
00049     return ((T)
00050         (revX * (revY * (revZ * val1  +
00051         posZ * val2) +
00052         posY * (revZ * val3  +
00053         posZ * val4))+
00054         posX * (revY * (revZ * val5  +
00055         posZ * val6)   +
00056         posY * (revZ * val7 +
00057         posZ * val8)))
00058         );
00059 }
00060 };
00061 
00062 #endif /* __CUDA_INTERPOLATION_H__ */

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1