Developer documentation
Version 3.0.3-105-gd3941f44
mapper_plugins.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 __dwi_tractography_mapping_mapper_plugins_h__
18#define __dwi_tractography_mapping_mapper_plugins_h__
19
20
21#include "image.h"
22#include "types.h"
23#include "interp/linear.h"
24#include "math/SH.h"
25
26#include "dwi/directions/set.h"
27
30
31
32namespace MR {
33 namespace DWI {
34 namespace Tractography {
35 namespace Mapping {
36
37
38
39
40
42 { MEMALIGN(DixelMappingPlugin)
43 public:
45 dirs (directions) { }
47 dirs (that.dirs) { }
48 DWI::Directions::index_type operator() (const Eigen::Vector3d& d) const { return dirs.select_direction (d); }
49 private:
51 };
52
53
54
56 { MEMALIGN(TODMappingPlugin)
57 public:
58 TODMappingPlugin (const size_t N) :
59 generator (new Math::SH::aPSF<float> (Math::SH::LforN (N))) { }
60 template <class VectorType, class UnitVectorType>
61 void operator() (VectorType& sh, const UnitVectorType& d) const { (*generator) (sh, d); }
62 private:
63 std::shared_ptr<Math::SH::aPSF<float>> generator;
64 };
65
66
67
68
69
71 { MEMALIGN(TWIImagePluginBase)
72 public:
73 TWIImagePluginBase (const std::string& input_image, const tck_stat_t track_statistic) :
74 statistic (track_statistic),
75 interp (Image<float>::open (input_image).with_direct_io()),
76 backtrack (false) { }
77
78 TWIImagePluginBase (Image<float>& input_image, const tck_stat_t track_statistic) :
79 statistic (track_statistic),
80 interp (input_image),
81 backtrack (false) { }
82
84 statistic (that.statistic),
85 interp (that.interp),
86 backtrack (that.backtrack),
88
89 virtual ~TWIImagePluginBase() { }
90
91 virtual TWIImagePluginBase* clone() const = 0;
92
93 void set_backtrack();
94
95 virtual void load_factors (const Streamline<>&, vector<default_type>&) const = 0;
96
97
98 protected:
100
101 //Image<float> voxel;
102 // Each instance of the class has its own interpolator for obtaining values
103 // in a thread-safe fashion
105
106 // For handling backtracking for endpoint-based track-wise statistics
109
110 // Helper functions; find the last point on the streamline from which valid image information can be read
111 ssize_t get_end_index (const Streamline<>&, const bool) const;
112 const Streamline<>::point_type get_end_point (const Streamline<>&, const bool) const;
113
114 };
115
116
117
118
120 { MEMALIGN(TWIScalarImagePlugin)
121 public:
122 TWIScalarImagePlugin (const std::string& input_image, const tck_stat_t track_statistic) :
123 TWIImagePluginBase (input_image, track_statistic)
124 {
125 assert (statistic != ENDS_CORR);
126 if (!((interp.ndim() == 3) || (interp.ndim() == 4 && interp.size(3) == 1)))
127 throw Exception ("Scalar image used for TWI must be a 3D image");
128 if (interp.ndim() == 4)
129 interp.index(3) = 0;
130 }
131
133 TWIImagePluginBase (that)
134 {
135 if (interp.ndim() == 4)
136 interp.index(3) = 0;
137 }
138
139 TWIScalarImagePlugin* clone() const override
140 {
141 return new TWIScalarImagePlugin (*this);
142 }
143
144 void load_factors (const Streamline<>&, vector<default_type>&) const override;
145 };
146
147
148
149
151 { MEMALIGN(TWIFODImagePlugin)
152 public:
153 TWIFODImagePlugin (const std::string& input_image, const tck_stat_t track_statistic) :
154 TWIImagePluginBase (input_image, track_statistic),
155 sh_coeffs (interp.size(3)),
156 precomputer (new Math::SH::PrecomputedAL<default_type> ())
157 {
158 if (track_statistic == ENDS_CORR)
159 throw Exception ("Cannot use ends_corr track statistic with an FOD image");
161 precomputer->init (Math::SH::LforN (sh_coeffs.size()));
162 }
163
164 TWIFODImagePlugin (const TWIFODImagePlugin& that) = default;
165
166 TWIFODImagePlugin* clone() const override
167 {
168 return new TWIFODImagePlugin (*this);
169 }
170
171 void load_factors (const Streamline<>&, vector<default_type>&) const override;
172
173 private:
174 mutable Eigen::Matrix<default_type, Eigen::Dynamic, 1> sh_coeffs;
175 std::shared_ptr<Math::SH::PrecomputedAL<default_type>> precomputer;
176 };
177
178
179
180
182 { MEMALIGN(TWDFCStaticImagePlugin)
183 public:
184 TWDFCStaticImagePlugin (Image<float>& input_image) :
185 TWIImagePluginBase (input_image, ENDS_CORR) { }
186
187 TWDFCStaticImagePlugin (const TWDFCStaticImagePlugin& that) = default;
188
189 TWDFCStaticImagePlugin* clone() const override
190 {
191 return new TWDFCStaticImagePlugin (*this);
192 }
193
194 void load_factors (const Streamline<>&, vector<default_type>&) const override;
195 };
196
197
198
199
201 { MEMALIGN(TWDFCDynamicImagePlugin)
202 public:
203 TWDFCDynamicImagePlugin (Image<float>& input_image, const vector<float>& kernel, const ssize_t timepoint) :
204 TWIImagePluginBase (input_image, ENDS_CORR),
205 kernel (kernel),
206 kernel_centre ((kernel.size()-1) / 2),
207 sample_centre (timepoint) { }
208
209 TWDFCDynamicImagePlugin (const TWDFCDynamicImagePlugin& that) = default;
210
211 TWDFCDynamicImagePlugin* clone() const override
212 {
213 return new TWDFCDynamicImagePlugin (*this);
214 }
215
216 void load_factors (const Streamline<>&, vector<default_type>&) const override;
217
218 protected:
221 };
222
223
224
225
226 }
227 }
228 }
229}
230
231#endif
232
233
234
ssize_t get_end_index(const Streamline<> &, const bool) const
const Streamline ::point_type get_end_point(const Streamline<> &, const bool) const
functions and classes related to image data input/output
Definition: image.h:41
Precomputed Associated Legrendre Polynomials - used to speed up SH calculation.
Definition: SH.h:400
a class to hold the coefficients for an apodised point-spread function.
Definition: SH.h:653
void check(const ImageType &H)
convenience function to check if an input image can contain SH coefficients
Definition: SH.h:745
size_t LforN(int N)
returns the largest lmax given N parameters
Definition: SH.h:70
unsigned int index_type
Definition: set.h:34
Definition: base.h:24