17#ifndef __dwi_tractography_connectome_metric_h__
18#define __dwi_tractography_connectome_metric_h__
26#include "connectome/connectome.h"
36namespace Tractography {
47 scale_by_length (
false),
48 scale_by_invlength (
false),
49 scale_by_invnodevol (
false),
50 scale_by_file (
false) { }
54 if (scale_by_invnodevol) {
55 assert (nodes.first < node_volumes.size());
56 assert (nodes.second < node_volumes.size());
57 const double sum_volumes = (node_volumes[nodes.first] + node_volumes[nodes.second]);
58 if (!sum_volumes)
return 0.0;
59 return (*
this)(tck) * 2.0 / sum_volumes;
66 if (scale_by_invnodevol) {
67 double sum_volumes = 0.0;
69 assert (*n < node_volumes.size());
70 sum_volumes += node_volumes[*n];
72 if (!sum_volumes)
return 0.0;
73 return (*
this)(tck) * nodes.size() / sum_volumes;
83 else if (scale_by_invlength)
86 if (tck.
get_index() >= size_t(file_values.size()))
87 throw Exception (
"File " + file_path +
" does not contain enough entries for this tractogram");
94 void set_scale_length (
const bool i =
true) {
95 if (i) assert (!scale_by_invlength);
98 void set_scale_invlength (
const bool i =
true) {
99 if (i) assert (!scale_by_length);
100 scale_by_invlength = i;
102 void set_scale_invnodevol (
Image<node_t>& nodes,
const bool i =
true) {
103 scale_by_invnodevol = i;
105 node_volumes.resize (0);
108 for (
auto l =
Loop() (nodes); l; ++l) {
110 if (
index >= node_volumes.size())
111 node_volumes.conservativeResizeLike (Eigen::VectorXd::Zero (
index + 1));
112 node_volumes[
index]++;
115 void set_scale_file (
const std::string& path,
const bool i =
true) {
119 file_values.resize (0);
128 bool scale_by_length, scale_by_invlength, scale_by_invnodevol, scale_by_file;
129 Eigen::VectorXd node_volumes;
130 std::string file_path;
131 Eigen::VectorXd file_values;
FORCE_INLINE LoopAlongAxes Loop()
std::pair< node_t, node_t > NodePair
MR::Connectome::node_t node_t
PointType::Scalar length(const vector< PointType > &tck)
std::string basename(const std::string &name)
Eigen::Matrix< ValueType, Eigen::Dynamic, 1 > load_vector(const std::string &filename)
read the vector data from filename