18#ifndef __misc_voxel2vector_h__
19#define __misc_voxel2vector_h__
43 typedef uint32_t index_t;
45 static const index_t invalid = std::numeric_limits<index_t>::max();
47 template <
class MaskType>
50 template <
class MaskType>
54 size_t size()
const {
return reverse.size(); }
57 assert (
index < reverse.size());
58 return reverse[
index];
61 template <
class PosType>
62 index_t operator() (
const PosType& pos)
const {
64 assign_pos_of (pos).to (temp);
65 if (is_out_of_bounds (temp))
77 template <
class MaskType>
78 Voxel2Vector::Voxel2Vector (MaskType& mask,
const Header& data) :
79 forward (
Image<index_t>::scratch (data,
"Voxel to vector index conversion scratch image"))
81 if (!dimensions_match (mask, data, 0, std::min (mask.ndim(), data.ndim())))
82 throw Exception (
"Dimension mismatch between image data and processing mask");
89 for (
auto l =
Loop(data) (r_mask, forward); l; ++l) {
91 forward.value() = counter++;
94 pos.push_back (forward.index(
index));
95 reverse.push_back (pos);
97 forward.value() = invalid;
100 DEBUG (
"Voxel2Vector class has " +
str(reverse.size()) +
" non-zero entries");
FORCE_INLINE LoopAlongAxes Loop()
std::string str(const T &value, int precision=0)