55 lines · plain
1// Copyright Nick Thompson, 20212// Use, modification and distribution are subject to the3// Boost Software License, Version 1.0.4// (See accompanying file LICENSE_1_0.txt5// or copy at http://www.boost.org/LICENSE_1_0.txt)6 7// This implements bilinear interpolation on a uniform grid.8// If dx and dy are both positive, then the (x,y) = (x0, y0) is associated with data index 0 (herein referred to as f[0])9// The point (x0 + dx, y0) is associated with f[1], and (x0 + i*dx, y0) is associated with f[i],10// i.e., we are assuming traditional C row major order.11// The y coordinate increases *downward*, as is traditional in 2D computer graphics.12// This is *not* how people generally think in numerical analysis (although it *is* how they lay out matrices).13// Providing the capability of a grid rotation is too expensive and not ergonomic; you'll need to perform any rotations at the call level.14 15// For clarity, the value f(x0 + i*dx, y0 + j*dy) must be stored in the f[j*cols + i] position.16 17#ifndef BOOST_MATH_INTERPOLATORS_BILINEAR_UNIFORM_HPP18#define BOOST_MATH_INTERPOLATORS_BILINEAR_UNIFORM_HPP19 20#include <utility>21#include <memory>22#include <boost/math/interpolators/detail/bilinear_uniform_detail.hpp>23 24namespace boost::math::interpolators {25 26template <class RandomAccessContainer>27class bilinear_uniform28{29public:30 using Real = typename RandomAccessContainer::value_type;31 using Z = typename RandomAccessContainer::size_type;32 33 bilinear_uniform(RandomAccessContainer && fieldData, Z rows, Z cols, Real dx = 1, Real dy = 1, Real x0 = 0, Real y0 = 0)34 : m_imp(std::make_shared<detail::bilinear_uniform_imp<RandomAccessContainer>>(std::move(fieldData), rows, cols, dx, dy, x0, y0))35 {36 }37 38 Real operator()(Real x, Real y) const39 {40 return m_imp->operator()(x,y);41 }42 43 44 friend std::ostream& operator<<(std::ostream& out, bilinear_uniform<RandomAccessContainer> const & bu) {45 out << *bu.m_imp;46 return out;47 }48 49private:50 std::shared_ptr<detail::bilinear_uniform_imp<RandomAccessContainer>> m_imp;51};52 53}54#endif55