17#ifndef __adapter_extract_h__
18#define __adapter_extract_h__
27 template <
class ImageType>
29 public Base<Extract1D<ImageType>,ImageType>
36 using base_type::ndim;
37 using base_type::spacing;
38 using base_type::parent;
45 nsize (indices.size()),
46 trans (original.transform()) {
49 if (extract_axis < 3) {
50 Eigen::Vector3d a (0.0, 0.0, 0.0);
51 a[extract_axis] = indices[0] * spacing (extract_axis);
52 trans.translation() = trans * a;
55 this->indices.push_back (indices.back());
60 for (
size_t n = 0; n < ndim(); ++n)
61 parent().index(n) = ( n == extract_axis ? indices[0] : 0 );
65 ssize_t size (
size_t axis)
const {
66 return (
axis == extract_axis ? nsize : base_type::size (
axis) );
71 ssize_t get_index (
size_t axis)
const {
return (
axis == extract_axis ? current_pos : parent().
index(
axis) ); }
72 void move_index (
size_t axis, ssize_t increment) {
73 if (
axis == extract_axis) {
74 ssize_t prev_pos = current_pos < nsize ? indices[current_pos] : 0;
75 current_pos += increment;
76 if (current_pos < nsize)
77 parent().index(
axis) += indices[current_pos] - prev_pos;
79 parent().index(
axis) = 0;
82 parent().index(
axis) += increment;
87 stream <<
"Extract1D adapter for image \"" << V.name() <<
"\", position [ ";
88 for (
size_t n = 0; n < V.ndim(); ++n)
89 stream << V.index(n) <<
" ";
90 stream <<
"], value = " << V.value();
95 const size_t extract_axis;
112 template <
class ImageType>
114 public Base<Extract<ImageType>,ImageType>
121 using base_type::ndim;
122 using base_type::spacing;
123 using base_type::parent;
127 base_type (original),
128 current_pos (ndim()),
130 trans (original.transform()) {
132 trans.translation() = trans * Eigen::Vector3d (
133 indices[0][0] * spacing (0),
134 indices[1][0] * spacing (1),
135 indices[2][0] * spacing (2)
138 for (
const auto& i : indices)
139 sizes.push_back (i.size());
143 ssize_t size (
size_t axis)
const {
return sizes[
axis]; }
148 for (
size_t n = 0; n < ndim(); ++n) {
150 parent().index(n) = indices[n][0];
154 ssize_t get_index (
size_t axis)
const {
return current_pos[
axis]; }
155 void move_index (
size_t axis, ssize_t increment) {
156 current_pos[
axis] += increment;
157 if (current_pos[
axis] < 0)
158 parent().index (
axis) = -1;
159 else if (current_pos[
axis] >= sizes[
axis])
160 parent().index (
axis) = parent().size (
axis);
162 parent().index (
axis) = indices[
axis][current_pos[
axis]];
MR::default_type value_type
Eigen::Transform< default_type, 3, Eigen::AffineCompact > transform_type
the type for the affine transform of an image: