ArraySamplers2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ArraySamplers2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D nearest array sampler class.
6 > Created Time: 2017/04/29
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_ARRAY_SAMPLERS2_H
10 #define CUBBYFLOW_ARRAY_SAMPLERS2_H
11 
14 #include <Core/Vector/Vector2.h>
15 
16 #include <functional>
17 
18 namespace CubbyFlow
19 {
28  template <typename T, typename R>
29  class NearestArraySampler<T, R, 2> final
30  {
31  public:
32  static_assert(std::is_floating_point<R>::value, "Samplers only can be instantiated with floating point types");
33 
42  explicit NearestArraySampler(
43  const ConstArrayAccessor2<T>& accessor,
44  const Vector2<R>& gridSpacing,
45  const Vector2<R>& gridOrigin);
46 
49 
51  T operator()(const Vector2<R>& pt) const;
52 
54  void GetCoordinate(const Vector2<R>& pt, Point2UI* index) const;
55 
57  std::function<T(const Vector2<R>&)> Functor() const;
58 
59  private:
60  Vector2<R> m_gridSpacing;
61  Vector2<R> m_origin;
62  ConstArrayAccessor2<T> m_accessor;
63  };
64 
66  template <typename T, typename R>
68 
77  template <typename T, typename R>
78  class LinearArraySampler<T, R, 2> final
79  {
80  public:
81  static_assert(std::is_floating_point<R>::value, "Samplers only can be instantiated with floating point types");
82 
91  explicit LinearArraySampler(
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 
103  void GetCoordinatesAndWeights(
104  const Vector2<R>& pt,
105  std::array<Point2UI, 4>* indices,
106  std::array<R, 4>* weights) const;
107 
110  void GetCoordinatesAndGradientWeights(
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> m_gridSpacing;
120  Vector2<R> m_invGridSpacing;
121  Vector2<R> m_origin;
122  ConstArrayAccessor2<T> m_accessor;
123  };
124 
126  template <typename T, typename R>
128 
137  template <typename T, typename R>
138  class CubicArraySampler<T, R, 2> final
139  {
140  public:
141  static_assert(std::is_floating_point<R>::value, "Samplers only can be instantiated with floating point types");
142 
151  explicit CubicArraySampler(
152  const ConstArrayAccessor2<T>& accessor,
153  const Vector2<R>& gridSpacing,
154  const Vector2<R>& gridOrigin);
155 
157  CubicArraySampler(const CubicArraySampler& other);
158 
160  T operator()(const Vector2<R>& pt) const;
161 
163  std::function<T(const Vector2<R>&)> Functor() const;
164 
165  private:
166  Vector2<R> m_gridSpacing;
167  Vector2<R> m_origin;
168  ConstArrayAccessor2<T> m_accessor;
169  };
170 
172  template <typename T, typename R>
174 }
175 
177 
178 #endif
2-D read-only array accessor class.
Definition: ArrayAccessor2.h:261
2-D nearest array sampler class.
Definition: ArraySamplers2.h:29
Generic N-D nearest array sampler class.
Definition: ArraySamplers.h:22
2-D point class.
Definition: Point2.h:25
Definition: pybind11Utils.h:24
Generic N-D cubic array sampler class.
Definition: ArraySamplers.h:50
2-D cubic array sampler class.
Definition: ArraySamplers2.h:138
2-D vector class.
Definition: Vector2.h:26
2-D linear array sampler class.
Definition: ArraySamplers2.h:78
Generic N-D linear array sampler class.
Definition: ArraySamplers.h:36