9 #ifndef CUBBYFLOW_ARRAY_SAMPLERS1_IMPL_H 10 #define CUBBYFLOW_ARRAY_SAMPLERS1_IMPL_H 16 template <
typename T,
typename R>
22 m_gridSpacing = gridSpacing;
23 m_origin = gridOrigin;
24 m_accessor = accessor;
27 template <
typename T,
typename R>
30 m_gridSpacing = other.m_gridSpacing;
31 m_origin = other.m_origin;
32 m_accessor = other.m_accessor;
35 template <
typename T,
typename R>
41 assert(m_gridSpacing > std::numeric_limits<R>::epsilon());
43 const R normalizedX = (pt - m_origin) / m_gridSpacing;
45 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size());
49 i = std::min(static_cast<ssize_t>(i + fx + 0.5), iSize - 1);
54 template <
typename T,
typename R>
60 assert(m_gridSpacing > std::numeric_limits<R>::epsilon());
62 const R normalizedX = (pt - m_origin) / m_gridSpacing;
64 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size());
68 *index = std::min(static_cast<ssize_t>(i + fx + 0.5), iSize - 1);
71 template <
typename T,
typename R>
75 return std::bind(&NearestArraySampler::operator(), sampler, std::placeholders::_1);
78 template <
typename T,
typename R>
84 m_gridSpacing = gridSpacing;
85 m_origin = gridOrigin;
86 m_accessor = accessor;
89 template <
typename T,
typename R>
92 m_gridSpacing = other.m_gridSpacing;
93 m_origin = other.m_origin;
94 m_accessor = other.m_accessor;
97 template <
typename T,
typename R>
103 assert(m_gridSpacing > std::numeric_limits<R>::epsilon());
105 const R normalizedX = (pt - m_origin) / m_gridSpacing;
107 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size());
111 const ssize_t ip1 = std::min(i + 1, iSize - 1);
113 return Lerp(m_accessor[i], m_accessor[ip1], fx);
116 template <
typename T,
typename R>
122 assert(m_gridSpacing > std::numeric_limits<R>::epsilon());
124 const R normalizedX = (pt - m_origin) / m_gridSpacing;
126 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size());
130 const ssize_t ip1 = std::min(i + 1, iSize - 1);
138 template <
typename T,
typename R>
142 return std::bind(&LinearArraySampler::operator(), sampler, std::placeholders::_1);
145 template <
typename T,
typename R>
151 m_gridSpacing = gridSpacing;
152 m_origin = gridOrigin;
153 m_accessor = accessor;
156 template <
typename T,
typename R>
159 m_gridSpacing = other.m_gridSpacing;
160 m_origin = other.m_origin;
161 m_accessor = other.m_accessor;
164 template <
typename T,
typename R>
170 assert(m_gridSpacing > std::numeric_limits<R>::epsilon());
172 const R normalizedX = (x - m_origin) / m_gridSpacing;
174 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size());
178 const ssize_t im1 = std::max(i - 1,
ZERO_SSIZE);
179 const ssize_t ip1 = std::min(i + 1, iSize - 1);
180 const ssize_t ip2 = std::min(i + 2, iSize - 1);
190 template <
typename T,
typename R>
194 return std::bind(&CubicArraySampler::operator(), sampler, std::placeholders::_1);
S Lerp(const S &value0, const S &value1, T f)
Computes linear interpolation.
Definition: MathUtils-Impl.h:184
Generic N-D nearest array sampler class.
Definition: ArraySamplers.h:22
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
Definition: pybind11Utils.h:24
Generic N-D cubic array sampler class.
Definition: ArraySamplers.h:50
constexpr ssize_t ZERO_SSIZE
Zero ssize_t.
Definition: Constants.h:20
T MonotonicCatmullRom(const T &f0, const T &f1, const T &f2, const T &f3, T f)
Computes monotonic Catmull-Rom interpolation.
Definition: MathUtils-Impl.h:228
Generic N-D linear array sampler class.
Definition: ArraySamplers.h:36
void GetBarycentric(T x, ssize_t iLow, ssize_t iHigh, ssize_t *i, T *f)
Gets the barycentric coordinate.
Definition: MathUtils-Impl.h:151