ankabackproject.cl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2011-2014 Karlsruhe Institute of Technology
  3. *
  4. * This file is part of Ufo.
  5. *
  6. * This library is free software: you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation, either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. kernel void backproject (global float *volume,
  20. read_only image2d_t projection,
  21. const sampler_t sampler,
  22. const float2 x_region,
  23. const float2 y_region,
  24. const float2 z_region,
  25. const float8 tmatrix,
  26. const uint cumulate)
  27. {
  28. int3 id = (int3) (get_global_id (0), get_global_id (1), get_global_id (2));
  29. float2 pixel;
  30. float3 voxel;
  31. voxel.x = mad((float) id.x, x_region.y, x_region.x);
  32. voxel.y = mad((float) id.y, y_region.y, y_region.x);
  33. voxel.z = mad((float) id.z, z_region.y, z_region.x);
  34. pixel.x = mad(voxel.x, tmatrix.s0, mad(voxel.y, tmatrix.s1, tmatrix.s3));
  35. pixel.y = mad(voxel.x, tmatrix.s4, mad(voxel.y, tmatrix.s5, mad(voxel.z, tmatrix.s6, tmatrix.s7)));
  36. if (cumulate) {
  37. volume[id.z * get_global_size (0) * get_global_size (1) +
  38. id.y * get_global_size (0) + id.x] += read_imagef (projection, sampler, pixel).x;
  39. }
  40. else {
  41. volume[id.z * get_global_size (0) * get_global_size (1) +
  42. id.y * get_global_size (0) + id.x] = read_imagef (projection, sampler, pixel).x;
  43. }
  44. }
  45. kernel void backproject_from_3d (global float *volume,
  46. read_only image3d_t projections,
  47. const sampler_t sampler,
  48. const float2 x_region,
  49. const float2 y_region,
  50. const float2 z_region,
  51. constant float *sines,
  52. constant float *cosines,
  53. const float2 center,
  54. const float sin_lamino,
  55. const float cos_lamino)
  56. {
  57. int3 id = (int3) (get_global_id (0), get_global_id (1), get_global_id (2));
  58. int i;
  59. float result = 0.0f;
  60. float4 pixel;
  61. float3 voxel;
  62. voxel.x = mad((float) id.x, x_region.y, x_region.x);
  63. voxel.y = mad((float) id.y, y_region.y, y_region.x);
  64. voxel.z = mad((float) id.z, z_region.y, z_region.x);
  65. for (i = 0; i < get_image_depth (projections); i++) {
  66. pixel.x = voxel.x * cosines[i] + voxel.y * sines[i] + center.x;
  67. pixel.y = voxel.x * cos_lamino * sines[i] - voxel.y * cos_lamino * cosines[i] + voxel.z * sin_lamino + center.y;
  68. pixel.z = (float) i;
  69. result += read_imagef (projections, sampler, pixel).x;
  70. }
  71. volume[id.z * get_global_size (0) * get_global_size (1) + id.y * get_global_size (0) + id.x] = result;
  72. }