47 #ifndef _MIRA_LINEARINTERPOLATOR_H_ 48 #define _MIRA_LINEARINTERPOLATOR_H_ 78 template <
typename Tx,
typename Ty,
typename ContainerTx,
typename ContainerTy>
79 Ty
apply(
const ContainerTx& x,
const ContainerTy& y,
const Tx& xx)
81 assert(x.size()==y.size());
84 double dx = (double)x.back() - (double)x.front();
86 if(
isApprox(dx,0.0, std::numeric_limits<double>::epsilon()))
89 return lerp(y.front(), y.back(), ((double)xx-(
double)x.front())/dx);
111 template <
typename Tx,
typename Ty,
typename ContainerTx,
typename ContainerTy>
112 Ty
apply(
const ContainerTx& x,
const ContainerTy& y,
const Tx& xx)
114 assert(x.size()==y.size());
117 double dx = (double)x.back() - (double)x.front();
119 if(
isApprox(dx,0.0, std::numeric_limits<double>::epsilon()))
122 return lerp(y.front(), y.back(), ((double)xx-(
double)x.front())/dx);
146 template <
typename Tx,
typename Ty,
typename ContainerTx,
typename ContainerTy>
147 Ty
apply(
const ContainerTx& x,
const ContainerTy& y,
const Tx& xx)
149 assert(x.size()==y.size());
158 double dx = (double)x.back() - (double)x.front();
160 if(
isApprox(dx,0.0, std::numeric_limits<double>::epsilon()))
163 return lerp(y.front(), y.back(), ((double)xx-(
double)x.front())/dx);
192 template <
typename Tx,
typename Ty,
typename ContainerTx,
typename ContainerTy>
193 Ty
apply(
const ContainerTx& x,
const ContainerTy& y,
const Tx& xx)
195 assert(x.size()==y.size());
198 double dx = (double)x.back() - (double)x.front();
200 if(
isApprox(dx,0.0, std::numeric_limits<double>::epsilon()))
204 double alpha = ((double)xx-(
double)x.front())/dx;
205 if (alpha < -mLimit || alpha > (1 + mLimit))
207 "LinearInterpolatorExtrapolationLimit: Lerp alpha " <<
208 "(" << alpha <<
") out of specified limits " <<
209 "(" << -mLimit <<
", " << 1 + mLimit <<
")");
211 return lerp(y.front(), y.back(), alpha);
bool canExtrapolate() const
Definition: LinearInterpolator.h:73
int samples() const
Definition: LinearInterpolator.h:74
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
int samplesBefore() const
Definition: LinearInterpolator.h:75
T lerp(const T &a, const T &b, S alpha)
Linear interpolation of different types like scalars, angles and rotations, vectors, etc.
Definition: Lerp.h:76
Functions for linear interpolation of different types like scalars, angles and rotations.
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Contains helper to check if two values are approximately the same.
1D linear interpolator.
Definition: LinearInterpolator.h:70
Ty apply(const ContainerTx &x, const ContainerTy &y, const Tx &xx)
Definition: LinearInterpolator.h:79
int samplesAfter() const
Definition: LinearInterpolator.h:76
IntervalFilter base class/concept.
Concept and base class for all Interpolators and Filters.
Definition: IntervalFilter.h:61
bool isApprox(const T &a, const T &b, const U &tol)
Returns true, if the value a has approximately the same value as b.
Definition: IsApprox.h:61