Jet  v1.3.3
array_samplers1.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_ARRAY_SAMPLERS1_H_
8 #define INCLUDE_JET_ARRAY_SAMPLERS1_H_
9 
10 #include <jet/array_samplers.h>
11 #include <jet/array_accessor1.h>
12 #include <functional>
13 
14 namespace jet {
15 
24 template <typename T, typename R>
25 class NearestArraySampler<T, R, 1> final {
26  public:
27  static_assert(
28  std::is_floating_point<R>::value,
29  "Samplers only can be instantiated with floating point types");
30 
40  const ConstArrayAccessor1<T>& accessor,
41  R gridSpacing,
42  R gridOrigin);
43 
46 
48  T operator()(R pt) const;
49 
51  void getCoordinate(R x, size_t* i) const;
52 
54  std::function<T(R)> functor() const;
55 
56  private:
57  R _gridSpacing;
58  R _origin;
59  ConstArrayAccessor1<T> _accessor;
60 };
61 
63 template <typename T, typename R> using NearestArraySampler1
65 
66 
75 template <typename T, typename R>
76 class LinearArraySampler<T, R, 1> final {
77  public:
78  static_assert(
79  std::is_floating_point<R>::value,
80  "Samplers only can be instantiated with floating point types");
81 
91  const ConstArrayAccessor1<T>& accessor,
92  R gridSpacing,
93  R gridOrigin);
94 
97 
99  T operator()(R pt) const;
100 
103  R x, size_t* i0, size_t* i1, T* weight0, T* weight1) const;
104 
106  std::function<T(R)> functor() const;
107 
108  private:
109  R _gridSpacing;
110  R _origin;
111  ConstArrayAccessor1<T> _accessor;
112 };
113 
115 template <typename T, typename R> using LinearArraySampler1
117 
118 
127 template <typename T, typename R>
128 class CubicArraySampler<T, R, 1> final {
129  public:
130  static_assert(
131  std::is_floating_point<R>::value,
132  "Samplers only can be instantiated with floating point types");
133 
143  const ConstArrayAccessor1<T>& accessor,
144  R gridSpacing,
145  R gridOrigin);
146 
149 
151  T operator()(R pt) const;
152 
154  std::function<T(R)> functor() const;
155 
156  private:
157  R _gridSpacing;
158  R _origin;
159  ConstArrayAccessor1<T> _accessor;
160 };
161 
163 template <typename T, typename R> using CubicArraySampler1
165 
166 } // namespace jet
167 
168 #include "detail/array_samplers1-inl.h"
169 
170 #endif // INCLUDE_JET_ARRAY_SAMPLERS1_H_
jet::LinearArraySampler< T, R, 1 >::functor
std::function< T(R)> functor() const
Returns a funtion object that wraps this instance.
jet::NearestArraySampler< T, R, 1 >::NearestArraySampler
NearestArraySampler(const ConstArrayAccessor1< T > &accessor, R gridSpacing, R gridOrigin)
Constructs a sampler using array accessor, spacing between the elements, and the position of the firs...
jet::NearestArraySampler
Generic N-D nearest array sampler class.
Definition: array_samplers.h:22
jet::ConstArrayAccessor< T, 1 >
1-D read-only array accessor class.
Definition: array_accessor1.h:184
jet::NearestArraySampler< T, R, 1 >::functor
std::function< T(R)> functor() const
Returns a funtion object that wraps this instance.
jet::LinearArraySampler< T, R, 1 >::LinearArraySampler
LinearArraySampler(const LinearArraySampler &other)
Copy constructor.
jet::LinearArraySampler< T, R, 1 >::operator()
T operator()(R pt) const
Returns sampled value at point pt.
jet::NearestArraySampler< T, R, 1 >
1-D nearest array sampler class.
Definition: array_samplers1.h:25
jet::LinearArraySampler< T, R, 1 >::LinearArraySampler
LinearArraySampler(const ConstArrayAccessor1< T > &accessor, R gridSpacing, R gridOrigin)
Constructs a sampler using array accessor, spacing between the elements, and the position of the firs...
jet::NearestArraySampler< T, R, 1 >::operator()
T operator()(R pt) const
Returns sampled value at point pt.
jet::CubicArraySampler
Generic N-D cubic array sampler class.
Definition: array_samplers.h:50
jet::NearestArraySampler< T, R, 1 >::NearestArraySampler
NearestArraySampler(const NearestArraySampler &other)
Copy constructor.
jet
Definition: advection_solver2.h:18
jet::CubicArraySampler< T, R, 1 >
1-D cubic array sampler class.
Definition: array_samplers1.h:128
jet::CubicArraySampler< T, R, 1 >::CubicArraySampler
CubicArraySampler(const CubicArraySampler &other)
Copy constructor.
jet::CubicArraySampler< T, R, 1 >::CubicArraySampler
CubicArraySampler(const ConstArrayAccessor1< T > &accessor, R gridSpacing, R gridOrigin)
Constructs a sampler using array accessor, spacing between the elements, and the position of the firs...
jet::CubicArraySampler< T, R, 1 >::functor
std::function< T(R)> functor() const
Returns a funtion object that wraps this instance.
jet::CubicArraySampler< T, R, 1 >::operator()
T operator()(R pt) const
Returns sampled value at point pt.
jet::LinearArraySampler< T, R, 1 >
1-D linear array sampler class.
Definition: array_samplers1.h:76
array_accessor1.h
jet::LinearArraySampler
Generic N-D linear array sampler class.
Definition: array_samplers.h:36
jet::LinearArraySampler< T, R, 1 >::getCoordinatesAndWeights
void getCoordinatesAndWeights(R x, size_t *i0, size_t *i1, T *weight0, T *weight1) const
Returns the indices of points and their sampling weight for given point.
array_samplers.h
jet::NearestArraySampler< T, R, 1 >::getCoordinate
void getCoordinate(R x, size_t *i) const
Returns the nearest array index for point x.