Developer documentation
Version 3.0.3-105-gd3941f44
hermite.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 __math_hermite_h__
18#define __math_hermite_h__
19
20#include <limits>
21
22#include "types.h"
23
24namespace MR
25{
26 namespace Math
27 {
28
29 template <typename T> class Hermite
31 public:
32 using value_type = T;
33
34 Hermite (value_type tension = 0.0) : t (T (0.5) *tension) { }
35
36 void set (value_type position) {
37 value_type p2 = position*position;
38 value_type p3 = position*p2;
39 w[0] = (T (0.5)-t) * (T (2.0) *p2 - p3 - position);
40 w[1] = T (1.0) + (T (1.5) +t) *p3 - (T (2.5) +t) *p2;
41 w[2] = (T (2.0) +T (2.0) *t) *p2 + (T (0.5)-t) *position - (T (1.5) +t) *p3;
42 w[3] = (T (0.5)-t) * (p3 - p2);
43 }
44
45 value_type coef (size_t i) const {
46 return (w[i]);
47 }
48
49 template <class S>
50 S value (const S* vals) const {
51 return (value (vals[0], vals[1], vals[2], vals[3]));
52 }
53
54 template <class S>
55 S value (const S& a, const S& b, const S& c, const S& d) const {
56 return (w[0]*a + w[1]*b + w[2]*c + w[3]*d);
57 }
58
59 private:
60 value_type w[4];
61 value_type t;
62 };
63
64 }
65}
66
67#endif
S value(const S &a, const S &b, const S &c, const S &d) const
Definition: hermite.h:55
Hermite(value_type tension=0.0)
Definition: hermite.h:34
value_type coef(size_t i) const
Definition: hermite.h:45
void set(value_type position)
Definition: hermite.h:36
S value(const S *vals) const
Definition: hermite.h:50
#define NOMEMALIGN
Definition: memory.h:22
Definition: base.h:24
Eigen::MatrixXd S