SIBCVector3Dd.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 // SIBCVector3Dd.h | Main header file for CSIBCVector3Dd 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 
00033 #ifndef _VECTOR3_H_
00034 #define _VECTOR3_H_
00035 
00036 //******************************************************************************
00037 // Includes
00038 //****************************************************************************** 
00039 #include "SIBCMathLib.h"
00040 
00041 //******************************************************************************
00042 // Typedefs
00043 //******************************************************************************
00044 
00045 //******************************************************************************
00046 // CSIBCVector3Dd | General 3D vector.
00047 //******************************************************************************
00048 
00050 
00061 class XSICOREEXPORT CSIBCVector3Dd
00062 {
00063     // Public members
00064     public:
00065 
00066         //****************************************
00067         // IMPLEMENTATION
00068         //****************************************
00069 
00073         CSIBCVector3Dd( );
00074 
00082         CSIBCVector3Dd( const double  in_dX, const double in_dY, const double  in_dZ );
00083 
00088         CSIBCVector3Dd( const double in_dXYZ[3] );
00089 
00094         CSIBCVector3Dd( int in_nIndex, double in_dVal );
00095 
00096         ~CSIBCVector3Dd();
00097 
00098         // Old stuff support: will be removed in next release.
00099 
00106          const double * GetArray() const;
00107     
00108         // Individual access to private members
00109 
00117         double GetX( void ) const;
00118 
00126         double GetY( void ) const;
00127 
00135         double GetZ( void ) const;
00136 
00145         double Get( const int in_nIndex ) const;
00146 
00147 
00157         void Get( double& out_dX, double& out_dY, double& out_dZ ) const;
00158 
00168         double GetMaxComponent( bool in_bInAbs = true ) const;
00169 
00179         double GetMinComponent( bool in_bInAbs = true ) const;
00180 
00189         int GetIndexOfMaxComponent( bool in_bInAbs = true ) const;
00190 
00199         int GetIndexOfMinComponent( bool in_bInAbs = true ) const;
00200 
00209         CSIBCVector3Dd& SetX ( const double in_dVal );
00210 
00219         CSIBCVector3Dd& SetY ( const double in_dVal );
00220 
00229         CSIBCVector3Dd& SetZ ( const double in_dVal );
00230 
00240         CSIBCVector3Dd& Set( const CSIBCVector3Dd& in_vct );
00241 
00249         CSIBCVector3Dd& Set( const int in_nIndex, const double in_dVal );
00250 
00262         CSIBCVector3Dd& Set( const double in_dX, const double in_dY,
00263             const double in_dZ );
00264 
00265 
00271         CSIBCVector3Dd& SetNull( void );
00272 
00281         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
00282 
00295         CSIBCVector3Dd& SetMinimal ( bool in_bInAbs = true, const double in_dEpsilon=PICO_EPS );
00296 
00310         CSIBCVector3Dd& SetMinimal ( const CSIBCVector3Dd &, bool in_bInAbs = true );
00311 
00322         friend bool AreAlmostEqual( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, 
00323             const double in_dEpsilon = PICO_EPS ) ;
00324 
00332         bool operator == ( const CSIBCVector3Dd& in_vct ) const;
00333 
00341         bool operator != ( const CSIBCVector3Dd& in_vct ) const;
00342 
00348         CSIBCVector3Dd& Negate( const CSIBCVector3Dd& in_vct );
00349 
00354         CSIBCVector3Dd& Negate( void );
00355 
00362         double GetSquaredLength( void ) const;
00363 
00370         double GetLength( void ) const;
00371 
00379         bool SetLength( const double in_dLength );
00380 
00387         bool Normalize( void );
00388 
00389 
00390         // Efficient arithmetic operations.
00391 
00398         CSIBCVector3Dd& Add( const CSIBCVector3Dd&  in_vct  );
00399 
00407         CSIBCVector3Dd& Add( const CSIBCVector3Dd&  in_vct1, const CSIBCVector3Dd& in_vct2 );
00408 
00415         CSIBCVector3Dd& Sub( const CSIBCVector3Dd& in_vct );
00416 
00424         CSIBCVector3Dd& Sub( const CSIBCVector3Dd&  in_vct1, const CSIBCVector3Dd& in_vct2 );
00425 
00435         CSIBCVector3Dd& Mul( const double in_dFactor );
00436 
00447         CSIBCVector3Dd& Mul( const double in_dFactor, const CSIBCVector3Dd& in_vct );
00448 
00459         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const double in_dFactor );
00460 
00471         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCMatrix33d& in_mat );
00472 
00483         CSIBCVector3Dd& Mul( const CSIBCMatrix33d& in_mat );
00484 
00495         CSIBCVector3Dd& Mul( const CSIBCMatrix33d& in_mat, const CSIBCVector3Dd& in_vct );
00496 
00497         // TODO  Remove set of functions to multiply by CSIBCRotMatd as soon as 
00498         //       CSIBCRotMatd and CSIBCMatrix33d will both derived public from a
00499         //       common base matrix class.
00500 
00511         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCRotMatd& in_mat );
00512 
00523         CSIBCVector3Dd& Mul( const CSIBCRotMatd& in_mat, const CSIBCVector3Dd& in_vct );
00524 
00538         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCXfoMatd& in_mat );
00539 
00552         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCMatrix44d& in_mat );
00553 
00563         CSIBCVector3Dd& Div( const double in_dFactor );
00564 
00575         CSIBCVector3Dd& Div( const CSIBCVector3Dd& in_vct, const double in_dFactor );
00576 
00587         CSIBCVector3Dd& MulComp( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2  );
00588 
00598         CSIBCVector3Dd& MulComp( const CSIBCVector3Dd& in_vct );
00599 
00609         CSIBCVector3Dd& DivComp( const CSIBCVector3Dd& in_vct ); 
00610 
00621         CSIBCVector3Dd& DivComp( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00622         
00623 
00630         friend double GetDot( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00631 
00639         CSIBCVector3Dd& SetCross( const CSIBCVector3Dd& in_vct );
00640 
00648         CSIBCVector3Dd& SetCross( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00649 
00662         bool SetOrthogonal( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00663 
00677         bool SetOrthoProj( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00678 
00690         friend bool AreOrthogonal( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, 
00691             const double in_dEpsilon = PICO_EPS );
00692 
00699         bool SetProjection( const CSIBCVector3Dd& in_vct );
00700 
00708         friend bool AreParallel( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, 
00709             const double in_dEpsilon = PICO_EPS );
00710 
00717         CSIBCVector3Dd& SetMirror( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00718 
00726         friend double GetDistance( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00727 
00735         friend double GetSquaredDistance( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00736 
00746         friend void GetOrthogonalBasis( const CSIBCVector3Dd& in_vct1, CSIBCVector3Dd& out_vct2, 
00747             CSIBCVector3Dd& out_vct3 );
00748 
00760         friend void GetOrthonormalBasis( CSIBCVector3Dd& io_vct1, CSIBCVector3Dd& out_vct2, 
00761             CSIBCVector3Dd& out_vct3 );
00762 
00770         CSIBCVector3Dd& SetMidpoint( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00771 
00772 
00781         CSIBCVector3Dd& SetMean (   const CSIBCVector3Dd *in_vct, ULONG in_nbVct );
00782 
00791         CSIBCVector3Dd& LinearPositionInterpolate( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, const double in_dT );
00792 
00806         friend double GetPntsAngle( const CSIBCVector3Dd& in_pntOrigin,
00807                                     const CSIBCVector3Dd& in_pnt1,
00808                                     const CSIBCVector3Dd& in_pnt2 );
00809 
00825         friend double Get2DPntsAngleSigned( const CSIBCVector3Dd& in_pntOrigin,
00826                                             const CSIBCVector3Dd& in_pnt1,
00827                                             const CSIBCVector3Dd& in_pnt2 );
00828 
00842         friend double GetPntsCosAngle(  const CSIBCVector3Dd& in_pntOrigin,
00843                                         const CSIBCVector3Dd& in_pnt1,
00844                                         const CSIBCVector3Dd& in_pnt2 );
00845 
00859         friend double GetVctsAngle( const CSIBCVector3Dd&   in_vct1,
00860                                     const CSIBCVector3Dd&   in_vct2,
00861                                     const double in_dEpsilon = PICO_EPS );
00862 
00877         friend double Get2DVctsAngleSigned( const CSIBCVector3Dd& in_vct1,
00878                                             const CSIBCVector3Dd& in_vct2 );
00879 
00880         
00892         friend double GetVctsCosAngle(  const CSIBCVector3Dd& in_vct1,
00893                                         const CSIBCVector3Dd& in_vct2,
00894                                         const double in_dEpsilon = PICO_EPS );
00895 
00896 
00904         friend int Get2DPntSide(    const CSIBCVector3Dd& in_pnt,
00905                                     const CSIBCVector3Dd& in_pntOrigin,
00906                                     const CSIBCVector3Dd& in_pntTip );
00907 
00908 
00915         friend double GetTriangleArea( 
00916             const CSIBCVector3Dd& in_rPoint0,
00917             const CSIBCVector3Dd& in_rPoint1,
00918             const CSIBCVector3Dd& in_rPoint2 );
00919 
00921         // To be implemented later //
00923 
00924         // Cardinal & Bezier Position Interpolate doens't exist in SI3D3.7
00925         // What about Linear, Cardinal & Bezier VectorInterpolate
00926 
00927         // SetBounds    | Readjust boundaries (min and max) to contain a given point.
00929         void SetBounds( const CSIBCVector3Dd& in_pnt, CSIBCVector3Dd& io_min, CSIBCVector3Dd& io_max );
00930 
00931         // Combine      | Compute this=s1*v1 + s2*v2.
00933         CSIBCVector3Dd& Combine( const CSIBCVector3Dd& in_vct1, const double in_dS1, 
00934             const CSIBCVector3Dd& in_vct2, const double in_dS2 );
00935 
00936 #ifdef _DEBUG
00937          void SelfDebug() const;
00938          void DoDebugInit();
00939 #endif
00940 
00942         // To finish implementing    //
00944         
00945         // BsplinePositionInterpolate | Interpolates a BSpline position between four 3D vectors.
00947         CSIBCVector3Dd& BsplinePositionInterpolate( const CSIBCVector3Dd& in_vct1,
00948                                     const CSIBCVector3Dd& in_vct2, const CSIBCVector3Dd& in_vct3,
00949                                     const CSIBCVector3Dd& in_vct4, const double in_dT );
00950 
00951         // BsplineVectorInterpolate | Interpolates a BSpline vector between four 3D vectors.
00953         CSIBCVector3Dd& BsplineVectorInterpolate( const CSIBCVector3Dd& in_vct1,
00954                                     const CSIBCVector3Dd& in_vct2, const CSIBCVector3Dd& in_vct3,
00955                                     const CSIBCVector3Dd& in_vct4, const double in_dT );
00956 
00957         // ArePntsCollinear | Verify if three points are collinear.
00959         friend bool ArePntsCollinear( const CSIBCVector3Dd& in_pnt1,
00960                                         const CSIBCVector3Dd& in_pnt2,
00961                                         const CSIBCVector3Dd& in_pnt3,
00962                                         const double in_dEpsilon = PICO_EPS );
00963 
00964         // AreVctsCoplanar  | Verify if two vectors are coplanar.
00966         friend bool AreVctsCoplanar ( const CSIBCVector3Dd& in_vct1,
00967                                         const CSIBCVector3Dd& in_vct2,
00968                                         const CSIBCVector3Dd& in_vct3,
00969                                         const double in_dEpsilon = PICO_EPS );
00970 
00971         // ArePntsCoplanar  | Verify if three points are coplanar.
00973         friend bool ArePntsCoplanar ( const CSIBCVector3Dd& in_pnt1,
00974                                         const CSIBCVector3Dd& in_pnt2,
00975                                         const CSIBCVector3Dd& in_pnt3,
00976                                         const CSIBCVector3Dd& in_pnt4,
00977                                         const double in_dEpsilon = PICO_EPS );
00978 
00979     // Private Members
00980     private:
00981 
00982         //****************************************
00983         // ATTRIBUTES
00984         //****************************************
00985         // double | CSIBCVector3Dd | m_dX | X component of the vector.
00986         // double | CSIBCVector3Dd | m_dY | Y component of the vector.
00987         // double | CSIBCVector3Dd | m_dZ | Z component of the vector.
00988         double  m_dX, m_dY, m_dZ;
00989 
00990     public:
00991 
00993     // Useful constants:
00995     static const CSIBCVector3Dd k_UnitVector;
00996 };
00997 
00998 typedef CSIBCVector3Dd* LP3DVECTOR3;
00999 
01000 //******************************************************************************
01001 //
01002 // Author       : Michel Carigan
01003 // Date         : 08/05/96
01004 // Updated by   : Eric Cabot (02/25/97)
01005 //
01006 // Set each component to be at least epsilon (in absolute or not depending on in_bInAbs).
01007 //
01008 // A reference on this.
01009 //
01010 // This function works like the macro _SI_VCT_EPS in v3.51
01011 // That is, each component are set to eps only if they are less than epsilon.
01012 // In that case the sign is unchanged.
01013 //
01014 //
01015 //******************************************************************************
01016 inline  CSIBCVector3Dd&  
01017 CSIBCVector3Dd::SetMinimal
01018     (
01019         bool in_bInAbs,             // Tells if the test is done in absolute value or not (true by default).
01020         const double in_dEpsilon    // The epsilon to compare with (PICO_EPS by default).
01021     )
01022 {
01023 
01024     if( in_bInAbs )
01025     {
01026 
01027         if( fabs(m_dX) < in_dEpsilon )
01028             m_dX = ( ( m_dX >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01029         if( fabs(m_dY) < in_dEpsilon )
01030             m_dY = ( ( m_dY >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01031         if( fabs(m_dZ) < in_dEpsilon )
01032             m_dZ = ( ( m_dZ >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01033     }
01034     else
01035     {
01036         if( m_dX < in_dEpsilon )
01037         {
01038             m_dX = in_dEpsilon;
01039         }
01040         if( m_dY < in_dEpsilon )
01041         {
01042             m_dY = in_dEpsilon;
01043         }
01044         if( m_dZ < in_dEpsilon )
01045         {
01046             m_dZ = in_dEpsilon;
01047         }
01048     }
01049 
01050     return *this;
01051 }
01052 
01053 #endif