17#ifndef __math_sinc_h__
18#define __math_sinc_h__
27 template <
typename T =
float>
class Sinc
34 max_offset_from_kernel_centre ((w-1) / 2),
42 template <
class ImageType>
45 if (position == current_pos)
48 const int kernel_centre =
std::round (position);
51 for (
size_t i = 0; i != window_size; ++i) {
53 const int voxel = kernel_centre - max_offset_from_kernel_centre + i;
55 indices[i] = -voxel - 1;
56 else if (voxel >= image.size (
axis))
57 indices[i] = (2 * int(image.size (
axis))) - voxel - 1;
72 if (lanczos_sinc_term)
73 lanczos_factor = std::sin (lanczos_sinc_term) / lanczos_sinc_term;
77 const value_type this_weight = lanczos_factor * sinc;
79 weights[i] = this_weight;
80 sum_weights += this_weight;
84 const value_type normalisation = 1.0 / sum_weights;
85 for (
size_t i = 0; i != window_size; ++i)
86 weights[i] *= normalisation;
88 current_pos = position;
92 size_t index (
const size_t i)
const {
return indices[i]; }
94 template <
class ImageType>
96 assert (current_pos != NAN);
97 const size_t init_pos = image.index(
axis);
99 for (
size_t i = 0; i != window_size; ++i) {
100 image.index(
axis) = indices[i];
101 sum += image.value() * weights[i];
103 image.index(
axis) = init_pos;
107 template <
class Cont>
109 assert (data.size() == window_size);
110 assert (current_pos != NAN);
112 for (
size_t i = 0; i != window_size; ++i)
113 sum += data[i] * weights[i];
118 assert (current_pos != NAN);
120 for (
size_t i = 0; i != window_size; ++i)
121 sum += data[i] * weights[i];
126 const size_t window_size, max_offset_from_kernel_centre;
void set(const ImageType &image, const size_t axis, const value_type position)
value_type value(value_type *data) const
value_type value(ImageType &image, const size_t axis) const
size_t index(const size_t i) const
value_type value(Cont &data) const
constexpr I round(const T x)
constexpr std::enable_if< std::is_arithmetic< X >::value &&std::is_unsigned< X >::value, X >::type abs(X x)