Wildmeshing Toolkit
bicubic_interpolation.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <Eigen/Core>
5 #include <Eigen/Dense>
6 #include <type_traits>
9 inline double get_value(float x)
10 {
11  return static_cast<double>(x);
12 }
13 inline double get_value(double x)
14 {
15  return x;
16 }
17 inline double get_value(
18  DScalar2<double, Eigen::Matrix<double, 2, 1>, Eigen::Matrix<double, 2, 2>> x)
19 {
20  return x.getValue();
21 }
22 
23 inline double get_value(
24  DScalar2<double, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<double, -1, -1>> x)
25 {
26  return x.getValue();
27 }
28 
29 template <class T>
30 using BicubicVector = Eigen::Matrix<T, 16, 1>;
31 using BicubicMatrix = Eigen::Matrix<float, 16, 16>;
32 
34  const size_t width,
35  const size_t height,
36  const float* buffer,
37  const double xx,
38  const double yy,
39  const WrappingMode mode_x,
40  const WrappingMode mode_y);
41 
43 
45 
46 template <class T>
47 std::decay_t<T> eval_bicubic_coeffs(const BicubicVector<float>& coeffs, const T& sx, const T& sy)
48 {
49  using ImageScalar = std::decay_t<T>;
50 
51  const auto xx = sx - (floor(get_value(sx) - 0.5f) + 0.5f);
52  const auto yy = sy - (floor(get_value(sy) - 0.5f) + 0.5f);
53  assert(0 <= get_value(xx) && get_value(xx) < 1);
54  assert(0 <= get_value(yy) && get_value(yy) < 1);
55 
57 
58  vv(0) = 1;
59  vv(1) = xx;
60  vv(2) = xx * xx;
61  vv(3) = xx * xx * xx;
62 
63  vv(4) = yy;
64  vv(5) = xx * yy;
65  vv(6) = xx * xx * yy;
66  vv(7) = xx * xx * xx * yy;
67 
68  vv(8) = yy * yy;
69  vv(9) = xx * yy * yy;
70  vv(10) = xx * xx * yy * yy;
71  vv(11) = xx * xx * xx * yy * yy;
72 
73  vv(12) = yy * yy * yy;
74  vv(13) = xx * yy * yy * yy;
75  vv(14) = xx * xx * yy * yy * yy;
76  vv(15) = xx * xx * xx * yy * yy * yy;
77 
78  return coeffs.cast<ImageScalar>().dot(vv);
79 }
80 
81 } // namespace wmtk::components::adaptive_tessellation::image
std::decay_t< T > eval_bicubic_coeffs(const BicubicVector< float > &coeffs, const T &sx, const T &sy)
BicubicVector< float > extract_samples(const size_t width, const size_t height, const float *buffer, const double sx_, const double sy_, const WrappingMode mode_x, const WrappingMode mode_y)
Automatic differentiation scalar with first- and second-order derivatives.
Definition: autodiff.h:501