SIBCTransfod.h

Go to the documentation of this file.
00001 //***************************************************************************************
00002 // File supervisor: Crosswalk team
00012 //***************************************************************************************
00013 
00014 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00015 #pragma once
00016 #endif
00017 
00018 //******************************************************************************
00019 // Defines
00020 //******************************************************************************
00021 #ifndef _TRANSFO_H_
00022 #define _TRANSFO_H_
00023 
00024 //******************************************************************************
00025 // Includes
00026 //******************************************************************************
00027 #include "SIBCMathLib.h"
00028 
00029 //******************************************************************************
00030 // Typedefs
00031 //******************************************************************************
00032 
00033 
00040 const unsigned char oSiTransfoSclFac                =   0x01;
00041 
00043 const unsigned char oSiTransfoSclRot                =   0x02;
00044 
00046 const unsigned char oSiTransfoAllScl                =   0x03;
00047 
00049 const unsigned char oSiTransfoRot                   =   0x04;
00050 
00052 const unsigned char oSiTransfoTrs                   =   0x08;
00053 
00055 const unsigned char oSiTransfoTrsAffectedByScl      =   0x10;   // Used only when combining transformations
00056 
00058 const unsigned char oSiTransfoTrsAffectedByOri      =   0x20;   // Used only when combining transformations
00059 
00061 const unsigned char oSiTransfoAllTrs                =   0x38;
00062 
00064 const unsigned char oSiTransfoNone                  =   0x00;
00065 
00067 const unsigned char oSiTransfoAll                   =   0x3F;
00070 
00071 typedef enum tagE3DSCLTYPE
00072 {
00073    XYZ_SCL_TYPE,        
00074    UNIFORM_SCL_TYPE,    
00075    VOLUMIC_SCL_TYPE     
00076 } E3DSclType;
00077 
00079 typedef enum tagE3DTRANSFOSPACE
00080 {
00081    LOCAL_TRANSFO_SPACE,     
00082    PARENT_TRANSFO_SPACE,    
00083    OTHER_TRANSFO_SPACE      
00084 } E3DTransfoSpace;
00085 
00087 typedef enum tagE3DVECTORTYPE
00088 {
00089    POINT_VECTOR_TYPE,      
00090    LINE_VECTOR_TYPE,       
00091    DIRECTION_VECTOR_TYPE   
00092 } E3DVectorType;
00093 
00094 
00095 //******************************************************************************
00096 //  Mask Values for m_oTransfoInfo. These are used internally by CSIBCTransfod,
00097 //  and thus do not require documentation.
00098 //******************************************************************************
00099 #define MASK_ARE_COMPONENTS_DIRTY       (1 << 0 )   // 0x1  00000001
00100 #define MASK_IS_XFOMAT_DIRTY            (1 << 1 )   // 0x2  00000010
00101 #define MASK_IS_SI_SCALING              (1 << 2 )   // 0x4  00000100
00102 
00105 class XSICOREEXPORT CSIBCTransfod
00106 {
00107     public:
00110         CSIBCTransfod();
00111 
00118         CSIBCTransfod(
00119                     const CSIBCVector3Dd&   in_vctScl,
00120                     const CSIBCRotationd&   in_rotScl,
00121                     const CSIBCRotationd&   in_rot,
00122                     const CSIBCVector3Dd&   in_vctTrs );
00123 
00129         CSIBCTransfod(
00130                     const CSIBCVector3Dd&   in_vctScl,
00131                     const CSIBCRotationd&   in_rot,
00132                     const CSIBCVector3Dd&   in_vctTrs );
00133 
00138          CSIBCTransfod(
00139                     const CSIBCVector3Dd&   in_vctScl,
00140                     const CSIBCRotationd&   in_rotScl );
00141 
00146         bool GetSIScalingFlag() const;
00147 
00154         CSIBCTransfod& SetSIScalingFlag( const bool in_bSIScaling );
00155 
00160          bool IsScalingOrientationExisting() const;
00161 
00163         // TODO  The following Get/Set functions assume that the referential //
00164         //       of this transformation object and of the given/received     //
00165         //       value are the same. We should provide some methods to       //
00166         //       Get/Set one or many transformation components in different  //
00167         //       referential spaces.                                         //
00169 
00174          CSIBCVector3Dd&    GetScaling( CSIBCVector3Dd& out_vctScl );
00175 
00182          void           GetScaling(
00183                                                 double& out_dX,
00184                                                 double& out_dY,
00185                                                 double& out_dZ );
00186 
00191         void            GetScaling(
00192                                                 CSIBCVector3Dd& out_vctScl,
00193                                                 CSIBCRotationd& out_rotSclOri );
00194 
00199          CSIBCRotationd&    GetScalingOrientation( CSIBCRotationd& in_rotSclOri );
00200 
00205          CSIBCVector3Dd&    GetScalingOrientation( CSIBCVector3Dd&  out_vctSclOri );
00206 
00212          void           GetScalingOrientation(
00213                                                             double& out_rdX,
00214                                                             double& out_rdY,
00215                                                             double& out_rdZ );
00216 
00221          CSIBCRotationd&        GetRotation( CSIBCRotationd& out_rot );
00222 
00227         CSIBCQuaterniond&       GetRotation( CSIBCQuaterniond& out_quat );
00228 
00233         CSIBCRotMatd&           GetRotation( CSIBCRotMatd& out_matRot );
00234 
00244         const CSIBCRotMatd* GetRotation();
00245 
00250         CSIBCVector3Dd&     GetRotation( CSIBCVector3Dd& out_vctXYZAngles );
00251 
00257         void                    GetRotation(
00258                                                     double& out_dX,
00259                                                     double& out_dY,
00260                                                     double& out_dZ );
00261 
00266         void                    GetRotation(
00267                                                     CSIBCVector3Dd& out_vctAxis,
00268                                                     double& out_dAngle );
00269 
00274          CSIBCVector3Dd&    GetTranslation( CSIBCVector3Dd& out_vctTrs );
00275 
00281          void           GetTranslation(
00282                                                     double& out_dX,
00283                                                     double& out_dY,
00284                                                     double& out_dZ );
00285 
00294          const CSIBCXfoMatd*    GetMatrix();
00295 
00296 
00301          CSIBCXfoMatd&      GetMatrix( CSIBCXfoMatd& out_matXfo );
00302 
00307          CSIBCXfoMatd&      GetInvMatrix( CSIBCXfoMatd& out_matInvXfo );
00308 
00316         CSIBCTransfod&  Set(
00317                                         const   CSIBCVector3Dd&     in_vctScl,
00318                                         const   CSIBCRotationd&     in_rotScl,
00319                                         const   CSIBCRotationd&     in_rot,
00320                                         const   CSIBCVector3Dd&     in_vctTrs );
00321 
00328         CSIBCTransfod&  Set(
00329                                         const   CSIBCVector3Dd&     in_vctScl,
00330                                         const   CSIBCRotationd&     in_rot,
00331                                         const   CSIBCVector3Dd&     in_vctTrs );
00332 
00337         CSIBCTransfod&  Set( const CSIBCTransfod& in_xfo );
00338 
00343         CSIBCTransfod&  Set( const CSIBCXfoMatd& in_matXfo );
00344 
00349         CSIBCTransfod&  Set( const CSIBCRotationd& in_rot );
00350 
00355         CSIBCTransfod&  Set( const CSIBCVector3Dd& in_vct );
00356 
00361         CSIBCTransfod&  SetScaling( const CSIBCVector3Dd& in_vctScl );
00362 
00370         CSIBCTransfod&  SetScaling(
00371                                                 double in_dX,
00372                                                 double in_dY,
00373                                                 double in_dZ );
00374 
00380         CSIBCTransfod&  SetScaling(
00381                                                 const   CSIBCVector3Dd&     in_vctScl,
00382                                                 const   CSIBCRotationd& in_rotSclOri );
00383 
00388         CSIBCTransfod&  SetScalingOrientation( const CSIBCRotationd& in_rotSclOri );
00389 
00394         CSIBCTransfod&  SetScalingOrientation( const CSIBCVector3Dd&  in_vctSclOri );
00395 
00403         CSIBCTransfod&  SetScalingOrientation(
00404                                                             const   double  in_dX,
00405                                                             const   double  in_dY,
00406                                                             const   double  in_dZ );
00407 
00408 
00413         CSIBCTransfod&  SetRotation( const CSIBCRotationd& in_rot );
00414 
00419         CSIBCTransfod&  SetRotation( const CSIBCQuaterniond& in_quat );
00420 
00425         CSIBCTransfod&  SetRotation( const CSIBCRotMatd& in_matRot );
00426 
00431         CSIBCTransfod&  SetRotation( const CSIBCVector3Dd& in_vctXYZAngles );
00432 
00439         CSIBCTransfod&  SetRotation(
00440                                                 double  in_dX,
00441                                                 double  in_dY,
00442                                                 double  in_dZ );
00443 
00449         CSIBCTransfod&  SetRotation(
00450                                                 const   E3DAxisType in_axis,
00451                                                 const   double      in_dAngle );
00452 
00458         CSIBCTransfod&  SetRotation(
00459                                                 const   CSIBCVector3Dd& in_vctAxis,
00460                                                 const   double      in_dAngle );
00461 
00472         bool            SetRotation(
00473                                                 const   CSIBCVector3Dd& in_vctFrom,
00474                                                 const   CSIBCVector3Dd& in_vctTo,
00475                                                 int&    out_bFlip );
00476 
00484          CSIBCTransfod& SetRotation(
00485                                                 const   CSIBCVector3Dd& in_vctX,
00486                                                 const   CSIBCVector3Dd& in_vctY,
00487                                                 const   CSIBCVector3Dd& in_vctZ );
00488 
00493          CSIBCTransfod& SetTranslation( const CSIBCVector3Dd& in_vctTrs );
00494 
00501          CSIBCTransfod& SetTranslation(
00502                                                     double in_dX,
00503                                                     double in_dY,
00504                                                     double in_dZ );
00505 
00512          CSIBCTransfod& SetIdentity( const unsigned char in_oWhichTransfo = oSiTransfoAll );
00513 
00518         CSIBCTransfod&  Invert( CSIBCTransfod& in_xfo );
00519 
00523         CSIBCTransfod&  Invert();
00524 
00562         CSIBCTransfod& Mul(
00563                         CSIBCTransfod&  in_xfo1,
00564                         CSIBCTransfod& in_xfo2,
00565                         unsigned char       in_oWhichComponents = oSiTransfoAll );
00566 
00575         CSIBCTransfod& Mul(
00576                                         CSIBCTransfod& in_xfo,
00577                                         unsigned char       in_oWhichComponents = oSiTransfoAll );
00578 
00606         CSIBCTransfod& Dif(
00607                             CSIBCTransfod&  in_xfo1,
00608                             CSIBCTransfod& in_xfo2,
00609                             unsigned char       in_oWhichComponents = oSiTransfoAll,
00610                             CSIBCTransfod* in_pXfo3 = NULL );
00611 
00616         CSIBCTransfod& MapSpaceToWorld( CSIBCTransfod& in_xfoFrom );
00617 
00622         CSIBCTransfod& MapWorldToSpace( CSIBCTransfod& in_xfoTo );
00623 
00629         CSIBCTransfod& MapSpaceToSpace(
00630                                                     CSIBCTransfod& in_xfoFrom,
00631                                                     CSIBCTransfod& in_xfoTo );
00632 
00661         CSIBCTransfod& AddScaling(
00662                                             const   CSIBCVector3Dd&     in_vctSclApplied,
00663                                             const   E3DTransfoSpace     in_eAlong = LOCAL_TRANSFO_SPACE,
00664                                                     CSIBCRotationd*     in_protAlong = NULL,
00665                                             const   E3DTransfoSpace     in_eAbout = LOCAL_TRANSFO_SPACE,
00666                                             const   CSIBCVector3Dd*     in_pvctAbout = NULL,
00667                                             const   E3DSclType          in_eSclType = XYZ_SCL_TYPE );
00668 
00694         CSIBCTransfod& AddRotation(
00695                                                     CSIBCRotationd& in_rotApplied,
00696                                             const   E3DTransfoSpace in_eAlong = LOCAL_TRANSFO_SPACE,
00697                                                     CSIBCRotationd* in_protAlong = NULL,
00698                                             const   E3DTransfoSpace in_eAround = LOCAL_TRANSFO_SPACE,
00699                                             const   CSIBCVector3Dd*     in_pvctAround = NULL,
00700                                                     bool            in_bIncrementEulerAngles = false);
00701 
00722         CSIBCTransfod& AddTranslation(
00723                                             const   CSIBCVector3Dd&     in_vctTrsApplied,
00724                                             const   E3DTransfoSpace in_eAlong = LOCAL_TRANSFO_SPACE,
00725                                                     CSIBCRotationd* in_protAlong = NULL );
00726 
00753         CSIBCTransfod& AddScalingOrientation(
00754                                                     CSIBCRotationd& in_rotApplied,
00755                                             const   E3DTransfoSpace in_eAlong = LOCAL_TRANSFO_SPACE,
00756                                                     CSIBCRotationd* in_protAlong = NULL,
00757                                             const   E3DTransfoSpace in_eAround = LOCAL_TRANSFO_SPACE,
00758                                             const   CSIBCVector3Dd* in_pvctAround = NULL,
00759                                                     bool            in_bIncrementEulerAngles = false);
00760 
00768         friend CSIBCXfoMatd&    GetMapSpaceToWorld(
00769                                                         const   E3DVectorType   in_eVctType,
00770                                                                 CSIBCTransfod&      in_xfoFrom,
00771                                                                 CSIBCXfoMatd&       out_matXfo );
00772 
00780         friend CSIBCXfoMatd&    GetMapWorldToSpace(
00781                                                         const   E3DVectorType   in_eVctType,
00782                                                                 CSIBCTransfod&      in_xfoTo,
00783                                                                 CSIBCXfoMatd&       out_matXfo );
00784 
00793         friend CSIBCXfoMatd&    GetMapSpaceToSpace(
00794                                                         const   E3DVectorType   in_eVctType,
00795                                                                 CSIBCTransfod&      in_xfoFrom,
00796                                                                 CSIBCTransfod&      in_xfoTo,
00797                                                                 CSIBCXfoMatd&       out_matXfo );
00798 
00799     // @access Protected members
00800     protected:
00801 
00802         //****************************************
00803         // IMPLEMENTATION
00804         //****************************************
00805         // @member Factorize          | Factorize the transformation matrix
00806         //                              into individual scaling, scaling
00807         //                              orientation, orientation and
00808         //                              translation components.
00809         // @member Combine            | Combine the individual scaling, scaling
00810         //                              orientation, orientation and translation
00811         //                              components into a transformation matrix.
00812          void Factorize( const unsigned char in_oWhichComponents = oSiTransfoAll );
00813          void Combine();
00814 
00815         // @member Init               | Initialize members of the object.
00816          void Init();
00817 
00818     // @access Private members
00819     private:
00820 
00821         //****************************************
00822         // ATTRIBUTES
00823         //****************************************
00824         CSIBCRotationd      m_rot;      // @mdata   CSIBCRotationd      | CSIBCTransfod | m_rot  | Orientation.
00825         CSIBCXfoMatd        m_matXfo;   // @mdata   CSIBCXfoMatd | CSIBCTransfod | m_matXfo | Transformation
00826                                     //          matrix to represent scaling, rotation, translation and shearing all
00827                                     //          at once.
00828         CSIBCVector3Dd      m_vctScl;   // @mdata   CSIBCVector3Dd      | CSIBCTransfod | m_vctScl  | XYZ scaling factors.
00829         CSIBCVector3Dd      m_vctTrs;   // @mdata   CSIBCVector3Dd      | CSIBCTransfod | m_vctTrs   | Translation.
00830         CSIBCRotationd* m_pSclOri;  // @mdata   CSIBCRotationd* | CSIBCTransfod | m_pSclOri | Scaling Orientation.
00831                                     //          This field allows to introduce explicit shearing in the transformation.
00832                                     //          The memory holding this pointer is allocated when shearing is detected in the transformation matrix,
00833                                     //          or when shearing is set explicitely by the clients. This same memory is freed whenever there is
00834                                     //          no more shearing.
00835 
00836         // @devnote     Classical vs SI Scaling:
00837         //              With SOFTIMAGE scaling, scaling factors
00838         //              are always applied along local axes.
00839         //              In classical scaling, shearing can occur.
00840         //              This is equivalent to saying that the scaling factors
00841         //              are not applied along local axis, but along other axes.
00842         //              To deal with this, we introduce a Scaling Orientation matrix
00843         //              which represents a rotation applied before scaling the object.
00844 
00845 
00846 
00847 
00848 
00849         // @mdata   bool | CSIBCTransfod | m_bComponentsDirty | Do the individual
00850         //          transformation's components (Scaling, Scaling orientation,
00851         //          Orientation, Translation) corresponding to the transformation
00852         //          matrix are dirty?
00853         // @mdata   bool | CSIBCTransfod | m_bXfoMatDirty | Do the transformation
00854         //          matrix corresponding to the individual transformation's
00855         //          components (Scaling, Scaling orientation, Orientation,
00856         //          Translation) is dirty?
00857 #ifdef _DEBUG
00858 
00859         bool m_bComponentsDirty;
00860         bool m_bXfoMatDirty;
00861 
00862         // @mdata   bool | CSIBCTransfod | m_bSIScaling | Do transformation's
00863         //          components are combined using SOFTIMAGE scaling (true) or
00864         //          classical scaling (false) ?
00865         bool m_bSIScaling;
00866 #endif
00867 
00868 
00869 
00870         // m_oTransfoInfo comprises formely known m_bComponentsDirty, m_bXfoMatDirty
00871         // and m_bSIScaling booleans.
00872         // Bit 0 = m_bComponentsDirty
00873         // Bit 1 = m_bXfoMatDirty
00874         // Bit 2 = m_bSIScaling
00875         // Bit 3 to 7 = unused
00876         unsigned char m_oTransfoInfo;
00877 
00878          void _SetComponentsDirty( const bool in_bIsDirty );
00879          bool _AreComponentsDirty() const;
00880          void _SetXfoMatDirty ( const bool in_bIsDirty );
00881          bool _IsXfoMatDirty() const;
00882          void _SetSIScaling( const bool in_bIsScaling );
00883          bool _IsSIScaling() const;
00884          bool HasShearing() const;
00885          void _AllocateScalingOrientationMatrix(const bool in_bAllocate);
00886 
00887 
00888         // Disable Copy constructor and operator=
00889         // @member CSIBCTransfod         | Copy constructor.
00890         CSIBCTransfod( const CSIBCTransfod& in_xfo );
00891         CSIBCTransfod( const CSIBCXfoMatd& in_matXfo );
00892         CSIBCTransfod( const CSIBCRotationd& in_rot );
00893         CSIBCTransfod( const CSIBCVector3Dd& in_vctTrs );
00894         // @member =                  | Transformation assignment from another
00895         //                              transformation.
00896         CSIBCTransfod& operator =( const CSIBCTransfod& in_xfo );
00897         CSIBCTransfod& operator =( const CSIBCXfoMatd& in_matXfo );
00898 };
00899 
00900 typedef CSIBCTransfod* LP3DTRANSFO;
00901 typedef const CSIBCTransfod* LPC3DTRANSFO;
00902 
00903 
00904 #endif