Jet  v1.3.3
array_samplers2.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_SAMPLERS2_H_
8 #define INCLUDE_JET_ARRAY_SAMPLERS2_H_
9 
10 #include <jet/array_samplers.h>
11 #include <jet/array_accessor2.h>
12 #include <jet/vector2.h>
13 #include <functional>
14 
15 namespace jet {
16 
25 template <typename T, typename R>
26 class NearestArraySampler<T, R, 2> final {
27  public:
28  static_assert(
29  std::is_floating_point<R>::value,
30  "Samplers only can be instantiated with floating point types");
31 
41  const ConstArrayAccessor2<T>& accessor,
42  const Vector2<R>& gridSpacing,
43  const Vector2<R>& gridOrigin);
44 
47 
49  T operator()(const Vector2<R>& pt) const;
50 
52  void getCoordinate(const Vector2<R>& pt, Point2UI* index) const;
53 
55  std::function<T(const Vector2<R>&)> functor() const;
56 
57  private:
58  Vector2<R> _gridSpacing;
59  Vector2<R> _origin;
60  ConstArrayAccessor2<T> _accessor;
61 };
62 
64 template <typename T, typename R> using NearestArraySampler2
66 
67 
76 template <typename T, typename R>
77 class LinearArraySampler<T, R, 2> final {
78  public:
79  static_assert(
80  std::is_floating_point<R>::value,
81  "Samplers only can be instantiated with floating point types");
82 
92  const ConstArrayAccessor2<T>& accessor,
93  const Vector2<R>& gridSpacing,
94  const Vector2<R>& gridOrigin);
95 
98 
100  T operator()(const Vector2<R>& pt) const;
101 
104  const Vector2<R>& pt,
105  std::array<Point2UI, 4>* indices,
106  std::array<R, 4>* weights) const;
107 
111  const Vector2<R>& pt,
112  std::array<Point2UI, 4>* indices,
113  std::array<Vector2<R>, 4>* weights) const;
114 
116  std::function<T(const Vector2<R>&)> functor() const;
117 
118  private:
119  Vector2<R> _gridSpacing;
120  Vector2<R> _invGridSpacing;
121  Vector2<R> _origin;
122  ConstArrayAccessor2<T> _accessor;
123 };
124 
126 template <typename T, typename R> using LinearArraySampler2
128 
129 
138 template <typename T, typename R>
139 class CubicArraySampler<T, R, 2> final {
140  public:
141  static_assert(
142  std::is_floating_point<R>::value,
143  "Samplers only can be instantiated with floating point types");
144 
154  const ConstArrayAccessor2<T>& accessor,
155  const Vector2<R>& gridSpacing,
156  const Vector2<R>& gridOrigin);
157 
160 
162  T operator()(const Vector2<R>& pt) const;
163 
165  std::function<T(const Vector2<R>&)> functor() const;
166 
167  private:
168  Vector2<R> _gridSpacing;
169  Vector2<R> _origin;
170  ConstArrayAccessor2<T> _accessor;
171 };
172 
174 template <typename T, typename R> using CubicArraySampler2
176 
177 } // namespace jet
178 
179 #include "detail/array_samplers2-inl.h"
180 
181 #endif // INCLUDE_JET_ARRAY_SAMPLERS2_H_
jet::Point< T, 2 >
2-D point class.
Definition: point2.h:23
array_accessor2.h
jet::NearestArraySampler
Generic N-D nearest array sampler class.
Definition: array_samplers.h:22
jet::NearestArraySampler< T, R, 2 >::operator()
T operator()(const Vector2< R > &pt) const
Returns sampled value at point pt.
jet::LinearArraySampler< T, R, 2 >::functor
std::function< T(const Vector2< R > &)> functor() const
Returns a funtion object that wraps this instance.
jet::CubicArraySampler< T, R, 2 >::CubicArraySampler
CubicArraySampler(const CubicArraySampler &other)
Copy constructor.
jet::NearestArraySampler< T, R, 2 >::getCoordinate
void getCoordinate(const Vector2< R > &pt, Point2UI *index) const
Returns the nearest array index for point x.
jet::CubicArraySampler< T, R, 2 >::operator()
T operator()(const Vector2< 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, 2 >::NearestArraySampler
NearestArraySampler(const ConstArrayAccessor2< T > &accessor, const Vector2< R > &gridSpacing, const Vector2< R > &gridOrigin)
Constructs a sampler using array accessor, spacing between the elements, and the position of the firs...
jet::CubicArraySampler< T, R, 2 >::functor
std::function< T(const Vector2< R > &)> functor() const
Returns a funtion object that wraps this instance.
jet::LinearArraySampler< T, R, 2 >
2-D linear array sampler class.
Definition: array_samplers2.h:77
jet::CubicArraySampler< T, R, 2 >
2-D cubic array sampler class.
Definition: array_samplers2.h:139
jet::LinearArraySampler< T, R, 2 >::operator()
T operator()(const Vector2< R > &pt) const
Returns sampled value at point pt.
jet
Definition: advection_solver2.h:18
vector2.h
jet::ConstArrayAccessor< T, 2 >
2-D read-only array accessor class.
Definition: array_accessor2.h:261
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::NearestArraySampler< T, R, 2 >::functor
std::function< T(const Vector2< R > &)> functor() const
Returns a funtion object that wraps this instance.
jet::LinearArraySampler< T, R, 2 >::getCoordinatesAndWeights
void getCoordinatesAndWeights(const Vector2< R > &pt, std::array< Point2UI, 4 > *indices, std::array< R, 4 > *weights) const
Returns the indices of points and their sampling weight for given point.
jet::NearestArraySampler< T, R, 2 >
2-D nearest array sampler class.
Definition: array_samplers2.h:26
jet::LinearArraySampler< T, R, 2 >::getCoordinatesAndGradientWeights
void getCoordinatesAndGradientWeights(const Vector2< R > &pt, std::array< Point2UI, 4 > *indices, std::array< Vector2< R >, 4 > *weights) const
jet::LinearArraySampler< T, R, 2 >::LinearArraySampler
LinearArraySampler(const ConstArrayAccessor2< T > &accessor, const Vector2< R > &gridSpacing, const Vector2< R > &gridOrigin)
Constructs a sampler using array accessor, spacing between the elements, and the position of the firs...
jet::LinearArraySampler
Generic N-D linear array sampler class.
Definition: array_samplers.h:36
array_samplers.h
jet::CubicArraySampler< T, R, 2 >::CubicArraySampler
CubicArraySampler(const ConstArrayAccessor2< T > &accessor, const Vector2< R > &gridSpacing, const Vector2< R > &gridOrigin)
Constructs a sampler using array accessor, spacing between the elements, and the position of the firs...
jet::LinearArraySampler< T, R, 2 >::LinearArraySampler
LinearArraySampler(const LinearArraySampler &other)
Copy constructor.
jet::NearestArraySampler< T, R, 2 >::NearestArraySampler
NearestArraySampler(const NearestArraySampler &other)
Copy constructor.