1#ifndef __PARALLELPROJ_CUDA_PROJECTOR_KERNELS_H__
2#define __PARALLELPROJ_CUDA_PROJECTOR_KERNELS_H__
3
4/** @brief Calculate whether a ray and a cube intersect and the possible intersection points
5 *
6 * The ray is given by origin + t*rdir (vector notation)
7 * if the ray intersects the cube, the two t values t1 and t2
8 * for the intersection points are computed.
9 *
10 * This algorithm assumes that the IEEE floating point arithmetic standard 754 is followed
11 * which handles divions by 0 and -0 correctly.
12 *
13 * @param orig0 ... 0 cordinate of the ray origin
14 * @param orig1 ... 1 cordinate of the ray origin
15 * @param orig2 ... 2 cordinate of the ray origin
16 * @param bounds0_min ... 0 cordinate of the start of the cube bounding box
17 * @param bounds1_min ... 1 cordinate of the start of the cube bounding box
18 * @param bounds2_min ... 2 cordinate of the start of the cube bounding box
19 * @param bounds0_max ... 0 cordinate of the end of the cube bounding box
20 * @param bounds1_max ... 1 cordinate of the end of the cube bounding box
21 * @param bounds2_max ... 2 cordinate of the end of the cube bounding box
22 * @param rdir0 ... 0 cordinate of the ray directional vector
23 * @param rdir1 ... 1 cordinate of the ray directional vector
24 * @param rdir2 ... 2 cordinate of the ray directional vector
25 * @param t1 ... (output) ray parameter of 1st intersection point
26 * @param t2 ... (output) ray parameter of 2nd intersection point
27 *
28 * @return ... unsigned char (0 or 1) whether ray intersects cube
29 */
30extern "C" __device__ unsigned char ray_cube_intersection_cuda(float orig0,
31 float orig1,
32 float orig2,
33 float bounds0_min,
34 float bounds1_min,
35 float bounds2_min,
36 float bounds0_max,
37 float bounds1_max,
38 float bounds2_max,
39 float rdir0,
40 float rdir1,
41 float rdir2,
42 float* t1,
43 float* t2);
44
45
46
47/**
48 * @brief Calculate the TOF bins along an LOR to which a voxel contributes
49 *
50 * @param x_m0 0-component of center of LOR
51 * @param x_m1 1-component of center of LOR
52 * @param x_m2 2-component of center of LOR
53 * @param x_v0 0-component of voxel
54 * @param x_v1 1-component of voxel
55 * @param x_v2 2-component of voxel
56 * @param u0 0-component of unit vector that points from start to end of LOR
57 * @param u1 1-component of unit vector that points from start to end of LOR
58 * @param u2 2-component of unit vector that points from start to end of LOR
59 * @param tofbin_width width of the TOF bins in spatial units
60 * @param tofcenter_offset offset of the central tofbin from the midpoint of the LOR in spatial units
61 * @param sigma_tof TOF resolution in spatial coordinates
62 * @param n_sigmas number of sigmas considered to be relevant
63 * @param n_half n_tofbins // 2
64 * @param it1 (output) lower relevant tof bin
65 * @param it2 (output) upper relevant tof bin
66 */
67extern "C" __device__ void relevant_tof_bins_cuda(float x_m0,
68 float x_m1,
69 float x_m2,
70 float x_v0,
71 float x_v1,
72 float x_v2,
73 float u0,
74 float u1,
75 float u2,
76 float tofbin_width,
77 float tofcenter_offset,
78 float sigma_tof,
79 float n_sigmas,
80 int n_half,
81 int *it1,
82 int *it2);
83
84
85
86/** @brief 3D non-tof joseph back projector CUDA kernel
87 *
88 * @param xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
89 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
90 * Units are the ones of voxsize.
91 * @param xend array of shape [3*nlors] with the coordinates of the end points of the LORs.
92 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
93 * Units are the ones of voxsize.
94 * @param img array of shape [n0*n1*n2] for the back projection image (output).
95 * The pixel [i,j,k] ist stored at [n1*n2*i + n2*j + k].
96 * @param img_origin array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
97 * @param voxsize array [vs0, vs1, vs2] of the voxel sizes
98 * @param p array of length nlors containg the values to be back projected
99 * @param nlors number of projections (length of p array)
100 * @param img_dim array with dimensions of image [n0,n1,n2]
101 */
102extern "C" __global__ void joseph3d_back_cuda_kernel(float *xstart,
103 float *xend,
104 float *img,
105 float *img_origin,
106 float *voxsize,
107 float *p,
108 long long nlors,
109 int *img_dim);
110
111
112
113/** @brief 3D non-tof joseph forward projector CUDA kernel
114 *
115 * @param xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
116 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
117 * Units are the ones of voxsize.
118 * @param xend array of shape [3*nlors] with the coordinates of the end points of the LORs.
119 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
120 * Units are the ones of voxsize.
121 * @param img array of shape [n0*n1*n2] containing the 3D image to be projected.
122 * The pixel [i,j,k] ist stored at [n1*n2*i + n2*j + k].
123 * @param img_origin array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
124 * @param voxsize array [vs0, vs1, vs2] of the voxel sizes
125 * @param p array of length nlors (output) used to store the projections
126 * @param nlors number of projections (length of p array)
127 * @param img_dim array with dimensions of image [n0,n1,n2]
128 */
129extern "C" __global__ void joseph3d_fwd_cuda_kernel(float *xstart,
130 float *xend,
131 float *img,
132 float *img_origin,
133 float *voxsize,
134 float *p,
135 long long nlors,
136 int *img_dim);
137
138
139
140
141/** @brief 3D sinogram tof cuda joseph back projector kernel
142 *
143 * @param xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
144 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
145 * Units are the ones of voxsize.
146 * @param xend array of shape [3*nlors] with the coordinates of the end points of the LORs.
147 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
148 * Units are the ones of voxsize.
149 * @param img array of shape [n0*n1*n2] containing the 3D image used for back projection (output).
150 * The pixel [i,j,k] ist stored at [n1*n2*i + n2*j + k].
151 * @param img_origin array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
152 * @param voxsize array [vs0, vs1, vs2] of the voxel sizes
153 * @param p array of length nlors with the values to be back projected
154 * @param nlors number of geometrical LORs
155 * @param img_dim array with dimensions of image [n0,n1,n2]
156 * @param n_tofbins number of TOF bins
157 * @param tofbin_width width of the TOF bins in spatial units (units of xstart and xend)
158 * @param sigma_tof array of length 1 or nlors (depending on lor_dependent_sigma_tof)
159 * with the TOF resolution (sigma) for each LOR in
160 * spatial units (units of xstart and xend)
161 * @param tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
162 * with the offset of the central TOF bin from the
163 * midpoint of each LOR in spatial units (units of xstart and xend).
164 * A positive value means a shift towards the end point of the LOR.
165 * @param n_sigmas number of sigmas to consider for calculation of TOF kernel
166 * @param lor_dependent_sigma_tof unsigned char 0 or 1
167 * 1 means that the TOF sigmas are LOR dependent
168 * any other value means that the first value in the sigma_tof
169 * array is used for all LORs
170 * @param lor_dependent_tofcenter_offset unsigned char 0 or 1
171 * 1 means that the TOF center offsets are LOR dependent
172 * any other value means that the first value in the
173 * tofcenter_offset array is used for all LORs
174 */
175extern "C" __global__ void joseph3d_back_tof_sino_cuda_kernel(float *xstart,
176 float *xend,
177 float *img,
178 float *img_origin,
179 float *voxsize,
180 float *p,
181 long long nlors,
182 int *img_dim,
183 short n_tofbins,
184 float tofbin_width,
185 float *sigma_tof,
186 float *tofcenter_offset,
187 float n_sigmas,
188 unsigned char lor_dependent_sigma_tof,
189 unsigned char lor_dependent_tofcenter_offset);
190
191
192
193
194/** @brief 3D sinogram tof joseph forward projector kernel
195 *
196 * @param xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
197 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
198 * Units are the ones of voxsize.
199 * @param xend array of shape [3*nlors] with the coordinates of the end points of the LORs.
200 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
201 * Units are the ones of voxsize.
202 * @param img array of shape [n0*n1*n2] containing the 3D image to be projected.
203 * The pixel [i,j,k] ist stored at [n1*n2*i + n2*j + k].
204 * @param img_origin array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
205 * @param voxsize array [vs0, vs1, vs2] of the voxel sizes
206 * @param p array of length nlors*n_tofbins (output) used to store the projections
207 * @param nlors number of geomtrical LORs
208 * @param img_dim array with dimensions of image [n0,n1,n2]
209 * @param n_tofbins number of TOF bins
210 * @param tofbin_width width of the TOF bins in spatial units (units of xstart and xend)
211 * @param sigma_tof array of length 1 or nlors (depending on lor_dependent_sigma_tof)
212 * with the TOF resolution (sigma) for each LOR in
213 * spatial units (units of xstart and xend)
214 * @param tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
215 * with the offset of the central TOF bin from the
216 * midpoint of each LOR in spatial units (units of xstart and xend).
217 * A positive value means a shift towards the end point of the LOR.
218 * @param n_sigmas number of sigmas to consider for calculation of TOF kernel
219 * @param lor_dependent_sigma_tof unsigned char 0 or 1
220 * 1 means that the TOF sigmas are LOR dependent
221 * any other value means that the first value in the sigma_tof
222 * array is used for all LORs
223 * @param lor_dependent_tofcenter_offset unsigned char 0 or 1
224 * 1 means that the TOF center offsets are LOR dependent
225 * any other value means that the first value in the
226 * tofcenter_offset array is used for all LORs
227 */
228extern "C" __global__ void joseph3d_fwd_tof_sino_cuda_kernel(float *xstart,
229 float *xend,
230 float *img,
231 float *img_origin,
232 float *voxsize,
233 float *p,
234 long long nlors,
235 int *img_dim,
236 short n_tofbins,
237 float tofbin_width,
238 float *sigma_tof,
239 float *tofcenter_offset,
240 float n_sigmas,
241 unsigned char lor_dependent_sigma_tof,
242 unsigned char lor_dependent_tofcenter_offset);
243
244
245
246
247/** @brief 3D listmode tof cuda joseph back projector kernel
248 *
249 * @param xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
250 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
251 * Units are the ones of voxsize.
252 * @param xend array of shape [3*nlors] with the coordinates of the end points of the LORs.
253 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
254 * Units are the ones of voxsize.
255 * @param img array of shape [n0*n1*n2] containing the 3D image used for back projection (output).
256 * The pixel [i,j,k] ist stored at [n1*n2*i + n2*j + k].
257 * @param img_origin array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
258 * @param voxsize array [vs0, vs1, vs2] of the voxel sizes
259 * @param p array of length nlors with the values to be back projected
260 * @param nlors number of geometrical LORs
261 * @param img_dim array with dimensions of image [n0,n1,n2]
262 * @param tofbin_width width of the TOF bins in spatial units (units of xstart and xend)
263 * @param sigma_tof array of length 1 or nlors (depending on lor_dependent_sigma_tof)
264 * with the TOF resolution (sigma) for each LOR in
265 * spatial units (units of xstart and xend)
266 * @param tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
267 * with the offset of the central TOF bin from the
268 * midpoint of each LOR in spatial units (units of xstart and xend).
269 * A positive value means a shift towards the end point of the LOR.
270 * @param n_sigmas number of sigmas to consider for calculation of TOF kernel
271 * @param tof_bin signed integer array with the tofbin of the events
272 * the center of TOF bin 0 is assumed to be at the center of the LOR
273 * (shifted by the tofcenter_offset)
274 * @param lor_dependent_sigma_tof unsigned char 0 or 1
275 * 1 means that the TOF sigmas are LOR dependent
276 * any other value means that the first value in the sigma_tof
277 * array is used for all LORs
278 * @param lor_dependent_tofcenter_offset unsigned char 0 or 1
279 * 1 means that the TOF center offsets are LOR dependent
280 * any other value means that the first value in the
281 * tofcenter_offset array is used for all LORs
282 */
283extern "C" __global__ void joseph3d_back_tof_lm_cuda_kernel(float *xstart,
284 float *xend,
285 float *img,
286 float *img_origin,
287 float *voxsize,
288 float *p,
289 long long nlors,
290 int *img_dim,
291 float tofbin_width,
292 float *sigma_tof,
293 float *tofcenter_offset,
294 float n_sigmas,
295 short *tof_bin,
296 unsigned char lor_dependent_sigma_tof,
297 unsigned char lor_dependent_tofcenter_offset);
298
299
300
301/** @brief 3D listmode tof joseph forward projector kernel
302 *
303 * @param xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
304 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
305 * Units are the ones of voxsize.
306 * @param xend array of shape [3*nlors] with the coordinates of the end points of the LORs.
307 * The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
308 * Units are the ones of voxsize.
309 * @param img array of shape [n0*n1*n2] containing the 3D image to be projected.
310 * The pixel [i,j,k] ist stored at [n1*n2*i + n2*j + k].
311 * @param img_origin array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
312 * @param voxsize array [vs0, vs1, vs2] of the voxel sizes
313 * @param p array of length nlors (output) used to store the projections
314 * @param nlors number of geomtrical LORs
315 * @param img_dim array with dimensions of image [n0,n1,n2]
316 * @param tofbin_width width of the TOF bins in spatial units (units of xstart and xend)
317 * @param sigma_tof array of length 1 or nlors (depending on lor_dependent_sigma_tof)
318 * with the TOF resolution (sigma) for each LOR in
319 * spatial units (units of xstart and xend)
320 * @param tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
321 * with the offset of the central TOF bin from the
322 * midpoint of each LOR in spatial units (units of xstart and xend).
323 * A positive value means a shift towards the end point of the LOR.
324 * @param n_sigmas number of sigmas to consider for calculation of TOF kernel
325 * @param tof_bin signed integer array with the tofbin of the events
326 * the center of TOF bin 0 is assumed to be at the center of the LOR
327 * (shifted by the tofcenter_offset)
328 * @param lor_dependent_sigma_tof unsigned char 0 or 1
329 * 1 means that the TOF sigmas are LOR dependent
330 * any other value means that the first value in the sigma_tof
331 * array is used for all LORs
332 * @param lor_dependent_tofcenter_offset unsigned char 0 or 1
333 * 1 means that the TOF center offsets are LOR dependent
334 * any other value means that the first value in the
335 * tofcenter_offset array is used for all LORs
336 */
337extern "C" __global__ void joseph3d_fwd_tof_lm_cuda_kernel(float *xstart,
338 float *xend,
339 float *img,
340 float *img_origin,
341 float *voxsize,
342 float *p,
343 long long nlors,
344 int *img_dim,
345 float tofbin_width,
346 float *sigma_tof,
347 float *tofcenter_offset,
348 float n_sigmas,
349 short *tof_bin,
350 unsigned char lor_dependent_sigma_tof,
351 unsigned char lor_dependent_tofcenter_offset);
352#endif