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