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_act_method_h__
18#define __dwi_tractography_act_method_h__
19
22
25
26#include "interp/linear.h"
27#include "interp/masked.h"
28
29
30#define GMWMI_NORMAL_PERTURBATION 0.001
31
32
33namespace MR
34{
35 namespace DWI
36 {
37 namespace Tractography
38 {
39 namespace ACT
40 {
41
42
43 using namespace MR::DWI::Tractography::Tracking;
44
46
47 public:
48 ACT_Method_additions (const SharedBase& shared) :
49 sgm_depth (0),
50 seed_in_sgm (false),
51 sgm_seed_to_wm (false),
52 act_image (shared.act().voxel) { }
53
55 sgm_depth (0),
56 seed_in_sgm (false),
57 sgm_seed_to_wm (false),
58 act_image (that.act_image) { }
59
60 ACT_Method_additions() = delete;
61
62
63 const Tissues& tissues() const { return tissue_values; }
64
65
66 term_t check_structural (const Eigen::Vector3f& pos)
67 {
68 if (!fetch_tissue_data (pos))
69 return EXIT_IMAGE;
70
71 if (tissues().is_csf())
72 return (sgm_depth ? EXIT_SGM : ENTER_CSF);
73
74 if (tissues().is_gm()) {
75 if (tissues().get_cgm() >= tissues().get_sgm())
76 return ENTER_CGM;
77 ++sgm_depth;
78 } else if (sgm_depth) {
79 if (seed_in_sgm && !sgm_seed_to_wm) {
80 sgm_seed_to_wm = true;
81 sgm_depth = 0;
82 return CONTINUE;
83 }
84 return EXIT_SGM;
85 }
86
87 return CONTINUE;
88 }
89
90
91 bool check_seed (const Eigen::Vector3f& pos)
92 {
93 sgm_depth = 0;
94
95 if (!fetch_tissue_data (pos))
96 return false;
97
98 if (tissues().is_sgm()) {
99 seed_in_sgm = true;
100 sgm_seed_to_wm = false;
101 return true;
102 }
103
104 seed_in_sgm = false;
105
106 if ((tissues().is_csf()) || !tissues().get_wm() || ((tissues().get_gm() - tissues().get_wm()) >= GMWMI_ACCURACY))
107 return false;
108
109 return true;
110 }
111
112
113 bool seed_is_unidirectional (const Eigen::Vector3f& pos, Eigen::Vector3f& dir)
114 {
115 // Tissue values should have already been acquired for the seed point when this function is run
116 if (tissues().is_sgm()) return false;
117 if ((tissues().get_wm() >= tissues().get_gm()) || (tissues().get_sgm() >= tissues().get_cgm()))
118 return false;
119
120 const Tissues tissues_at_pos (tissues());
121
122 const Eigen::Vector3f pos_plus (pos + (dir * GMWMI_NORMAL_PERTURBATION));
123 fetch_tissue_data (pos_plus);
124 const Tissues tissues_plus (tissues());
125
126 const Eigen::Vector3f pos_minus (pos - (dir * GMWMI_NORMAL_PERTURBATION));
127 fetch_tissue_data (pos_minus);
128 const Tissues& tissues_minus (tissues());
129
130 const float gradient = (tissues_plus.get_gm() - tissues_plus.get_wm()) - (tissues_minus.get_gm() - tissues_minus.get_wm());
131 if (gradient > 0.0)
132 dir = -dir;
133
134 // Restore the tissue values to those at the seed point
135 tissue_values = tissues_at_pos;
136 return true;
137 }
138
139
140 bool fetch_tissue_data (const Eigen::Vector3f& pos)
141 {
142 if (!act_image.scanner (pos)) {
143 tissue_values.reset();
144 return false;
145 }
146 return tissue_values.set (act_image);
147 }
148
149
150 bool in_pathology() const { return (tissue_values.valid() && tissue_values.is_path()); }
151
152 void reverse_track() { sgm_depth = 0; }
153
154
155 size_t sgm_depth;
156 bool seed_in_sgm;
157 bool sgm_seed_to_wm;
158
159
160 private:
162 Tissues tissue_values;
163
164 };
165
166
167 }
168 }
169 }
170}
171
172#endif
173
#define GMWMI_NORMAL_PERTURBATION
Definition: method.h:30
#define GMWMI_ACCURACY
Definition: act.h:28
Implicit masking for interpolator class.
Definition: masked.h:43
Definition: base.h:24