Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reslice adapter: allow use with complex numbers #2768

Merged
merged 4 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions core/adapter/reslice.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,23 @@ namespace MR
return value_type(std::round (sum*norm));
}

template <typename value_type>
typename std::enable_if<std::is_floating_point<value_type>::value, value_type>::type
inline normalise (const default_type sum, const default_type norm)
// Standard implementation for floating point (either real or complex)
template <typename value_type, typename summing_type>
typename std::enable_if<!std::is_same<value_type, bool>::value && !std::is_integral<value_type>::value, value_type>::type
inline normalise (const summing_type sum, const default_type norm)
{
return (sum * norm);
return value_type (sum * norm);
}

// If summing complex numbers, use double precision complex;
// otherwise, use double precision real
template <typename value_type> struct summing_type { NOMEMALIGN
using type = double;
};
template <typename value_type> struct summing_type<is_complex<value_type>> { NOMEMALIGN
using type = std::complex<double>;
};

}


Expand Down Expand Up @@ -114,7 +125,6 @@ namespace MR

using value_type = typename ImageType::value_type;


template <class HeaderType>
Reslice (const ImageType& original,
const HeaderType& reference,
Expand Down Expand Up @@ -195,7 +205,7 @@ namespace MR
using namespace Eigen;
if (oversampling) {
Vector3d d (x[0]+from[0], x[1]+from[1], x[2]+from[2]);
default_type sum (0.0);
typename summing_type<value_type>::type sum (0);
Vector3d s;
for (uint32_t z = 0; z < OS[2]; ++z) {
s[2] = d[2] + z*inc[2];
Expand Down