ocmath_2d_interpolate

 

Description

This function interpolates or extrpolates an input matrix to find Z values at given X and Y coordinates.

Syntax

int ocmath_2d_interpolate( int nSize, double * pX, double * pY, double * pZ, UINT nRows, UINT nCols, double * pMat, double dxMin, double dxMax, double dyMin, double dyMax, int nMethod = INTERP2_NEAREST )

Parameters

nSize
[input] The size of pX, pY and pZ vector.
pX
[input] Specifies X coordinates at which the data Z is given.
pY
[input] Specifies Y coordinates at which the data Z is given.
pZ
[output] The interpolated data values.
nRows
[input] The number of rows.
nCols
[input] The number of columns.
pMat
[input] The input matrix with size nRows*nCols.
dxMin
[input] The X minimum.
dxMax
[input] The X maximum.
dyMin
[input] The Y minimum.
dyMax
[input] The Y maximum.
nMethod
[input] The interpolation methods:
INTERP2_NEAREST, INTERP2_BILINEAR, INTERP2_BICUBIC, INTERP2_SPLINE, INTERP2_BIQUADRATIC, INTERP2_LAGRANGE

Return

Returns OE_NOERROR if succeed, error codes otherwise.

Examples

EX1

//Before running, make sure a matrixlayer exists and is active in current project
void ocmath_2d_interpolate_ex1(int nSize)
{
    MatrixLayer ml = Project.ActiveLayer();
    MatrixObject mo = ml.MatrixObjects(0);
    matrixbase& matbase = mo.GetDataObject();
    matrix mat = matbase;
    Matrix mA;
    mA.Attach(ml);

    int nCols = mA.GetNumCols();
    int nRows = mA.GetNumRows();
    double dxMin = mA.GetXMin();
    double dxMax = mA.GetXMax();
    double dyMin = mA.GetYMin();
    double dyMax = mA.GetYMax();
    
    vector vx,vy,vz;
    vx.Data(dxMin, dxMax, (dxMax-dxMin)/(nSize-1));
    vy.Data(dyMin, dyMax, (dyMax-dyMin)/(nSize-1));
    vz.SetSize(nSize);
    int nRet = ocmath_2d_interpolate(nSize, vx, vy, vz, nRows, nCols, mat,dxMin, dxMax, dyMin, dyMax,INTERP2_NEAREST);
    if (nRet != OE_NOERROR)
    {
        printf("Error occurs when calling ocmath function!\n");
        return
    }
    Worksheet    wksResult;
    wksResult.Create("InterResult");
    while(wksResult.Columns())
        wksResult.DeleteCol(0);
    for(int n=0; n < 3; n++)
        wksResult.AddCol();
    DataRange drOut;
    drOut.Add("X", wksResult, 0, 0, -1, 0);
    drOut.Add("Y", wksResult, 0, 1, -1, 1);
    drOut.Add("Z", wksResult, 0, 2, -1, 2);
    drOut.SetData(&vz, &vy, &vx);
}

Remark

Remarks: This function interpolates or extrpolates an input matrix to find Z values at given X and Y coordinates.

The interpolation algorithms are

1) Nearest, direct value of pixel that the point on the line falls into;

2) Bilinear, interpolation of 2*2 pixels around point on line

3) Bicubic Convolution, interpolation of 4*4 pixels around point on the line

4) Spline, cubic B-Spline interpolation.

5) Biquadratic, quadratic interpolation of 3*3 pixels around point on line.

6) Bicubic Lagrange, quadratic interpolation of 4*4 pixels around point on line.

The least size of input matrix is 2*2 for Nearest, 2*2 for Bilinear, 4*4 for Bicubic Convolution, 4*4 for Spline, 3*3 for Biquadratic and 4*4 for Bicubic Lagrange;

See Also

ocmath_interpolate, ocmath_3d_interpolate

Header to Include

origin.h

Reference