GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/nrrd/winKernel.c Lines: 28 28 100.0 %
Date: 2017-05-26 Branches: 180 216 83.3 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
#include "nrrd.h"
25
26
#define _SINC(x) (sin(AIR_PI*x)/(AIR_PI*x))
27
28
static double
29
_nrrdWindSincInt(const double *parm) {
30
31
  AIR_UNUSED(parm);
32
  /* This isn't true, but there aren't good accurate, closed-form
33
     approximations for these integrals ... */
34
24
  return 1.0;
35
}
36
37
static double
38
_nrrdDWindSincInt(const double *parm) {
39
40
  AIR_UNUSED(parm);
41
  /* ... or their derivatives */
42
48
  return 0.0;
43
}
44
45
static double
46
_nrrdWindSincSup(const double *parm) {
47
  double S;
48
49
72
  S = parm[0];
50
36
  return parm[1]*S;
51
}
52
53
#define POW1(S) (S)
54
#define POW2(S) ((S)*(S))
55
#define POW3(S) ((S)*(S)*(S))
56
57
#define WS_1_F(name, mac, spow)                               \
58
static float                                                  \
59
_nrrd##name##_1_f(float x, const double *parm) {              \
60
  float R, S;                                                 \
61
                                                              \
62
  S = AIR_CAST(float, parm[0]); R = AIR_CAST(float, parm[1]); \
63
  x /= S;                                                     \
64
  return AIR_CAST(float, mac(x, R)/spow(S));                  \
65
}
66
67
#define WS_N_F(name, mac, spow)                                     \
68
static void                                                         \
69
_nrrd##name##_N_f(float *f, const float *x, size_t len,             \
70
                  const double *parm) {                             \
71
  float S, R, t;                                                    \
72
  size_t i;                                                         \
73
                                                                    \
74
  S = AIR_CAST(float, parm[0]); R = AIR_CAST(float, parm[1]);       \
75
  for (i=0; i<len; i++) {                                           \
76
    t = x[i]/S;                                                     \
77
    f[i] = AIR_CAST(float, mac(t, R)/spow(S));                      \
78
  }                                                                 \
79
}
80
81
#define WS_1_D(name, mac, spow)                   \
82
static double                                     \
83
_nrrd##name##_1_d(double x, const double *parm) { \
84
  double R, S;                                    \
85
                                                  \
86
  S = parm[0]; R = parm[1];                       \
87
  x /= S;                                         \
88
  return mac(x, R)/spow(S);                       \
89
}
90
91
#define WS_N_D(name, mac, spow)                                     \
92
static void                                                         \
93
_nrrd##name##_N_d(double *f, const double *x, size_t len,           \
94
                  const double *parm) {                             \
95
  double S, R, t;                                                   \
96
  size_t i;                                                         \
97
                                                                    \
98
  S = parm[0]; R = parm[1];                                         \
99
  for (i=0; i<len; i++) {                                           \
100
    t = x[i]/S;                                                     \
101
    f[i] = mac(t, R)/spow(S);                                       \
102
  }                                                                 \
103
}
104
105
/* ------------------------------------------------------------ */
106
107
#define _HANN(x, R) \
108
   (x > R ? 0 : (x < -R ? 0 : (\
109
   (x < R/50000 && x > -R/50000) \
110
     ? 1.1 - x*x*(AIR_PI*AIR_PI*(3 + 2*R*R)/(12*R*R) \
111
                + AIR_PI*AIR_PI*AIR_PI*AIR_PI*(5 + 2*R*R*(5 + 2*R*R))*x*x/(240*R*R*R*R)) \
112
     : (1 + cos(AIR_PI*x/R))*_SINC(x)/2) \
113
    ))
114
115


14040141
WS_1_D(Hann, _HANN, POW1)
116


4680006
WS_1_F(Hann, _HANN, POW1)
117


4680030
WS_N_F(Hann, _HANN, POW1)
118


