Developer documentation
Version 3.0.3-105-gd3941f44
method.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_tracking_method_h__
18#define __dwi_tractography_tracking_method_h__
19
20#include "memory.h"
21#include "types.h"
25
26
27
28namespace MR
29{
30 namespace DWI
31 {
32 namespace Tractography
33 {
34 namespace Tracking
35 {
36
37
38
39 class MethodBase { MEMALIGN(MethodBase)
40
41 public:
42
43 MethodBase (const SharedBase& shared) :
44 pos (0.0, 0.0, 0.0),
45 dir (0.0, 0.0, 1.0),
46 S (shared),
47 act_method_additions (S.is_act() ? new ACT::ACT_Method_additions (S) : nullptr),
48 values (shared.source.size(3)) { }
49
50 MethodBase (const MethodBase& that) :
51 pos (0.0, 0.0, 0.0),
52 dir (0.0, 0.0, 1.0),
53 S (that.S),
54 act_method_additions (S.is_act() ? new ACT::ACT_Method_additions (that.act()) : nullptr),
55 uniform (that.uniform),
56 values (that.values.size()) { }
57
58
59 template <class InterpolatorType>
60 FORCE_INLINE bool get_data (InterpolatorType& source, const Eigen::Vector3f& position)
61 {
62 if (!source.scanner (position))
63 return false;
64 for (auto l = Loop (3) (source); l; ++l)
65 values[source.index(3)] = source.value();
66 return !std::isnan (values[0]);
67 }
68
69 template <class InterpolatorType>
70 FORCE_INLINE bool get_data (InterpolatorType& source)
71 {
72 return get_data (source, pos);
73 }
74
75 virtual bool init() = 0;
76 virtual term_t next() = 0;
77 virtual float get_metric (const Eigen::Vector3f& position, const Eigen::Vector3f& direction) = 0;
78
79 virtual void reverse_track() { if (act_method_additions) act().reverse_track(); }
80 virtual void truncate_track (GeneratedTrack& tck, const size_t length_to_revert_from, const size_t revert_step);
81
82 bool check_seed();
83
84 ACT::ACT_Method_additions& act() const { return *act_method_additions; }
85
86 Eigen::Vector3f pos, dir;
87
88
89 private:
90 const SharedBase& S;
91 std::unique_ptr<ACT::ACT_Method_additions> act_method_additions;
92
93
94 protected:
95 std::uniform_real_distribution<float> uniform;
96 Eigen::VectorXf values;
97
98 Eigen::Vector3f random_direction ();
99 Eigen::Vector3f random_direction (const float max_angle, const float sin_max_angle);
100 Eigen::Vector3f rotate_direction (const Eigen::Vector3f& reference, const Eigen::Vector3f& direction);
101
102 FORCE_INLINE Eigen::Vector3f random_direction (const Eigen::Vector3f& d, const float max_angle, const float sin_max_angle)
103 {
104 return rotate_direction (d, random_direction (max_angle, sin_max_angle));
105 }
106
107 };
108
109
110
111 }
112 }
113 }
114}
115
116#endif
117
118
119
std::uniform_real_distribution< float > uniform
Definition: method.h:95
Eigen::Vector3f random_direction(const float max_angle, const float sin_max_angle)
Eigen::Vector3f rotate_direction(const Eigen::Vector3f &reference, const Eigen::Vector3f &direction)
FORCE_INLINE Eigen::Vector3f random_direction(const Eigen::Vector3f &d, const float max_angle, const float sin_max_angle)
Definition: method.h:102
ssize_t size(size_t axis) const
Definition: image.h:66
FORCE_INLINE LoopAlongAxes Loop()
Definition: loop.h:419
Definition: base.h:24
#define FORCE_INLINE
Definition: types.h:156