16#ifndef __math_stats_import_h__
17#define __math_stats_import_h__
61 virtual void operator() (matrix_type::RowXpr column)
const = 0;
69 const std::string&
name()
const {
return path; }
71 virtual size_t size()
const = 0;
94 template <
class SubjectDataImport>
95 void initialise (
const std::string& listpath,
const std::string& explicit_from_directory =
"");
105 std::shared_ptr<SubjectDataImportBase>
operator[] (
const size_t i)
const
107 assert (i <
files.size());
119 template <
class SubjectDataImport>
136 std::ifstream ifs (listpath.c_str());
138 throw Exception (
"Unable to open subject file list \"" + listpath +
"\"");
141 size_t p = line.find_last_not_of(
" \t");
142 if (p != std::string::npos)
145 lines.push_back (line);
150 if (directories[0].empty())
151 directories[0] =
".";
152 else if (directories[0] !=
".")
153 directories.push_back (
".");
154 if (explicit_from_directory.size())
155 directories.insert (directories.begin(), explicit_from_directory);
157 Exception e_nosuccess (
"Unable to load all input data from file \"" + listpath +
"\"");
158 std::string load_from_dir;
159 for (
const auto& directory : directories) {
161 for (
const auto& line : lines) {
162 const std::string full_path =
Path::join (directory, line);
164 throw Exception (
"File \"" + full_path +
"\" not found");
166 load_from_dir = directory;
169 e_nosuccess.
push_back (
"If loading relative to directory \"" + directory +
"\": ");
174 if (load_from_dir.empty())
177 ProgressBar progress (
"Importing data from files listed in \""
179 +
"\" as found relative to directory \""
180 + load_from_dir +
"\"");
182 for (
const auto& line : lines) {
184 std::shared_ptr<SubjectDataImport> subject (
new SubjectDataImport (
Path::join (load_from_dir, line)));
185 files.emplace_back (subject);
187 throw Exception (
e,
"Input data not successfully loaded: \"" + line +
"\"");
void push_back(const std::string &s)
vector_type operator()(const size_t index) const
vector< std::shared_ptr< SubjectDataImportBase > > files
void initialise(const std::string &listpath, const std::string &explicit_from_directory="")
std::shared_ptr< SubjectDataImportBase > operator[](const size_t i) const
const std::string & name() const
virtual ~SubjectDataImportBase()
virtual default_type operator[](const size_t index) const =0
SubjectDataImportBase(const std::string &path)
virtual size_t size() const =0
virtual void operator()(matrix_type::RowXpr column) const =0
implements a progress meter to provide feedback to the user
Eigen::Array< value_type, Eigen::Dynamic, 1 > vector_type
std::string join(const std::string &first, const std::string &second)
bool is_file(const std::string &path)
std::string basename(const std::string &name)
std::string dirname(const std::string &name)
double default_type
the default type used throughout MRtrix
std::istream & getline(std::istream &stream, std::string &string)
read a line from the stream