Interpolate2D.h
Classes
- Interpolate2D -- A two dimension interpolator for Matrices or Arrays (full description)
Types
- NEAREST
-
Nearest neighbour
- LINEAR
-
Bilinear
- CUBIC
-
Bicubic
Interface
- Public Members
- Interpolate2D(Interpolate2D::Method method=Interpolate2D::LINEAR)
- Interpolate2D(const Interpolate2D &other)
- ~Interpolate2D()
- Interpolate2D &operator=(const Interpolate2D &other)
- Bool interp (Float &result, const Vector<Double> &where, const Matrix<Float> &data) const
- Bool interp (Float &result, const Vector<Double> &where, const Matrix<Float> &data, const Matrix<Bool> &mask) const
- Bool interp (Double &result, const Vector<Double> &where, const Matrix<Double> &data) const
- Bool interp (Double &result, const Vector<Double> &where, const Matrix<Double> &data, const Matrix<Bool> &mask) const
- Bool interp(Double &resultI, Double &resultJ, const Vector<Double> &where, const Matrix<Double> &dataI, const Matrix<Double> &dataJ, const Matrix<Bool> &mask) const
- template <typename T> Bool interpLinear2(T &resultI, T &resultJ, const T<Double> &where, const Vector<T> &dataI, const Vector<T> &dataJ, const Vector<Bool> &mask) const
- Bool interp (Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
- Method interpolationMethod() const
- static Interpolate2D::Method stringToMethod(const String &method)
- Private Members
- Bool anyBadMaskPixels (const Matrix<Bool>* &mask, Int i1, Int i2, Int j1, Int j2) const
- template <typename T> Bool interpNearest(T &result, const T<Double> &where, const Vector<T> &data, const Vector<Bool>* &maskPtr) const
- Bool interpNearestBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
- template <typename T> Bool interpLinear(T &result, const T<Double> &where, const Vector<T> &data, const Vector<Bool>* &maskPtr) const
- Bool interpLinearBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
- template <typename T> Bool interpCubic(T &result, const T<Double> &where, const Vector<T> &data, const Vector<Bool>* &maskPtr) const
- Bool interpCubicBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
- void bcucof (Double c[4][4], const Double y[4], const Double y1[4], const Double y2[4], const Double y12[4]) const
- typedef Bool(Interpolate2D::*FuncPtrFloat) (Float &result, const FuncPtr<Double> &where, const Vector<Float> &data, const Vector<Bool>* &maskPtr) const
- typedef Bool(Interpolate2D::*FuncPtrDouble) (Double &result, const FuncPtr<Double> &where, const Vector<Double> &data, const Vector<Bool>* &maskPtr) const
- typedef Bool(Interpolate2D::*FuncPtrBool) (Bool &result, const FuncPtr<Double> &where, const Vector<Bool> &data) const
Review Status
- Reviewed By:
- wbrouw
- Date Reviewed:
- 2004/05/26
Prerequisite
Etymology
This class is called Interpolate2D because it does 2 dimensional interpolations
Synopsis
Given a regular Array or Matrix and a vector of pixel
coordinates, interpolate the values of that array/matrix onto those
pixel coordinates.
Absolutely no checking of the consistency of the input data
is done in order to preserve maximum speed. The coordinate vector
*must* have at least 2 elements (others will be ignored). If
you supply data and mask, those arrays *must* be the same shape.
Failure to follow these rules will result in your program
crashing.
Example
Matrix<Float> matt(10,10);
Vector<Float> where(2);
where(0) = 3.452; where(1) = 6.1;
Interpolate2D myInterp(Interpolate2D::LINEAR);
Float result;
Bool ok = myInterp(result, where, matt);
Motivation
2-D interpolation is required in geometry transformation routines
such as in ImageRegrid.
To Do
- Now that there are float/double/bool versions, the class should
be templated and specialized versions made as needed. The
code duplucation in the Float/Double versions is pretty awful presently.
- Alternative approach: instantiate with an Array, take a block of
vector locations, return a block of interpolation results
Member Description
Interpolate2D(Interpolate2D::Method method=Interpolate2D::LINEAR)
Constructor
Interpolate2D(const Interpolate2D &other)
Copy constructor (copy semantics)
destructor
Interpolate2D &operator=(const Interpolate2D &other)
Assignment operator (copy semantics)
Bool interp (Float &result, const Vector<Double> &where, const Matrix<Float> &data) const
Bool interp (Float &result, const Vector<Double> &where, const Matrix<Float> &data, const Matrix<Bool> &mask) const
Do one Float interpolation, supply Matrix and mask (True is good),
and pixel coordinate. Returns False if coordinate out of range or data
are masked. No shape integrity checking is done (see above).
Bool interp (Double &result, const Vector<Double> &where, const Matrix<Double> &data) const
Bool interp (Double &result, const Vector<Double> &where, const Matrix<Double> &data, const Matrix<Bool> &mask) const
Do one Double interpolation, supply Matrix/Array and mask (True is good),
and pixel coordinate. Returns False if coordinate out of range or data
are masked. No shape integrity checking is done (see above).
Bool interp(Double &resultI, Double &resultJ, const Vector<Double> &where, const Matrix<Double> &dataI, const Matrix<Double> &dataJ, const Matrix<Bool> &mask) const
template <typename T> Bool interpLinear2(T &resultI, T &resultJ, const T<Double> &where, const Vector<T> &dataI, const Vector<T> &dataJ, const Vector<Bool> &mask) const
Do two linear interpolations simultaneously. The second call is direct.
The first call transfers to the second call. It is assumed that the
structure (shape, steps) of the mask and data files are the same.
Bool interp (Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
Do one interpolation, supply boolean Matrix (True is good),
and pixel coordinate. Returns False if coordinate
out of range. The result is False if any data value in the interpolation
grid are False (bad), else True. No shape integrity checking is done.
Recover interpolation method
Convert string ("nearest", "linear", "cubic") to interpolation method
Minimum match will do.
Bool anyBadMaskPixels (const Matrix<Bool>* &mask, Int i1, Int i2, Int j1, Int j2) const
Are any of the mask pixels bad ? Returns False if no mask.
template <typename T> Bool interpNearest(T &result, const T<Double> &where, const Vector<T> &data, const Vector<Bool>* &maskPtr) const
nearest neighbour interpolation
Bool interpNearestBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
template <typename T> Bool interpLinear(T &result, const T<Double> &where, const Vector<T> &data, const Vector<Bool>* &maskPtr) const
bi-linear interpolation
Bool interpLinearBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
template <typename T> Bool interpCubic(T &result, const T<Double> &where, const Vector<T> &data, const Vector<Bool>* &maskPtr) const
bi-cubic interpolation
Bool interpCubicBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const
void bcucof (Double c[4][4], const Double y[4], const Double y1[4], const Double y2[4], const Double y12[4]) const
helping routine from numerical recipes
typedef Bool(Interpolate2D::*FuncPtrFloat) (Float &result, const FuncPtr<Double> &where, const Vector<Float> &data, const Vector<Bool>* &maskPtr) const
Typedefs for function pointers
typedef Bool(Interpolate2D::*FuncPtrDouble) (Double &result, const FuncPtr<Double> &where, const Vector<Double> &data, const Vector<Bool>* &maskPtr) const
typedef Bool(Interpolate2D::*FuncPtrBool) (Bool &result, const FuncPtr<Double> &where, const Vector<Bool> &data) const