USML
data_grid_bathy Class Reference
Collaboration diagram for data_grid_bathy:

Detailed Description

Implements fast calculations for data_grids using a non-recursive engine on interpolation.

Takes an existing data_grid and wraps it into a new data_grid_fast and overrides the interpolate function to implement the non-recursive algorithm.

Assumes that both axes of the passed data_grid both have the same interp_type.

WARNING: This wrapper is specific to 2-dimensional grids only. For 3-dimensional grids, the user should implement the data_grid_svp wrapper instead.

Since the data is passed in and referenced by this wrapper, the data is taken control of and destroyed at the end of its use cycle.

Constructor & Destructor Documentation

data_grid_bathy ( const data_grid< double, 2 > &  grid,
bool  copy_data = true 
)
inline

Constructor - Creates a fast interpolation grid from an existing data_grid.

Also constructs the inverse bicubic coefficient matrix to be used at a later time during pchip calculations.

Parameters
gridThe data_grid that is to be wrapped.
copy_dataIf true, copies the data grids data fields as well as the axises.

Member Function Documentation

double data_2d ( unsigned  row,
unsigned  col 
)
inlineprivate

Utility accessor function for data grid values.

double fast_pchip ( const unsigned *  interp_index,
double *  location,
double *  derivative = NULL 
)
inlineprivate

A non-recursive version of the Piecewise Cubic Hermite polynomial (PCHIP) specific to the 2-dimensional grid of data.

This algorithm was generated from the below formula and by performing a linear transformation from the data set to the interval [0,1] x [0,1]:

g(x,y) = sum [i,0,3] ( sum [j,0,3] ( a_ij * x^i * y^j ) )

where (x,y) is the point of interpolation and a_ij are known as the bicubic interpolation coefficients. An inverse matrix is then constructed from the 16 equations that are generated. Using this inverse matrix and the 4 surround data points, their respective derivatives with respect to x and y, and mixed xy xy derivatives, we can construct each a_ij.

The partial and mixed derivates are computed using a centered differencing approximation, so that,

 f_x(i,j) = [ f(i+1,j) - f(i-1,j) ] / [ x_(i+1) - x(i-1) ]
 f_y(i,j) = [ f(i,j+1) - f(i,j-1) ] / [ y_(i+1) - y(i-1) ]
 f_xy(i,j) = { f(i+1,j+1) - f(i+1,j-1) - f(i-1,j+1) +
             f(i-1,j-1) } / [ x_(i+1) - x(i-1) ] *
             [ y_(i+1) - y(i-1) ]
References:

http://en.wikipedia.org/wiki/Bicubic_interpolation

http://en.wikipedia.org/wiki/Finite_difference

Below is a representation of the data extracted from the field and how it is stored within the matrix:

         * field(1,0)                  * field(3,0)
                 * (interp point)

         * field(0,0)                  * field(2,0)

field(0,0) to field(3,0) are the data points that surrounding the interpolation point. field(4,0) to field(7,0) are the derivatives with respect to x of the extracted data points. field(8,0) to field(11,0) are the derivatives with respect to y of the extracted data points. field(12,0) to field(15,0) are the derivatives with respect to x and y of the extracted data points.

Parameters
interp_indexindex on the grid for the closest data point
locationLocation of the field calculation
derivativeGenerate the derivative at the location (output)
Returns
Returns the value at the field location
double interpolate ( double *  location,
double *  derivative = NULL 
)
inline

Overrides the interpolate function within data_grid using the non-recursive formula.

Determines which interpolate function to based on the interp_type enumeral stored within the 0th dimensional axis.

Interpolate at a single location.

Parameters
locationLocation to do the interpolation at
derivativeDerivative at the location (output)
Returns
Returns the value at the field location
void interpolate ( const matrix< double > &  x,
const matrix< double > &  y,
matrix< double > *  result,
matrix< double > *  dx = NULL,
matrix< double > *  dy = NULL 
)
inline

Overrides the interpolate function within data_grid using the non-recursive formula.

Interpolate at a series of locations.

Parameters
xFirst dimension of location.
ySecond dimension of location.
resultInterpolated values at each location (output).
dxFirst dimension of derivative (output).
dySecond dimension of derivative (output).

Member Data Documentation

c_matrix<double, 16, 1> _bicubic_coeff
private

Create variables that are used multiple times through out the course of multiple calls per instance.

Thus allowing these variables to be created once and used as many times as needed and save memory and time.

matrix<double> _derv_x
private
matrix<double> _derv_x_y
private
matrix<double> _derv_y
private
unsigned _fast_index[2]
private
c_matrix<double, 16, 1> _field
private
c_matrix<double, 16, 16> _inv_bicubic_coeff
private

Matrix that is the inverse of the bicubic coefficients This matrix will be used to construct the bicubic coefficients.

The result will be a 16x1 matrix.

const int _k0max
private
const int _k1max
private
const int _kmin
private
c_matrix<double, 1, 1> _result_pchip
private
c_matrix<double, 4, 4> _value
private
c_matrix<double, 1, 16> _xyloc
private