Developer documentation
Version 3.0.3-105-gd3941f44
base.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 __algo_adapter_base_h__
18#define __algo_adapter_base_h__
19
20#include "image_helpers.h"
21#include "types.h"
22
23namespace MR
24{
25 class Header;
26
27 namespace Adapter
28 {
29
30 template <template <class ImageType> class AdapterType, class ImageType, typename... Args>
31 inline AdapterType<ImageType> make (const ImageType& parent, Args&&... args) {
32 return AdapterType<ImageType> (parent, std::forward<Args> (args)...);
33 }
34
35 template <class AdapterType, class ImageType>
36 class Base :
37 public ImageBase<AdapterType, typename ImageType::value_type>
39 public:
40
41 using value_type = typename ImageType::value_type;
42
43 Base (const ImageType& parent) : parent_ (parent) { }
44
45
46 template <class U>
47 const Base& operator= (const U& V) { return parent_ = V; }
48
49 FORCE_INLINE ImageType& parent () { return parent_; }
50 FORCE_INLINE bool valid () const { return parent_.valid(); }
51 FORCE_INLINE bool operator! () const { return !valid(); }
52 FORCE_INLINE const ImageType& parent () const { return parent_; }
53 FORCE_INLINE const std::string& name () const { return parent_.name(); }
54 FORCE_INLINE size_t ndim () const { return parent_.ndim(); }
55 FORCE_INLINE ssize_t size (size_t axis) const { return parent_.size (axis); }
56 FORCE_INLINE default_type spacing (size_t axis) const { return parent_.spacing (axis); }
57 FORCE_INLINE ssize_t stride (size_t axis) const { return parent_.stride (axis); }
58 FORCE_INLINE const transform_type& transform () const { return parent_.transform(); }
59 FORCE_INLINE const KeyValues& keyval () const { return parent_.keyval(); }
60
61 FORCE_INLINE ssize_t get_index (size_t axis) const { return parent_.index (axis); }
62 FORCE_INLINE void move_index (size_t axis, ssize_t increment) { parent_.index (axis) += increment; }
63
64 FORCE_INLINE value_type get_value () const { return parent_.value(); }
65 FORCE_INLINE void set_value (value_type val) { parent_.value() = val; }
66
67 FORCE_INLINE void reset () { parent_.reset(); }
68
69 friend std::ostream& operator<< (std::ostream& stream, const Base& V) {
70 stream << "image adapter \"" << V.name() << "\", datatype " << MR::DataType::from<value_type>().specifier() << ", position [ ";
71 for (size_t n = 0; n < V.ndim(); ++n)
72 stream << V[n] << " ";
73 stream << "], value = " << V.value();
74 return stream;
75 }
76
77 protected:
78 ImageType parent_;
79 };
80
81
82 }
83}
84
85#endif
86
87
88
89
90
ImageType parent_
Definition: base.h:78
friend std::ostream & operator<<(std::ostream &stream, const Base &V)
Definition: base.h:69
AdapterType< ImageType > make(const ImageType &parent, Args &&... args)
Definition: base.h:31
MR::default_type value_type
Definition: typedefs.h:33
Definition: base.h:24
std::map< std::string, std::string > KeyValues
used in various places for storing key-value pairs
Definition: types.h:238
double default_type
the default type used throughout MRtrix
Definition: types.h:228
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
#define FORCE_INLINE
Definition: types.h:156