Developer documentation
Version 3.0.3-105-gd3941f44
tckfactor.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_sift2_tckfactor_h__
18#define __dwi_tractography_sift2_tckfactor_h__
19
20
21#include <fstream>
22#include <limits>
23#include <mutex>
24
25#include "image.h"
26#include "types.h"
27
28#include "dwi/directions/set.h"
29
32
34
35
36
37#define SIFT2_REGULARISATION_TIKHONOV_DEFAULT 0.0
38#define SIFT2_REGULARISATION_TV_DEFAULT 0.1
39
40#define SIFT2_MIN_TD_FRAC_DEFAULT 0.10
41
42#define SIFT2_MIN_ITERS_DEFAULT 10
43#define SIFT2_MAX_ITERS_DEFAULT 1000
44#define SIFT2_MIN_COEFF_DEFAULT (-std::numeric_limits<default_type>::infinity())
45#define SIFT2_MAX_COEFF_DEFAULT (std::numeric_limits<default_type>::infinity())
46#define SIFT2_MAX_COEFF_STEP_DEFAULT 1.0
47#define SIFT2_MIN_CF_DECREASE_DEFAULT 2.5e-5
48
49
50
51namespace MR {
52 namespace DWI {
53 namespace Tractography {
54 namespace SIFT2 {
55
56
57
58
59 class TckFactor : public SIFT::Model<Fixel>
60 { MEMALIGN(TckFactor)
61
62 public:
63
65 SIFT::Model<Fixel> (fod_image, dirs),
66 reg_multiplier_tikhonov (0.0),
67 reg_multiplier_tv (0.0),
68 min_iters (SIFT2_MIN_ITERS_DEFAULT),
69 max_iters (SIFT2_MAX_ITERS_DEFAULT),
70 min_coeff (SIFT2_MIN_COEFF_DEFAULT),
71 max_coeff (SIFT2_MAX_COEFF_DEFAULT),
72 max_coeff_step (SIFT2_MAX_COEFF_STEP_DEFAULT),
73 min_cf_decrease_percentage (SIFT2_MIN_CF_DECREASE_DEFAULT),
74 data_scale_term (0.0) { }
75
76
77 void set_reg_lambdas (const double, const double);
78 void set_min_iters (const int i) { min_iters = i; }
79 void set_max_iters (const int i) { max_iters = i; }
80 void set_min_factor (const double i) { min_coeff = i ? std::log(i) : -std::numeric_limits<double>::infinity(); }
81 void set_min_coeff (const double i) { min_coeff = i; }
82 void set_max_factor (const double i) { max_coeff = std::log(i); }
83 void set_max_coeff (const double i) { max_coeff = i; }
84 void set_max_coeff_step (const double i) { max_coeff_step = i; }
85 void set_min_cf_decrease (const double i) { min_cf_decrease_percentage = i; }
86
87 void set_csv_path (const std::string& i) { csv_path = i; }
88
89
90 void store_orig_TDs();
91
92 void remove_excluded_fixels (const float);
93
94 // Function that prints the cost function, then sets the streamline weights according to
95 // the inverse of length, and re-calculates and prints the cost function
96 void test_streamline_length_scaling();
97
98 // AFCSA method: Sum the attributable fibre volumes along the streamline length;
99 // divide by streamline length, convert to a weighting coefficient,
100 // see how the cost function fares
101 void calc_afcsa();
102
103 void estimate_factors();
104
105 void output_factors (const std::string&) const;
106 void output_coefficients (const std::string&) const;
107
108 void output_all_debug_images (const std::string&) const;
109
110
111 private:
112 Eigen::Array<default_type, Eigen::Dynamic, 1> coefficients;
113
114 double reg_multiplier_tikhonov, reg_multiplier_tv;
115 size_t min_iters, max_iters;
116 double min_coeff, max_coeff, max_coeff_step, min_cf_decrease_percentage;
117 std::string csv_path;
118
119 double data_scale_term;
120
121
122 friend class LineSearchFunctor;
127 friend class FixelUpdater;
129
130
131 // For when multiple threads are trying to write their final information back
132 std::mutex mutex;
133
134 void indicate_progress() { if (App::log_level) fprintf (stderr, "."); }
135
136 };
137
138
139
140
141
142 }
143 }
144 }
145}
146
147
148#endif
149
const DWI::Directions::FastLookupSet & dirs
Definition: fixel_td_map.h:59
int log_level
Definition: exception.h:34
Definition: base.h:24
#define SIFT2_MIN_COEFF_DEFAULT
Definition: tckfactor.h:44
#define SIFT2_MAX_COEFF_DEFAULT
Definition: tckfactor.h:45
#define SIFT2_MAX_COEFF_STEP_DEFAULT
Definition: tckfactor.h:46
#define SIFT2_MIN_CF_DECREASE_DEFAULT
Definition: tckfactor.h:47
#define SIFT2_MAX_ITERS_DEFAULT
Definition: tckfactor.h:43
#define SIFT2_MIN_ITERS_DEFAULT
Definition: tckfactor.h:42