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
22
namespace
MR
23
{
24
namespace
Adapter
25
{
26
27
template
<
class
ImageType>
28
class
Gradient1D
:
29
public
Base
<Gradient1D<ImageType>, ImageType>
30
{
MEMALIGN
(
Gradient1D<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
),
47
wrt_spacing
(
wrt_spacing
),
48
derivative_weights
(3, 1.0),
49
half_derivative_weights
(3, 0.5) {
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) {
73
result
=
base_type::value
();
74
index
(
axis
) = pos + 1;
75
result
=
derivative_weights
[
axis
] * (
base_type::value
() -
result
);
76
}
else
if
(pos == size(
axis
) - 1) {
77
result
=
base_type::value
();
78
index
(
axis
) = pos - 1;
79
result
=
derivative_weights
[
axis
] * (
result
-
base_type::value
());
80
}
else
{
81
index
(
axis
) = pos + 1;
82
result
=
base_type::value
();
83
index
(
axis
) = pos - 1;
84
result
=
half_derivative_weights
[
axis
] * (
result
-
base_type::value
());
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
;
96
vector<value_type>
derivative_weights
;
97
vector<value_type>
half_derivative_weights
;
98
};
99
}
100
}
101
102
103
#endif
104
MR::Adapter::Base
Definition:
base.h:38
MR::Adapter::Gradient1D
Definition:
gradient1D.h:30
MR::Adapter::Gradient1D::axis
size_t axis
Definition:
gradient1D.h:93
MR::Adapter::Gradient1D::derivative_weights
vector< value_type > derivative_weights
Definition:
gradient1D.h:96
MR::Adapter::Gradient1D::wrt_spacing
const bool wrt_spacing
Definition:
gradient1D.h:95
MR::Adapter::Gradient1D::result
value_type result
Definition:
gradient1D.h:94
MR::Adapter::Gradient1D::half_derivative_weights
vector< value_type > half_derivative_weights
Definition:
gradient1D.h:97
MR::vector< value_type >
base.h
MR::Math::SH::value
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::Math::Stats::value_type
MR::default_type value_type
Definition:
typedefs.h:33
MR
Definition:
base.h:24
index
size_t index
Definition:
ordered_thread_queue.h:38
MEMALIGN
#define MEMALIGN(...)
Definition:
types.h:185
name
const std::string name
Definition:
thread.h:108
core
adapter
gradient1D.h
Generated on Mon Jul 4 2022 08:00:06 for MRtrix by
1.9.3