Developer documentation
Version 3.0.3-105-gd3941f44
multi_contrast.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_multi_contrast_h__
18#define __registration_multi_contrast_h__
19
20#include <vector>
21
22#include "types.h"
23#include "math/SH.h"
24#include "image.h"
25#include "header.h"
26#include "adapter/subset.h"
27#include "adapter/base.h"
28#include "image_io/default.h"
29#include "image_io/scratch.h"
30#include "file/name_parser.h"
31#include "header.h"
32#include "formats/list.h"
33
34namespace MR
35{
36 namespace Registration
37 {
38
39 FORCE_INLINE void check_image_output (const std::string& image_name, const Header& reference) {
41 if (!image_name.size()) throw Exception ("image output path is empty");
42 if (Path::exists (image_name) && !App::overwrite_files)
43 throw Exception ("output image \"" + image_name + "\" already exists (use -force option to force overwrite)");
44
45 Header H = reference;
46 File::NameParser parser;
47 parser.parse (image_name);
48 vector<int> Pdim (parser.ndim());
49
50 H.name() = image_name;
51
52 const Formats::Base** format_handler = Formats::handlers;
53 for (; *format_handler; format_handler++)
54 if ((*format_handler)->check (H, H.ndim() - Pdim.size()))
55 break;
56
57 if (!*format_handler) {
58 const std::string basename = Path::basename (image_name);
59 const size_t extension_index = basename.find_last_of (".");
60 if (extension_index == std::string::npos)
61 throw Exception ("unknown format for image \"" + image_name + "\" (no file extension specified)");
62 else
63 throw Exception ("unknown format for image \"" + image_name + "\" (unsupported file extension: " + basename.substr (extension_index) + ")");
64 }
65 }
66
68 size_t start; // index to volume in image holding all tissue contrasts
69 size_t nvols; // number of volumes preloaded into image holding all tissue contrasts
70 ssize_t lmax; // maximum requested lmax
71 bool do_reorientation; // registration treats this image as (possibly 4D) scalar image
72 size_t image_nvols; // number of volumes in original image
73 ssize_t image_lmax; // lmax available in image (preloaded, might differ from original image), 0 if not an FOD image
75
76 MultiContrastSetting (): start (0), nvols (0), do_reorientation (false), weight (1.0) {}
77 MultiContrastSetting (size_t image_nvols, bool do_reorientation = false, ssize_t limit_lmax = std::numeric_limits<ssize_t>::max()) :
79 if (do_reorientation) {
82 } else {
83 image_lmax = 0;
84 lmax = 0;
85 }
86 lower_lmax (limit_lmax);
87 }
88
89 FORCE_INLINE void lower_lmax (ssize_t new_lmax) {
90 assert (new_lmax >= 0);
91 if (new_lmax < lmax) {
92 lmax = new_lmax;
93 if (new_lmax > 0) {
94 nvols = Math::SH::NforL (new_lmax);
95 } else {
96 nvols = 1;
97 }
98 }
99 }
100 };
101
102 inline std::ostream& operator << (std::ostream & o, const MultiContrastSetting & a) {
103 o << "MultiContrast: [start:" << a.start << ", nvols:" << a.nvols << ", lmax:" << a.lmax << ", image_lmax:" << a.image_lmax
104 << ", reorient:" << a.do_reorientation << ", weight:" << a.weight << "]";
105 return o;
106 }
107
109
110 }
111}
112#endif
a class to interpret numbered filenames
Definition: name_parser.h:32
size_t ndim() const
Definition: name_parser.h:108
void parse(const std::string &imagename, size_t max_num_sequences=std::numeric_limits< size_t >::max())
the interface for classes that support the various image formats.
Definition: list.h:42
size_t LforN(int N)
returns the largest lmax given N parameters
Definition: SH.h:70
size_t NforL(int lmax)
the number of (even-degree) coefficients for the given value of lmax
Definition: SH.h:46
#define NOMEMALIGN
Definition: memory.h:22
bool overwrite_files
const Base * handlers[]
std::string basename(const std::string &name)
Definition: path.h:60
bool exists(const std::string &path)
Definition: path.h:88
void preload_data(vector< Header > &input, Image< default_type > &images, const vector< MultiContrastSetting > &mc_params)
std::ostream & operator<<(std::ostream &o, const MultiContrastSetting &a)
FORCE_INLINE void check_image_output(const std::string &image_name, const Header &reference)
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
Eigen::MatrixXd H
#define FORCE_INLINE
Definition: types.h:156
MultiContrastSetting(size_t image_nvols, bool do_reorientation=false, ssize_t limit_lmax=std::numeric_limits< ssize_t >::max())
FORCE_INLINE void lower_lmax(ssize_t new_lmax)