9 #ifndef CUBBYFLOW_ARRAY_SAMPLERS2_IMPL_H 10 #define CUBBYFLOW_ARRAY_SAMPLERS2_IMPL_H 16 template <
typename T,
typename R>
22 m_gridSpacing = gridSpacing;
23 m_origin = gridOrigin;
24 m_accessor = accessor;
27 template <
typename T,
typename R>
30 m_gridSpacing = other.m_gridSpacing;
31 m_origin = other.m_origin;
32 m_accessor = other.m_accessor;
35 template <
typename T,
typename R>
41 assert(m_gridSpacing.x > std::numeric_limits<R>::epsilon());
42 assert(m_gridSpacing.y > std::numeric_limits<R>::epsilon());
44 const Vector2<R> normalizedX = (pt - m_origin) / m_gridSpacing;
46 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size().x);
47 const ssize_t jSize =
static_cast<ssize_t
>(m_accessor.size().y);
52 i = std::min(static_cast<ssize_t>(i + fx + 0.5), iSize - 1);
53 j = std::min(static_cast<ssize_t>(j + fy + 0.5), jSize - 1);
55 return m_accessor(i, j);
58 template <
typename T,
typename R>
64 assert(m_gridSpacing.x > std::numeric_limits<R>::epsilon());
65 assert(m_gridSpacing.y > std::numeric_limits<R>::epsilon());
67 const Vector2<R> normalizedX = (pt - m_origin) / m_gridSpacing;
69 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size().x);
70 const ssize_t jSize =
static_cast<ssize_t
>(m_accessor.size().y);
75 index->
x = std::min(static_cast<ssize_t>(i + fx + 0.5), iSize - 1);
76 index->
y = std::min(static_cast<ssize_t>(j + fy + 0.5), jSize - 1);
79 template <
typename T,
typename R>
83 return std::bind(&NearestArraySampler::operator(), sampler, std::placeholders::_1);
86 template <
typename T,
typename R>
92 m_gridSpacing = gridSpacing;
93 m_invGridSpacing =
static_cast<R
>(1) / m_gridSpacing;
94 m_origin = gridOrigin;
95 m_accessor = accessor;
98 template <
typename T,
typename R>
101 m_gridSpacing = other.m_gridSpacing;
102 m_invGridSpacing = other.m_invGridSpacing;
103 m_origin = other.m_origin;
104 m_accessor = other.m_accessor;
107 template <
typename T,
typename R>
113 assert(m_gridSpacing.x > std::numeric_limits<R>::epsilon());
114 assert(m_gridSpacing.y > std::numeric_limits<R>::epsilon());
116 const Vector2<R> normalizedX = (pt - m_origin) / m_gridSpacing;
118 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size().x);
119 const ssize_t jSize =
static_cast<ssize_t
>(m_accessor.size().y);
124 const ssize_t ip1 = std::min(i + 1, iSize - 1);
125 const ssize_t jp1 = std::min(j + 1, jSize - 1);
128 m_accessor(i, j), m_accessor(ip1, j),
129 m_accessor(i, jp1), m_accessor(ip1, jp1),
133 template <
typename T,
typename R>
136 std::array<Point2UI, 4>* indices,
137 std::array<R, 4>* weights)
const 142 assert(m_gridSpacing.x > std::numeric_limits<R>::epsilon());
143 assert(m_gridSpacing.y > std::numeric_limits<R>::epsilon());
145 const Vector2<R> normalizedX = (pt - m_origin) / m_gridSpacing;
147 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size().x);
148 const ssize_t jSize =
static_cast<ssize_t
>(m_accessor.size().y);
153 const ssize_t ip1 = std::min(i + 1, iSize - 1);
154 const ssize_t jp1 = std::min(j + 1, jSize - 1);
161 (*weights)[0] = (1 - fx) * (1 - fy);
162 (*weights)[1] = fx * (1 - fy);
163 (*weights)[2] = (1 - fx) * fy;
164 (*weights)[3] = fx * fy;
167 template <
typename T,
typename R>
170 std::array<Point2UI, 4>* indices,
176 assert(m_gridSpacing.x > 0.0);
177 assert(m_gridSpacing.y > 0.0);
179 const Vector2<R> normalizedX = (x - m_origin) * m_invGridSpacing;
181 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size().x);
182 const ssize_t jSize =
static_cast<ssize_t
>(m_accessor.size().y);
187 const ssize_t ip1 = std::min(i + 1, iSize - 1);
188 const ssize_t jp1 = std::min(j + 1, jSize - 1);
195 (*weights)[0] =
Vector2<R>(fy * m_invGridSpacing.x - m_invGridSpacing.x, fx * m_invGridSpacing.y - m_invGridSpacing.y);
196 (*weights)[1] =
Vector2<R>(-fy * m_invGridSpacing.x + m_invGridSpacing.x, -fx * m_invGridSpacing.y);
197 (*weights)[2] =
Vector2<R>(-fy * m_invGridSpacing.x, -fx * m_invGridSpacing.y + m_invGridSpacing.y);
198 (*weights)[3] =
Vector2<R>(fy * m_invGridSpacing.x, fx * m_invGridSpacing.y);
201 template <
typename T,
typename R>
205 return std::bind(&LinearArraySampler::operator(), sampler, std::placeholders::_1);
208 template <
typename T,
typename R>
214 m_gridSpacing = gridSpacing;
215 m_origin = gridOrigin;
216 m_accessor = accessor;
219 template <
typename T,
typename R>
222 m_gridSpacing = other.m_gridSpacing;
223 m_origin = other.m_origin;
224 m_accessor = other.m_accessor;
227 template <
typename T,
typename R>
233 assert(m_gridSpacing.x > std::numeric_limits<R>::epsilon());
234 assert(m_gridSpacing.y > std::numeric_limits<R>::epsilon());
236 const Vector2<R> normalizedX = (pt - m_origin) / m_gridSpacing;
238 const ssize_t iSize =
static_cast<ssize_t
>(m_accessor.size().x);
239 const ssize_t jSize =
static_cast<ssize_t
>(m_accessor.size().y);
244 const ssize_t is[4] = { std::max(i - 1,
ZERO_SSIZE), i, std::min(i + 1, iSize - 1), std::min(i + 2, iSize - 1) };
245 const ssize_t js[4] = { std::max(j - 1,
ZERO_SSIZE), j, std::min(j + 1, jSize - 1), std::min(j + 2, jSize - 1) };
250 for (
int n = 0; n < 4; ++n)
253 m_accessor(is[0], js[n]),
254 m_accessor(is[1], js[n]),
255 m_accessor(is[2], js[n]),
256 m_accessor(is[3], js[n]),
263 template <
typename T,
typename R>
267 return std::bind(&CubicArraySampler::operator(), sampler, std::placeholders::_1);
2-D read-only array accessor class.
Definition: ArrayAccessor2.h:261
T x
X (or the first) component of the vector.
Definition: Vector2.h:29
T x
X (or the first) component of the point.
Definition: Point2.h:28
Generic N-D nearest array sampler class.
Definition: ArraySamplers.h:22
2-D point class.
Definition: Point2.h:25
Point2< size_t > Point2UI
Unsigned integer-type 2D point.
Definition: Point2.h:315
T y
Y (or the second) component of the point.
Definition: Point2.h:34
Definition: pybind11Utils.h:24
Generic N-D cubic array sampler class.
Definition: ArraySamplers.h:50
T y
Y (or the second) component of the vector.
Definition: Vector2.h:35
S BiLerp(const S &f00, const S &f10, const S &f01, const S &f11, T tx, T ty)
Computes bilinear interpolation.
Definition: MathUtils-Impl.h:190
constexpr ssize_t ZERO_SSIZE
Zero ssize_t.
Definition: Constants.h:20
2-D vector class.
Definition: Vector2.h:26
T MonotonicCatmullRom(const T &f0, const T &f1, const T &f2, const T &f3, T f)
Computes monotonic Catmull-Rom interpolation.
Definition: MathUtils-Impl.h:228
Generic N-D linear array sampler class.
Definition: ArraySamplers.h:36
void GetBarycentric(T x, ssize_t iLow, ssize_t iHigh, ssize_t *i, T *f)
Gets the barycentric coordinate.
Definition: MathUtils-Impl.h:151