4680030
WS_N_D(Hann, _HANN, POW1)
119
120
static NrrdKernel
121
_nrrdKernelHann = {
122
  "hann",
123
  2, _nrrdWindSincSup,  _nrrdWindSincInt,
124
  _nrrdHann_1_f, _nrrdHann_N_f, _nrrdHann_1_d, _nrrdHann_N_d
125
};
126
NrrdKernel *const
127
nrrdKernelHann = &_nrrdKernelHann;
128
129
/* ------------------------------------------------------------ */
130
131
#define _DHANN(x, R)                                              \
132
   (x > R ? 0.0 : (x < -R ? 0.0 : (                               \
133
    (x < R/50000 && x > -R/50000)                                 \
134
     ? -x*AIR_PI*AIR_PI*(3 + 2*R*R)/(6*R*R)                           \
135
     : ((R*(1 + cos(AIR_PI*x/R))*(AIR_PI*x*cos(AIR_PI*x) - sin(AIR_PI*x)) \
136
       - AIR_PI*x*sin(AIR_PI*x)*sin(AIR_PI*x/R))/(2*R*AIR_PI*x*x))        \
137
   )))
138
139


14040141
WS_1_D(DHann, _DHANN, POW2)
140


4680006
WS_1_F(DHann, _DHANN, POW2)
141


4680030
WS_N_F(DHann, _DHANN, POW2)
142


4680030
WS_N_D(DHann, _DHANN, POW2)
143
144
static NrrdKernel
145
_nrrdKernelDHann = {
146
  "hannD",
147
  2, _nrrdWindSincSup, _nrrdDWindSincInt,
148
  _nrrdDHann_1_f,  _nrrdDHann_N_f,  _nrrdDHann_1_d,  _nrrdDHann_N_d
149
};
150
NrrdKernel *const
151
nrrdKernelHannD = &_nrrdKernelDHann;
152
153
/* ------------------------------------------------------------ */
154
155
#define _DDHANN_A(x, R) \
156
  (2*AIR_PI*R*cos(AIR_PI*x)*(R + R*cos(AIR_PI*x/R) + AIR_PI*x*sin(AIR_PI*x/R)))
157
#define _DDHANN_B(x, R)                                      \
158
  (cos(AIR_PI*x/R)*(AIR_PI*AIR_PI*x*x + R*R*(AIR_PI*AIR_PI*x*x - 2)) + \
159
   R*(R*(AIR_PI*AIR_PI*x*x - 2) - 2*AIR_PI*x*sin(AIR_PI*x/R)))
160
#define _DDHANN(x, R)                                                         \
161
   (x > R ? 0 : (x < -R ? 0 : (                                               \
162
     (x < R/50000 && x > -R/50000)                                            \
163
      ? (AIR_PI*AIR_PI/(2*R*R))*( -(3 + 2*R*R)/3                                  \
164
                             + AIR_PI*AIR_PI*(5 + 2*R*R*(5 + R*R))*x*x/(10*R*R))  \
165
      : -(_DDHANN_A(x,R) + sin(AIR_PI*x)*_DDHANN_B(x,R)/x)/(2*AIR_PI*R*R*x*x)     \
166
    )))
167
168


4680132
WS_1_D(DDHann, _DDHANN, POW3)
169


4680006
WS_1_F(DDHann, _DDHANN, POW3)
170


4680030
WS_N_F(DDHann, _DDHANN, POW3)
171


4680030
WS_N_D(DDHann, _DDHANN, POW3)
172
173
static NrrdKernel
174
_nrrdKernelDDHann = {
175
  "hannDD",
176
  2, _nrrdWindSincSup, _nrrdDWindSincInt,
177
  _nrrdDDHann_1_f, _nrrdDDHann_N_f, _nrrdDDHann_1_d, _nrrdDDHann_N_d
178
};
179
NrrdKernel *const
180
nrrdKernelHannDD = &_nrrdKernelDDHann;
181
182
/* ------------------------------------------------------------ */
183
184
#define _BLACK(x, R)                                             \
185
   (x > R ? 0 : (x < -R ? 0 : (                                  \
186
    (x < R/50000 && x > -R/50000)                                \
187
     ? 1.0 - x*x*(1.6449340668482264 + 4.046537804446637/(R*R))  \
188
     : (0.42 + cos(AIR_PI*x/R)/2 + 0.08*cos(2*AIR_PI*x/R))*_SINC(x)  \
189
   )))
190
191


14040141
WS_1_D(Black, _BLACK, POW1)
192


4680006
WS_1_F(Black, _BLACK, POW1)
193


4680030
WS_N_F(Black, _BLACK, POW1)
194


