17#ifndef __dwi_tractography_sift_output_h__
18#define __dwi_tractography_sift_output_h__
42 namespace Tractography
48 template <
class Fixel>
53 for (
auto l =
Loop(out) (out, v); l; ++l) {
57 value += i().get_FOD();
65 template <
class Fixel>
77 for (
auto l =
Loop (0, 3) (out, v); l; ++l) {
79 Eigen::Matrix<default_type, Eigen::Dynamic, 1> sum = Eigen::Matrix<default_type, Eigen::Dynamic, 1>::Zero (N);
82 Eigen::Matrix<default_type, Eigen::Dynamic, 1> this_lobe;
83 aPSF (this_lobe, i().get_dir());
84 for (
size_t c = 0; c != N; ++c)
85 sum[c] += i().get_FOD() * this_lobe[c];
88 for (
auto l =
Loop (3) (out); l; ++l)
89 out.value() = sum[out.index(3)];
91 for (
auto l =
Loop (3) (out); l; ++l)
97 template <
class Fixel>
103 H_fixel.datatype().set_byte_order_native();
108 for (
auto l =
Loop (out) (out, v); l; ++l) {
110 out.value().set_size ((*v.value()).num_fixels());
113 FixelMetric fixel (iter().get_dir().
template cast<float>(), iter().get_FOD(), iter().get_FOD());
114 out.value()[
index] = fixel;
120 template <
class Fixel>
126 for (
auto l =
Loop (out) (out, v); l; ++l) {
130 value += i().get_TD();
131 out.value() =
value * current_mu;
138 template <
class Fixel>
144 for (
auto l =
Loop (out) (out, v); l; ++l) {
149 value += i().get_TD();
151 out.value() =
value * current_mu;
158 template <
class Fixel>
171 for (
auto l =
Loop (v) (out, v); l; ++l) {
173 Eigen::Matrix<default_type, Eigen::Dynamic, 1> sum = Eigen::Matrix<default_type, Eigen::Dynamic, 1>::Zero (N);
176 Eigen::Matrix<default_type, Eigen::Dynamic, 1> this_lobe;
177 aPSF (this_lobe, i().get_dir());
178 for (
size_t c = 0; c != N; ++c)
179 sum[c] += i().get_TD() * this_lobe[c];
181 for (
auto l =
Loop (3) (out); l; ++l)
182 out.value() = sum[out.index(3)] * current_mu;
185 for (
auto l =
Loop (3) (out); l; ++l)
191 template <
class Fixel>
198 H_fixel.datatype().set_byte_order_native();
203 for (
auto l =
Loop (out) (out, v); l; ++l) {
205 out.value().set_size ((*v.value()).num_fixels());
208 FixelMetric fixel (iter().get_dir().
template cast<float>(), iter().get_FOD(), current_mu * iter().get_TD());
209 out.value()[
index] = fixel;
215 template <
class Fixel>
223 for (
auto l =
Loop (v) (v, out_max_abs_diff, out_diff, out_cost); l; ++l) {
225 default_type max_abs_diff = 0.0, diff = 0.0, cost = 0.0;
227 const default_type this_diff = i().get_diff (current_mu);
228 max_abs_diff = std::max (max_abs_diff,
abs (this_diff));
230 cost += i().get_cost (current_mu) * i().get_weight();
232 out_max_abs_diff.value() = max_abs_diff;
233 out_diff.value() = diff;
234 out_cost.value() = cost;
236 out_max_abs_diff.value() =
NaN;
237 out_diff.value() =
NaN;
238 out_cost.value() =
NaN;
243 template <
class Fixel>
250 H_fixel.datatype().set_byte_order_native();
256 for (
auto l =
Loop (v) (v, out_diff, out_cost); l; ++l) {
258 out_diff.value().set_size ((*v.value()).num_fixels());
259 out_cost.value().set_size ((*v.value()).num_fixels());
262 FixelMetric fixel_diff (iter().get_dir().
template cast<float>(), iter().get_FOD(), iter().get_diff (current_mu));
263 out_diff.value()[
index] = fixel_diff;
264 FixelMetric fixel_cost (iter().get_dir().
template cast<float>(), iter().get_FOD(), iter().get_cost (current_mu));
265 out_cost.value()[
index] = fixel_cost;
271 template <
class Fixel>
274 File::OFStream out (path, std::ios_base::out | std::ios_base::trunc);
277 out <<
"#Fibre density,Track density (unscaled),Track density (scaled),Weight,\n";
279 out <<
str (i->get_FOD()) <<
"," <<
str (i->get_TD()) <<
"," <<
str (i->get_TD() * current_mu) <<
"," <<
str (i->get_weight()) <<
",\n";
283 template <
class Fixel>
290 for (
auto l =
Loop (v) (v, out); l; ++l) {
292 out.value() = (*v.value()).num_fixels();
298 template <
class Fixel>
306 for (
auto l =
Loop (v) (v, out_count, out_amps, v); l; ++l) {
313 sum += i().get_FOD();
316 out_count.value() = count;
317 out_amps .value() = sum;
319 out_count.value() = 0;
320 out_amps .value() =
NaN;
void output_tdi_fixel(const std::string &) const
void output_target_image_fixel(const std::string &) const
void output_untracked_fixels(const std::string &, const std::string &) const
void output_target_image_sh(const std::string &) const
void output_target_image(const std::string &) const
void output_error_images(const std::string &, const std::string &, const std::string &) const
void output_scatterplot(const std::string &) const
void output_tdi_null_lobes(const std::string &) const
void output_fixel_count_image(const std::string &) const
void output_tdi_sh(const std::string &) const
void output_tdi(const std::string &) const
void output_error_fixel_images(const std::string &, const std::string &) const
static constexpr uint8_t UInt64
static constexpr uint8_t UInt8
open output files for writing, checking for pre-existing file if necessary
static Image create(const std::string &image_name, const Header &template_header, bool add_to_command_history=true)
a class to hold the coefficients for an apodised point-spread function.
FORCE_INLINE LoopAlongAxes Loop()
size_t NforL(int lmax)
the number of (even-degree) coefficients for the given value of lmax
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
std::string command_history_string
const std::string size_key("sparse_data_size")
const std::string name_key("sparse_data_name")
double default_type
the default type used throughout MRtrix
constexpr std::enable_if< std::is_arithmetic< X >::value &&std::is_unsigned< X >::value, X >::type abs(X x)
std::string str(const T &value, int precision=0)
constexpr default_type NaN