summaryrefslogtreecommitdiffstats
path: root/src/kernels/roll_kernel.cl
blob: 129e14f27bfe070fdd7f7fa374fbb1bf9e2a6f09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#define rotate()    pixel.x -= x_center.x; \
                    pixel.y -= y_center; \
                    pixel.x = pixel.x * cos_roll + pixel.y * sin_roll; \
                    pixel.y = -pixel.x * sin_roll + pixel.y * cos_roll; \
                    pixel.x += x_center.x; \
                    pixel.y += y_center;

/*
 * Copyright (C) 2015-2016 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

kernel void backproject_burst_1 (
read_only image2d_t projection_0,
                                    global float *volume,
                                    const sampler_t sampler,
                                    const int3 real_size,
                                    const float2 x_center,
                                    const float y_center,
                                    const float2 x_region,
                                    const float2 y_region,
                                    const float2 z_region,
                                    const float2 lamino_region,
                                    const float2 roll_region,
                                    float sin_lamino,
                                    float cos_lamino,
                                    const float sines,
                                    const float cosines,
                                    const float norm_factor,
                                    float sin_roll,
                                    float cos_roll,
                                    const int cumulate)
{
    int idx = get_global_id (0);
    int idy = get_global_id (1);
    int idz = get_global_id (2);
    float result, tmp, tmp_x, tmp_y;
    float2 pixel;
    float3 voxel;

    if (idx < real_size.x && idy < real_size.y && idz < real_size.z) {
        voxel.x = mad((float) idx, x_region.y, x_region.x);
        voxel.y = mad((float) idy, y_region.y, y_region.x);
        sin_roll = sincos (mad((float) idz, -roll_region.y, -roll_region.x), &cos_roll);
        tmp = mad(z_region.x, sin_lamino, y_center);
        tmp_x = voxel.x * cos_lamino;
        tmp_y = -voxel.y * cos_lamino;

        pixel.x = mad(voxel.x, cosines, mad(voxel.y, sines, x_center.x));
        pixel.y = mad(tmp_x, sines, mad(tmp_y, cosines, tmp));
        rotate ();
        result = read_imagef (projection_0, sampler, pixel).x;


        if (cumulate) {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] += result * norm_factor;
        } else {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] = result * norm_factor;
        }
    }
}
/*
 * Copyright (C) 2015-2016 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

kernel void backproject_burst_2 (
read_only image2d_t projection_0,
read_only image2d_t projection_1,
                                    global float *volume,
                                    const sampler_t sampler,
                                    const int3 real_size,
                                    const float2 x_center,
                                    const float y_center,
                                    const float2 x_region,
                                    const float2 y_region,
                                    const float2 z_region,
                                    const float2 lamino_region,
                                    const float2 roll_region,
                                    float sin_lamino,
                                    float cos_lamino,
                                    const float2 sines,
                                    const float2 cosines,
                                    const float norm_factor,
                                    float sin_roll,
                                    float cos_roll,
                                    const int cumulate)
{
    int idx = get_global_id (0);
    int idy = get_global_id (1);
    int idz = get_global_id (2);
    float result, tmp, tmp_x, tmp_y;
    float2 pixel;
    float3 voxel;

    if (idx < real_size.x && idy < real_size.y && idz < real_size.z) {
        voxel.x = mad((float) idx, x_region.y, x_region.x);
        voxel.y = mad((float) idy, y_region.y, y_region.x);
        sin_roll = sincos (mad((float) idz, -roll_region.y, -roll_region.x), &cos_roll);
        tmp = mad(z_region.x, sin_lamino, y_center);
        tmp_x = voxel.x * cos_lamino;
        tmp_y = -voxel.y * cos_lamino;

        pixel.x = mad(voxel.x, cosines.s0, mad(voxel.y, sines.s0, x_center.x));
        pixel.y = mad(tmp_x, sines.s0, mad(tmp_y, cosines.s0, tmp));
        rotate ();
        result = read_imagef (projection_0, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s1, mad(voxel.y, sines.s1, x_center.x));
        pixel.y = mad(tmp_x, sines.s1, mad(tmp_y, cosines.s1, tmp));
        rotate ();
        result += read_imagef (projection_1, sampler, pixel).x;


        if (cumulate) {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] += result * norm_factor;
        } else {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] = result * norm_factor;
        }
    }
}
/*
 * Copyright (C) 2015-2016 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

kernel void backproject_burst_4 (
read_only image2d_t projection_0,
read_only image2d_t projection_1,
read_only image2d_t projection_2,
read_only image2d_t projection_3,
                                    global float *volume,
                                    const sampler_t sampler,
                                    const int3 real_size,
                                    const float2 x_center,
                                    const float y_center,
                                    const float2 x_region,
                                    const float2 y_region,
                                    const float2 z_region,
                                    const float2 lamino_region,
                                    const float2 roll_region,
                                    float sin_lamino,
                                    float cos_lamino,
                                    const float4 sines,
                                    const float4 cosines,
                                    const float norm_factor,
                                    float sin_roll,
                                    float cos_roll,
                                    const int cumulate)
{
    int idx = get_global_id (0);
    int idy = get_global_id (1);
    int idz = get_global_id (2);
    float result, tmp, tmp_x, tmp_y;
    float2 pixel;
    float3 voxel;

    if (idx < real_size.x && idy < real_size.y && idz < real_size.z) {
        voxel.x = mad((float) idx, x_region.y, x_region.x);
        voxel.y = mad((float) idy, y_region.y, y_region.x);
        sin_roll = sincos (mad((float) idz, -roll_region.y, -roll_region.x), &cos_roll);
        tmp = mad(z_region.x, sin_lamino, y_center);
        tmp_x = voxel.x * cos_lamino;
        tmp_y = -voxel.y * cos_lamino;

        pixel.x = mad(voxel.x, cosines.s0, mad(voxel.y, sines.s0, x_center.x));
        pixel.y = mad(tmp_x, sines.s0, mad(tmp_y, cosines.s0, tmp));
        rotate ();
        result = read_imagef (projection_0, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s1, mad(voxel.y, sines.s1, x_center.x));
        pixel.y = mad(tmp_x, sines.s1, mad(tmp_y, cosines.s1, tmp));
        rotate ();
        result += read_imagef (projection_1, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s2, mad(voxel.y, sines.s2, x_center.x));
        pixel.y = mad(tmp_x, sines.s2, mad(tmp_y, cosines.s2, tmp));
        rotate ();
        result += read_imagef (projection_2, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s3, mad(voxel.y, sines.s3, x_center.x));
        pixel.y = mad(tmp_x, sines.s3, mad(tmp_y, cosines.s3, tmp));
        rotate ();
        result += read_imagef (projection_3, sampler, pixel).x;


        if (cumulate) {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] += result * norm_factor;
        } else {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] = result * norm_factor;
        }
    }
}
/*
 * Copyright (C) 2015-2016 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

kernel void backproject_burst_8 (
read_only image2d_t projection_0,
read_only image2d_t projection_1,
read_only image2d_t projection_2,
read_only image2d_t projection_3,
read_only image2d_t projection_4,
read_only image2d_t projection_5,
read_only image2d_t projection_6,
read_only image2d_t projection_7,
                                    global float *volume,
                                    const sampler_t sampler,
                                    const int3 real_size,
                                    const float2 x_center,
                                    const float y_center,
                                    const float2 x_region,
                                    const float2 y_region,
                                    const float2 z_region,
                                    const float2 lamino_region,
                                    const float2 roll_region,
                                    float sin_lamino,
                                    float cos_lamino,
                                    const float8 sines,
                                    const float8 cosines,
                                    const float norm_factor,
                                    float sin_roll,
                                    float cos_roll,
                                    const int cumulate)
{
    int idx = get_global_id (0);
    int idy = get_global_id (1);
    int idz = get_global_id (2);
    float result, tmp, tmp_x, tmp_y;
    float2 pixel;
    float3 voxel;

    if (idx < real_size.x && idy < real_size.y && idz < real_size.z) {
        voxel.x = mad((float) idx, x_region.y, x_region.x);
        voxel.y = mad((float) idy, y_region.y, y_region.x);
        sin_roll = sincos (mad((float) idz, -roll_region.y, -roll_region.x), &cos_roll);
        tmp = mad(z_region.x, sin_lamino, y_center);
        tmp_x = voxel.x * cos_lamino;
        tmp_y = -voxel.y * cos_lamino;

        pixel.x = mad(voxel.x, cosines.s0, mad(voxel.y, sines.s0, x_center.x));
        pixel.y = mad(tmp_x, sines.s0, mad(tmp_y, cosines.s0, tmp));
        rotate ();
        result = read_imagef (projection_0, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s1, mad(voxel.y, sines.s1, x_center.x));
        pixel.y = mad(tmp_x, sines.s1, mad(tmp_y, cosines.s1, tmp));
        rotate ();
        result += read_imagef (projection_1, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s2, mad(voxel.y, sines.s2, x_center.x));
        pixel.y = mad(tmp_x, sines.s2, mad(tmp_y, cosines.s2, tmp));
        rotate ();
        result += read_imagef (projection_2, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s3, mad(voxel.y, sines.s3, x_center.x));
        pixel.y = mad(tmp_x, sines.s3, mad(tmp_y, cosines.s3, tmp));
        rotate ();
        result += read_imagef (projection_3, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s4, mad(voxel.y, sines.s4, x_center.x));
        pixel.y = mad(tmp_x, sines.s4, mad(tmp_y, cosines.s4, tmp));
        rotate ();
        result += read_imagef (projection_4, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s5, mad(voxel.y, sines.s5, x_center.x));
        pixel.y = mad(tmp_x, sines.s5, mad(tmp_y, cosines.s5, tmp));
        rotate ();
        result += read_imagef (projection_5, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s6, mad(voxel.y, sines.s6, x_center.x));
        pixel.y = mad(tmp_x, sines.s6, mad(tmp_y, cosines.s6, tmp));
        rotate ();
        result += read_imagef (projection_6, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s7, mad(voxel.y, sines.s7, x_center.x));
        pixel.y = mad(tmp_x, sines.s7, mad(tmp_y, cosines.s7, tmp));
        rotate ();
        result += read_imagef (projection_7, sampler, pixel).x;


        if (cumulate) {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] += result * norm_factor;
        } else {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] = result * norm_factor;
        }
    }
}
/*
 * Copyright (C) 2015-2016 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

kernel void backproject_burst_16 (
read_only image2d_t projection_0,
read_only image2d_t projection_1,
read_only image2d_t projection_2,
read_only image2d_t projection_3,
read_only image2d_t projection_4,
read_only image2d_t projection_5,
read_only image2d_t projection_6,
read_only image2d_t projection_7,
read_only image2d_t projection_8,
read_only image2d_t projection_9,
read_only image2d_t projection_10,
read_only image2d_t projection_11,
read_only image2d_t projection_12,
read_only image2d_t projection_13,
read_only image2d_t projection_14,
read_only image2d_t projection_15,
                                    global float *volume,
                                    const sampler_t sampler,
                                    const int3 real_size,
                                    const float2 x_center,
                                    const float y_center,
                                    const float2 x_region,
                                    const float2 y_region,
                                    const float2 z_region,
                                    const float2 lamino_region,
                                    const float2 roll_region,
                                    float sin_lamino,
                                    float cos_lamino,
                                    const float16 sines,
                                    const float16 cosines,
                                    const float norm_factor,
                                    float sin_roll,
                                    float cos_roll,
                                    const int cumulate)
{
    int idx = get_global_id (0);
    int idy = get_global_id (1);
    int idz = get_global_id (2);
    float result, tmp, tmp_x, tmp_y;
    float2 pixel;
    float3 voxel;

    if (idx < real_size.x && idy < real_size.y && idz < real_size.z) {
        voxel.x = mad((float) idx, x_region.y, x_region.x);
        voxel.y = mad((float) idy, y_region.y, y_region.x);
        sin_roll = sincos (mad((float) idz, -roll_region.y, -roll_region.x), &cos_roll);
        tmp = mad(z_region.x, sin_lamino, y_center);
        tmp_x = voxel.x * cos_lamino;
        tmp_y = -voxel.y * cos_lamino;

        pixel.x = mad(voxel.x, cosines.s0, mad(voxel.y, sines.s0, x_center.x));
        pixel.y = mad(tmp_x, sines.s0, mad(tmp_y, cosines.s0, tmp));
        rotate ();
        result = read_imagef (projection_0, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s1, mad(voxel.y, sines.s1, x_center.x));
        pixel.y = mad(tmp_x, sines.s1, mad(tmp_y, cosines.s1, tmp));
        rotate ();
        result += read_imagef (projection_1, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s2, mad(voxel.y, sines.s2, x_center.x));
        pixel.y = mad(tmp_x, sines.s2, mad(tmp_y, cosines.s2, tmp));
        rotate ();
        result += read_imagef (projection_2, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s3, mad(voxel.y, sines.s3, x_center.x));
        pixel.y = mad(tmp_x, sines.s3, mad(tmp_y, cosines.s3, tmp));
        rotate ();
        result += read_imagef (projection_3, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s4, mad(voxel.y, sines.s4, x_center.x));
        pixel.y = mad(tmp_x, sines.s4, mad(tmp_y, cosines.s4, tmp));
        rotate ();
        result += read_imagef (projection_4, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s5, mad(voxel.y, sines.s5, x_center.x));
        pixel.y = mad(tmp_x, sines.s5, mad(tmp_y, cosines.s5, tmp));
        rotate ();
        result += read_imagef (projection_5, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s6, mad(voxel.y, sines.s6, x_center.x));
        pixel.y = mad(tmp_x, sines.s6, mad(tmp_y, cosines.s6, tmp));
        rotate ();
        result += read_imagef (projection_6, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s7, mad(voxel.y, sines.s7, x_center.x));
        pixel.y = mad(tmp_x, sines.s7, mad(tmp_y, cosines.s7, tmp));
        rotate ();
        result += read_imagef (projection_7, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s8, mad(voxel.y, sines.s8, x_center.x));
        pixel.y = mad(tmp_x, sines.s8, mad(tmp_y, cosines.s8, tmp));
        rotate ();
        result += read_imagef (projection_8, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.s9, mad(voxel.y, sines.s9, x_center.x));
        pixel.y = mad(tmp_x, sines.s9, mad(tmp_y, cosines.s9, tmp));
        rotate ();
        result += read_imagef (projection_9, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.sa, mad(voxel.y, sines.sa, x_center.x));
        pixel.y = mad(tmp_x, sines.sa, mad(tmp_y, cosines.sa, tmp));
        rotate ();
        result += read_imagef (projection_10, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.sb, mad(voxel.y, sines.sb, x_center.x));
        pixel.y = mad(tmp_x, sines.sb, mad(tmp_y, cosines.sb, tmp));
        rotate ();
        result += read_imagef (projection_11, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.sc, mad(voxel.y, sines.sc, x_center.x));
        pixel.y = mad(tmp_x, sines.sc, mad(tmp_y, cosines.sc, tmp));
        rotate ();
        result += read_imagef (projection_12, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.sd, mad(voxel.y, sines.sd, x_center.x));
        pixel.y = mad(tmp_x, sines.sd, mad(tmp_y, cosines.sd, tmp));
        rotate ();
        result += read_imagef (projection_13, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.se, mad(voxel.y, sines.se, x_center.x));
        pixel.y = mad(tmp_x, sines.se, mad(tmp_y, cosines.se, tmp));
        rotate ();
        result += read_imagef (projection_14, sampler, pixel).x;
        pixel.x = mad(voxel.x, cosines.sf, mad(voxel.y, sines.sf, x_center.x));
        pixel.y = mad(tmp_x, sines.sf, mad(tmp_y, cosines.sf, tmp));
        rotate ();
        result += read_imagef (projection_15, sampler, pixel).x;


        if (cumulate) {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] += result * norm_factor;
        } else {
            volume[idz * real_size.x * real_size.y + idy * real_size.x + idx] = result * norm_factor;
        }
    }
}