17#ifndef __registration_warp_compose_h__
18#define __registration_warp_compose_h__
30 namespace Registration
41 template <
class InputDeformationFieldType,
class OutputDeformationFieldType>
42 void operator() (InputDeformationFieldType& deform_input, OutputDeformationFieldType& deform_output) {
43 deform_output.row(3) =
transform * Eigen::Vector3d (deform_input.row(3));
53 template<
class DisplacementFieldType>
59 template <
class DisplacementFieldType,
class DeformationFieldType>
60 void operator() (DisplacementFieldType& disp_input, DeformationFieldType& deform_output) {
61 Eigen::Vector3d voxel (disp_input.index(0), disp_input.index(1), disp_input.index(2));
79 Eigen::Vector3d original_position = voxel_position + Eigen::Vector3d(disp_input1.row(3));
82 disp_output.row(3) = disp_input1.row(3);
84 Eigen::Vector3d displacement (Eigen::Vector3d(
disp2_interp.row(3)).array() *
step);
85 Eigen::Vector3d new_position = displacement + original_position;
86 disp_output.row(3) = new_position - voxel_position;
97 template <
class DeformationField1Type,
class DeformationField2Type>
110 Eigen::Vector3d position =
linear1 * voxel;
121 deform.row(3) =
linear2 * position3;
136 template <
class DisplacementFieldType,
class DeformationFieldType>
139 check_dimensions (disp_in, deform_out, 0, 3);
144 template <
class InputDeformationFieldType,
class OutputDeformationFieldType>
147 check_dimensions (deform_in, deform_out, 0, 3);
154 check_dimensions (input, output, 0, 3);
161 check_dimensions (input, output, 0, 3);
165 default_type norm = Eigen::Vector3d (update.row(3)).norm();
175 if (max_norm * step < min_vox_size / 2.0) {
178 scale_factor = std::pow (2,
std::ceil (std::log ((max_norm * step) / (min_vox_size / 2.0)) / std::log (2.0)));
187 scaled_update.row(3) = Eigen::Vector3d (update.row(3)) * scaled_step;
188 }, update, *scaled_update);
193 for (
size_t i = 0; i < std::log2 (scale_factor); ++i) {
221 template <
class DeformationField1Type,
class DeformationField2Type,
class OutputDeformationFieldType>
224 OutputDeformationFieldType& deform_out)
228 ThreadedLoop (deform_out, 0, 3).run (compose_kernel, deform_out);
232 template <
class DeformationField1Type,
class DeformationField2Type,
class OutputDeformationFieldType>
235 OutputDeformationFieldType& deform_out)
239 ThreadedLoop (message, deform_out, 0, 3).run (compose_kernel, deform_out);
242 template <
class WarpType>
245 midway_header.ndim() = 4;
246 midway_header.size(3) = 3;
247 WarpType deformation = WarpType::scratch (midway_header);
263 template <
class WarpType,
class TemplateType>
265 Header deform_header (template_image);
266 deform_header.ndim() = 4;
267 deform_header.size(3) = 3;
268 WarpType deform = WarpType::scratch (deform_header);
static Image scratch(const Header &template_header, const std::string &label="scratch image")
default_type spacing(size_t axis) const
MR::Transform disp1_transform
Interp::Linear< Image< default_type > > disp2_interp
Interp::Linear< DeformationField2Type > deform1_interp
const transform_type linear2
Interp::Linear< DeformationField2Type > deform2_interp
Eigen::Vector3d out_of_bounds
const transform_type linear1
MR::Transform image_transform
const transform_type linear_transform
constexpr I ceil(const T x)
template function with cast to different type
std::enable_if< std::is_fundamental< ValueType >::value &&sizeof(ValueType)==1, ValueType >::type swap(ValueType v)
void warp(ImageTypeSource &source, ImageTypeDestination &destination, WarpType &warp, const typename ImageTypeDestination::value_type value_when_out_of_bounds=Interpolator< ImageTypeSource >::default_out_of_bounds_value(), const vector< uint32_t > oversample=Adapter::AutoOverSample, const bool jacobian_modulate=false)
convenience function to warp one image onto another
FORCE_INLINE void update_displacement_scaling_and_squaring(Image< default_type > &input, Image< default_type > &update, Image< default_type > &output, const default_type step=1.0)
FORCE_INLINE void compose_linear_displacement(const transform_type &transform, DisplacementFieldType &disp_in, DeformationFieldType &deform_out)
FORCE_INLINE void update_displacement(Image< default_type > &input, Image< default_type > &update, Image< default_type > &output, default_type step=1.0)
FORCE_INLINE WarpType compute_midway_deformation(WarpType &warp, const int from)
transform_type parse_linear_transform(InputWarpType &input_warps, std::string name)
FORCE_INLINE void compose_linear_deformation(const transform_type &transform, InputDeformationFieldType &deform_in, OutputDeformationFieldType &deform_out)
FORCE_INLINE void compute_full_deformation(const transform_type &linear1, DeformationField1Type &deform1, DeformationField2Type &deform2, const transform_type &linear2, OutputDeformationFieldType &deform_out)
double default_type
the default type used throughout MRtrix
Eigen::Transform< default_type, 3, Eigen::AffineCompact > transform_type
the type for the affine transform of an image:
ThreadedLoopRunOuter< decltype(Loop(vector< size_t >()))> ThreadedLoop(const HeaderType &source, const vector< size_t > &outer_axes, const vector< size_t > &inner_axes)
Multi-threaded loop object.
constexpr default_type NaN