Developer documentation
Version 3.0.3-105-gd3941f44
matrix.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_connectome_matrix_h__
18#define __dwi_tractography_connectome_matrix_h__
19
20#include <set>
21
22#include "types.h"
23
24#include "connectome/connectome.h"
25#include "connectome/mat2vec.h"
26#include "math/math.h"
27
30
31
32namespace MR {
33namespace DWI {
34namespace Tractography {
35namespace Connectome {
36
37
38
39enum stat_edge { SUM, MEAN, MIN, MAX };
40extern const char* statistics[];
42
43
44// The number of nodes that must be exceeded in a connectome matrix in
45// order for mechanisms relating to RAM usage reduction to be activated
47
48
49template <typename T>
50class Matrix
52
53 public:
54 using vector_type = Eigen::Matrix<T, Eigen::Dynamic, 1>;
55
56 Matrix (const node_t max_node_index, const stat_edge stat, const bool vector_output, const bool track_assignments) :
57 statistic (stat),
58 vector_output (vector_output),
59 track_assignments (track_assignments),
60 mat2vec (vector_output ?
61 nullptr :
62 new MR::Connectome::Mat2Vec (max_node_index+1)),
63 data (vector_type::Zero (vector_output ?
64 (max_node_index + 1) :
65 mat2vec->vec_size())),
66 counts (stat == stat_edge::MEAN ?
67 vector_type::Zero (vector_output ?
68 (max_node_index + 1) :
69 mat2vec->vec_size()) :
71 {
72 if (statistic == stat_edge::MIN)
73 data = vector_type::Constant (vector_output ? (max_node_index + 1) : mat2vec->vec_size(), std::numeric_limits<T>::infinity());
74 else if (statistic == stat_edge::MAX)
75 data = vector_type::Constant (vector_output ? (max_node_index + 1) : mat2vec->vec_size(), -std::numeric_limits<T>::infinity());
76 }
77
78 bool operator() (const Mapped_track_nodepair&);
79 bool operator() (const Mapped_track_nodelist&);
80
81 void finalize();
82
83 void error_check (const std::set<node_t>&);
84
85 void write_assignments (const std::string&) const;
86
87 bool is_vector() const { return (vector_output); }
88
89 void save (const std::string&, const bool, const bool, const bool) const;
90
91
92 private:
93 const stat_edge statistic;
94 const bool vector_output;
95 const bool track_assignments;
96
97 const std::unique_ptr<MR::Connectome::Mat2Vec> mat2vec;
98
99 vector_type data, counts;
100 vector<node_t> assignments_single;
101 vector<NodePair> assignments_pairs;
102 vector< vector<node_t> > assignments_lists;
103
104 FORCE_INLINE void apply_data (const size_t, const T, const T);
105 FORCE_INLINE void apply_data (const size_t, const size_t, const T, const T);
106 FORCE_INLINE void apply_data (T&, const T, const T);
107 FORCE_INLINE void inc_count (const size_t, const T);
108 FORCE_INLINE void inc_count (const size_t, const size_t, const T);
109
110};
111
112
113
114extern template class Matrix<float>;
115extern template class Matrix<double>;
116
117
118
119
120
121}
122}
123}
124}
125
126
127#endif
128
A class to specify a command-line option.
const App::Option EdgeStatisticOption
MR::Connectome::node_t node_t
Definition: connectome.h:40
constexpr node_t node_count_ram_limit
Definition: matrix.h:46
Eigen::Array< value_type, Eigen::Dynamic, 1 > vector_type
Definition: typedefs.h:35
Definition: base.h:24
#define MEMALIGN(...)
Definition: types.h:185
#define FORCE_INLINE
Definition: types.h:156