17#ifndef __connectome_connectome_h__
18#define __connectome_connectome_h__
31 namespace Connectome {
37 using matrix_type = Eigen::Array<value_type, Eigen::Dynamic, Eigen::Dynamic>;
38 using vector_type = Eigen::Array<value_type, Eigen::Dynamic, 1>;
39 using mask_type = Eigen::Array<bool, Eigen::Dynamic, Eigen::Dynamic>;
47 template <
class MatrixType>
48 void check (
const MatrixType& in,
const node_t num_nodes = 0)
50 if (in.rows() != in.cols())
51 throw Exception (
"Connectome matrix is not square (" +
str(in.rows()) +
" x " +
str(in.cols()) +
")");
52 if (num_nodes && (in.rows() != num_nodes))
53 throw Exception (
"Connectome matrix contains " +
str(in.rows()) +
" nodes; expected " +
str(num_nodes));
58 template <
class MatrixType>
61 if (in.rows() != in.cols())
62 throw Exception (
"Connectome matrix is not square (" +
str(in.rows()) +
" x " +
str(in.cols()) +
")");
64 for (
node_t row = 0; row != in.rows(); ++row) {
65 for (
node_t col = row+1; col != in.cols(); ++col) {
67 const typename MatrixType::Scalar lower_value = in (col, row);
68 const typename MatrixType::Scalar upper_value = in (row, col);
70 if (upper_value && lower_value && (upper_value != lower_value))
80 template <
class MatrixType>
84 throw Exception (
"Cannot convert a non-symmetric directed matrix to be symmetric");
86 for (
node_t row = 0; row != in.rows(); ++row) {
87 for (
node_t col = row+1; col != in.cols(); ++col) {
89 const typename MatrixType::Scalar lower_value = in (col, row);
90 const typename MatrixType::Scalar upper_value = in (row, col);
92 if (upper_value && !lower_value)
93 in (row, col) = in (col, row) = upper_value;
94 else if (lower_value && !upper_value)
95 in (row, col) = in (col, row) = lower_value;
102 template <
class MatrixType>
106 throw Exception (
"Cannot convert a non-symmetric directed matrix to upper triangular");
108 for (
node_t row = 0; row != in.rows(); ++row) {
109 for (
node_t col = row+1; col != in.cols(); ++col) {
111 const typename MatrixType::Scalar lower_value = in (col, row);
112 const typename MatrixType::Scalar upper_value = in (row, col);
114 if (!upper_value && lower_value)
115 in (row, col) = lower_value;
116 in (col, row) =
typename MatrixType::Scalar(0);
123 void check (
const Header&);
bool is_directed(MatrixType &in)
void check(const MatrixType &in, const node_t num_nodes=0)
Eigen::Array< value_type, Eigen::Dynamic, Eigen::Dynamic > matrix_type
void to_symmetric(MatrixType &in)
void to_upper(MatrixType &in)
Eigen::Array< bool, Eigen::Dynamic, Eigen::Dynamic > mask_type
Eigen::Array< value_type, Eigen::Dynamic, 1 > vector_type
const App::OptionGroup MatrixOutputOptions
double default_type
the default type used throughout MRtrix
std::string str(const T &value, int precision=0)