17#ifndef __adapter_permute_axes_h__
18#define __adapter_permute_axes_h__
27 template <
class ImageType>
29 public Base<PermuteAxes<ImageType>,ImageType>
36 using base_type::size;
37 using base_type::parent;
42 for (
int i = 0; i < static_cast<int> (parent().ndim()); ++i) {
43 for (
size_t a = 0; a < axes_.size(); ++a) {
44 if (axes_[a] >=
int (parent().ndim()))
45 throw Exception (
"axis " +
str(axes_[a]) +
" exceeds image dimensionality");
49 if (parent().size (i) != 1)
50 throw Exception (
"omitted axis \"" +
str (i) +
"\" has dimension greater than 1");
55 int non_existent_index = -1;
56 for (
auto& a : axes_) {
58 a = non_existent_index--;
59 non_existent_axes.push_back (0);
64 size_t ndim ()
const {
67 ssize_t size (
size_t axis)
const {
68 return axes_[
axis] < 0 ? 1 : parent().size (axes_[
axis]);
71 return axes_[
axis] < 0 ? std::numeric_limits<default_type>::quiet_NaN() : parent().spacing (axes_[
axis]);
73 ssize_t stride (
size_t axis)
const {
74 return axes_[
axis] < 0 ? 0 : parent().stride (axes_[
axis]);
77 void reset () { parent().reset(); }
79 ssize_t get_index (
size_t axis)
const {
const auto a = axes_[
axis];
return a < 0 ? non_existent_axes[-1-a] : parent().index (a); }
80 void move_index (
size_t axis, ssize_t increment) {
81 const auto a = axes_[
axis];
82 if (a < 0) non_existent_axes[-1-a] += increment;
83 else parent().index (a) += increment;
MR::default_type value_type
double default_type
the default type used throughout MRtrix
std::string str(const T &value, int precision=0)