17#ifndef __adapter_warp_h__
18#define __adapter_warp_h__
51 template <
template <
class ImageType>
class Interpolator,
class ImageType,
class WarpType>
53 public ImageBase<Warp<Interpolator,ImageType,WarpType>, typename ImageType::value_type>
58 Warp (
const ImageType& original,
60 const value_type value_when_out_of_bounds = Interpolator<ImageType>::default_out_of_bounds_value(),
61 const bool jacobian_modulate =
false) :
62 interp (original, value_when_out_of_bounds),
65 dim { warp.size(0), warp.size(1), warp.size(2) },
66 vox { warp.spacing(0), warp.spacing(1), warp.spacing(2) },
67 value_when_out_of_bounds (value_when_out_of_bounds),
68 jac_modulate (jacobian_modulate),
69 jacobian_adapter (warp,
true) {
70 assert (warp.ndim() == 4);
71 assert (warp.size(3) == 3);
75 size_t ndim ()
const {
return interp.ndim(); }
76 bool valid ()
const {
return interp.valid(); }
77 int size (
size_t axis)
const {
return axis < 3 ? dim[
axis]: interp.size (
axis); }
79 const std::string& name ()
const {
return interp.name(); }
81 ssize_t stride (
size_t axis)
const {
82 return interp.stride (
axis);
86 x[0] = x[1] = x[2] = 0;
87 for (
size_t n = 3; n < interp.ndim(); ++n)
93 Eigen::Vector3d pos = get_position();
94 if (std::isnan(pos[0]) || std::isnan(pos[1]) || std::isnan(pos[2]))
95 return value_when_out_of_bounds;
98 if (jac_modulate && val != 0.0) {
99 for (
size_t dim = 0; dim < 3; ++dim)
100 jacobian_adapter.index(dim) = x[dim];
101 val *= jacobian_adapter.value().template cast<default_type>().determinant();
106 ssize_t get_index (
size_t axis)
const {
return axis < 3 ? x[
axis] : interp.index(
axis); }
107 void move_index (
size_t axis, ssize_t increment) {
109 else interp.index(
axis) += increment;
114 Eigen::Vector3d get_position (){
115 warp.index(0) = x[0];
116 warp.index(1) = x[1];
117 warp.index(2) = x[2];
122 Interpolator<ImageType> interp;
125 const ssize_t dim[3];
128 const bool jac_modulate;
an Image providing interpolated values from another Image
MR::default_type value_type
double default_type
the default type used throughout MRtrix