SIBCXfoMatd.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.  
00006 // Use of this software is subject to the terms of the Autodesk license agreement 
00007 // provided at the time of installation or download, or which otherwise accompanies 
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00013 #pragma once
00014 #endif
00015 
00016 //******************************************************************************
00017 // Defines
00018 //******************************************************************************
00019 
00020 #ifndef _XFOMAT_H_
00021 #define _XFOMAT_H_
00022 
00023 //******************************************************************************
00024 // Includes
00025 //******************************************************************************
00026 #include "SIBCMathLib.h"
00027 #include "SIBCMatrix.h"
00028 
00029 //This number must represent the number of bits flags in 
00030 //CSIBCMatrix44d::m_MaskInfo reserved for the specific usage of CSIBCXfoMatd.
00031 #define _3D_NB_BITS_RESERVED_BY_XFOMAT (unsigned char)( 3 ) 
00032 
00033 //******************************************************************************
00034 // CSIBCXfoMatd | 4x4 transformation matrix.
00035 //******************************************************************************
00036 
00038 
00054 class XSICOREEXPORT CSIBCXfoMatd : private CSIBCMatrix44d
00055 {
00056     // Public members
00057     public:
00058         //****************************************
00059         // Constructors/destructor:
00060         //****************************************
00061 
00066         CSIBCXfoMatd( void );
00067 
00079         CSIBCXfoMatd( 
00080             const CSIBCVector4Dd& in_vct0,
00081             const CSIBCVector4Dd& in_vct1,
00082             const CSIBCVector4Dd& in_vct2,
00083             const CSIBCVector4Dd& in_vct3,
00084             const bool in_bAreRows = true );
00085 
00105         CSIBCXfoMatd( 
00106             const double in_dA00, const double in_dA01, const double in_dA02, const double in_dA03, 
00107             const double in_dA10, const double in_dA11, const double in_dA12, const double in_dA13, 
00108             const double in_dA20, const double in_dA21, const double in_dA22, const double in_dA23, 
00109             const double in_dA30, const double in_dA31, const double in_dA32, const double in_dA33 );
00110 
00111         //****************************************
00112         // General access functions:
00113         //****************************************
00114 
00121         double Get( const int in_nRow, const int in_nCol ) const;
00122 
00129         const double * GetArray() const;
00130 
00131         //****************************************
00132         // Matrix element modification functions:
00133         //****************************************
00134 
00145         CSIBCXfoMatd& Set( int in_nRow, int in_nCol, const double in_dVal );
00146 
00156         CSIBCXfoMatd& Set( double in_dVal[4][4] );
00157 
00163         CSIBCXfoMatd& Set( double in_dVal[3][3] );
00164 
00173         CSIBCXfoMatd& Set( const CSIBCMatrix44d& in_mat );
00174 
00184         CSIBCXfoMatd& Set( const CSIBCMatrix33d& in_mat );
00185 
00194         CSIBCXfoMatd& Set( const CSIBCXfoMatd& in_mat );
00195 
00204         CSIBCXfoMatd& Set( const CSIBCRotMatd& in_mat );
00205 
00215         CSIBCXfoMatd& SetWithTranspose( const CSIBCRotMatd& in_mat );
00216 
00226         CSIBCXfoMatd& SetRow( const int in_nRow, const CSIBCVector4Dd& in_vct );
00227 
00239         CSIBCXfoMatd& SetRow( const int in_nRow, double in_dA0, double in_dA1, double in_dA2, double in_dA3 );
00240 
00250         CSIBCXfoMatd& SetCol( const int in_nCol, const CSIBCVector4Dd& in_vct );
00251 
00263         CSIBCXfoMatd& SetCol( const int in_nCol, double in_dA0, double in_dA1, double in_dA2, double in_dA3 );
00264 
00269         CSIBCXfoMatd& SetIdentity( void );
00270 
00271         //****************************************
00272         // Matrix comparison functions:
00273         //****************************************
00274 
00285         friend bool AreAlmostEqual( const CSIBCXfoMatd& in_mat1,
00286                                 const CSIBCXfoMatd& in_mat2,
00287                                 const double in_dEpsilon = HEXA_EPS );
00288 
00296         bool operator ==( const CSIBCMatrix44d& in_mat ) const;
00297 
00305         bool operator !=( const CSIBCMatrix44d& in_mat ) const;
00306 
00307         //****************************************
00308         // Matrix algebra functions:
00309         //****************************************
00310 
00319         CSIBCXfoMatd& Mul( const CSIBCXfoMatd& in_mat1, const CSIBCXfoMatd& in_mat2 );
00320 
00328         CSIBCXfoMatd& Mul( const CSIBCXfoMatd& in_mat );
00329 
00338         CSIBCXfoMatd& Mul( const CSIBCXfoMatd& in_xfomat, const CSIBCRotMatd& in_rotmat );
00339 
00348         CSIBCXfoMatd& Mul( const CSIBCRotMatd& in_rotmat, const CSIBCXfoMatd& in_xfomat );
00349 
00350         
00361         CSIBCXfoMatd& MulTransByReg( const CSIBCRotMatd& in_rotmat,
00362                             const CSIBCXfoMatd& in_xfomat );
00363 
00369         double GetDet( void ) const;
00370 
00376         double GetDet33( void ) const;
00377 
00383         double GetTrace( void ) const;
00384 
00390         CSIBCXfoMatd& Transpose( const CSIBCXfoMatd& in_mat );
00391 
00396         CSIBCXfoMatd& Transpose( void );
00397 
00404         bool Invert( const CSIBCXfoMatd& in_mat );
00405 
00411         bool Invert( void );
00412 
00419         CSIBCVector3Dd& GetTranslation( CSIBCVector3Dd& out_vctTrs ) const;
00420 
00427         CSIBCXfoMatd& SetTranslation( const CSIBCVector3Dd& in_vctTrs );
00428 
00435         CSIBCXfoMatd& AddTranslation( const CSIBCVector3Dd& in_vctTrs );
00436 
00444         CSIBCRotMatd& GetRotation( CSIBCRotMatd& out_matRot ) const;
00445 
00453         CSIBCRotationd& GetRotation( CSIBCRotationd& out_rot ) const;
00454 
00461         CSIBCXfoMatd& SetRotation( const CSIBCRotMatd& in_matRot );
00462 
00469         CSIBCXfoMatd& AddRotation( const CSIBCRotMatd& in_matRot );
00470 
00477         CSIBCVector3Dd& GetScaling( CSIBCVector3Dd& out_vctScl ) const;
00478 
00485         CSIBCXfoMatd& SetScaling( const CSIBCVector3Dd& in_vctScl );
00486 
00496         CSIBCXfoMatd& AddScaling( const CSIBCVector3Dd& in_vctScl, bool in_bPreScaling = true );
00497 
00506         void SetScalingAndRotation( const CSIBCVector3Dd& in_vctScl, CSIBCRotationd& in_rot );
00507 
00516         void GetScalingAndRotation( CSIBCVector3Dd& out_vctScl, CSIBCRotationd& out_rot ) const;
00517 
00524         void GetAffineDecomposition ( CSIBCRotMatd& out_sclRot, CSIBCXfoMatd& out_matSRT ) const;
00525 
00533         void GetSmartDecomposition ( CSIBCVector3D& out_Scale, CSIBCVector3D& out_Rotate, CSIBCVector3D& out_Trans ) const;
00534 
00535     // Protected members
00536     protected:
00537 
00538         // If you have to reserve other bits in CSIBCMatrix44d::m_MaskInfo for the specific usage of CSIBCMatrix44d
00539         // please update the value of _3D_NB_BITS_RESERVED_BY_XFOMAT accordingly.
00540         enum { 
00541             _3D_X_NEGATIVE              = (unsigned char)( 1 << (_3D_NB_BITS_RESERVED_BY_MAT44 + 0) ),
00542             _3D_Y_NEGATIVE              = (unsigned char)( 1 << (_3D_NB_BITS_RESERVED_BY_MAT44 + 1) ),
00543             _3D_Z_NEGATIVE              = (unsigned char)( 1 << (_3D_NB_BITS_RESERVED_BY_MAT44 + 2) ),
00544             _3D_ALLAXES_NEGATIVE_MASK   = (unsigned char)( _3D_X_NEGATIVE | _3D_Y_NEGATIVE | _3D_Z_NEGATIVE ),
00545         };
00546 
00547     // Private members
00548     private:
00549 
00550         // Please do not re-enable the following cast operator as it will cause problems for the following Scenario:
00551         // CSIBCMatrix44d l_mat;
00552         // CSIBCVector3Dd l_vct;
00553         // l_vct.Mul( l_vct, l_mat );
00554         // there are two Mul functions applicable:
00555         // 1-   CSIBCVector3Dd & CSIBCVector3Dd::Mul( const CSIBCVector3Dd &, const CSIBCMatrix44d & );
00556         // 2-   CSIBCVector3Dd & CSIBCVector3Dd::Mul( const CSIBCVector3Dd &, const CSIBCXfoMatd & );
00557         // Unfortunately, if the following operator is enabled, the second Mul function will be taken
00558         // which is not what the client wants !!!
00559         // EC.
00560         CSIBCXfoMatd( const CSIBCMatrix44d & ); // Disable this cast operator
00561         CSIBCXfoMatd( const CSIBCMatrix33d& in_mat );
00562 
00563         //Disable copy constructor and operator =
00564         CSIBCXfoMatd( const CSIBCXfoMatd& in_mat );
00565         CSIBCXfoMatd& operator =( const CSIBCXfoMatd& in_mat );
00566 
00567         //Methods to handles SignBits for the scaling factor.
00568         void SetSclSignBits( const CSIBCVector3Dd &in_vctScl ); // SetSclSignBits | Set m_MaskInfo from in_vctScl.
00569         void XORSclSignBits( const CSIBCVector3Dd &in_vctScl ); // XORSclSignBits | XOR m_MaskInfo from in_vctScl.
00570 
00571         void SetSclSignBits( const unsigned char in_SclBits );  // SetSclSignBits | Set the sign bits of m_MaskInfo to those of in_SclBits.
00572         void XORSclSignBits( const unsigned char in_Bits1, const unsigned char in_Bits2 );// XORSclSignBits | Return the XOR of in_Mask1 and in_Mask2 masked with _3D_ALLAXES_NEGATIVE_MASK.
00573         unsigned char GetSclSignBits( ) const;              // GetSclSignBits | Return the sign bits sub-part of m_MaskInfo.
00574         void ClearSclSignBits();                            // ClearSclSignBits | Clear the bit signs part of m_MaskInfo
00575         bool IsSclAxisNegative( int in_axe ) const;         // IsSclAxisNegative | Look if one scl bit is set.
00576 };
00577 typedef CSIBCXfoMatd* LP3DXFOMAT;
00578 typedef const CSIBCXfoMatd* LPC3DXFOMAT;
00579 
00580 #endif