📄 matrixdata.h
字号:
/*------------------------------------------------------------------------------*
* File Name: MatrixData.h *
* Creation: TD 4-16-03 *
* Purpose: Origin C header file for Origin basic Data matrix types *
* Copyright (c) OriginLab Corp. 2002 - 2007 *
* All Rights Reserved *
* Modifications:
*------------------------------------------------------------------------------*/
#ifndef _MATRIXDATA_H
#define _MATRIXDATA_H
#ifndef _STRING_H
#include <string.h> // Most likely will need strings
#endif // _STRING_H
#ifndef _OC_TYPES_H
#include <OC_types.h> // Structures used in Origin internal functions
#endif
#ifndef _WKSHEET_H
#include <Wksheet.h>
#endif // _WKSHEET_H
#ifndef _VECTOR_H
#include <vector.h>
#endif
/////////////////////////////////////////////////////////////////////////
// matrixbase object
/** >Composite Data Types
The Origin C matrixbase class is an abstract base class used for polymorphic
handling of the matrix and Matrix template class types. Origin C objects of
type matrixbase can not be constructed. Derived classes such as matrix and
Matrix inherit matrixbase class methods and should be used instead.
*/
class matrixbase
{
protected:
/**#
Objects of type matrixbase can not be constructed. This is an abstract base
class used for polymorphic handling of all matrix and Matrix template types.
*/
matrixbase();
public:
/**
Set the size (number of columns and number of rows) in any matrixbase derived
object (e.g. matrix, Matrix).
Example:
matrix m;
int iNumRows = 7;
int iNumCols = 5;
m.SetSize( iNumRows, iNumCols ); // Set the number of rows and columns in matrix
ASSERT( m.GetNumRows() == iNumRows); // Check the number of rows is correct
ASSERT( m.GetNumCols() == iNumCols ); // Check the number of columns is correct
Parameters:
wNumRows=The number of rows in the newly sized matrix
wNumCols=The number of columns in the newly sized matrix
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::GetNumRows, matrixbase::GetNumCols
*/
BOOL SetSize(UINT wNumRows, UINT wNumCols); // Set the size of any matrixbase derived object.
/**
Get the number of rows in any matrixbase derived object (e.g. matrix, Matrix).
Example:
// Assumes Matrix1 window in Origin
Matrix mat("Matrix1");
int iNumRows;
iNumRows = mat.GetNumRows(); // Get number of rows
Return:
Returns the number of rows in this matrixbase object.
SeeAlso:
matrixbase::SetSize, matrixbase::GetNumCols
*/
UINT GetNumRows() const; // Get the number of rows in any matrixbase derived object.
/**
Get the number of columns in any matrixbase derived object (e.g. matrix, Matrix).
Example:
// Assumes Matrix1 window in Origin
Matrix mat("Matrix1");
int iNumCols;
iNumCols = mat.GetNumCols(); // Get number of columns
Return:
Returns the number of columns in this matrixbase object.
SeeAlso:
matrixbase::SetSize, matrixbase::GetNumRows
*/
UINT GetNumCols() const; // Get the number of columns in any matrixbase derived object.
/**
Pad a matrix with 0 or with adjacent cell values.
Example:
// Assumes Matrix1 and Matrix2 exist in Origin
Matrix mat1("Matrix1"), mat2("Matrix2");
mat1.Padding( mat2, 2, 1 );
Parameters:
mPadding=Output matrix with padded cells having same underlying base type of this matrix
nPadSize=Input padding width, must be larger than 0
nPaddingOption=Input padding method, 0 pads with zeroes and 1 pads with adjacent cell values
Return:
Returns TRUE on success and FALSE on failure.
*/
BOOL Padding( matrixbase &mPadding, int nPadSize, int nPaddingOption = 0 ); // Pad a matrix with 0 or with adjacent cell values.
/**
MedianFilter examines the N x N pixels centered around each pixel
of an image (matrix), finds the median value of the N x N pixels,
and then replaces the central pixel with the median value. It is a useful
filter to remove spot noise (white spots, black spots) in an
image because such noisy pixels have values way off the median value.
Sample Data:
// Matrix1 is 5 x 5 with following data
2 2 2 2 2
100 2 2 100 2
2 2 2 2 2
2 100 2 2 2
2 2 2 2 2
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.MedianFilter(3,1); // Use 3 x 3 median filter padding outside borders with adjacent cells
// Results in all cells of Matrix1 = 2
Parameters:
nWindowSize=The size of the window (N) for median filter
nPaddingOption=Pads the area outside the borders in one of the following ways
nPaddingOption=0 -- pads with zeroes
nPaddingOption=1 -- pads with values from adjacent cells
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::ApplyFilter
*/
BOOL MedianFilter(int nWindowSize, int nPaddingOption = 0); // Median filter.
/**
Takes an N x N filter (or mask) matrix and places it centered over
each pixel in this image (or matrix). For each cell in the filter/mask
it computes the product of the filter/mask element with the overlayed
cell of the original image (matrix), sums all of the products,
normalizes to the weight of the filter/mask (if specified to do so),
and then replaces the pixel in the original image with the weighted
average.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 0 0 0 0
0 2 0 0 0
2 1 2 0 0
0 2 0 0 0
0 0 0 0 0
// Matrix1 after running Example program
0 0.8 0 0 0
1.2 0.6 0.8 0 0
0.8 1.8 0.6 0.4 0
1.2 0.6 0.8 0 0
0 0.8 0 0 0
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
matrix mfilter(3,3);
mfilter = 1; // mfilter
mfilter[0][0] = 0; // 0 1 0
mfilter[2][0] = 0; // 1 1 1
mfilter[0][2] = 0; // 0 1 0
mfilter[2][2] = 0;
ASSERT( mat[2][1] == 1 ); // Before filter
// Use mfilter as mask/filter for Matrix1 padding outside borders with adjacent cells and weighting to mfilter
mat.ApplyFilter(mfilter,1);
ASSERT( mat[2][1] == 1.8 ); // After filter: (0*0+1*2+0*0+1*2+1*1+1*2+0*0+1*2+0*0)/(0+1+0+1+1+1+0+1+0)=9/5=1.8
Parameters:
matfilter=An N x N filter/mask matrix used by Applyfilter
nPaddingOption=Pads the area outside the borders in one of the following ways
nPaddingOption=0 -- pads with zeroes
nPaddingOption=1 -- pads with values from adjacent cells
bNormalize=Normalize replacement value with weight of mask/filter if TRUE
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::MedianFilter
*/
BOOL ApplyFilter(matrix &mfilter, int nPaddingOption = 0, BOOL bNormalize = TRUE); // Apply filter.
/**
Horizontally flips this matrixbase derived object about a vertical
axis through the center of the matrix. For the example below, the
first column will contain all 5's and the last column will contain
all 1's after the flip.
Sample Data:
// Matrix1 is 5 x 5 with following data
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.FlipHorizontal();
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::FlipVertical, matrixbase::Rotate, matrixbase::Reorder, matrixbase::Transpose
*/
BOOL FlipHorizontal(); // Horizontally flips this matrixbase derived object.
/**
Vertically flips this matrixbase derived object about a horizontal
axis through the center of the matrix. For the example below, the
first row will contain all 5's and the last row will contain
all 1's after the flip.
Sample Data:
// Matrix1 is 5 x 5 with following data
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.FlipVertical();
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::FlipHorizontal, matrixbase::Rotate, matrixbase::Reorder, matrixbase::Transpose
*/
BOOL FlipVertical(); // Vertically flips this matrixbase derived object.
/**
Rotates the matrix counter-clockwize by the specified angle. Angles must
be multiples of 90 degrees but can be negative. Rotating a matrix by 90
degrees has the simultaneous effect of making the first row become the
last column, the last column becomes the last row in reverse order, the
last row becomes the first column, and the first column becomes the first
row in reverse order.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
// Matrix1 after running Matrix1 after running
// Example program once Example program twice
4 5 6 7 8 8 7 6 5 4
3 4 5 6 7 7 6 5 4 3
2 3 4 5 6 6 5 4 3 2
1 2 3 4 5 5 4 3 2 1
0 1 2 3 4 4 3 2 1 0
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.Rotate(90);
Parameters:
nAngleDegree=The rotation angle in degrees, can be negative but must be a multiple
of 90 otherwise the closest multiple is used
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::FlipHorizontal, matrixbase::FlipVertical, matrixbase::Reorder, matrixbase::Transpose
*/
BOOL Rotate(int nAngleDegree = 90 ); // Rotates the matrix counter-clockwize by the specified angle.
/**
Replace all cell values less than dThresholdVal with dReplaceVal.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
// Matrix1 after running Example program
0 0 0 0 4
0 0 0 4 5
0 0 4 5 6
0 4 5 6 7
4 5 6 7 8
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.ReplaceLessThan(4,0);
Parameters:
dThresholdVal=Condition or threshold value
dReplaceVal=Replacement value
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::Replace, matrixbase::ReplaceGreaterThan
*/
BOOL ReplaceLessThan(double dThresholdVal, double dReplaceVal); // Replace all cell values less than dThresholdVal with dReplaceVal.
/**
Replace all cell values greater than dThresholdVal with dReplaceVal.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
// Matrix1 after running Example program
0 1 2 3 4
1 2 3 4 0
2 3 4 0 0
3 4 0 0 0
4 0 0 0 0
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
mat.ReplaceGreaterThan(4,0);
Parameters:
dThresholdVal=Condition or threshold value
dReplaceVal=Replacement value
Return:
Returns TRUE on success and FALSE on failure.
SeeAlso:
matrixbase::Replace, matrixbase::ReplaceLessThan
*/
BOOL ReplaceGreaterThan(double dThresholdVal, double dReplaceVal); // Replace all cell values greater than dThresholdVal with dReplaceVal.
/**
Set the values of a matrix column equal to the values of a vector. The
column is specified by a 0 based column index. If the matrix column and
vector do not have the same size then the maximum number of elements
possible are assigned from the vector to the matrix column.
Sample Data:
// Matrix1 is 5 x 5 with following data
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
// Matrix1 after running Example program
0 1 -99 3 4
1 2 -99 4 5
2 3 -99 5 6
3 4 -99 6 7
4 5 -99 7 8
Example:
// Assumes Matrix1 window in Origin with Sample Data
Matrix mat("Matrix1");
vector v = {-99,-99,-99,-99,-99};
mat.SetColumn( v, 2);
Parameters:
vb=Vector whose values are assigned to the column
nIndexCol=Specifies the 0 based offset or column index of the column in the matrix
Return:
Returns 0 if successful and the vector size matches the matrix column size,
otherwise returns the size of the matrix column minus the size of the vector.
SeeAlso:
matrixbase::GetColumn, matrixbase::SetRow, matrixbase::GetRow, matrixbase::GetAsVector, matrixbase::SetByVector
*/
int SetColumn(vectorbase &vb, UINT wIndexCol); // Set the values of a matrix column equal to the values of a vector.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -