11 #ifndef CUBBYFLOW_ARRAY_SAMPLERS_IMPL_HPP 12 #define CUBBYFLOW_ARRAY_SAMPLERS_IMPL_HPP 20 template <
typename T,
size_t N,
size_t I>
25 template <
typename View,
typename... RemainingIndices>
29 using Next =
Lerp<T, N, I - 1>;
32 Next::Call(view, i, t, i[I - 1] + 1, indices...),
37 template <
typename T,
size_t N>
42 template <
typename View,
typename... RemainingIndices>
47 view(i[0] + 1, indices...), t[0]);
51 template <
typename T,
size_t N,
size_t I>
56 template <
typename View,
typename CubicInterpolationOp,
57 typename... RemainingIndices>
60 RemainingIndices... indices)
62 using Next =
Cubic<T, N, I - 1>;
65 Next::Call(view, i, t, op, std::max(i[I - 1] - 1,
ZERO_SSIZE),
67 Next::Call(view, i, t, op, i[I - 1], indices...),
68 Next::Call(view, i, t, op,
69 std::min(i[I - 1] + 1,
70 static_cast<ssize_t>(view.Size()[I - 1]) - 1),
72 Next::Call(view, i, t, op,
73 std::min(i[I - 1] + 2,
74 static_cast<ssize_t>(view.Size()[I - 1]) - 1),
80 template <
typename T,
size_t N>
85 template <
typename View,
typename CubicInterpolationOp,
86 typename... RemainingIndices>
89 RemainingIndices... indices)
92 view(std::max(i[0] - 1,
ZERO_SSIZE), indices...),
93 view(i[0], indices...),
94 view(std::min(i[0] + 1, static_cast<ssize_t>(view.Size()[0]) - 1),
96 view(std::min(i[0] + 2, static_cast<ssize_t>(view.Size()[0]) - 1),
102 template <
typename T,
size_t N,
size_t I>
107 template <
typename Coords,
typename Weights,
typename... RemainingIndices>
113 Next::Call(c, w, i, t, acc * (1 - t[I - 1]), 0, idx...);
114 Next::Call(c, w, i, t, acc * t[I - 1], 1, idx...);
118 template <
typename T,
size_t N>
123 template <
typename Coords,
typename Weights,
typename... RemainingIndices>
130 w(0, idx...) = acc * (1 - t[0]);
131 w(1, idx...) = acc * (t[0]);
135 template <
typename T,
size_t N,
size_t I>
138 template <
typename Coords,
typename Weights,
typename... RemainingIndices>
148 Next::Call(c, w, i, t,
ElemMul(acc, w0), 0, idx...);
149 Next::Call(c, w, i, t,
ElemMul(acc, w1), 1, idx...);
153 template <
typename T,
size_t N>
156 template <
typename Coords,
typename Weights,
typename... RemainingIndices>
168 w(0, idx...) =
ElemMul(acc, w0);
169 w(1, idx...) =
ElemMul(acc, w1);
174 template <
typename T,
size_t N>
179 m_gridSpacing(gridSpacing),
180 m_invGridSpacing(
ScalarType{ 1 } / gridSpacing),
181 m_gridOrigin(gridOrigin)
186 template <
typename T,
size_t N>
188 : m_view(other.m_view),
189 m_gridSpacing(other.m_gridSpacing),
190 m_invGridSpacing(other.m_invGridSpacing),
191 m_gridOrigin(other.m_gridOrigin)
196 template <
typename T,
size_t N>
198 : m_view(std::move(other.m_view)),
199 m_gridSpacing(std::move(other.m_gridSpacing)),
200 m_invGridSpacing(std::move(other.m_invGridSpacing)),
201 m_gridOrigin(std::move(other.m_gridOrigin))
206 template <
typename T,
size_t N>
210 m_view = other.m_view;
211 m_gridSpacing = other.m_gridSpacing;
212 m_invGridSpacing = other.m_invGridSpacing;
213 m_gridOrigin = other.m_gridOrigin;
218 template <
typename T,
size_t N>
222 m_view = std::move(other.m_view);
223 m_gridSpacing = std::move(other.m_gridSpacing);
224 m_invGridSpacing = std::move(other.m_invGridSpacing);
225 m_gridOrigin = std::move(other.m_gridOrigin);
230 template <
typename T,
size_t N>
236 template <
typename T,
size_t N>
244 for (
size_t i = 0; i < N; ++i)
249 std::min(static_cast<ssize_t>(is[i] + ts[i] + 0.5), size[i] - 1);
252 return is.template CastTo<size_t>();
255 template <
typename T,
size_t N>
256 std::function<T(const typename NearestArraySampler<T, N>::VectorType&)>
261 return [sampler](
const VectorType& x) -> T {
return sampler(x); };
264 template <
typename T,
size_t N>
269 m_gridSpacing(gridSpacing),
270 m_invGridSpacing(
ScalarType{ 1 } / gridSpacing),
271 m_gridOrigin(gridOrigin)
276 template <
typename T,
size_t N>
278 : m_view(other.m_view),
279 m_gridSpacing(other.m_gridSpacing),
280 m_invGridSpacing(other.m_invGridSpacing),
281 m_gridOrigin(other.m_gridOrigin)
286 template <
typename T,
size_t N>
288 : m_view(std::move(other.m_view)),
289 m_gridSpacing(std::move(other.m_gridSpacing)),
290 m_invGridSpacing(std::move(other.m_invGridSpacing)),
291 m_gridOrigin(std::move(other.m_gridOrigin))
296 template <
typename T,
size_t N>
300 m_view = other.m_view;
301 m_gridSpacing = other.m_gridSpacing;
302 m_invGridSpacing = other.m_invGridSpacing;
303 m_gridOrigin = other.m_gridOrigin;
308 template <
typename T,
size_t N>
312 m_view = std::move(other.m_view);
313 m_gridSpacing = std::move(other.m_gridSpacing);
314 m_invGridSpacing = std::move(other.m_invGridSpacing);
315 m_gridOrigin = std::move(other.m_gridOrigin);
320 template <
typename T,
size_t N>
328 for (
size_t i = 0; i < N; ++i)
336 template <
typename T,
size_t N>
338 const VectorType& pt, std::array<CoordIndexType, FLAT_KERNEL_SIZE>& indices,
339 std::array<ScalarType, FLAT_KERNEL_SIZE>& weights)
const 346 for (
size_t i = 0; i < N; ++i)
356 indexView, weightView, is.template CastTo<size_t>(), ts, 1);
359 template <
typename T,
size_t N>
361 const VectorType& pt, std::array<CoordIndexType, FLAT_KERNEL_SIZE>& indices,
362 std::array<VectorType, FLAT_KERNEL_SIZE>& weights)
const 369 for (
size_t i = 0; i < N; ++i)
379 indexView, weightView, is.template CastTo<size_t>(), ts,
383 template <
typename T,
size_t N>
384 std::function<T(const typename LinearArraySampler<T, N>::VectorType&)>
389 return [sampler](
const VectorType& x) -> T {
return sampler(x); };
392 template <
typename T,
size_t N,
typename CIOp>
397 m_gridSpacing(gridSpacing),
398 m_invGridSpacing(
ScalarType{ 1 } / gridSpacing),
399 m_gridOrigin(gridOrigin)
404 template <
typename T,
size_t N,
typename CIOp>
406 : m_view(other.m_view),
407 m_gridSpacing(other.m_gridSpacing),
408 m_invGridSpacing(other.m_invGridSpacing),
409 m_gridOrigin(other.m_gridOrigin)
414 template <
typename T,
size_t N,
typename CIOp>
416 : m_view(std::move(other.m_view)),
417 m_gridSpacing(std::move(other.m_gridSpacing)),
418 m_invGridSpacing(std::move(other.m_invGridSpacing)),
419 m_gridOrigin(std::move(other.m_gridOrigin))
424 template <
typename T,
size_t N,
typename CIOp>
428 m_view = other.m_view;
429 m_gridSpacing = other.m_gridSpacing;
430 m_invGridSpacing = other.m_invGridSpacing;
431 m_gridOrigin = other.m_gridOrigin;
436 template <
typename T,
size_t N,
typename CIOp>
440 m_view = std::move(other.m_view);
441 m_gridSpacing = std::move(other.m_gridSpacing);
442 m_invGridSpacing = std::move(other.m_invGridSpacing);
443 m_gridOrigin = std::move(other.m_gridOrigin);
448 template <
typename T,
size_t N,
typename CIOp>
456 for (
size_t i = 0; i < N; ++i)
464 template <
typename T,
size_t N,
typename CIOp>
465 std::function<T(const typename CubicArraySampler<T, N, CIOp>::VectorType&)>
470 return [sampler](
const VectorType& x) -> T {
return sampler(x); };
Definition: ArraySamplers-Impl.hpp:21
NearestArraySampler()=default
Default constructor.
std::enable_if_t< std::is_arithmetic< T >::value, S > Lerp(const S &f0, const S &f1, T t)
Computes linear interpolation.
Definition: MathUtils-Impl.hpp:295
static void Call(Coords &c, Weights &w, Vector< size_t, N > i, Vector< ScalarType, N > t, T acc, RemainingIndices... idx)
Definition: ArraySamplers-Impl.hpp:124
static auto Call(const View &view, Vector< ssize_t, N > i, Vector< ScalarType, N > t, CubicInterpolationOp op, RemainingIndices... indices)
Definition: ArraySamplers-Impl.hpp:87
N-D nearest array sampler class.
Definition: ArraySamplers.hpp:29
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers-Impl.hpp:121
std::enable_if_t< std::is_arithmetic< T >::value > GetBarycentric(T x, size_t begin, size_t end, size_t &i, T &t)
Computes the barycentric coordinate.
Definition: MathUtils-Impl.hpp:196
Definition: ArrayView.hpp:60
static auto Call(const View &view, Vector< ssize_t, N > i, Vector< ScalarType, N > t, RemainingIndices... indices)
Definition: ArraySamplers-Impl.hpp:43
static auto Call(const View &view, Vector< ssize_t, N > i, Vector< ScalarType, N > t, RemainingIndices... indices)
Definition: ArraySamplers-Impl.hpp:26
T operator()(const VectorType &pt) const
Returns sampled value at point pt.
Definition: ArraySamplers-Impl.hpp:449
NearestArraySampler & operator=(const NearestArraySampler &other)
Copy assignment operator.
Definition: ArraySamplers-Impl.hpp:207
LinearArraySampler()=default
Default constructor.
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers-Impl.hpp:23
static auto Call(const View &view, Vector< ssize_t, N > i, Vector< ScalarType, N > t, CubicInterpolationOp op, RemainingIndices... indices)
Definition: ArraySamplers-Impl.hpp:58
Definition: ArraySamplers-Impl.hpp:103
CubicArraySampler()=default
Default constructor.
typename GetScalarType< CubbyFlow::Matrix< double, N > >::value ScalarType
Definition: ArraySamplers.hpp:111
Definition: ArraySamplers-Impl.hpp:136
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers.hpp:34
Definition: Matrix.hpp:27
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >), D > MakeConstant(ValueType val)
Makes a static matrix with constant entries.
Definition: MatrixDenseBase-Impl.hpp:152
T operator()(const VectorType &pt) const
Returns sampled value at point pt.
Definition: ArraySamplers-Impl.hpp:231
Definition: pybind11Utils.hpp:20
CubicArraySampler & operator=(const CubicArraySampler &other)
Copy assignment operator.
Definition: ArraySamplers-Impl.hpp:425
constexpr auto ElemMul(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: MatrixExpression-Impl.hpp:1085
N-D cubic array sampler class.
Definition: ArraySamplers.hpp:195
static void Call(Coords &c, Weights &w, Vector< size_t, N > i, Vector< ScalarType, N > t, T acc, RemainingIndices... idx)
Definition: ArraySamplers-Impl.hpp:108
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers-Impl.hpp:83
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers-Impl.hpp:54
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers-Impl.hpp:105
Definition: ArraySamplers-Impl.hpp:52
Generic N-dimensional array class interface.
Definition: Array.hpp:32
constexpr ssize_t ZERO_SSIZE
Zero ssize_t.
Definition: Constants.hpp:22
CoordIndexType GetCoordinate(const VectorType &pt) const
Returns the nearest array index for point pt.
Definition: ArraySamplers-Impl.hpp:238
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers-Impl.hpp:40
N-D array sampler using linear interpolation.
Definition: ArraySamplers.hpp:106
const Vector< size_t, N > & Size() const
Definition: ArrayBase-Impl.hpp:51
static void Call(Coords &c, Weights &w, Vector< size_t, N > i, Vector< T, N > t, Vector< T, N > acc, RemainingIndices... idx)
Definition: ArraySamplers-Impl.hpp:139
T value
Definition: TypeHelpers.hpp:20
static void Call(Coords &c, Weights &w, Vector< size_t, N > i, Vector< T, N > t, Vector< T, N > acc, RemainingIndices... idx)
Definition: ArraySamplers-Impl.hpp:157
typename GetScalarType< T >::value ScalarType
Definition: ArraySamplers.hpp:200