17#ifndef __dwi_fixel_map_h__
18#define __dwi_fixel_map_h__
35 template <
class Fixel>
43 for (
auto l =
Loop() (_accessor); l; ++l)
44 _accessor.value() =
nullptr;
47 fixels.push_back (Fixel());
56 for (
auto l =
Loop() (_accessor); l; ++l) {
57 if (_accessor.value()) {
58 delete _accessor.value();
59 _accessor.value() =
nullptr;
71 Fixel& operator[] (
const size_t i) {
return fixels[i]; }
72 const Fixel& operator[] (
const size_t i)
const {
return fixels[i]; }
79 const ::MR::Header& header()
const {
return _header; }
87 HeaderHelper (const ::MR::Header&
H) :
92 HeaderHelper() =
default;
95 VoxelAccessor _accessor;
102 template <
class Fixel>
107 first_fixel_index (first),
109 lookup_table (
new uint8_t[in.lut.size()])
111 memcpy (lookup_table, &in.lut[0], in.lut.size() * sizeof (uint8_t));
114 MapVoxel (
const size_t first,
const size_t size) :
115 first_fixel_index (first),
117 lookup_table (
nullptr) { }
122 delete[] lookup_table;
123 lookup_table =
nullptr;
127 size_t first_index()
const {
return first_fixel_index; }
128 size_t num_fixels()
const {
return count; }
129 bool empty()
const {
return !count; }
132 size_t dir2fixel (
const size_t dir)
const
134 assert (lookup_table);
135 const size_t offset = lookup_table[dir];
136 return ((
offset == count) ? 0 : (first_fixel_index +
offset));
141 size_t first_fixel_index, count;
142 uint8_t* lookup_table;
148 template <
class Fixel>
152 Iterator (const MapVoxel* const voxel, Fixel_map<Fixel>& parent) :
153 index (voxel ? voxel->first_index() : 0),
154 last (voxel ? (index + voxel->num_fixels()) : 0),
155 fixel_map (parent) { }
159 operator bool ()
const {
return (
index != last); }
160 operator size_t ()
const {
return index; }
166 template <
class Fixel>
170 index (voxel ? voxel->first_index() : 0),
171 last (voxel ? (
index + voxel->num_fixels()) : 0),
172 fixel_map (parent) { }
175 const Fixel& operator() ()
const {
return fixel_map.fixels[
index]; }
176 operator bool ()
const {
return (
index != last); }
177 operator size_t ()
const {
return index; }
186 template <
class Fixel>
192 assign_pos_of (in.vox).to (v);
193 if (is_out_of_bounds (v))
196 throw Exception (
"FIXME: FOD_map has received multiple segmentations for the same voxel!");
197 v.value() =
new MapVoxel (in, fixels.size());
198 for (
const auto& i : in)
199 fixels.push_back (Fixel (i));
ConstIterator(const MapVoxel *const voxel, const Fixel_map &parent)
ConstIterator(const ConstIterator &)=default
Iterator(const Iterator &)=default
functions and classes related to image data input/output
FORCE_INLINE LoopAlongAxes Loop()