Developer documentation
Version 3.0.3-105-gd3941f44
subset.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __adapter_subset_h__
18#define __adapter_subset_h__
19
20#include "image.h"
21#include "adapter/base.h"
22
23namespace MR
24{
25 namespace Adapter {
26
27 template <class ImageType>
28 class Subset :
29 public Base<Subset<ImageType>,ImageType>
31 public:
32
33 using base_type = Base<Subset<ImageType>, ImageType>;
34 using value_type = typename ImageType::value_type;
35
36 using base_type::name;
37 using base_type::spacing;
38
39 template <class VectorType>
40 Subset (const ImageType& original, const VectorType& from, const VectorType& size) :
41 base_type (original),
42 from_ (container_cast<decltype(from_)>(from)),
43 size_ (container_cast<decltype(size_)>(size)),
44 transform_ (original.transform()) {
45
46 for (size_t n = 0; n < ndim(); ++n) {
47 if (size_[n] < 1)
48 throw Exception ("FIXME: sizes requested for Subset adapter must be positive");
49 if (from_[n] + size_[n] > original.size(n) || from_[n] < 0)
50 throw Exception ("FIXME: dimensions requested for Subset adapter are out of bounds!");
51 }
52
53 for (size_t j = 0; j < 3; ++j)
54 for (size_t i = 0; i < 3; ++i)
55 transform_(i,3) += from[j] * spacing(j) * transform_(i,j);
56 }
57
58 void reset () {
59 for (size_t n = 0; n < ndim(); ++n)
60 set_pos (n, 0);
61 }
62
63 size_t ndim () const { return size_.size(); }
64 ssize_t size (size_t axis) const { return size_ [axis]; }
65 const transform_type& transform() const { return transform_; }
66
67 ssize_t get_index (size_t axis) const { return parent().index(axis)-from_[axis]; }
68 void move_index (size_t axis, ssize_t increment) { parent().index(axis) += increment; }
69
70 protected:
71 using base_type::parent;
74 };
75
76 }
77}
78
79#endif
80
81
const vector< ssize_t > from_
Definition: subset.h:72
const vector< ssize_t > size_
Definition: subset.h:72
transform_type transform_
Definition: subset.h:73
MR::default_type value_type
Definition: typedefs.h:33
Definition: base.h:24
Eigen::Transform< default_type, 3, Eigen::AffineCompact > transform_type
the type for the affine transform of an image:
Definition: types.h:234
int axis
#define MEMALIGN(...)
Definition: types.h:185
const std::string name
Definition: thread.h:108