lamino_bp_generic.cl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // all kernels must process volme voxelwise
  2. // please be careful with local and global workers
  3. // we need a 3D processing (not 2D)
  4. // using tests we show max volume grosse: 1024 x 1024 x 256 or 2048 x 2048 x 64
  5. // theory: 223 MB (CL_DEVICE_MAX_MEM_ALLOC_SIZE) x 5 cards / 4 Bytes (Float) = 1024 x 1024 x 278 voxels
  6. #include <lamino-filter-def.h>
  7. #define PI 3.1415926535897932384626433832795028841971693993751
  8. #define PI_2 1.5707963267948966192313216916397514420985846996876
  9. float
  10. interpolate (global float *proj,
  11. global CLParameters *param,
  12. float oldx,
  13. float oldy)
  14. {
  15. /* Check if vertically out of projection plane boundaries */
  16. if (oldy < 0)
  17. oldy = 0.5;;
  18. if (oldy > param->proj_sy)
  19. oldy = param->proj_sy - 0.5;
  20. /* bilinear interpolation */
  21. const float yf_1 = oldy - floor(oldy);
  22. const float yf_0 = 1.0f - yf_1;
  23. const float xf_1 = oldx - floor(oldx);
  24. const float xf_0 = 1.0f - xf_1;
  25. const int base = ((int) floor(oldx)) + ((int) floor(oldy)) * param->proj_sx;
  26. float result;
  27. result = proj[base ] * xf_0 * yf_0;
  28. result += proj[base + 1] * xf_1 * yf_0;
  29. result += proj[base + param->proj_sx ] * xf_0 * yf_1;
  30. result += proj[base + param->proj_sx + 1] * xf_1 * yf_1;
  31. return result;
  32. }
  33. kernel void
  34. lamino_bp_generic (global float *proj,
  35. global float *volume,
  36. global CLParameters *param)
  37. {
  38. const ushort vX = get_global_id(0);
  39. const ushort vY = get_global_id(1);
  40. const ushort vZ = get_global_id(2);
  41. const long int idx = (vZ * get_global_size(1) * get_global_size(0)) +
  42. (vY * get_global_size(0)) + vX;
  43. const float newz = (float) vZ * param->z_spacing - param->vol_oz;
  44. const float newy = (float) vY - param->vol_oy;
  45. const float newx = (float) vX - param->vol_ox;
  46. const float oldx = newx * param->mat_0 + newy * param->mat_1 + newz * param->mat_2 + param->proj_ox;
  47. const float oldy = newx * param->mat_3 + newy * param->mat_4 + newz * param->mat_5 + param->proj_oy;
  48. volume[idx] += interpolate (proj, param, oldx, oldy);
  49. }
  50. kernel void
  51. lamino_bp_varied (global float *proj,
  52. global float *volume,
  53. global CLParameters *param)
  54. {
  55. const ushort vX = get_global_id(0);
  56. const ushort vY = get_global_id(1);
  57. const ushort vZ = get_global_id(2);
  58. const long int idx = (vZ * get_global_size(1) * get_global_size(0)) +
  59. (vY * get_global_size(0)) + vX;
  60. const float newz = (float) vZ * param->z_spacing - param->vol_oz;
  61. const float newy = (float) vY - param->vol_oy;
  62. const float newx = (float) vX - param->vol_ox;
  63. /* Vary alpha depending on the z height */
  64. const float alpha = -3 * PI_2 + param->theta;
  65. const float cf = cos(param->phi);
  66. const float ct = cos(alpha);
  67. const float cg = cos(param->psi);
  68. const float sf = sin(param->phi);
  69. const float st = sin(alpha);
  70. const float sg = sin(param->psi);
  71. const float mat_0 = cg * cf - sg * st * sf;
  72. const float mat_1 = -cg * sf - sg * st * cf;
  73. const float mat_2 = -sg * ct;
  74. const float mat_3 = sg * cf + cg * st * sf;
  75. const float mat_4 = -sg * sf + cg * st * cf;
  76. const float mat_5 = cg * ct;
  77. /* Force newz values to be equal to 0 */
  78. const float oldx = newx * mat_0 + newy * mat_1 /* + newz * mat_2 */ + param->proj_ox + newz / param->vol_sz * param->proj_ox_variation;
  79. const float oldy = newx * mat_3 + newy * mat_4 /* + newz * mat_5 */ + param->proj_oy;
  80. volume[idx] += interpolate (proj, param, oldx, oldy);
  81. }
  82. kernel void
  83. lamino_clean_vol (global float *volume)
  84. {
  85. const ushort vX = get_global_id(0);
  86. const ushort vY = get_global_id(1);
  87. const ushort vZ = get_global_id(2);
  88. const ushort vSX = get_global_size(0);
  89. const ushort vSY = get_global_size(1);
  90. const ushort vSZ = get_global_size(2);
  91. const int idx = (vZ * vSY * vSX) + (vY * vSX) + vX;
  92. volume[idx] = 0;
  93. }
  94. kernel void
  95. lamino_norm_vol(global float *volume,
  96. const float factor)
  97. {
  98. const ushort vX = get_global_id(0);
  99. const ushort vY = get_global_id(1);
  100. const ushort vZ = get_global_id(2);
  101. const ushort vSX = get_global_size(0);
  102. const ushort vSY = get_global_size(1);
  103. const ushort vSZ = get_global_size(2);
  104. const int idx = (vZ * vSY * vSX) + (vY * vSX) + vX;
  105. //const int idx = (vY * vSX) + vX;
  106. float val = volume[idx] * factor;
  107. volume[idx] = val;
  108. }