Developer documentation
Version 3.0.3-105-gd3941f44
gradient1D.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 __image_adapter_gradient1D_h__
18#define __image_adapter_gradient1D_h__
19
20#include "adapter/base.h"
21
22namespace MR
23{
24 namespace Adapter
25 {
26
27 template <class ImageType>
28 class Gradient1D :
29 public Base<Gradient1D<ImageType>, ImageType>
31 public:
32
33 using base_type = Base<Gradient1D<ImageType>, ImageType>;
34 using value_type = typename ImageType::value_type;
35
36 using base_type::name;
37 using base_type::size;
38 using base_type::spacing;
39 using base_type::index;
40
41
42 Gradient1D (const ImageType& parent,
43 size_t axis = 0,
44 bool wrt_spacing = false) :
45 base_type (parent),
46 axis (axis),
48 derivative_weights (3, 1.0),
50 if (wrt_spacing) {
51 for (size_t dim = 0; dim < 3; ++dim) {
52 derivative_weights[dim] /= spacing(dim);
53 half_derivative_weights[dim] /= spacing(dim);
54 }
55 }
56 }
57
58 void set_axis (size_t val)
59 {
60 axis = val;
61 }
62
67 value_type value ()
68 {
69 const ssize_t pos = index (axis);
70 result = 0.0;
71
72 if (pos == 0) {
74 index (axis) = pos + 1;
76 } else if (pos == size(axis) - 1) {
78 index (axis) = pos - 1;
80 } else {
81 index (axis) = pos + 1;
83 index (axis) = pos - 1;
85 }
86 index (axis) = pos;
87
88 return result;
89 }
90
91
92 protected:
93 size_t axis;
94 value_type result;
95 const bool wrt_spacing;
98 };
99 }
100}
101
102
103#endif
104
vector< value_type > derivative_weights
Definition: gradient1D.h:96
const bool wrt_spacing
Definition: gradient1D.h:95
vector< value_type > half_derivative_weights
Definition: gradient1D.h:97
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
size_t index
#define MEMALIGN(...)
Definition: types.h:185
const std::string name
Definition: thread.h:108