-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGPUGradientOrientationMatchingKernel.cl
97 lines (77 loc) · 2.77 KB
/
GPUGradientOrientationMatchingKernel.cl
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
/*=========================================================================
Ibis Neuronav
Copyright (c) Simon Drouin, Anna Kochanowska, Louis Collins.
All rights reserved.
See Copyright.txt or http://ibisneuronav.org/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Thanks to Dante De Nigris for writing this class
// Modified on Oct 18, 2021 by Houssem Gueziri:
// - use mask in gradient computation kernels
#define REAL float
#define REAL2 float2
#define REAL4 float4
#define REAL8 float8
#define REAL16 float16
#define DIM_3
#define INT uint
#ifdef DIM_3
__kernel void OrientationMatchingMetricSparseMask(
__constant REAL4 * rigidContext,
__global REAL4 * g_fg, __global REAL4 * g_fl,
read_only image3d_t mgImage,
__global REAL * metricOutput,
__local REAL * metricAccums
)
{
unsigned int gidx = get_global_id(0);
unsigned int lid = get_local_id(0);
unsigned int groupID = get_group_id(0);
/* Evaluate Fixed Image Gradient */
REAL4 loc = g_fl[gidx];
const sampler_t mySampler = CLK_FILTER_LINEAR | CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP;
REAL4 rcX = rigidContext[0];
REAL4 rcY = rigidContext[1];
REAL4 rcZ = rigidContext[2];
REAL4 cId = (REAL4)(0.5f, 0.5f, 0.5f, 0.0f);
cId.x += dot(rcX, loc);
cId.y += dot(rcY, loc);
cId.z += dot(rcZ, loc);
/* Interpolated Moving Gradient */
REAL4 movingGrad = read_imagef(mgImage, mySampler, cId);
REAL metricValue;
if( (!USEMASK && (movingGrad.w > -1.0f)) || (USEMASK && (movingGrad.w > 0.0f)) )
{
REAL4 rctX = rigidContext[3];
REAL4 rctY = rigidContext[4];
REAL4 rctZ = rigidContext[5];
/* Transformed Moving Gradient */
REAL4 trMovingGrad = (REAL4)(0.0f, 0.0f, 0.0f, 0.0f);
trMovingGrad.x = dot(rctX, movingGrad);
trMovingGrad.y = dot(rctY, movingGrad);
trMovingGrad.z = dot(rctZ, movingGrad);
REAL4 trMovingGradN = normalize(trMovingGrad);
REAL4 fixedGrad = g_fg[gidx];
REAL4 fixedGradN = normalize(fixedGrad);
REAL innerProduct = dot(fixedGradN, trMovingGradN);
metricValue = pown(innerProduct, SEL);
}
else
{
metricValue = 0.0f;
}
metricAccums[lid] = metricValue;
barrier(CLK_LOCAL_MEM_FENCE);
for( unsigned int s = LOCALSIZE / 2; s > 0; s >>= 1 )
{
if( lid < s )
{
metricAccums[lid] += metricAccums[lid + s];
}
barrier(CLK_LOCAL_MEM_FENCE);
}
if( lid == 0 ) metricOutput[groupID] = metricAccums[0];
}
#endif