Developer documentation
Version 3.0.3-105-gd3941f44
replicate.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_replicate_h__
18#define __adapter_replicate_h__
19
20#include "header.h"
21#include "image_helpers.h"
22#include "adapter/base.h"
23
24namespace MR
25{
26 namespace Adapter
27 {
28
29 template <class ImageType>
30 class Replicate :
31 public Base<Replicate<ImageType>,ImageType>
33 public:
34
35 using base_type = Base<Replicate<ImageType>, ImageType>;
36 using value_type = typename ImageType::value_type;
37
38 using base_type::name;
39 using base_type::ndim;
40 using base_type::spacing;
41
42 Replicate (ImageType& original, const Header& replication_template) :
43 base_type (original),
44 header_ (replication_template),
45 pos_ (std::max<size_t> (parent().ndim(), header_.ndim()), 0)
46 {
47 for (size_t n = 0; n < std::min<size_t> (parent().ndim(), header_.ndim()); ++n) {
48 if (n < parent().ndim())
49 parent().index(n) = 0;
50 if (parent().size(n) > 1 && parent().size(n) != header_.size(n))
51 throw Exception ("cannot replicate over non-singleton dimensions");
52 }
53 }
54
55 size_t ndim () const {
56 return header_.ndim();
57 }
58 ssize_t size (size_t axis) const {
59 return header_.size (axis);
60 }
61 float spacing (size_t axis) const {
62 return header_.spacing(axis);
63 }
64 ssize_t stride (size_t axis) const {
65 return axis < parent().ndim() ? parent().stride (axis) : 0;
66 }
67
68 ssize_t get_index (size_t axis) const {
69 return pos_[axis];
70 }
71 void move_index (size_t axis, ssize_t increment) {
72 pos_[axis] += increment;
73 if (axis < parent().ndim())
74 if (parent().size(axis) > 1)
75 parent().index(axis) += increment;
76 }
77
78 protected:
79 using base_type::parent;
82
83 };
84
85 }
86}
87
88#endif
89
90
91
vector< ssize_t > pos_
Definition: replicate.h:81
MR::default_type value_type
Definition: typedefs.h:33
Definition: base.h:24
int axis
#define MEMALIGN(...)
Definition: types.h:185
const std::string name
Definition: thread.h:108