⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrixobj.cpp

📁 图像处理的压缩算法
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return FALSE; // LabTalk command error

	double dXYMaxMin[4];
	myMatrix.GetMatrixXY(dXYMaxMin);
	dValue = dXYMaxMin[3]; // YMax is the fourth element

	return TRUE; // LabTalk command succeeded
}

//---------------------------------------------------------------------------
// CMatrixDemo::MethodGetValue
//
//---------------------------------------------------------------------------
BOOL CMatrixDemo::MethodGetValue(double &dReturn, CStringArray &argarray)
{
	dReturn = NANUM;

	// Method requires 3 arguments: matrix name, row index, and column index
	if( argarray.GetSize() != 3 )
		return FALSE; // LabTalk command error

	// Get and check matrix name
	CString strMatrixName = argarray[0];
	if( strMatrixName.IsEmpty() )
		strMatrixName = m_MatrixName;

	// Create a reference to a matrix by name
	MoMatrix myMatrix(strMatrixName);
	if( !myMatrix.IsValid() )
	{
		MessageBox(NULL, "GetValue method received invalid matrix", "MOCA Matrix Example", MB_OK);
		return FALSE; // LabTalk command error
	}

	// Get and check the row and column index
	int iRowIndex = LabTalkStr2int(argarray[1]); 
	int iColumnIndex = LabTalkStr2int(argarray[2]); 
	if( iRowIndex <= 0 || iColumnIndex <= 0 )
		return FALSE; // LabTalk command error

	// Return the cell's value to LabTalk
	dReturn = myMatrix(iRowIndex - 1, iColumnIndex - 1);

	return TRUE; // LabTalk command succeeded
}

//---------------------------------------------------------------------------
// CMatrixDemo::MethodSetValue
//
//---------------------------------------------------------------------------
BOOL CMatrixDemo::MethodSetValue(double &dReturn, CStringArray &argarray)
{
	dReturn = NANUM;

	// Method requires 4 arguments: matrix name, row index, column index, value
	if( argarray.GetSize() != 4 )
		return FALSE; // LabTalk command error

	// Get and check matrix name
	CString strMatrixName = argarray[0];
	if( strMatrixName.IsEmpty() )
		strMatrixName = m_MatrixName;

	// Create a reference to a matrix by name
	MoMatrix myMatrix(strMatrixName);
	if( !myMatrix.IsValid() )
	{
		MessageBox(NULL, "SetValue method received invalid matrix", "MOCA Matrix Example", MB_OK);
		return FALSE; // LabTalk command error
	}

	// Get and check the row and column index
	int iRowIndex = atoi(argarray[1]); 
	int iColumnIndex = atoi(argarray[2]); 
	if( iRowIndex <= 0 || iColumnIndex <= 0 )
		return FALSE; // LabTalk command error

	// Get the value and set the matrix cell
	double dValue = atof(argarray[3]); 
	myMatrix.SetVal(iRowIndex - 1, iColumnIndex - 1, dValue);
	
	dReturn = 0;

	return TRUE; // LabTalk command succeeded
}

//---------------------------------------------------------------------------
// CMatrixDemo::MethodGetRows
//
//---------------------------------------------------------------------------
BOOL CMatrixDemo::MethodGetRows(double &dReturn, CStringArray &argarray)
{
	dReturn = NANUM;

	// Method requires 1 arguments: matrix name
	if( argarray.GetSize() != 1 )
		return FALSE; // LabTalk command error

	// Get and check matrix name
	CString strMatrixName = argarray[0];
	if( strMatrixName.IsEmpty() )
		strMatrixName = m_MatrixName;

	// Create a reference to a matrix by name
	MoMatrix myMatrix(strMatrixName);
	if( !myMatrix.IsValid() )
	{
		MessageBox(NULL, "GetRows method received invalid matrix", "MOCA Matrix Example", MB_OK);
		return FALSE; // LabTalk command error
	}

	// Return the number of rows to LabTalk
	dReturn = myMatrix.nRows();

	return TRUE; // LabTalk command succeeded
}

//---------------------------------------------------------------------------
// CMatrixDemo::MethodGetColumns
//
//---------------------------------------------------------------------------
BOOL CMatrixDemo::MethodGetColumns(double &dReturn, CStringArray &argarray)
{
	dReturn = NANUM;

	// Method requires 1 arguments: matrix name
	if( argarray.GetSize() != 1 )
		return FALSE; // LabTalk command error

	// Get and check matrix name
	CString strMatrixName = argarray[0];
	if( strMatrixName.IsEmpty() )
		strMatrixName = m_MatrixName;

	// Create a reference to a matrix by name
	MoMatrix myMatrix(strMatrixName);
	if( !myMatrix.IsValid() )
	{
		MessageBox(NULL, "GetColumns method received invalid matrix", "MOCA Matrix Example", MB_OK);
		return FALSE; // LabTalk command error
	}

	// Return the number of columns to LabTalk
	dReturn = myMatrix.nCols();

	return TRUE; // LabTalk command succeeded
}

