00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00040 #ifndef _LINEAR_ALGEBRA_H_
00041 #define _LINEAR_ALGEBRA_H_
00042
00043
00044
00045
00046
00047 class CFloatMatrix;
00048 class CFloatVector;
00049 class CDoubleMatrix;
00050 class CDoubleVector;
00051 struct Mat3d;
00052 struct Vec2d;
00053
00054
00055
00056
00057
00058
00059
00064 namespace LinearAlgebra
00065 {
00066
00067 void Zero(CFloatMatrix *pMatrix);
00068 void Zero(CFloatVector *pVector);
00069
00070 void SelfProduct(const CFloatMatrix *pMatrix, CFloatMatrix *pResultMatrix, bool AAT = false);
00071 void MulMatMat(const CFloatMatrix *A, const CFloatMatrix *B, CFloatMatrix *pResultMatrix, bool bTransposeB = false);
00072 void Transpose(const CFloatMatrix *pMatrix, CFloatMatrix *pResultMatrix);
00073
00074 void MulMatVec(const CFloatMatrix *pMatrix, const CFloatVector *pVector, CFloatVector *pResultVector);
00075 void MulMatVec(const CFloatMatrix *pMatrix, const CFloatVector *pVector1, const CFloatVector *pVector2, CFloatVector *pResultVector);
00076
00077 void AddMatMat(const CFloatMatrix *pMatrix1, const CFloatMatrix *pMatrix2, CFloatMatrix *pResultMatrix);
00078 void SubtractMatMat(const CFloatMatrix *pMatrix1, const CFloatMatrix *pMatrix2, CFloatMatrix *pResultMatrix);
00079 void AddVecVec(const CFloatVector *pVector1, const CFloatVector *pVector2, CFloatVector *pResultVector);
00080 void SubtractVecVec(const CFloatVector *pVector1, const CFloatVector *pVector2, CFloatVector *pResultVector);
00081
00082 void AddToMat(CFloatMatrix *pMatrix, const CFloatMatrix *pMatrixToAdd);
00083 void SubtractFromMat(CFloatMatrix *pMatrix, const CFloatMatrix *pMatrixToSubtract);
00084 void AddToVec(CFloatVector *pVector, const CFloatVector *pVectorToAdd);
00085 void SubtractFromVec(CFloatVector *pVector, const CFloatVector *pVectorToSubtract);
00086
00087 void SubtractMeanFromColumns(const CFloatMatrix *pMatrix, CFloatMatrix *pResultMatrix);
00088 void SubtractMeanFromRows(const CFloatMatrix *pMatrix, CFloatMatrix *pResultMatrix);
00089
00090 extern void SVD(const CFloatMatrix *A, CFloatMatrix *W, CFloatMatrix *U = 0, CFloatMatrix *V = 0,
00091 bool bAllowModifyA = false, bool bReturnUTransposed = false, bool bReturnVTransposed = false);
00092
00093
00094 bool SolveLinearLeastSquaresSimple(const CFloatMatrix *A, const CFloatVector *b, CFloatVector *x);
00095 void SolveLinearLeastSquaresSVD(const CFloatMatrix *A, const CFloatVector *b, CFloatVector *x);
00096 void SolveLinearLeastSquaresHomogeneousSVD(const CFloatMatrix *A, CFloatVector *x);
00097
00098
00099 void CalculatePseudoInverseSVD(const CFloatMatrix *pInputMatrix, CFloatMatrix *pOutputMatrix);
00100 bool CalculatePseudoInverseSimple(const CFloatMatrix *pInputMatrix, CFloatMatrix *pResultMatrix);
00101
00102
00103 bool Invert(const CFloatMatrix *pInputMatrix, CFloatMatrix *pResultMatrix);
00104
00105
00106 void PCA(const CFloatMatrix *pData, CFloatMatrix *pTransformationMatrix, CFloatMatrix *pTransformedData, int nTargetDimension);
00107 void PCA(const CFloatMatrix *pData, CFloatMatrix *pTransformationMatrix, CFloatMatrix *pEigenValues);
00108
00109
00110
00111 void Zero(CDoubleMatrix *pMatrix);
00112 void Zero(CDoubleVector *pVector);
00113
00114 void SelfProduct(const CDoubleMatrix *pMatrix, CDoubleMatrix *pResultMatrix, bool AAT = false);
00115 void MulMatMat(const CDoubleMatrix *pMatrix1, const CDoubleMatrix *pMatrix2, CDoubleMatrix *pResultMatrix, bool bTransposeB = false);
00116 void Transpose(const CDoubleMatrix *pMatrix, CDoubleMatrix *pResultMatrix);
00117
00118 void MulMatVec(const CDoubleMatrix *pMatrix, const CDoubleVector *pVector, CDoubleVector *pResultVector);
00119 void MulMatVec(const CDoubleMatrix *pMatrix, const CDoubleVector *pVector1, const CDoubleVector *pVector2, CDoubleVector *pResultVector);
00120
00121 void AddMatMat(const CDoubleMatrix *pMatrix1, const CDoubleMatrix *pMatrix2, CDoubleMatrix *pResultMatrix);
00122 void SubtractMatMat(const CDoubleMatrix *pMatrix1, const CDoubleMatrix *pMatrix2, CDoubleMatrix *pResultMatrix);
00123 void AddVecVec(const CDoubleVector *pVector1, const CDoubleVector *pVector2, CDoubleVector *pResultVector);
00124 void SubtractVecVec(const CDoubleVector *pVector1, const CDoubleVector *pVector2, CDoubleVector *pResultVector);
00125
00126 void AddToMat(CDoubleMatrix *pMatrix, const CDoubleMatrix *pMatrixToAdd);
00127 void SubtractFromMat(CDoubleMatrix *pMatrix, const CDoubleMatrix *pMatrixToSubtract);
00128 void AddToVec(CDoubleVector *pVector, const CDoubleVector *pVectorToAdd);
00129 void SubtractFromVec(CDoubleVector *pVector, const CDoubleVector *pVectorToSubtract);
00130
00131 void SubtractMeanFromColumns(const CDoubleMatrix *pMatrix, CDoubleMatrix *pResultMatrix);
00132 void SubtractMeanFromRows(const CDoubleMatrix *pMatrix, CDoubleMatrix *pResultMatrix);
00133
00134 extern void SVD(const CDoubleMatrix *A, CDoubleMatrix *W, CDoubleMatrix *U = 0, CDoubleMatrix *V = 0,
00135 bool bAllowModifyA = false, bool bReturnUTransposed = false, bool bReturnVTransposed = false);
00136
00137
00138 bool SolveLinearLeastSquaresSimple(const CDoubleMatrix *A, const CDoubleVector *b, CDoubleVector *x);
00139 void SolveLinearLeastSquaresSVD(const CDoubleMatrix *A, const CDoubleVector *b, CDoubleVector *x);
00140 void SolveLinearLeastSquaresHomogeneousSVD(const CDoubleMatrix *A, CDoubleVector *x);
00141
00142
00143 void CalculatePseudoInverseSVD(const CDoubleMatrix *pInputMatrix, CDoubleMatrix *pOutputMatrix);
00144 bool CalculatePseudoInverseSimple(const CDoubleMatrix *pInputMatrix, CDoubleMatrix *pResultMatrix);
00145
00146
00147 bool Invert(const CDoubleMatrix *pInputMatrix, CDoubleMatrix *pResultMatrix);
00148
00149
00150
00151
00152
00180 bool DetermineAffineTransformation(const Vec2d *pSourcePoints, const Vec2d *pTargetPoints, int nPoints, Mat3d &A, bool bUseSVD = false);
00181
00209 bool DetermineHomography(const Vec2d *pSourcePoints, const Vec2d *pTargetPoints, int nPoints, Mat3d &A, bool bUseSVD = false);
00210 }
00211
00212
00213
00214 #endif