Developer documentation
Version 3.0.3-105-gd3941f44
voxel.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_gaussian_voxel_h__
18#define __dwi_tractography_mapping_gaussian_voxel_h__
19
20
22
23namespace MR {
24 namespace DWI {
25 namespace Tractography {
26 namespace Mapping {
27 namespace Gaussian {
28
29
30
31
32 // Base class to handle case where the factor contributed by the streamline varies along its length
33 // (currently only occurs when the track-wise statistic is Gaussian)
36 public:
37 VoxelAddon() : sum_factors (0.0) { }
38 VoxelAddon (const default_type v) : sum_factors (v) { }
39 default_type get_factor() const { return sum_factors; }
40 protected:
41 void operator+= (const default_type f) const { sum_factors += f; }
42 void operator= (const default_type f) { sum_factors = f; }
43 void operator= (const VoxelAddon& that) { sum_factors = that.sum_factors; }
44 void normalize (const default_type l) const { sum_factors /= l; }
45 private:
46 mutable default_type sum_factors;
47 };
48
49
50
51
52 class Voxel : public Mapping::Voxel, public VoxelAddon
53 { MEMALIGN(Voxel)
54
55 using Base = Mapping::Voxel;
56
57 public:
58 Voxel (const int x, const int y, const int z) : Base (x, y, z) , VoxelAddon () { }
59 Voxel (const Eigen::Vector3i& that) : Base (that), VoxelAddon() { }
60 Voxel (const Eigen::Vector3i& v, const default_type l) : Base (v, l), VoxelAddon () { }
61 Voxel (const Eigen::Vector3i& v, const default_type l, const default_type f) : Base (v, l), VoxelAddon (f) { }
62 Voxel () : Base (), VoxelAddon () { }
63
64 Voxel& operator= (const Voxel& V) { Base::operator= (V); VoxelAddon::operator= (V); return *this; }
65 void operator+= (const default_type l) const { Base::operator+= (l); }
66 bool operator== (const Voxel& V) const { return Base::operator== (V); }
67 bool operator< (const Voxel& V) const { return Base::operator< (V); }
68
69 void add (const default_type l, const default_type f) const { Base::operator+= (l); VoxelAddon::operator+= (f); }
70 void normalize() const { VoxelAddon::normalize (get_length()); Base::normalize(); }
71
72 };
73
74
75 class VoxelDEC : public Mapping::VoxelDEC, public VoxelAddon
76 { MEMALIGN(VoxelDEC)
77
78 using Base = Mapping::VoxelDEC;
79
80 public:
81 VoxelDEC () : Base (), VoxelAddon () { }
82 VoxelDEC (const Eigen::Vector3i& V) : Base (V), VoxelAddon () { }
83 VoxelDEC (const Eigen::Vector3i& V, const Eigen::Vector3d& d) : Base (V, d), VoxelAddon () { }
84 VoxelDEC (const Eigen::Vector3i& V, const Eigen::Vector3d& d, const default_type l) : Base (V, d, l), VoxelAddon () { }
85 VoxelDEC (const Eigen::Vector3i& V, const Eigen::Vector3d& d, const default_type l, const default_type f) : Base (V, d, l), VoxelAddon (f) { }
86
88 void operator+= (const default_type) const { assert (0); }
89 void operator+= (const Eigen::Vector3d&) const { assert (0); }
90 bool operator== (const VoxelDEC& V) const { return Base::operator== (V); }
91 bool operator< (const VoxelDEC& V) const { return Base::operator< (V); }
92
93 void add (const Eigen::Vector3d&, const default_type) const { assert (0); }
94 void add (const Eigen::Vector3d& i, const default_type l, const default_type f) const { Base::add (i, l); VoxelAddon::operator+= (f); }
95 void normalize() const { VoxelAddon::normalize (get_length()); Base::normalize(); }
96
97 };
98
99
100 class Dixel : public Mapping::Dixel, public VoxelAddon
101 { MEMALIGN(Dixel)
102
103 using Base = Mapping::Dixel;
104
105 public:
107
108 Dixel () : Base (), VoxelAddon () { }
109 Dixel (const Eigen::Vector3i& V) : Base (V), VoxelAddon () { }
110 Dixel (const Eigen::Vector3i& V, const dir_index_type b) : Base (V, b), VoxelAddon () { }
111 Dixel (const Eigen::Vector3i& V, const dir_index_type b, const default_type l) : Base (V, b, l), VoxelAddon () { }
112 Dixel (const Eigen::Vector3i& V, const dir_index_type b, const default_type l, const default_type f) : Base (V, b, l), VoxelAddon (f) { }
113
114 Dixel& operator= (const Dixel& V) { Base::operator= (V); VoxelAddon::operator= (V); return *this; }
115 bool operator== (const Dixel& V) const { return Base::operator== (V); }
116 bool operator< (const Dixel& V) const { return Base::operator< (V); }
117 void operator+= (const default_type) const { assert (0); }
118
120 void normalize() const { VoxelAddon::normalize (get_length()); Base::normalize(); }
121
122 };
123
124
125 class VoxelTOD : public Mapping::VoxelTOD, public VoxelAddon
126 { MEMALIGN(VoxelTOD)
127
128 using Base = Mapping::VoxelTOD;
129
130 public:
131 using vector_type = Eigen::Matrix<default_type, Eigen::Dynamic, 1>;
132
133 VoxelTOD () : Base (), VoxelAddon () { }
134 VoxelTOD (const Eigen::Vector3i& V) : Base (V), VoxelAddon () { }
135 VoxelTOD (const Eigen::Vector3i& V, const vector_type& t) : Base (V, t), VoxelAddon () { }
136 VoxelTOD (const Eigen::Vector3i& V, const vector_type& t, const default_type l) : Base (V, t, l), VoxelAddon () { }
137 VoxelTOD (const Eigen::Vector3i& V, const vector_type& t, const default_type l, const default_type f) : Base (V, t, l), VoxelAddon (f) { }
138
140 bool operator== (const VoxelTOD& V) const { return Base::operator== (V); }
141 bool operator< (const VoxelTOD& V) const { return Base::operator< (V); }
142 void operator+= (const vector_type&) const { assert (0); }
143
144 void add (const vector_type&, const default_type) const { assert (0); }
145 void add (const vector_type& i, const default_type l, const default_type f) const { Base::add (i, l); VoxelAddon::operator+= (f); }
146 void normalize() const { VoxelAddon::normalize (get_length()); Base::normalize(); }
147
148 };
149
150
151
152
153
154
155 // Unlike standard TWI, with Gaussian smoothing the TWI factor is stored per point rather than per streamline
156 // However, it's handy from a code perspective to still use the same base class
157 /*
158 class SetVoxelExtras
159 { MEMALIGN(SetVoxelExtras)
160 public:
161 size_t index;
162 float weight;
163 };
164 */
165
166
167
168
169
170 class SetVoxel : public std::set<Voxel>, public Mapping::SetVoxelExtras
172 public:
173
174 using VoxType = Voxel;
175
176 inline void insert (const Eigen::Vector3i& v, const default_type l, const default_type f)
177 {
178 const Voxel temp (v, l, f);
179 iterator existing = std::set<Voxel>::find (temp);
180 if (existing == std::set<Voxel>::end())
181 std::set<Voxel>::insert (temp);
182 else
183 (*existing).add (l, f);
184 }
185 };
186
187
188 class SetVoxelDEC : public std::set<VoxelDEC>, public Mapping::SetVoxelExtras
190 public:
191
192 using VoxType = VoxelDEC;
193
194 inline void insert (const Eigen::Vector3i& v, const Eigen::Vector3d& d, const default_type l, const default_type f)
195 {
196 const VoxelDEC temp (v, d, l, f);
197 iterator existing = std::set<VoxelDEC>::find (temp);
198 if (existing == std::set<VoxelDEC>::end())
199 std::set<VoxelDEC>::insert (temp);
200 else
201 (*existing).add (d, l, f);
202 }
203 };
204
205
206 class SetDixel : public std::set<Dixel>, public Mapping::SetVoxelExtras
208 public:
209
210 using VoxType = Dixel;
211 using dir_index_type = Dixel::dir_index_type;
212
213 inline void insert (const Eigen::Vector3i& v, const dir_index_type d, const default_type l, const default_type f)
214 {
215 const Dixel temp (v, d, l, f);
216 iterator existing = std::set<Dixel>::find (temp);
217 if (existing == std::set<Dixel>::end())
218 std::set<Dixel>::insert (temp);
219 else
220 (*existing).add (l, f);
221 }
222 };
223
224
225 class SetVoxelTOD : public std::set<VoxelTOD>, public Mapping::SetVoxelExtras
227 public:
228
229 using VoxType = VoxelTOD;
230 using vector_type = VoxelTOD::vector_type;
231
232 inline void insert (const Eigen::Vector3i& v, const vector_type& t, const default_type l, const default_type f)
233 {
234 const VoxelTOD temp (v, t, l, f);
235 iterator existing = std::set<VoxelTOD>::find (temp);
236 if (existing == std::set<VoxelTOD>::end())
237 std::set<VoxelTOD>::insert (temp);
238 else
239 (*existing).add (t, l, f);
240 }
241 };
242
243
244
245 }
246 }
247 }
248 }
249}
250
251#endif
252
253
254
Array & operator=(const MR::Helper::ConstRow< ImageType > &row)
Definition: array.h:25
DWI::Directions::index_type index_type
Definition: voxel.h:106
Dixel(const Eigen::Vector3i &V, const dir_index_type b)
Definition: voxel.h:110
void operator+=(const default_type) const
Definition: voxel.h:117
Dixel(const Eigen::Vector3i &V, const dir_index_type b, const default_type l)
Definition: voxel.h:111
Dixel(const Eigen::Vector3i &V, const dir_index_type b, const default_type l, const default_type f)
Definition: voxel.h:112
bool operator<(const Dixel &V) const
Definition: voxel.h:116
bool operator==(const Dixel &V) const
Definition: voxel.h:115
void add(const default_type l, const default_type f) const
Definition: voxel.h:119
void normalize(const default_type l) const
Definition: voxel.h:44
void operator+=(const default_type f) const
Definition: voxel.h:41
VoxelDEC & operator=(const VoxelDEC &V)
Definition: voxel.h:87
bool operator==(const VoxelDEC &V) const
Definition: voxel.h:90
VoxelDEC(const Eigen::Vector3i &V, const Eigen::Vector3d &d, const default_type l)
Definition: voxel.h:84
void operator+=(const default_type) const
Definition: voxel.h:88
bool operator<(const VoxelDEC &V) const
Definition: voxel.h:91
VoxelDEC(const Eigen::Vector3i &V, const Eigen::Vector3d &d)
Definition: voxel.h:83
VoxelDEC(const Eigen::Vector3i &V, const Eigen::Vector3d &d, const default_type l, const default_type f)
Definition: voxel.h:85
void add(const Eigen::Vector3d &, const default_type) const
Definition: voxel.h:93
void add(const Eigen::Vector3d &i, const default_type l, const default_type f) const
Definition: voxel.h:94
Voxel(const Eigen::Vector3i &v, const default_type l)
Definition: voxel.h:60
Voxel(const Eigen::Vector3i &v, const default_type l, const default_type f)
Definition: voxel.h:61
void operator+=(const default_type l) const
Definition: voxel.h:65
bool operator==(const Voxel &V) const
Definition: voxel.h:66
bool operator<(const Voxel &V) const
Definition: voxel.h:67
Voxel(const int x, const int y, const int z)
Definition: voxel.h:58
void add(const default_type l, const default_type f) const
Definition: voxel.h:69
Voxel(const Eigen::Vector3i &that)
Definition: voxel.h:59
bool operator==(const VoxelTOD &V) const
Definition: voxel.h:140
VoxelTOD & operator=(const VoxelTOD &V)
Definition: voxel.h:139
VoxelTOD(const Eigen::Vector3i &V, const vector_type &t)
Definition: voxel.h:135
VoxelTOD(const Eigen::Vector3i &V, const vector_type &t, const default_type l)
Definition: voxel.h:136
void add(const vector_type &i, const default_type l, const default_type f) const
Definition: voxel.h:145
void operator+=(const vector_type &) const
Definition: voxel.h:142
VoxelTOD(const Eigen::Vector3i &V, const vector_type &t, const default_type l, const default_type f)
Definition: voxel.h:137
void add(const vector_type &, const default_type) const
Definition: voxel.h:144
Eigen::Matrix< default_type, Eigen::Dynamic, 1 > vector_type
Definition: voxel.h:131
bool operator<(const VoxelTOD &V) const
Definition: voxel.h:141
Derived & operator+=(const MR::Helper::ConstRow< ImageType > &row)
Definition: dense_base.h:28
#define NOMEMALIGN
Definition: memory.h:22
unsigned int index_type
Definition: set.h:34
void set(HeaderType &header, const List &stride)
set the strides of header from a vector<ssize_t>
Definition: stride.h:135
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
#define MEMALIGN(...)
Definition: types.h:185