Interpolation.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 template <typename T>
5 T LinearInterpolate(T p1, T p2, T x)
6 {
7  return p1*(1 - x) + p2*x;
8 }
9 
10 template <typename T>
11 T LinearInterpolate(T p[2], T x)
12 {
13  return p[0]*(1 - x) + p[1]*x;
14 }
15 
16 template <typename T>
17 T BilinearInterpolate(T p[2][2], T x, T y)
18 {
19  T arr[2];
20  arr[0] = LinearInterpolate(p[0], y);
21  arr[1] = LinearInterpolate(p[1], y);
22  return LinearInterpolate(arr, x);
23 }
24 
25 template <typename T>
26 T TrilinearInterpolate(T p[2][2][2], T x, T y, T z)
27 {
28  T arr[2];
29  arr[0] = BilinearInterpolate(p[0], y, z);
30  arr[1] = BilinearInterpolate(p[1], y, z);
31  return LinearInterpolate(arr, x);
32 }
33 
34 template <typename T>
35 T CubicInterpolate(T p[4], T x)
36 {
37  return p[1] + (T) 0.5 * x*(p[2] - p[0] + x*(2*p[0] - 5*p[1] + 4*p[2] - p[3] + x*(3*(p[1] - p[2]) + p[3] - p[0])));
38 }
39 
40 template <typename T>
41 T BicubicInterpolate(T p[4][4], T x, T y)
42 {
43  T arr[4];
44  arr[0] = CubicInterpolate(p[0], y);
45  arr[1] = CubicInterpolate(p[1], y);
46  arr[2] = CubicInterpolate(p[2], y);
47  arr[3] = CubicInterpolate(p[3], y);
48  return CubicInterpolate(arr, x);
49 }
50 
51 template <typename T>
52 T TricubicInterpolate(T p[4][4][4], T x, T y, T z)
53 {
54  T arr[4];
55  arr[0] = BicubicInterpolate(p[0], y, z);
56  arr[1] = BicubicInterpolate(p[1], y, z);
57  arr[2] = BicubicInterpolate(p[2], y, z);
58  arr[3] = BicubicInterpolate(p[3], y, z);
59  return CubicInterpolate(arr, x);
60 }
61 
62 template <typename T>
63 T Gaussian(T x, T sigma)
64 {
65  return pow(Constants32::e, - Sq(x) / (2 * Sq(sigma))) / sqrt(2 * Constants32::Pi * Sq(sigma));
66 }
f32 const Pi
Definition: Constants.h:11
T Sq(T const &a)
Definition: ionUtils.h:60
T CubicInterpolate(T p[4], T x)
Definition: Interpolation.h:35
T BicubicInterpolate(T p[4][4], T x, T y)
Definition: Interpolation.h:41
T Gaussian(T x, T sigma)
Definition: Interpolation.h:63
T BilinearInterpolate(T p[2][2], T x, T y)
Definition: Interpolation.h:17
T TrilinearInterpolate(T p[2][2][2], T x, T y, T z)
Definition: Interpolation.h:26
f32 const e
Definition: Constants.h:12
T TricubicInterpolate(T p[4][4][4], T x, T y, T z)
Definition: Interpolation.h:52
T LinearInterpolate(T p1, T p2, T x)
Definition: Interpolation.h:5