Developer documentation
Version 3.0.3-105-gd3941f44
convert.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __registration_warp_convert_h__
18#define __registration_warp_convert_h__
19
20
21
22#include "algo/loop.h"
23#include "transform.h"
24
25namespace MR
26{
27 namespace Registration
28 {
29
30 namespace Warp
31 {
32
33 template <class ImageType>
34 void displacement2deformation (ImageType& input, ImageType& output) {
35 MR::Transform transform (input);
36 auto kernel = [&] (ImageType& input, ImageType& output) {
37 Eigen::Vector3d voxel ((default_type)input.index(0), (default_type)input.index(1), (default_type)input.index(2));
38 output.row(3) = (transform.voxel2scanner * voxel).template cast<typename ImageType::value_type> () + Eigen::Vector3d (input.row(3));
39 };
40 ThreadedLoop (input, 0, 3).run (kernel, input, output);
41 }
42
43 template <class ImageType>
44 void deformation2displacement (ImageType& input, ImageType& output) {
45 MR::Transform transform (input);
46 auto kernel = [&] (ImageType& input, ImageType& output) {
47 Eigen::Vector3d voxel ((default_type)input.index(0), (default_type)input.index(1), (default_type)input.index(2));
48 output.row(3) = Eigen::Vector3d(input.row(3)) - transform.voxel2scanner * voxel;
49 };
50 ThreadedLoop (input, 0, 3).run (kernel, input, output);
51 }
52 }
53 }
54}
55
56#endif
const transform_type voxel2scanner
Definition: transform.h:43
void deformation2displacement(ImageType &input, ImageType &output)
Definition: convert.h:44
void displacement2deformation(ImageType &input, ImageType &output)
Definition: convert.h:34
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
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.