SIBCMatrix44d.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 // SIBCMatrix44d.h | Main header file for SIBCMatrix44d 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 // Defines
00031 //******************************************************************************
00032 #ifndef _MATRIX44_H_
00033 #define _MATRIX44_H_
00034 
00035 //******************************************************************************
00036 // Includes
00037 //******************************************************************************
00038 #include <assert.h>
00039 #include "SIBCMathLib.h"
00040 
00041 #define _3D_NB_BITS_RESERVED_BY_MAT44 (unsigned char)1  //This number must represent the number of bits flags in m_MaskInfo 
00042                                                         //reserved for the specific usage of CSIBCMatrix44d
00043 
00044 //******************************************************************************
00045 //
00046 // CSIBCMatrix44d | General 4X4 matrix.
00047 //
00048 //******************************************************************************
00049 
00051 
00060 class XSICOREEXPORT CSIBCMatrix44d
00061 {
00062     public:
00063 
00064         //****************************************
00065         // Constructors/destructor:
00066         //****************************************
00067 
00072         CSIBCMatrix44d( void );
00073 
00085         CSIBCMatrix44d( 
00086             const CSIBCVector4Dd& in_vct0,
00087             const CSIBCVector4Dd& in_vct1,
00088             const CSIBCVector4Dd& in_vct2,
00089             const CSIBCVector4Dd& in_vct3,
00090             const bool in_bAreRows = true );
00091 
00111         CSIBCMatrix44d(
00112             const double in_dA00, const double in_dA01, const double in_dA02, const double in_dA03,
00113             const double in_dA10, const double in_dA11, const double in_dA12, const double in_dA13,
00114             const double in_dA20, const double in_dA21, const double in_dA22, const double in_dA23,
00115             const double in_dA30, const double in_dA31, const double in_dA32, const double in_dA33 );
00116 
00117         // Destructor.
00118         ~CSIBCMatrix44d();
00119 
00120         //****************************************
00121         // General access functions:
00122         //****************************************
00123 
00130         double Get( const int in_nRow, const int in_nCol ) const;
00131 
00132         //****************************************
00133         // Matrix element modification functions:
00134         //****************************************
00135 
00146         CSIBCMatrix44d& Set( int in_nRow, int in_nCol, const double in_dVal );
00147 
00171         CSIBCMatrix44d& Set(
00172             const double in_dA00, const double in_dA01, const double in_dA02, const double in_dA03,
00173             const double in_dA10, const double in_dA11, const double in_dA12, const double in_dA13,
00174             const double in_dA20, const double in_dA21, const double in_dA22, const double in_dA23,
00175             const double in_dA30, const double in_dA31, const double in_dA32, const double in_dA33 );
00176 
00177 
00187         CSIBCMatrix44d& Set( const double in_dArray[4][4] );
00188 
00198         CSIBCMatrix44d& Set( const double *in_dPtr ) 
00199         {
00200             return Set( (const double (*)[4] ) in_dPtr );
00201         };
00202 
00203         
00212         CSIBCMatrix44d& Set( const CSIBCMatrix44d& in_mat );
00213 
00223         CSIBCMatrix44d& SetRow( const int in_nRow, const CSIBCVector4Dd& in_vct );
00224 
00236         CSIBCMatrix44d& SetRow( const int in_nRow, double in_dA0, double in_dA1, 
00237             double in_dA2, double in_dA3 );
00238 
00248         CSIBCMatrix44d& SetCol( const int in_nCol, const CSIBCVector4Dd& in_vct );
00249 
00261         CSIBCMatrix44d& SetCol( const int in_nCol, double in_dA0, double in_dA1,
00262             double in_dA2, double in_dA3 );
00263 
00269         CSIBCMatrix44d& SetNull();
00270 
00276         CSIBCMatrix44d& SetIdentity();
00277 
00278         //****************************************
00279         // Matrix comparison functions:
00280         //****************************************
00281 
00292         friend bool AreAlmostEqual( const CSIBCMatrix44d& in_mat1,
00293             const CSIBCMatrix44d& in_mat2, const double in_dEpsilon = PICO_EPS );
00294 
00302         bool operator ==( const CSIBCMatrix44d& in_mat ) const;
00303 
00311         bool operator !=( const CSIBCMatrix44d& in_mat ) const;
00312 
00322         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
00323 
00324         //****************************************
00325         // Matrix algebra functions:
00326         //****************************************
00327         
00335         CSIBCMatrix44d& Add( const CSIBCMatrix44d& in_mat1, const CSIBCMatrix44d& in_mat2 );
00336 
00343         CSIBCMatrix44d& Add( const CSIBCMatrix44d& in_mat );
00344 
00352         CSIBCMatrix44d& Sub( const CSIBCMatrix44d& in_mat1, const CSIBCMatrix44d& in_mat2 );
00353 
00361         CSIBCMatrix44d& Sub( const CSIBCMatrix44d& in_mat );
00362 
00373         CSIBCMatrix44d& Mul( const CSIBCMatrix44d& in_mat1, const CSIBCMatrix44d& in_mat2 );
00374 
00384         CSIBCMatrix44d& Mul( const CSIBCMatrix44d& in_mat );
00385 
00396         CSIBCMatrix44d& MulTransByReg( const CSIBCMatrix44d& in_mat1, const CSIBCMatrix44d& in_mat2 );
00397 
00408         CSIBCMatrix44d& MulRegByTrans( const CSIBCMatrix44d& in_mat1, const CSIBCMatrix44d& in_mat2 );
00409 
00416         CSIBCMatrix44d& Negate( const CSIBCMatrix44d& in_mat );
00417 
00423         CSIBCMatrix44d& Negate();
00424 
00433         CSIBCMatrix44d& Mul( const double in_dFactor, const CSIBCMatrix44d& in_mat );
00434 
00443         CSIBCMatrix44d& Mul( const CSIBCMatrix44d& in_mat, const double in_dFactor );
00444 
00451         CSIBCMatrix44d& Mul( const double in_dFactor );
00452 
00461         CSIBCMatrix44d& Div( const CSIBCMatrix44d& in_mat, const double in_dFactor );
00462 
00469         CSIBCMatrix44d& Div( const double in_dFactor );
00470 
00476         double GetDet( void ) const;
00477 
00486         double GetDet( int in_nRow, int in_nCol ) const;
00487 
00492         double GetTrace( void ) const;
00493 
00500         CSIBCMatrix44d& Transpose( const CSIBCMatrix44d& in_mat );
00501 
00507         CSIBCMatrix44d& Transpose( void );
00508 
00516         bool Invert( const CSIBCMatrix44d& in_mat );
00517 
00524         bool Invert( void );
00525 
00534         bool TransposeInverse( const CSIBCMatrix44d& in_mat );
00535 
00543         bool TransposeInverse( void );
00544 
00545         //****************************************
00546         // Utility functions:
00547         //****************************************
00548 
00549         //****************************************
00550         // To be implemented later:
00551         //****************************************
00552 
00553         // Set this matrix to the symmetrical of the input matrix.
00555         CSIBCMatrix44d& Symmetry( CSIBCMatrix44d& in_mat ) const;
00556 
00557         // Set this matrix to its symmetrical.
00559         CSIBCMatrix44d& Symmetry( void ) const;
00560 
00561         // Set this matrix to the adjoint of the input matrix.
00563         CSIBCMatrix44d& Adjoint( CSIBCMatrix44d& in_mat ) const;
00564 
00565         // Set this matrix to its adjoint.
00567         CSIBCMatrix44d& Adjoint( void ) const;
00568 
00569         // Set this matrix to the product of V1^T and V2.
00571         void SetOuterProduct( const CSIBCVector4Dd& in_vct1, const CSIBCVector4Dd& in_vct2 );
00572 
00573     // Protected members
00574     protected:
00575 
00576         //****************************************
00577         // Protected data
00578         //****************************************
00579         // double[4][4] | CSIBCMatrix44d | m_dMat | Matrix itself.
00580         double m_dMat[4][4];
00581 
00582         //****************************************
00583         // Utility functions:
00584         //****************************************
00585         // Computes the inverse of a matrix.
00586         bool ComputeInverse( const double in_dMat[4][4],
00587             double out_dInv[4][4], const bool bTransposeResult=false );
00588 
00589 
00590    protected:
00591         //****************************************
00592         // Private data
00593         //****************************************
00594         // unsigned char | CSIBCMatrix44d | m_MaskInfo | 
00595         // Flag to indicate if matrix content has changed 
00596         // since last call to SetContentUnchanged().
00597 
00598         unsigned char   m_MaskInfo;
00599 };
00600 
00601 
00602 #endif