//---------------------------------------------------------------------------
//CMatrixDemo::MethodSetDims
//
//---------------------------------------------------------------------------
BOOL CMatrixDemo::MethodSetDims(double &dReturn, CStringArray &argarray)
{
	dReturn = NANUM;

	// Method requires 3 arguments: matrix name, x dim, y dim
	if( argarray.GetSize() != 3 )
		return FALSE; // LabTalk command error

	// Get and check matrix name
	CString strMatrixName = argarray[0];
	if( strMatrixName.IsEmpty() )
		strMatrixName = m_MatrixName;

	// Create a reference to a matrix by name
	MoMatrix myMatrix(strMatrixName);
	if( !myMatrix.IsValid() )
	{
		MessageBox(NULL, "SetDims method received invalid matrix", "MOCA Matrix Example", MB_OK);
		return FALSE; // LabTalk command error
	}

	// Get and check the X and Y dimensions
	int iXDim = atoi(argarray[1]); 
	int iYDim = atoi(argarray[2]); 
	if( iXDim <= 0 || iYDim <= 0 )
		return FALSE; // LabTalk command error

	// Set the dimensions of the matrix to (x dim * y dim)
	myMatrix.SetDim(iXDim, iYDim);
	
	dReturn = 0;

	return TRUE; // LabTalk command succeeded
}

//---------------------------------------------------------------------------
//CMatrixDemo::MethodSetXY
//
//---------------------------------------------------------------------------
BOOL CMatrixDemo::MethodSetXY(double &dReturn, CStringArray &argarray)
{
	dReturn = NANUM;

	// Method requires 5 arguments: matrix name, x min, y min, x max, y max
	if( argarray.GetSize() != 5 )
		return FALSE; // LabTalk command error

	// Get and check matrix name
	CString strMatrixName = argarray[0];
	if( strMatrixName.IsEmpty() )
		strMatrixName = m_MatrixName;

	// Create a reference to a matrix by name
	MoMatrix myMatrix(strMatrixName);
	if( !myMatrix.IsValid() )
	{
		MessageBox(NULL, "SetXY method received invalid matrix", "MOCA Matrix Example", MB_OK);
		return FALSE; // LabTalk command error
	}

	// Get and check the X and Y range values
	double dXY[4];
	for( int i = 1; i <= 4; i++ )
	{
		dXY[i - 1] = atof(argarray[i]);
		if( dXY[i - 1] < 0 )
			return FALSE; // LabTalk command error
	}

	// Set the X and Y range for plotting
	myMatrix.SetXY(dXY);
	
	dReturn = 0;

	return TRUE; // LabTalk command succeeded
}

// test setting matrix values using direct assignment
// ma.fill(); init to some values and set datatype to short
BOOL CMatrixDemo::MethodFillValues(double &dReturn, CStringArray &argarray)
{
	MoMatrix mm(m_MatrixName);
	if( !mm.IsValid() )
	{
		MessageBox(NULL, "MethodFillValues method received invalid matrix", "MOCA Matrix Example", MB_OK);
		return FALSE; // LabTalk command error
	}
	OCELL_VALUE	cell;

	if(argarray.GetSize() == 0) // no arguemnt, init matrix
	{
		mm.SetInternalDataType(2); // set to short int
		cell.wFlags = OCV_SET | OCV_NO_CHK_BOUND;
		for(UINT ii = 0; ii < mm.nCols(); ii++)
			for(UINT jj = 0; jj < mm.nRows(); jj++)
			{
				cell.sValue = jj+3*ii;
				//mm.SetVal(jj, ii, value);
				cell.index = mm.GetInternalIndex(jj, ii);
				mm.DirectValue(&cell);
			}
	}
	else   // just need one argument, a number to add to each cell
	{
		int AddAmount = atoi(argarray[0]); 
		for(UINT ii = 0; ii < mm.nCols(); ii++)
			for(UINT jj = 0; jj < mm.nRows(); jj++)
			{
				cell.index = mm.GetInternalIndex(jj, ii);
				cell.wFlags = OCV_NO_CHK_BOUND;
				mm.DirectValue(&cell);
				cell.sValue += AddAmount;
				cell.wFlags = OCV_SET | OCV_NO_CHK_BOUND;
				mm.DirectValue(&cell);
			}
	}
	dReturn = 0;
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -