Loading...
Searching...
No Matches
ArraySamplers.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_ARRAY_SAMPLERS_HPP
12#define CUBBYFLOW_ARRAY_SAMPLERS_HPP
13
15
16#include <functional>
17
18namespace CubbyFlow
19{
28template <typename T, size_t N>
30{
31 public:
32 static_assert(N > 0, "Dimension should be greater than 0");
33
35
36 static_assert(std::is_floating_point<ScalarType>::value,
37 "NearestArraySampler only can be instantiated with floating "
38 "point types");
39
42
45
55 const VectorType& gridOrigin);
56
59
62
65
68
71
73 T operator()(const VectorType& pt) const;
74
77
79 [[nodiscard]] std::function<T(const VectorType&)> Functor() const;
80
81 private:
83 VectorType m_gridSpacing;
84 VectorType m_invGridSpacing;
85 VectorType m_gridOrigin;
86};
87
88template <typename T>
90
91template <typename T>
93
94template <typename T>
96
105template <typename T, size_t N>
107{
108 public:
109 static_assert(N > 0, "N should be greater than 0");
110
112
113 static_assert(std::is_floating_point<ScalarType>::value,
114 "LinearArraySampler only can be instantiated with floating "
115 "point types");
116
119
120 static constexpr size_t FLAT_KERNEL_SIZE = 1 << N;
121
124
133 const VectorType& gridSpacing,
134 const VectorType& gridOrigin);
135
138
141
144
147
150
152 T operator()(const VectorType& pt) const;
153
156 const VectorType& pt,
157 std::array<CoordIndexType, FLAT_KERNEL_SIZE>& indices,
158 std::array<ScalarType, FLAT_KERNEL_SIZE>& weights) const;
159
163 const VectorType& pt,
164 std::array<CoordIndexType, FLAT_KERNEL_SIZE>& indices,
165 std::array<VectorType, FLAT_KERNEL_SIZE>& weights) const;
166
168 [[nodiscard]] std::function<T(const VectorType&)> Functor() const;
169
170 private:
172 VectorType m_gridSpacing;
173 VectorType m_invGridSpacing;
174 VectorType m_gridOrigin;
175};
176
177template <typename T>
179
180template <typename T>
182
183template <typename T>
185
194template <typename T, size_t N, typename CubicInterpolationOp>
196{
197 public:
198 static_assert(N > 0, "N should be greater than 0");
199
201
202 static_assert(std::is_floating_point<ScalarType>::value,
203 "CubicArraySampler only can be instantiated with floating "
204 "point types");
205
208
210 CubicArraySampler() = default;
211
220 const VectorType& gridSpacing,
221 const VectorType& gridOrigin);
222
225
228
231
234
237
239 T operator()(const VectorType& pt) const;
240
242 [[nodiscard]] std::function<T(const VectorType&)> Functor() const;
243
244 private:
246 VectorType m_gridSpacing;
247 VectorType m_invGridSpacing;
248 VectorType m_gridOrigin;
249};
250
251template <typename T>
253{
255
256 T operator()(const T& f0, const T& f1, const T& f2, const T& f3,
257 ScalarType t) const
258 {
259 return CatmullRom(f0, f1, f2, f3, t);
260 }
261};
262
263template <typename T>
265{
267
268 T operator()(const T& f0, const T& f1, const T& f2, const T& f3,
269 ScalarType t) const
270 {
271 return MonotonicCatmullRom(f0, f1, f2, f3, t);
272 }
273};
274
275template <typename T>
277
278template <typename T>
280
281template <typename T>
283
284template <typename T>
287
288template <typename T>
291
292template <typename T>
295} // namespace CubbyFlow
296
298
299#endif
N-D cubic array sampler class.
Definition ArraySamplers.hpp:196
CubicArraySampler & operator=(const CubicArraySampler &other)
Copy assignment operator.
Definition ArraySamplers-Impl.hpp:425
typename GetScalarType< T >::value ScalarType
Definition ArraySamplers.hpp:200
T operator()(const VectorType &pt) const
Returns sampled value at point pt.
Definition ArraySamplers-Impl.hpp:449
CubicArraySampler()=default
Default constructor.
~CubicArraySampler()=default
Default destructor.
std::function< T(const VectorType &)> Functor() const
Returns a std::function object that wraps this instance.
Definition ArraySamplers-Impl.hpp:466
N-D array sampler using linear interpolation.
Definition ArraySamplers.hpp:107
~LinearArraySampler()=default
Default destructor.
static constexpr size_t FLAT_KERNEL_SIZE
Definition ArraySamplers.hpp:120
T operator()(const VectorType &pt) const
Returns sampled value at point pt.
Definition ArraySamplers-Impl.hpp:321
LinearArraySampler & operator=(const LinearArraySampler &other)
Copy assignment operator.
Definition ArraySamplers-Impl.hpp:297
typename GetScalarType< T >::value ScalarType
Definition ArraySamplers.hpp:111
LinearArraySampler()=default
Default constructor.
void GetCoordinatesAndWeights(const VectorType &pt, std::array< CoordIndexType, FLAT_KERNEL_SIZE > &indices, std::array< ScalarType, FLAT_KERNEL_SIZE > &weights) const
Returns the indices of points and their sampling weight for given point.
Definition ArraySamplers-Impl.hpp:337
void GetCoordinatesAndGradientWeights(const VectorType &pt, std::array< CoordIndexType, FLAT_KERNEL_SIZE > &indices, std::array< VectorType, FLAT_KERNEL_SIZE > &weights) const
Definition ArraySamplers-Impl.hpp:360
std::function< T(const VectorType &)> Functor() const
Returns a std::function instance that wraps this instance.
Definition ArraySamplers-Impl.hpp:385
Definition Matrix.hpp:30
N-D nearest array sampler class.
Definition ArraySamplers.hpp:30
NearestArraySampler & operator=(const NearestArraySampler &other)
Copy assignment operator.
Definition ArraySamplers-Impl.hpp:207
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.hpp:34
T operator()(const VectorType &pt) const
Returns sampled value at point pt.
Definition ArraySamplers-Impl.hpp:231
NearestArraySampler()=default
Default constructor.
std::function< T(const VectorType &)> Functor() const
Returns a std::function object that wraps this instance.
Definition ArraySamplers-Impl.hpp:257
~NearestArraySampler()=default
Default destructor.
Definition pybind11Utils.hpp:21
std::enable_if_t< std::is_arithmetic< T >::value, S > CatmullRom(const S &f0, const S &f1, const S &f2, const S &f3, T t)
Computes Catmull-Rom interpolation.
Definition MathUtils-Impl.hpp:318
std::enable_if_t< std::is_arithmetic< T >::value, T > MonotonicCatmullRom(const T &f0, const T &f1, const T &f2, const T &f3, T t)
Computes monotonic Catmull-Rom interpolation.
Definition MathUtils-Impl.hpp:336
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
Definition ArraySamplers.hpp:253
T operator()(const T &f0, const T &f1, const T &f2, const T &f3, ScalarType t) const
Definition ArraySamplers.hpp:256
typename GetScalarType< T >::value ScalarType
Definition ArraySamplers.hpp:254
Definition ArraySamplers.hpp:265
T operator()(const T &f0, const T &f1, const T &f2, const T &f3, ScalarType t) const
Definition ArraySamplers.hpp:268
typename GetScalarType< T >::value ScalarType
Definition ArraySamplers.hpp:266
T value
Definition TypeHelpers.hpp:20