2.2.4.28.7 MatrixObject::GetDataObject

Description

Access to the internal Matrix data

Syntax

matrixbase & GetDataObject( )

Parameters

Return

A referance to the matrix containing the data of Matrix window.

Examples

EX1

//This example shows how you can use matrixbase reference to access data 
//in a Matrix without knowing its internal data type
//copy data from active matrix of unknown internal data type(double, BYTE, int etc) to a new worksheet
void copy_mat_to_wks()
{
	MatrixLayer ml = Project.ActiveLayer();
	MatrixObject mobj = ml.MatrixObjects(0);

	Worksheet wks;
	wks.Create("Origin");
	//get the ref to internal data without knowing the actual internal data type
	matrixbase& mb = mobj.GetDataObject();
	mb.CopyTo(wks, 0, 0, -1, -1, 0, 0, false, false);
}

EX2

// Create an internal matrix and fill it from an existing Origin matrix window
// Start with an Origin matrix window active with values
// The sample makes internal matrices that copy the data from the existing matrix
int MatrixObject_GetDataObject_Ex1()
{
    MatrixLayer mlActive = Project.ActiveLayer();
    if(mlActive == NULL)
        return -1;
    
    mlActive.SetInternalDataType(FSI_DOUBLE);
    matrix<double> ma(mlActive.MatrixObjects(0).GetDataObject()); // copy data from matrix window
    
    matrix<double> mb;
    mb = mlActive.MatrixObjects(0).GetDataObject(); // copy data from matrix window
    ma = ma - 2 * mb; // trivial example for test : negates ma since mb==ma
    
    Matrix    mWindow(mlActive);
    mWindow = ma; // The Origin matrix now gets its values from the internal matrix
    return 0;
}

EX3

//The following example shows how to manipulate a matrix that is an imported image of 8bits gray
void MatrixObject_GetDataObject_Ex2(int nDivideFactor = 2)
{
    MatrixLayer ml = Project.ActiveLayer();
    if(!ml)
        return;
    MatrixObject mo = ml.MatrixObjects();
    if(mo.GetInternalDataType() != FSI_BYTE)
        return;

    // not to copy, but get access to the actual data
    // if mo is an image, Origin automatically prepare an internal matrix of the corret type
    // and when this copy is modified, Origin will automatically update the image.
    Matrix<BYTE>& mat = mo.GetDataObject(); 
    double min = mat.GetMin();
    double max = mat.GetMax();
    printf("before, min=%g, max=%g\n", min, max);
    mat /= nDivideFactor;
    min = mat.GetMin();
    max = mat.GetMax();
    printf("After, min=%g, max=%g\n", min, max);
}

Remark

See Also

Header to Include

origin.h