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 __interp_base_h__
18#define __interp_base_h__
19
20#include "image_helpers.h"
21#include "transform.h"
22
23
24namespace MR
25{
26
27 class Header;
28
29 namespace Interp
30 {
31
33 // @{
34
36
69 template <class ImageType> class Base : public ImageType, public Transform
71 public:
72 using image_type = ImageType;
73 using value_type = typename ImageType::value_type;
74
77 Base (const ImageType& parent, value_type value_when_out_of_bounds = default_out_of_bounds_value()) :
78 ImageType (parent),
79 Transform (parent),
80 out_of_bounds_value (value_when_out_of_bounds),
81 bounds { parent.size(0) - 0.5, parent.size(1) - 0.5, parent.size(2) - 0.5 },
82 out_of_bounds (true) { }
83
84
86
93
106
123
138
155
180 // Value to return when the position is outside the bounds of the image volume
181 const value_type out_of_bounds_value;
182
183 static inline value_type default_out_of_bounds_value () {
184 return std::numeric_limits<value_type>::quiet_NaN();
185 }
186
188
189 bool operator! () const { return out_of_bounds; }
190
191
192
193 protected:
196
197
198 // Some helper functions
199 template <class VectorType>
200 bool set_out_of_bounds (const VectorType& pos) {
201 return ((out_of_bounds = (pos[0] <= -0.5 || pos[0] >= bounds[0] ||
202 pos[1] <= -0.5 || pos[1] >= bounds[1] ||
203 pos[2] <= -0.5 || pos[2] >= bounds[2])));
204 }
205
206 void set_out_of_bounds (const bool value) {
208 }
209
210 template <class VectorType>
211 Eigen::Vector3d intravoxel_offset (const VectorType& pos) {
212 if (set_out_of_bounds (pos))
213 return Eigen::Vector3d (NaN, NaN, NaN);
214 return Eigen::Vector3d (pos[0]-std::floor (pos[0]), pos[1]-std::floor (pos[1]), pos[2]-std::floor (pos[2]));
215 }
216
217 };
218
219
220
222
223 }
224}
225
226#endif
227
228
This class defines the interface for classes that perform image interpolation.
Definition: base.h:70
bool out_of_bounds
Definition: base.h:195
Eigen::Vector3d intravoxel_offset(const VectorType &pos)
Definition: base.h:211
void set_out_of_bounds(const bool value)
Definition: base.h:206
bool set_out_of_bounds(const VectorType &pos)
Definition: base.h:200
default_type bounds[3]
Definition: base.h:194
Transform(const HeaderType &header)
An object for transforming between voxel, scanner and image coordinate spaces.
Definition: transform.h:29
constexpr I floor(const T x)
template function with cast to different type
Definition: math.h:75
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
Definition: SH.h:233
MR::default_type value_type
Definition: typedefs.h:33
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
constexpr default_type NaN
Definition: types.h:230
#define MEMALIGN(...)
Definition: types.h:185