SIBCMatrix33d.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Softimage 3D Games & 3D Bridge team
00004 //
00005 // (c) Copyright 1999-2002 Avid Technology, Inc. . All rights reserved.
00006 //
00007 // SIBCMatrix33d.h | Main header file for SIBCMatrix33d implementation
00008 //***************************************************************************************
00009 
00010 /****************************************************************************************
00011 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00012 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE
00013 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00014 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00016 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE .
00017 
00018 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00019 
00020 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00021 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00022 trademarks contained herein are the property of their respective owners. 
00023 ****************************************************************************************/
00024 
00025 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00026 #pragma once
00027 #endif
00028 
00029 //******************************************************************************
00030 //
00031 // Defines
00032 //
00033 //******************************************************************************
00034 #ifndef _MATRIX33_H_
00035 #define _MATRIX33_H_
00036 
00037 //******************************************************************************
00038 //
00039 // Includes
00040 //
00041 //******************************************************************************
00042 #include "SIBCMathLib.h"
00043 
00044 //******************************************************************************
00045 //
00046 // CSIBCMatrix33d | General 3X3 matrix.
00047 //
00048 //******************************************************************************
00049 
00051 
00063 class XSICOREEXPORT CSIBCMatrix33d
00064 {
00065     // Public members
00066     public:
00067 
00068         //****************************************
00069         // Constructors/destructor:
00070         //****************************************
00071 
00076         CSIBCMatrix33d( void );
00077 
00088         CSIBCMatrix33d( 
00089             const CSIBCVector3Dd& in_vct0,
00090             const CSIBCVector3Dd& in_vct1,
00091             const CSIBCVector3Dd& in_vct2,
00092             const bool in_bAreRows = true );
00093 
00106         CSIBCMatrix33d( 
00107             const double in_dA00, const double in_dA01, const double in_dA02, 
00108             const double in_dA10, const double in_dA11, const double in_dA12, 
00109             const double in_dA20, const double in_dA21, const double in_dA22 );
00110 
00121         CSIBCMatrix33d( int in_nRow, int in_nCol, const CSIBCMatrix44d& in_mat );
00122 
00123 
00124         // Destructor.
00125         ~CSIBCMatrix33d();
00126 
00127         //****************************************
00128         // General access functions:
00129         //****************************************
00130 
00137         double Get( const int in_nRow, const int in_nCol ) const;
00138 
00139         //****************************************
00140         // Matrix element modification functions:
00141         //****************************************
00142         
00153         CSIBCMatrix33d& Set( int in_nRow, int in_nCol, const double in_dVal );
00154 
00171         CSIBCMatrix33d& Set( 
00172             const double in_dA00, const double in_dA01, const double in_dA02, 
00173             const double in_dA10, const double in_dA11, const double in_dA12, 
00174             const double in_dA20, const double in_dA21, const double in_dA22 );
00175 
00185         CSIBCMatrix33d& Set( double in_dVal[3][3] );
00186 
00195         CSIBCMatrix33d& Set( const CSIBCMatrix33d& in_mat );
00196 
00208         CSIBCMatrix33d& Set( int in_nRow, int in_nCol, const CSIBCMatrix44d& in_mat );
00209 
00219         CSIBCMatrix33d& SetRow( const int in_nRow, const CSIBCVector3Dd& in_vct );
00220 
00231         CSIBCMatrix33d& SetRow( const int in_nRow, double in_dA0, double in_dA1, double in_dA2 );
00232 
00242         CSIBCMatrix33d& SetCol( const int in_nCol, const CSIBCVector3Dd& in_vct );
00243 
00254         CSIBCMatrix33d& SetCol( const int in_nCol, double in_dA0, double in_dA1,    double in_dA2 );
00255 
00261         CSIBCMatrix33d& SetNull();
00262 
00268         CSIBCMatrix33d& SetIdentity();
00269 
00270         //****************************************
00271         // Matrix comparison functions:
00272         //****************************************
00273 
00284         friend bool AreAlmostEqual( const CSIBCMatrix33d& in_mat1,
00285             const CSIBCMatrix33d& in_mat2, const double in_dEpsilon = PICO_EPS );
00286 
00294         bool operator ==( const CSIBCMatrix33d& in_mat ) const;
00295 
00303         bool operator !=( const CSIBCMatrix33d& in_mat ) const;
00304 
00314         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
00315 
00325         bool IsSingular( const double in_dEpsilon=PICO_EPS ) const;
00326 
00335         bool IsSymmetric( const double in_dEpsilon=PICO_EPS ) const;
00336 
00337         //****************************************
00338         // Matrix algebra functions:
00339         //****************************************
00340 
00348         CSIBCMatrix33d& Add( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
00349 
00356         CSIBCMatrix33d& Add( const CSIBCMatrix33d& in_mat );
00357 
00365         CSIBCMatrix33d& Sub( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
00366 
00374         CSIBCMatrix33d& Sub( const CSIBCMatrix33d& in_mat );
00375 
00386         CSIBCMatrix33d& Mul( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
00387 
00397         CSIBCMatrix33d& Mul( const CSIBCMatrix33d& in_mat );
00398 
00409         CSIBCMatrix33d& MulTransByReg( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
00410 
00421         CSIBCMatrix33d& MulRegByTrans( const CSIBCMatrix33d& in_mat1, const CSIBCMatrix33d& in_mat2 );
00422 
00429         CSIBCMatrix33d& Negate( const CSIBCMatrix33d& in_mat );
00430 
00436         CSIBCMatrix33d& Negate();
00437         
00446         CSIBCMatrix33d& Mul( const double in_dFactor, const CSIBCMatrix33d& in_mat );
00447 
00456         CSIBCMatrix33d& Mul( const CSIBCMatrix33d& in_mat, const double in_dFactor );
00457 
00464         CSIBCMatrix33d& Mul( const double in_dFactor );
00465 
00474         CSIBCMatrix33d& Div( const CSIBCMatrix33d& in_mat, const double in_dFactor );
00475 
00482         CSIBCMatrix33d& Div( const double in_dFactor );
00483 
00489         double GetDet( void ) const;
00490 
00495         double GetTrace( void ) const;
00496 
00504         CSIBCMatrix33d& Transpose( const CSIBCMatrix33d& in_mat );
00505 
00511         CSIBCMatrix33d& Transpose( void );
00512 
00520         bool Invert( const CSIBCMatrix33d& in_mat );
00521 
00528         bool Invert( void );
00529 
00538         bool TransposeInverse( const CSIBCMatrix33d& in_mat );
00539 
00547         bool TransposeInverse( void );
00548 
00554         CSIBCMatrix33d& Adjoint( const CSIBCMatrix33d& in_mat );
00555 
00560         CSIBCMatrix33d& Adjoint( void );
00561 
00569         bool GetEigenVectors( CSIBCMatrix33d& out_matEigenVectors, CSIBCVector3Dd& out_vctEigenValues, const double in_dEps=PICO_EPS ) const;
00570 
00571         //****************************************
00572         // Utility functions:
00573         //****************************************
00574 
00575         //****************************************
00576         // To be implemented later:
00577         //****************************************
00578 
00579         // Set this matrix to the symmetrical of the input matrix.
00581         CSIBCMatrix33d& Symmetry( CSIBCMatrix33d& in_mat ) const;
00582         
00583         // Set this matrix to its symmetrical.
00585         CSIBCMatrix33d& Symmetry( void ) const;
00586 
00587         // Set this matrix to the product of V1^T and V2.
00589         void SetOuterProduct( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00590 
00591     // Protected members
00592     protected:
00593 
00594         //****************************************
00595         // Protected data
00596         //****************************************
00597         // double[3][3] | CSIBCMatrix33d | m_dMat | Matrix itself.
00598         double m_dMat[3][3];
00599 
00600         //****************************************
00601         // Utility functions:
00602         //****************************************
00603 
00604         // Computes the inverse of a matrix.
00605         bool ComputeInverse( const double in_dMat[3][3], double out_dInv[3][3], 
00606                 const bool in_bTransposeResult=false, const double in_dDetMin=PICO_EPS ) const;
00607         // Computes the adjoint of a matrix.
00608         void ComputeAdjoint( const double in_dMat[3][3], double out_dAdj[3][3] ) const;
00609         
00610         // Computes the determinant of a matrix given its adjoint.
00611         double ComputeDetFast( double in_dMat[3][3], double in_dAdj[3][3] ) const;
00612         
00613         // Compute the determinant of a matrix and compute a measure of its scale (max. order of magnitude).
00614         void ComputeDetAndDetSize( const double in_dMat[3][3], 
00615                 double &out_dDet, double &out_dDetSize ) const;
00616         // Computes eigenvalues and eigenvectors of a symmetric matrix
00617         bool ComputeEigen( const double in_dMat[3][3], double out_dMatEigenVectors[3][3], CSIBCVector3Dd &out_vctEigenValues,
00618                 const double in_dEps=PICO_EPS ) const;
00619 };
00620 
00621  
00622 #endif
00623