Developer documentation
Version 3.0.3-105-gd3941f44
nulldist.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_algorithms_nulldist_h__
18#define __dwi_tractography_algorithms_nulldist_h__
19
24
25
26
27namespace MR
28{
29 namespace DWI
30 {
31 namespace Tractography
32 {
33 namespace Algorithms
34 {
35
36 using namespace MR::DWI::Tractography::Tracking;
37
39 public:
40
41 class Shared : public SharedBase { MEMALIGN(Shared)
42 public:
43 Shared (const std::string& diff_path, DWI::Tractography::Properties& property_set) :
44 SharedBase (diff_path, property_set)
45 {
48 rk4);
49 set_num_points();
50 set_cutoff (0.0f);
51 sin_max_angle_1o = std::sin (max_angle_1o);
52 properties["method"] = "Nulldist1";
53 }
54 float sin_max_angle_1o;
55 };
56
57 NullDist1 (const Shared& shared) :
58 MethodBase (shared),
59 S (shared),
60 source (S.source) { }
61
62
63 bool init() override {
64 if (!get_data (source))
65 return false;
66 dir = S.init_dir.allFinite() ? S.init_dir : random_direction();
67 return true;
68 }
69
70 term_t next () override {
71 if (!get_data (source))
72 return EXIT_IMAGE;
73 dir = rand_dir (dir);
74 dir.normalize();
75 pos += S.step_size * dir;
76 return CONTINUE;
77 }
78
79 float get_metric (const Eigen::Vector3f&, const Eigen::Vector3f&) override { return uniform(rng); }
80
81
82 protected:
83 const Shared& S;
85
86 Eigen::Vector3f rand_dir (const Eigen::Vector3f& d) { return (random_direction (d, S.max_angle_1o, S.sin_max_angle_1o)); }
87
88 };
89
91 public:
92
93 class Shared : public iFOD2::Shared { MEMALIGN(Shared)
94 public:
95 Shared (const std::string& diff_path, DWI::Tractography::Properties& property_set) :
96 iFOD2::Shared (diff_path, property_set)
97 {
98 set_cutoff (0.0f);
99 properties["method"] = "Nulldist2";
100 }
101 };
102
103 NullDist2 (const Shared& shared) :
104 iFOD2 (shared),
105 S (shared),
106 source (S.source),
107 positions (S.num_samples),
108 tangents (S.num_samples),
109 sample_idx (S.num_samples) { }
110
111 NullDist2 (const NullDist2& that) :
112 iFOD2 (that),
113 S (that.S),
114 source (S.source),
115 positions (S.num_samples),
116 tangents (S.num_samples),
117 sample_idx (S.num_samples) { }
118
119 bool init() override {
120 if (!get_data (source))
121 return false;
122 dir = S.init_dir.allFinite() ? S.init_dir : random_direction();
123 sample_idx = S.num_samples;
124 return true;
125 }
126
127 term_t next () override {
128
129 if (++sample_idx < S.num_samples) {
130 pos = positions[sample_idx];
131 dir = tangents [sample_idx];
132 return CONTINUE;
133 }
134
136 if (S.is_act()) {
137 if (!act().fetch_tissue_data (positions[S.num_samples - 1]))
138 return EXIT_IMAGE;
139 }
140 pos = positions[0];
141 dir = tangents[0];
142 sample_idx = 0;
143 return CONTINUE;
144
145 }
146
147 void reverse_track() override
148 {
149 sample_idx = S.num_samples;
150 MethodBase::reverse_track();
151 }
152
153 void truncate_track (GeneratedTrack& tck, const size_t length_to_revert_from, const size_t revert_step) override
154 {
155 iFOD2::truncate_track (tck, length_to_revert_from, revert_step);
156 sample_idx = S.num_samples;
157 }
158
159 float get_metric (const Eigen::Vector3f&, const Eigen::Vector3f&) override { return uniform(rng); }
160
161
162 protected:
163 const Shared& S;
165
168
169 };
170
171 }
172 }
173 }
174}
175
176#endif
177
178
Eigen::Vector3f rand_dir(const Eigen::Vector3f &d)
Definition: nulldist.h:86
Interpolator< Image< float > >::type source
Definition: nulldist.h:84
Interpolator< Image< float > >::type source
Definition: nulldist.h:164
vector< Eigen::Vector3f > tangents
Definition: nulldist.h:166
vector< Eigen::Vector3f > positions
Definition: nulldist.h:166
FORCE_INLINE Eigen::Vector3f rand_dir(const Eigen::Vector3f &d)
Definition: iFOD2.h:450
void get_path(vector< Eigen::Vector3f > &positions, vector< Eigen::Vector3f > &tangents, const Eigen::Vector3f &end_dir) const
Definition: iFOD2.h:415
std::uniform_real_distribution< float > uniform
Definition: method.h:95
thread_local Math::RNG rng
thread-local, but globally accessible RNG to vastly simplify multi-threading
Definition: base.h:24
#define MEMALIGN(...)
Definition: types.h:185