4680030
WS_N_D(Black, _BLACK, POW1)
195
196
static NrrdKernel
197
_nrrdKernelBlackman = {
198
  "blackman",
199
  2, _nrrdWindSincSup,  _nrrdWindSincInt,
200
  _nrrdBlack_1_f, _nrrdBlack_N_f, _nrrdBlack_1_d, _nrrdBlack_N_d
201
};
202
NrrdKernel *const
203
nrrdKernelBlackman = &_nrrdKernelBlackman;
204
205
/* ------------------------------------------------------------ */
206
207
#define _DBLACK_A(x, R)                                   \
208
  R*x*cos(AIR_PI*x)*(2.638937829015426 + AIR_PI*cos(AIR_PI*x/R) \
209
                   + 0.5026548245743669*cos(2*AIR_PI*x/R))
210
#define _DBLACK_B(x, R)                                                     \
211
  sin(AIR_PI*x)*(-0.84*R - R*cos(AIR_PI*x/R) - 0.16*R*cos(2*AIR_PI*x/R) -         \
212
               AIR_PI*x*sin(AIR_PI*x/R) - 1.0053096491487339*x*sin(2*AIR_PI*x/R))
213
#define _DBLACK(x, R)                                 \
214
  (x > R ? 0.0 : (x < -R ? 0.0 : (                    \
215
   (x < R/50000 && x > -R/50000)                      \
216
   ? -x*(3.289868133696453 + 8.093075608893272/(R*R)) \
217
   : (_DBLACK_A(x,R) + _DBLACK_B(x,R))/(2*AIR_PI*R*x*x) \
218
  )))
219
220


14040141
WS_1_D(DBlack, _DBLACK, POW2)
221


4680006
WS_1_F(DBlack, _DBLACK, POW2)
222


4680030
WS_N_F(DBlack, _DBLACK, POW2)
223


4680030
WS_N_D(DBlack, _DBLACK, POW2)
224
225
static NrrdKernel
226
_nrrdKernelDBlack = {
227
  "blackmanD",
228
  2, _nrrdWindSincSup, _nrrdDWindSincInt,
229
  _nrrdDBlack_1_f,  _nrrdDBlack_N_f,  _nrrdDBlack_1_d,  _nrrdDBlack_N_d
230
};
231
NrrdKernel *const
232
nrrdKernelBlackmanD = &_nrrdKernelDBlack;
233
234
/* ------------------------------------------------------------ */
235
236
#define _DDBLACK(x, R)                                                          \
237
  (x > R ? 0.0 : (x < -R ? 0.0 : (                                              \
238
   (x < R/30 && x > -R/30)                                                      \
239
   ? (-(3.289868133696453 + 8.093075608893272/(R*R))                            \
240
      + x*x*(9.7409091034 + 86.694091020262/(R*R*R*R) + 79.8754546479/(R*R)))   \
241
   : ((R*x*cos(AIR_PI*x)*(-2.638937829015426*R - AIR_PI*R*cos((AIR_PI*x)/R)           \
242
            - 0.5026548245743669*R*cos((2*AIR_PI*x)/R)                            \
243
            - AIR_PI*AIR_PI*x*sin((AIR_PI*x)/R)                                       \
244
            - 3.158273408348595*x*sin((2*AIR_PI*x)/R))                            \
245
  + sin(AIR_PI*x)*((-4.934802200544679*x*x                                        \
246
           + R*R*(1 - 4.934802200544679*x*x))*cos((AIR_PI*x)/R)                   \
247
          + (-3.158273408348595*x*x                                             \
248
             + R*R*(0.16 - 0.7895683520871487*x*x))*cos((2*AIR_PI*x)/R)           \
249
          + R*(0.84*R - 4.14523384845753*R*x*x                                  \
250
               + AIR_PI*x*sin((AIR_PI*x)/R)                                         \
251
               + 1.0053096491487339*x*sin((2*AIR_PI*x)/R))))/(AIR_PI*R*R*x*x*x))    \
252
   )))
253
254


4692126
WS_1_D(DDBlack, _DDBLACK, POW3)
255


4692000
WS_1_F(DDBlack, _DDBLACK, POW3)
256


4692024
WS_N_F(DDBlack, _DDBLACK, POW3)
257


4692024
WS_N_D(DDBlack, _DDBLACK, POW3)
258
259
static NrrdKernel
260
_nrrdKernelDDBlack = {
261
  "blackmanDD",
262
  2, _nrrdWindSincSup, _nrrdDWindSincInt,
263
  _nrrdDDBlack_1_f, _nrrdDDBlack_N_f, _nrrdDDBlack_1_d, _nrrdDDBlack_N_d
264
};
265
NrrdKernel *const
266
nrrdKernelBlackmanDD = &_nrrdKernelDDBlack;
267