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

📄 omat.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
	Tree trDMC;
	trDMC.Reset();
	trDMC.AddNode("SelRange");
	trDMC.AddNode("xVariesAcrossCols");
	trDMC.AddNode("xInRow1");
	trDMC.AddNode("yInCol1");
	trDMC.AddNode("xInCol1");
	trDMC.AddNode("yInRow1");

	// *** Initialize node values ***
	InitDirectMatConvertTree(trDMC);

	return trDMC;
}

/**
		Initialize a DirectMatConvert tree.
	Parameters:
		trDMC=DirectMatConvert tree to initialize
	Return:
		Returns an initialized DirectMatConvert tree by reference.
*/
BOOL InitDirectMatConvertTree(Tree& trDMC)
{
	// *** Set tree nodes ***
	trDMC.SelRange.strVal = "";
	trDMC.xVariesAcrossCols.nVal = 1;
	trDMC.xInRow1.nVal = 0;
	trDMC.yInCol1.nVal = 0;
	trDMC.xInCol1.nVal = 0;
	trDMC.yInRow1.nVal = 0;

	return TRUE;
}

/**
		HLOC function to perfrom conditional replace on an internal Origin matrix.
	Example:
		See the OnClickReplace function in OMatDlgMR.c for a sample call.
	Parameters:
		trMR=Input MatrixReplace tree containing all dialog settings
	Return:
		Returns MR_NO_ERROR or a MR_ERROR code on failure.
*/
int MatrixReplace(Tree& trMR)
{
	PageBase pbActiveWindow;
	MatrixLayer ml;
	Matrix mat;
	WorksheetPage wpUndo;
	Worksheet wksUndo;
	Column colUndo;
	Dataset dsUndo;
	int iUndoColNum;
	uint wBitwiseOption;
	BOOL bUndo;
	string strMatrixName;
	
	waitCursor wcCursor;                            // Put up an hour glass
	bUndo = FALSE;                                  // Init to FALSE

	// *** Get bitwise option value ***
	wBitwiseOption = trMR.ConditionSign.nVal + 1;              // nVal (adjusted for 0 based offeset) is same as wBitwiseOption
	if(wBitwiseOption>6) wBitwiseOption+=2;                    // Except must add 2 if Choice > 6 to set Bit 3 for absolute value
	wBitwiseOption += 16 * trMR.ReplaceSign.nVal;              // And must add 16 to keep original sign when replacing 
	wBitwiseOption += 32 * trMR.ReplaceMissingValue.nVal;      // And must add 32 to set to missing value when not replacing

	// *** If using abs value function with negative or missing condition value in Condition tell user and return *** 
	if( ( wBitwiseOption & 8 ) && ( trMR.ConditionValue.dVal < 0 ) )
	{
		MessageBox(NULL, _L(MR_ABS_COND_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONEXCLAMATION);
		return MR_ABS_COND_ERROR;
	}		

	// *** Get active matrix ***
	pbActiveWindow = Project.Pages();               // Get active page (window)
	if( !pbActiveWindow.IsValid() )                 // If not valid...
	{
		MessageBox(NULL, _L(MR_ACT_MAT_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONSTOP);
		return MR_ACT_MATRIX_ERROR;                 // Output error message and return error code
	}
	
	if( pbActiveWindow.GetType() != EXIST_MATRIX )  // If window is not a matrix...
	{
		MessageBox(NULL, _L(MR_ACT_MAT_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONSTOP);
		return MR_ACT_MATRIX_ERROR;                 // Output error message and return error code
	}
	
	strMatrixName = pbActiveWindow.GetName();       // Get name of active matrix

	ml = (MatrixLayer) Project.ActiveLayer();       // Get active matrix layer
	if( !ml.IsValid() )                             // If not valid...
	{
		MessageBox(NULL, _L(MR_ACT_MAT_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONSTOP);
		return MR_ACT_MATRIX_ERROR;                 // Output error message and return error code
	}

	mat.Attach(ml);                                 // Attach to matrix
	if( !mat.IsValid() )                            // If not valid...
	{
		MessageBox(NULL, _L(MR_ACT_MAT_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONSTOP);
		return MR_ACT_MATRIX_ERROR;                 // Output error message and return error code
	}
	
	// *** Save Original matrix values in Matrix Replace Undo worksheet column ***
	wpUndo = Project.WorksheetPages(MR_UNDO_WKS_NAME);      // Attach to worksheet page
	if( !wpUndo.IsValid() )                         // If not valid (page does not exist) then create
	{
		wpUndo.Create("0", CREATE_HIDDEN);          // Create hidden worksheet from no template
		wpUndo.Rename(MR_UNDO_WKS_NAME);                    // Rename worksheet page MRUndo
	}

	wksUndo = (Worksheet) wpUndo.Layers();          // Attach to worksheet (layer)
	if( !wksUndo.IsValid() )                        // If not valid...
	{
		if( MessageBox(NULL, _L(MR_UNDO_WARNING_MSG), _L(MR_TITLE), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDNO )
			return MR_NO_UNDO_QUIT_ERROR;           // Ask user to continue and return if answer is No
	}
	else
	{
		colUndo = wksUndo.Columns(strMatrixName);   // Attach to column for active matrix
		if( !colUndo.IsValid() )                    // If not valid (column does not exist)...
			iUndoColNum = wksUndo.AddCol(strMatrixName);// Add column and get column number
		else
			iUndoColNum = colUndo.GetIndex();       // Else just get column number
		
		dsUndo.Attach(wksUndo, iUndoColNum);        // Attach Dataset to Undo column
		if( !dsUndo.IsValid() )                     // If not valid...
		{
			if( MessageBox(NULL, _L(MR_UNDO_WARNING_MSG), _L(MR_TITLE), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDNO )
				return MR_NO_UNDO_QUIT_ERROR;       // Ask user to continue and return if answer is No
		}
		else
		{
			if( !mat.GetAsVector(dsUndo) )          // Copy matrix to Undo Dataset...if not valid...
			{
				if( MessageBox(NULL, _L(MR_UNDO_WARNING_MSG), _L(MR_TITLE), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDNO )
					return MR_NO_UNDO_QUIT_ERROR;           // Ask user to continue and return if answer is No
			}
			else
				bUndo = TRUE;                       // Enable restorative Undo
		}
	}

	// *** Replace matrix values ***
	if( !mat.Replace(trMR.ConditionValue.dVal, trMR.ReplaceValue.dVal, wBitwiseOption) ) // If matrix replace fails...
	{
		if( bUndo ) // If Undo is enabled...
		{
			if( !mat.SetByVector(dsUndo) )		// If Undo Matrix Replace is successful...
			{
				MessageBox(NULL, _L(MR_FAILED_UNDO_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONSTOP); // Output an error message
				return MR_FAILED_ERROR;             // And return error code
			}
		}

		// Else, if there is no Undo or if Undo is not successful...
		MessageBox(NULL, _L(MR_FAILED_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONSTOP); // Output an error message
		return MR_FAILED_ERROR;                 	// And return error code
	}
	
	return MR_NO_ERROR;                             // Everything went well
}

/**
		HLOC to undo matrix replace.
	Example:
		iRet = UndoMatrixReplace();
	Return:
		Returns MR_NO_ERROR on success or MR_UNDO_FAILED_ERROR on failure.
*/
int UndoMatrixReplace()
{
	PageBase pbActiveWindow;
	MatrixLayer ml;
	Matrix mat;
	WorksheetPage wpUndo;
	Worksheet wksUndo;
	Column colUndo;
	Dataset dsUndo;
	string strMatrixName;
	int iColNum;

	waitCursor wcCursor; // Put up an hour glass

	pbActiveWindow = Project.Pages(); // Get active page
	if( pbActiveWindow.IsValid() )
	{
		// If page is valid...
		if( pbActiveWindow.GetType() == EXIST_MATRIX )
		{
			// If page type is matrix...
			strMatrixName = pbActiveWindow.GetName(); // Get matrix name

			ml = (MatrixLayer) Project.ActiveLayer(); // Get active matrix layer
			if( ml.IsValid() )
			{
				// If matrix layer is valid...
				mat.Attach(ml); // Attach to matrix
				if( mat.IsValid() )
				{
					// If matrix is valid...
					wpUndo = Project.WorksheetPages(MR_UNDO_WKS_NAME); // Get Undo worksheet page
					if( wpUndo.IsValid() )
					{
						// If worksheet page is valid...
						wksUndo = (Worksheet) wpUndo.Layers(); // Get Undo worksheet (layer)
						if( wksUndo.IsValid() )
						{
							// If worksheet is valid...
							colUndo = wksUndo.Columns(strMatrixName); // Get Undo column
							if( colUndo.IsValid() )
							{
								// If column is valid...
								dsUndo.Attach(colUndo); // Get Undo dataset
								if( dsUndo.IsValid() )
								{
									// If dataset is valid...
									if( dsUndo.GetSize() == mat.GetNumRows() * mat.GetNumCols() )
									{
										// If dataset has same number of cells as matrix...
										if( !mat.SetByVector(dsUndo) )
										{
											// Refresh page before message box
											ml.GetPage().Refresh(TRUE);
											
											// If Undo Matrix Replace is successful...
											iColNum = colUndo.GetIndex(); // Get index of undo column
											if( iColNum > 0 )
												wksUndo.DeleteCol(iColNum); // Delete column if found
											
											MessageBox(NULL, _L(MR_UNDO_SUCCESS_MSG), _L(MR_TITLE), MB_OK | MB_ICONASTERISK); 
											return MR_NO_ERROR; // Success!
										}	// End Undo Matrix Replace is successful
									}	// End same number of cells
								}	// End dataset is valid
							}	// End column is valid
						}	// End worksheet is valid
					}	// End worksheet page is valid
				}	// End matrix is valid
			}	// End matrix layer is valid
		}	// End page type is matrix
	}	// End page is valid
	
	// Else (for all ifs)...	
	MessageBox(NULL, _L(MR_UNDO_FAILED_ERROR_MSG), _L(MR_TITLE), MB_OK | MB_ICONSTOP);
	return MR_UNDO_FAILED_ERROR; // Failure
}	// End Undo Matrix Replace

/**
		Create and initialize a MatrixReplace tree.
	Return:
		Returns a newly created MatrixReplace tree.
*/
Tree CreateMatrixReplaceTree()
{
	// *** Create tree and nodes ***
	Tree trMR;
	trMR.Reset();
	trMR.AddNode("ConditionSign");
	trMR.AddNode("ConditionValue");
	trMR.AddNode("ReplaceValue");
	trMR.AddNode("ReplaceSign");
	trMR.AddNode("ReplaceMissingValue");

	// *** Initialize node values ***
	InitMatrixReplaceTree(trMR);

	return trMR;
}

/**
		Initialize a MatrixReplace tree.
	Parameters:
		trMR=MatrixReplace tree to initialize
	Return:
		Returns an initialized MatrixReplace tree by reference.
*/
BOOL InitMatrixReplaceTree(Tree& trMR)
{
	// *** Set tree nodes ***
	trMR.ConditionSign.nVal = 1;
	trMR.ConditionValue.dVal = NANUM;
	trMR.ReplaceValue.dVal = 0.0;
	trMR.ReplaceSign.nVal = 0;
	trMR.ReplaceMissingValue.nVal = 0;

	return TRUE;
}

⌨️ 快捷键说明

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