SIBCVector3Dd.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 
00022 #ifndef _VECTOR3_H_
00023 #define _VECTOR3_H_
00024 
00025 //******************************************************************************
00026 // Includes
00027 //******************************************************************************
00028 #include "SIBCMathLib.h"
00029 
00030 //******************************************************************************
00031 // Typedefs
00032 //******************************************************************************
00033 
00034 //******************************************************************************
00035 // CSIBCVector3Dd | General 3D vector.
00036 //******************************************************************************
00037 
00051 class XSICOREEXPORT CSIBCVector3Dd
00052 {
00053     // Public members
00054     public:
00055 
00056         //****************************************
00057         // IMPLEMENTATION
00058         //****************************************
00059 
00063         CSIBCVector3Dd( );
00064 
00072         CSIBCVector3Dd( const double  in_dX, const double in_dY, const double  in_dZ );
00073 
00078         CSIBCVector3Dd( const double in_dXYZ[3] );
00079 
00085         CSIBCVector3Dd( int in_nIndex, double in_dVal );
00086 
00087         ~CSIBCVector3Dd();
00088 
00089         // Old stuff support: will be removed in next release.
00090 
00097          const double * GetArray() const;
00098 
00099         // Individual access to private members
00100 
00108         double GetX( void ) const;
00109 
00117         double GetY( void ) const;
00118 
00126         double GetZ( void ) const;
00127 
00136         double Get( const int in_nIndex ) const;
00137 
00138 
00148         void Get( double& out_dX, double& out_dY, double& out_dZ ) const;
00149 
00158         double GetMaxComponent( bool in_bInAbs = true ) const;
00159 
00169         double GetMinComponent( bool in_bInAbs = true ) const;
00170 
00179         int GetIndexOfMaxComponent( bool in_bInAbs = true ) const;
00180 
00189         int GetIndexOfMinComponent( bool in_bInAbs = true ) const;
00190 
00199         CSIBCVector3Dd& SetX ( const double in_dVal );
00200 
00209         CSIBCVector3Dd& SetY ( const double in_dVal );
00210 
00219         CSIBCVector3Dd& SetZ ( const double in_dVal );
00220 
00230         CSIBCVector3Dd& Set( const CSIBCVector3Dd& in_vct );
00231 
00239         CSIBCVector3Dd& Set( const int in_nIndex, const double in_dVal );
00240 
00252         CSIBCVector3Dd& Set( const double in_dX, const double in_dY,
00253             const double in_dZ );
00254 
00255 
00261         CSIBCVector3Dd& SetNull( void );
00262 
00272         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
00273 
00286         CSIBCVector3Dd& SetMinimal ( bool in_bInAbs = true, const double in_dEpsilon=PICO_EPS );
00287 
00296         CSIBCVector3Dd& SetMinimal (
00297                                      const CSIBCVector3Dd &,    
00298                                      bool in_bInAbs = true      
00300                                     );
00301 
00313         friend bool AreAlmostEqual( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2,
00314             const double in_dEpsilon = PICO_EPS ) ;
00315 
00324         bool operator == ( const CSIBCVector3Dd& in_vct ) const;
00325 
00334         bool operator != ( const CSIBCVector3Dd& in_vct ) const;
00335 
00341         CSIBCVector3Dd& Negate( const CSIBCVector3Dd& in_vct );
00342 
00347         CSIBCVector3Dd& Negate( void );
00348 
00355         double GetSquaredLength( void ) const;
00356 
00363         double GetLength( void ) const;
00364 
00372         bool SetLength( const double in_dLength );
00373 
00380         bool Normalize( void );
00381 
00382 
00383         // Efficient arithmetic operations.
00384 
00391         CSIBCVector3Dd& Add( const CSIBCVector3Dd&  in_vct  );
00392 
00400         CSIBCVector3Dd& Add( const CSIBCVector3Dd&  in_vct1, const CSIBCVector3Dd& in_vct2 );
00401 
00408         CSIBCVector3Dd& Sub( const CSIBCVector3Dd& in_vct );
00409 
00417         CSIBCVector3Dd& Sub( const CSIBCVector3Dd&  in_vct1, const CSIBCVector3Dd& in_vct2 );
00418 
00428         CSIBCVector3Dd& Mul( const double in_dFactor );
00429 
00440         CSIBCVector3Dd& Mul( const double in_dFactor, const CSIBCVector3Dd& in_vct );
00441 
00452         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const double in_dFactor );
00453 
00464         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCMatrix33d& in_mat );
00465 
00475         CSIBCVector3Dd& Mul( const CSIBCMatrix33d& in_mat );
00476 
00487         CSIBCVector3Dd& Mul( const CSIBCMatrix33d& in_mat, const CSIBCVector3Dd& in_vct );
00488 
00489         // TODO  Remove set of functions to multiply by CSIBCRotMatd as soon as
00490         //       CSIBCRotMatd and CSIBCMatrix33d will both derived public from a
00491         //       common base matrix class.
00492 
00503         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCRotMatd& in_mat );
00504 
00515         CSIBCVector3Dd& Mul( const CSIBCRotMatd& in_mat, const CSIBCVector3Dd& in_vct );
00516 
00530         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCXfoMatd& in_mat );
00531 
00544         CSIBCVector3Dd& Mul( const CSIBCVector3Dd& in_vct, const CSIBCMatrix44d& in_mat );
00545 
00555         CSIBCVector3Dd& Div( const double in_dFactor );
00556 
00567         CSIBCVector3Dd& Div( const CSIBCVector3Dd& in_vct, const double in_dFactor );
00568 
00579         CSIBCVector3Dd& MulComp( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2  );
00580 
00590         CSIBCVector3Dd& MulComp( const CSIBCVector3Dd& in_vct );
00591 
00601         CSIBCVector3Dd& DivComp( const CSIBCVector3Dd& in_vct );
00602 
00613         CSIBCVector3Dd& DivComp( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00614 
00615 
00622         friend double GetDot( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00623 
00631         CSIBCVector3Dd& SetCross( const CSIBCVector3Dd& in_vct );
00632 
00641         CSIBCVector3Dd& SetCross( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00642 
00655         bool SetOrthogonal( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00656 
00670         bool SetOrthoProj( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00671 
00684         friend bool AreOrthogonal( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2,
00685             const double in_dEpsilon = PICO_EPS );
00686 
00694         bool SetProjection( const CSIBCVector3Dd& in_vct );
00695 
00703         friend bool AreParallel( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2,
00704             const double in_dEpsilon = PICO_EPS );
00705 
00712         CSIBCVector3Dd& SetMirror( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2 );
00713 
00721         friend double GetDistance( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00722 
00730         friend double GetSquaredDistance( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00731 
00741         friend void GetOrthogonalBasis( const CSIBCVector3Dd& in_vct1, CSIBCVector3Dd& out_vct2,
00742             CSIBCVector3Dd& out_vct3 );
00743 
00755         friend void GetOrthonormalBasis( CSIBCVector3Dd& io_vct1, CSIBCVector3Dd& out_vct2,
00756             CSIBCVector3Dd& out_vct3 );
00757 
00765         CSIBCVector3Dd& SetMidpoint( const CSIBCVector3Dd& in_pnt1, const CSIBCVector3Dd& in_pnt2 );
00766 
00767 
00776         CSIBCVector3Dd& SetMean (   const CSIBCVector3Dd *in_vct, ULONG in_nbVct );
00777 
00786         CSIBCVector3Dd& LinearPositionInterpolate( const CSIBCVector3Dd& in_vct1, const CSIBCVector3Dd& in_vct2, const double in_dT );
00787 
00800         friend double GetPntsAngle( const CSIBCVector3Dd& in_pntOrigin,
00801                                     const CSIBCVector3Dd& in_pnt1,
00802                                     const CSIBCVector3Dd& in_pnt2 );
00803 
00818         friend double Get2DPntsAngleSigned( const CSIBCVector3Dd& in_pntOrigin,
00819                                             const CSIBCVector3Dd& in_pnt1,
00820                                             const CSIBCVector3Dd& in_pnt2 );
00821 
00834         friend double GetPntsCosAngle(  const CSIBCVector3Dd& in_pntOrigin,
00835                                         const CSIBCVector3Dd& in_pnt1,
00836                                         const CSIBCVector3Dd& in_pnt2 );
00837 
00850         friend double GetVctsAngle( const CSIBCVector3Dd&   in_vct1,
00851                                     const CSIBCVector3Dd&   in_vct2,
00852                                     const double in_dEpsilon = PICO_EPS );
00853 
00867         friend double Get2DVctsAngleSigned( const CSIBCVector3Dd& in_vct1,
00868                                             const CSIBCVector3Dd& in_vct2 );
00869 
00870 
00882         friend double GetVctsCosAngle(  const CSIBCVector3Dd& in_vct1,
00883                                         const CSIBCVector3Dd& in_vct2,
00884                                         const double in_dEpsilon = PICO_EPS );
00885 
00886 
00895         friend int Get2DPntSide(    const CSIBCVector3Dd& in_pnt,
00896                                     const CSIBCVector3Dd& in_pntOrigin,
00897                                     const CSIBCVector3Dd& in_pntTip );
00898 
00899 
00906         friend double GetTriangleArea(
00907             const CSIBCVector3Dd& in_rPoint0,
00908             const CSIBCVector3Dd& in_rPoint1,
00909             const CSIBCVector3Dd& in_rPoint2 );
00910 
00912         // To be implemented later //
00914 
00915         // Cardinal & Bezier Position Interpolate doens't exist in SI3D3.7
00916         // What about Linear, Cardinal & Bezier VectorInterpolate
00917 
00918         // SetBounds    | Readjust boundaries (min and max) to contain a given point.
00920         void SetBounds( const CSIBCVector3Dd& in_pnt, CSIBCVector3Dd& io_min, CSIBCVector3Dd& io_max );
00921 
00922         // Combine      | Compute this=s1*v1 + s2*v2.
00924         CSIBCVector3Dd& Combine( const CSIBCVector3Dd& in_vct1, const double in_dS1,
00925             const CSIBCVector3Dd& in_vct2, const double in_dS2 );
00926 
00927 #ifdef _DEBUG
00928          void SelfDebug() const;
00929          void DoDebugInit();
00930 #endif
00931 
00933         // To finish implementing    //
00935 
00936         // BsplinePositionInterpolate | Interpolates a BSpline position between four 3D vectors.
00938         CSIBCVector3Dd& BsplinePositionInterpolate( const CSIBCVector3Dd& in_vct1,
00939                                     const CSIBCVector3Dd& in_vct2, const CSIBCVector3Dd& in_vct3,
00940                                     const CSIBCVector3Dd& in_vct4, const double in_dT );
00941 
00942         // BsplineVectorInterpolate | Interpolates a BSpline vector between four 3D vectors.
00944         CSIBCVector3Dd& BsplineVectorInterpolate( const CSIBCVector3Dd& in_vct1,
00945                                     const CSIBCVector3Dd& in_vct2, const CSIBCVector3Dd& in_vct3,
00946                                     const CSIBCVector3Dd& in_vct4, const double in_dT );
00947 
00948         // ArePntsCollinear | Verify if three points are collinear.
00950         friend bool ArePntsCollinear( const CSIBCVector3Dd& in_pnt1,
00951                                         const CSIBCVector3Dd& in_pnt2,
00952                                         const CSIBCVector3Dd& in_pnt3,
00953                                         const double in_dEpsilon = PICO_EPS );
00954 
00955         // AreVctsCoplanar  | Verify if two vectors are coplanar.
00957         friend bool AreVctsCoplanar ( const CSIBCVector3Dd& in_vct1,
00958                                         const CSIBCVector3Dd& in_vct2,
00959                                         const CSIBCVector3Dd& in_vct3,
00960                                         const double in_dEpsilon = PICO_EPS );
00961 
00962         // ArePntsCoplanar  | Verify if three points are coplanar.
00964         friend bool ArePntsCoplanar ( const CSIBCVector3Dd& in_pnt1,
00965                                         const CSIBCVector3Dd& in_pnt2,
00966                                         const CSIBCVector3Dd& in_pnt3,
00967                                         const CSIBCVector3Dd& in_pnt4,
00968                                         const double in_dEpsilon = PICO_EPS );
00969 
00970     // Private Members
00971     private:
00972 
00973         //****************************************
00974         // ATTRIBUTES
00975         //****************************************
00976         // double | CSIBCVector3Dd | m_dX | X component of the vector.
00977         // double | CSIBCVector3Dd | m_dY | Y component of the vector.
00978         // double | CSIBCVector3Dd | m_dZ | Z component of the vector.
00979         double  m_dX, m_dY, m_dZ;
00980 
00981     public:
00982 
00984     // Useful constants:
00986     static const CSIBCVector3Dd k_UnitVector;
00987 };
00988 
00989 typedef CSIBCVector3Dd* LP3DVECTOR3;
00990 
00991 //******************************************************************************
00992 //
00993 // Author       : Michel Carigan
00994 // Date         : 08/05/96
00995 // Updated by   : Eric Cabot (02/25/97)
00996 //
00997 // Set each component to be at least epsilon (in absolute or not depending on in_bInAbs).
00998 //
00999 // A reference on this.
01000 //
01001 // This function works like the macro _SI_VCT_EPS in v3.51
01002 // That is, each component are set to eps only if they are less than epsilon.
01003 // In that case the sign is unchanged.
01004 //
01005 //
01006 //******************************************************************************
01007 inline  CSIBCVector3Dd&
01008 CSIBCVector3Dd::SetMinimal
01009     (
01010         bool in_bInAbs,             // Tells if the test is done in absolute value or not (true by default).
01011         const double in_dEpsilon    // The epsilon to compare with (PICO_EPS by default).
01012     )
01013 {
01014 
01015     if( in_bInAbs )
01016     {
01017 
01018         if( fabs(m_dX) < in_dEpsilon )
01019             m_dX = ( ( m_dX >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01020         if( fabs(m_dY) < in_dEpsilon )
01021             m_dY = ( ( m_dY >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01022         if( fabs(m_dZ) < in_dEpsilon )
01023             m_dZ = ( ( m_dZ >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
01024     }
01025     else
01026     {
01027         if( m_dX < in_dEpsilon )
01028         {
01029             m_dX = in_dEpsilon;
01030         }
01031         if( m_dY < in_dEpsilon )
01032         {
01033             m_dY = in_dEpsilon;
01034         }
01035         if( m_dZ < in_dEpsilon )
01036         {
01037             m_dZ = in_dEpsilon;
01038         }
01039     }
01040 
01041     return *this;
01042 }
01043 
01044 #endif