17#ifndef __dwi_tractography_file_base_h__
18#define __dwi_tractography_file_base_h__
37 namespace Tractography
44 __ReaderBase__() : current_index (0) { }
50 void open (
const std::string& file,
const std::string& firstline, Properties& properties);
52 void close () { in.close(); }
57 uint64_t current_index;
61 template <
typename ValueType =
float>
67 __WriterBase__(
const std::string&
name) :
71 dtype (DataType::from<ValueType>()),
75 dtype.set_byte_order_native();
78 throw Exception (
"only supported datatype for tracks file are "
79 "Float32LE, Float32BE, Float64LE & Float64BE");
86 File::OFStream out (
name, std::ios::in | std::ios::out | std::ios::binary);
91 void create (File::OFStream& out,
const Properties& properties,
const std::string& type)
93 out <<
"mrtrix " + type +
"\nEND\n";
95 for (
const auto& i : properties) {
96 if ((i.first !=
"count") && (i.first !=
"total_count")) {
98 out << i.first <<
": " << line <<
"\n";
102 for (
const auto& i : properties.comments)
103 out <<
"comment: " << i <<
"\n";
105 for (
size_t n = 0; n < properties.seeds.num_seeds(); ++n)
106 out <<
"roi: seed " << properties.seeds[n]->get_name() <<
"\n";
107 for (
size_t n = 0; n < properties.include.size(); ++n)
108 out <<
"roi: include " << properties.include[n].parameters() <<
"\n";
109 for (
size_t n = 0; n < properties.exclude.size(); ++n)
110 out <<
"roi: exclude " << properties.exclude[n].parameters() <<
"\n";
111 for (
size_t n = 0; n < properties.mask.size(); ++n)
112 out <<
"roi: mask " << properties.mask[n].parameters() <<
"\n";
114 for (
const auto& it : properties.prior_rois)
115 out <<
"prior_roi: " << it.first <<
" " << it.second <<
"\n";
117 out <<
"datatype: " << dtype.specifier() <<
"\n";
118 int64_t data_offset = int64_t(out.tellp()) + 65;
119 data_offset += (4 - (data_offset % 4)) % 4;
120 out <<
"file: . " << data_offset <<
"\n";
122 count_offset = out.tellp();
125 out <<
"mrtrix " + type +
" ";
126 out.seekp (data_offset);
130 void skip() { ++total_count; }
133 uint64_t count, total_count;
139 int64_t count_offset;
143 void verify_stream (
const File::OFStream& out) {
145 throw Exception (
"error writing file \"" +
name +
"\": " + strerror (errno));
148 void update_counts (File::OFStream& out) {
149 out.seekp (count_offset);
150 out << count <<
"\ntotal_count: " << total_count <<
"\nEND\n";
static constexpr uint8_t Float64LE
static constexpr uint8_t Float32BE
static constexpr uint8_t Float32LE
static constexpr uint8_t Float64BE
void check_overwrite(const std::string &name)
std::unique_ptr< ImageIO::Base > create(Header &H)
MR::default_type value_type
vector< std::string > split_lines(const std::string &string, bool ignore_empty_fields=true, size_t num=std::numeric_limits< size_t >::max())