MatrixObject::SetXY

Description

Set matrix object xy mapping coordinates

Syntax

BOOL SetXY( double dXMin, double dYMin, double dXMax, double dYMax, BOOL bUndo = FALSE )

Parameters

dXMin
[input] map 1st column (0) of matrix to this X value
dYMin
[input] map 1st row (0) of matrix to this Y value
dXMax
[input] map last column (nCols-1) of matrix to this X value
dYMax
[input] map last row (nRows-1) of matrix to this Y value
bUndo
[input] Whether to support Undo (TRUE) or not (FALSE).
Its default value is FALSE.

Return

FALSE if dXMin == dXMax or dYMin == dYMax, otherwise return TRUE

Examples

EX1

// Create a new matrix window,
//  set the number of rows and columns and the XY mapping
//  and fill the matrix
void MatrixObject_SetXY_Ex1(int nr = 32, int nc = 24, double xmin = -10, double xmax = 20, double ymin = -2.3, double ymax = 12.4)
{
   MatrixPage mp;
   mp.Create("Origin", CREATE_HIDDEN);
   MatrixLayer ml = mp.Layers();
   MatrixObject mo = ml.MatrixObjects(0);
   mo.SetSize(nr, nc);
   mo.SetXY(xmin, ymin, xmax, ymax);
   Matrix& mat = mo.GetDataObject();
   double xinc = (xmax-xmin)/nc;
   double yinc = (ymax-ymin)/nr;
   for(int ii = 0; ii < nr; ii++)
   {
       for(int jj = 0; jj < nc; jj++)
       {
           double x = xmin + xinc * jj;
           double y = ymin + yinc * ii;
           mat[ii][jj] = sin(x) + cos(y);
       }
   }
   mp.SetShow();
}

EX2

void lowpass_filter(int nRows = 512, int nCols = 640, double cutoff = 0.5, int n = 1)
{
    string strLowpassButterworth =
    "1/(1+ (sqrt(x^2+y^2)/cutoff)^(2*N))";
    
    MatrixLayer ml1 = Project.ActiveLayer();
    MatrixObject mo = ml1.MatrixObjects(0);
    double d1 = GetTickCount();
    int nErr = make_filter_2D(strLowpassButterworth, mo, nRows, nCols, cutoff, n);
    if(nErr != 0)
        out_int("err = ", nErr);    
}

int make_filter_2D(LPCSTR lpcszExpression, MatrixObject& mo, int nRows, int nCols, double cutoff, int nn)
{
    if(cutoff < 0 || cutoff > 0.5)
        return -1;
    if(nn < 1)
        return -2;
    // just incase matrix was not double, force it to be so
    mo.SetInternalData(FSI_DOUBLE, false, false);
 
    mo.SetSize(nRows, nCols, 0);// no need to restore or init to be faster
    //normaliz to +-0.5 for both rows and cols
    mo.SetXY(-0.5, -0.5, 0.5, 0.5);
    //define cutoff and nn to as LT variable
    string strBeforeScript;
    strBeforeScript.Format("cutoff=%g; \r\n n=%d;", cutoff, nn);
    string strFormula = (string)lpcszExpression + STR_COL_FORMULAR_SEPARATOR + strBeforeScript;
    mo.SetFormula(strFormula);
    mo.ExecuteFormula(0, -1, false);// disable undo to make it faster
    return 0;
}

Remark

Set matrix object xy mapping coordinates. All matrices have linearly mapped values for columns and rows.

See Also

MatrixObject::GetXY, Matrix::GetXMax, Matrix::GetYMin, Matrix::GetYMax, Matrix::SetXMin, Matrix::SetYMin, Matrix::SetXMax, Matrix::SetYMax

header to Include

origin.h