Developer documentation
Version 3.0.3-105-gd3941f44
helpers.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_utils_h__
18#define __registration_warp_utils_h__
19
20namespace MR
21{
22 namespace Registration
23 {
24
25 namespace Warp
26 {
27
28 template <class HeaderType>
29 inline void check_warp (const HeaderType& warp_header)
30 {
31 if (warp_header.ndim() != 4)
32 throw Exception ("input warp is not a 4D image");
33 if (warp_header.size(3) != 3)
34 throw Exception ("input warp should have 3 volumes in the 4th dimension");
35 }
36
37 template <class HeaderType>
38 inline void check_warp_full (const HeaderType& warp_header)
39 {
40 if (warp_header.ndim() != 5)
41 throw Exception ("the input warp image must be a 5D file.");
42 if (warp_header.size(3) != 3)
43 throw Exception ("the input warp image must have 3 volumes (x,y,z) in the 4th dimension.");
44 if (warp_header.size(4) != 4)
45 throw Exception ("the input warp image must have 4 volumes in the 5th dimension.");
46 }
47
48 template <class InputWarpType>
49 transform_type parse_linear_transform (InputWarpType& input_warps, std::string name) {
50 transform_type linear;
51 const auto it = input_warps.keyval().find (name);
52 if (it != input_warps.keyval().end()) {
53 const auto lines = split_lines (it->second);
54 if (lines.size() != 3)
55 throw Exception ("linear transform in initialisation syn warps image header does not contain 3 rows");
56 for (size_t row = 0; row < 3; ++row) {
57 const auto values = split (lines[row], " ", true);
58 if (values.size() != 4)
59 throw Exception ("linear transform in initialisation syn warps image header does not contain 4 columns");
60 for (size_t col = 0; col < 4; ++col)
61 linear (row, col) = std::stod (values[col]);
62 }
63 } else {
64 throw Exception ("no linear transform found in initialisation syn warps image header");
65 }
66
67 return linear;
68 }
69
70 }
71 }
72}
73
74#endif
void check_warp(const HeaderType &warp_header)
Definition: helpers.h:29
transform_type parse_linear_transform(InputWarpType &input_warps, std::string name)
Definition: helpers.h:49
void check_warp_full(const HeaderType &warp_header)
Definition: helpers.h:38
Definition: base.h:24
Eigen::Transform< default_type, 3, Eigen::AffineCompact > transform_type
the type for the affine transform of an image:
Definition: types.h:234
vector< std::string > split_lines(const std::string &string, bool ignore_empty_fields=true, size_t num=std::numeric_limits< size_t >::max())
Definition: mrtrix.h:179
vector< std::string > split(const std::string &string, const char *delimiters=" \t\n", bool ignore_empty_fields=false, size_t num=std::numeric_limits< size_t >::max())
const std::string name
Definition: thread.h:108