# SIBCVectorwd.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 _VECTORW_H_
    00021 #define _VECTORW_H_
    00022
    00023 //******************************************************************************
    00024 // Includes
    00025 //******************************************************************************
    00026
    00027 #include "SIBCMathLib.h"
    00028
    00029 //******************************************************************************
    00030 // Typedefs
    00031 //******************************************************************************
    00032
    00033 //******************************************************************************
    00034 // CSIBCVectorwd | General 3D vector.
    00035 //******************************************************************************
    00036
    00038
    00049 class XSICOREEXPORT CSIBCVectorwd
    00050 {
    00051     // Public members
    00052     public:
    00053
    00054         //****************************************
    00055         // IMPLEMENTATION
    00056         //****************************************
    00057
    00061         CSIBCVectorwd ( );
    00062
    00071         CSIBCVectorwd ( const double in_dX, const double in_dY,
    00072                         const double in_dZ, const double in_dW );
    00073
    00074         ~CSIBCVectorwd();
    00075
    00076         // Individual access to private member:
    00077
    00086         double GetX( void ) const;
    00087
    00096         double GetY( void ) const;
    00097
    00106         double GetZ( void ) const;
    00107
    00116         double GetW( void ) const;
    00117
    00128         double Get( const int in_iIndex ) const;
    00129
    00141         void  Get(  double& out_dX, double& out_dY,
    00142                     double& out_dZ, double& out_dW ) const;
    00143
    00153         CSIBCVectorwd& SetX( const double in_dVal );
    00154
    00164         CSIBCVectorwd& SetY( const double in_dVal );
    00165
    00175         CSIBCVectorwd& SetZ( const double in_dVal );
    00176
    00186         CSIBCVectorwd& SetW( const double in_dVal );
    00187
    00196         CSIBCVectorwd& Set( const int in_nIndex, const double in_dVal );
    00197
    00198
    00212         CSIBCVectorwd& Set( const double in_dX, const double in_dY,
    00213                             const double in_dZ, const double in_dW );
    00214
    00215
    00221         CSIBCVectorwd& SetNull( void );
    00222
    00231         bool IsNull( const double in_dEpsilon=PICO_EPS ) const;
    00232
    00239         CSIBCVectorwd& SetMinimal ( const double in_dEpsilon=PICO_EPS );
    00240
    00250         bool AreAlmostEqual ( const CSIBCVectorwd& in_vct,
    00251                               const double in_dEpsilon = PICO_EPS ) ;
    00252
    00260         bool operator == ( const CSIBCVectorwd& in_vct ) const;
    00261
    00269         bool operator != ( const CSIBCVectorwd& in_vct ) const;
    00270
    00275         CSIBCVectorwd& Negate( void );
    00276
    00283         double GetLength( void ) const;
    00284
    00292         bool SetLength( const double in_dLength );
    00293
    00300         bool Normalize( void );
    00301
    00302         // Efficient arithmetic operations.
    00303
    00304
    00313         CSIBCVectorwd& Add( const CSIBCVectorwd& in_vct );
    00314
    00324         CSIBCVectorwd& Add( const CSIBCVectorwd& in_vct1, const CSIBCVectorwd& in_vct2  );
    00325
    00334         CSIBCVectorwd& Sub( const CSIBCVectorwd& in_vct1 );
    00335
    00345         CSIBCVectorwd& Sub( const CSIBCVectorwd& in_vct1, const CSIBCVectorwd& in_vct2  );
    00346
    00356         CSIBCVectorwd& Mul( const double in_vct );
    00357
    00368         CSIBCVectorwd& Mul( const double in_dFactor, const CSIBCVectorwd& in_vct );
    00369
    00380         CSIBCVectorwd& Mul( const CSIBCVectorwd& in_vct, const double in_dFactor );
    00381
    00391         CSIBCVectorwd& Div( const double in_vct1);
    00392
    00403         CSIBCVectorwd& Div( const double in_dFactor, const CSIBCVectorwd& in_vct );
    00404
    00416         CSIBCVectorwd& MulComp( const CSIBCVectorwd& in_vct1, const CSIBCVectorwd& in_vct2  );
    00417
    00428         CSIBCVectorwd& MulComp( const CSIBCVectorwd& in_vct );
    00429
    00440         CSIBCVectorwd& DivComp( const CSIBCVectorwd& in_vct );
    00441
    00453         CSIBCVectorwd& DivComp( const CSIBCVectorwd& in_vct1, const CSIBCVectorwd& in_vct2 );
    00454
    00455
    00462         friend double GetDot(   const CSIBCVectorwd& in_vct1,
    00463                                 const CSIBCVectorwd& in_vct2 );
    00464
    00465
    00473         friend double GetDistance(  const CSIBCVectorwd& in_pnt1,
    00474                                     const CSIBCVectorwd& in_pnt2 );
    00475
    00483         friend double GetSquaredDistance (  const CSIBCVectorwd& in_pnt1,
    00484                                             const CSIBCVectorwd& in_pnt2 );
    00485
    00486
    00495         CSIBCVectorwd& SetMidpoint (    const CSIBCVectorwd& in_pnt1,
    00496                                         const CSIBCVectorwd& in_pnt2 );
    00497
    00498
    00508         CSIBCVectorwd& LinearPositionInterpolate (  const CSIBCVectorwd& in_vct1,
    00509                                                     const CSIBCVectorwd& in_vct2,
    00510                                                     const double in_dT );
    00511
    00512
    00514         // To be implemented later //
    00516
    00517
    00518
    00519         // SetOrthogonal    | Given v1 and v2, compute the vector that
    00520         //                    is orthogonal to v1, and that is in the same
    00521         //                    plane as v1 and v2.
    00523         bool SetOrthogonal ( const CSIBCVectorwd& in_vct1,
    00524                              const CSIBCVectorwd& in_vct2 );
    00525
    00526         // SetOrthoProj     | Same as SetOrthogonal, but the resulting
    00527         //                    vector is the projection of v2.
    00529         bool SetOrthoProj  ( const CSIBCVectorwd& in_vct1,
    00530                              const CSIBCVectorwd& in_vct2 );
    00531
    00532         // AreOrthogonal    | Verify if two vectors are orthogonal.
    00534         friend bool AreOrthogonal ( const CSIBCVectorwd& in_vct1,
    00535                                     const CSIBCVectorwd& in_vct2,
    00536                                     const double in_dEpsilon = PICO_EPS );
    00537
    00538         // SetProjection    | Project this vector onto another vector.
    00540         CSIBCVectorwd& SetProjection ( const CSIBCVectorwd& in_vct );
    00541
    00542         // SetMirror        | Compute this=2*v2 - v1.
    00544         CSIBCVectorwd& SetMirror(   const CSIBCVectorwd& in_vct1,
    00545                                     const CSIBCVectorwd& in_vct2 );
    00546
    00548         CSIBCVectorwd& BsplinePositionInterpolate ( const CSIBCVectorwd& in_vct1,
    00549                                             const CSIBCVectorwd& in_vct2,
    00550                                             const CSIBCVectorwd& in_vct3,
    00551                                             const CSIBCVectorwd& in_vct4,
    00552                                             const double in_dT );
    00553
    00554
    00555         // Combine          | Compute this=s1*v1 + s2*v2.
    00557          CSIBCVectorwd& Combine(    const CSIBCVectorwd& in_vct1, const double in_dS1,
    00558                                     const CSIBCVectorwd& in_vct2, const double in_dS2 );
    00559
    00560         // SetBounds        | Readjust boundaries (min and max) to contain a given point.
    00562          void SetBounds     ( const CSIBCVectorwd& in_pnt,
    00563                               CSIBCVectorwd& io_min,
    00564                               CSIBCVectorwd& io_max );
    00565
    00567          friend double GetVctAngle  (   const CSIBCVectorwd& in_vct1,
    00568                                         const CSIBCVectorwd& in_vct2,
    00569                                         const bool in_bIsSigned = false );
    00570
    00571         // GetPntAngle  | Compute angle (signed or not) between three points.
    00573         friend double GetPntAngle(  const CSIBCVectorwd& in_pnt1,
    00574                                     const CSIBCVectorwd& in_pnt2,
    00575                                     const CSIBCVectorwd& in_pnt3,
    00576                                     const bool in_bIsSigned = false );
    00577
    00578         // GetVctCosAngle   | Compute cosinus of angle between two vectors.
    00580           friend double GetVctCosAngle( const CSIBCVectorwd& in_vct1,
    00581                                         const CSIBCVectorwd& in_vct2 );
    00582
    00583         // GetPntCosAngle   | Compute cosinus of angle between three points.
    00585         friend double GetPntCosAngle(   const CSIBCVectorwd& in_pnt1,
    00586                                         const CSIBCVectorwd& in_pnt2,
    00587                                         const CSIBCVectorwd& in_pnt3 );
    00588
    00589         // ArePntCollinear | Verify if three points are collinear.
    00591         friend bool ArePntCollinear(    const CSIBCVectorwd& in_pnt1,
    00592                                         const CSIBCVectorwd& in_pnt2,
    00593                                         const CSIBCVectorwd& in_pnt3,
    00594                                         const double in_dEpsilon = PICO_EPS );
    00595
    00596         // AreVctCoplanar   | Verify if two vectors are coplanar.
    00598         friend bool AreVctCoplanar (    const CSIBCVectorwd& in_vct1,
    00599                                         const CSIBCVectorwd& in_vct2,
    00600                                         const CSIBCVectorwd& in_vct3,
    00601                                         const double in_dEpsilon = PICO_EPS );
    00602
    00603         // ArePntCoplanar   | Verify if three points are coplanar.
    00605         friend bool ArePntCoplanar( const CSIBCVectorwd& in_pnt1,
    00606                                     const CSIBCVectorwd& in_pnt2,
    00607                                     const CSIBCVectorwd& in_pnt3,
    00608                                     const CSIBCVectorwd& in_pnt4,
    00609                                     const double in_dEpsilon = PICO_EPS );
    00610
    00611         // GetVctAngle      | Compute angle (signed or not) between two vectors.
    00612
    00613
    00614     // Private Members
    00615     private:
    00616
    00617         //****************************************
    00618         // ATTRIBUTES
    00619         //****************************************
    00620         // double | CSIBCVectorwd | m_dX | X component of the vector.
    00621         // double | CSIBCVectorwd | m_dY | Y component of the vector.
    00622         // double | CSIBCVectorwd | m_dZ | Z component of the vector.
    00623         double  m_dX, m_dY, m_dZ, m_dW;
    00624
    00625         //Disable copy constructor and operator =
    00626         // CSIBCVectorwd      | The copy Constructor
    00627         CSIBCVectorwd ( const CSIBCVectorwd& in_vct );
    00628         // operator=                    | Assigment operator.
    00629         CSIBCVectorwd& operator = ( const CSIBCVectorwd& in_vct );
    00630 };
    00631
    00632 //******************************************************************************
    00633 //
    00634 // Author : Michel Carigan
    00635 // Date  : 08/15/96
    00636 //
    00637 // CSIBCVectorwd& | CSIBCVectorwd | SetMinimal | Sets each component to be at least
    00638 //                                epsilon (in absolute).
    00639 //
    00640 // CSIBCVectorwd& SetMinimal( const double in_dEpsilon = PICO_EPS )
    00641 //
    00642 // double | in_dEpsilon | Specify the user minimal value. If not given, the default
    00643 //                                        value will be <t PICO_EPS>
    00644 //
    00645 // A reference on this.
    00646 //
    00647 // This function works like the macro _SI_VCT_EPS in v3.51
    00648 // That is, each component are set to eps only if they are less than epsilon.
    00649 // In that case the sign is unchanged.
    00650 // The w component is set to 1.0
    00651 //
    00652 //
    00653 //******************************************************************************
    00654 inline  CSIBCVectorwd&
    00655 CSIBCVectorwd::SetMinimal
    00656     (
    00657         const double in_dEpsilon /* = PICO_EPS */
    00658     )
    00659 {
    00660     if( fabs(m_dX) < in_dEpsilon )
    00661         m_dX = ( ( m_dX >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
    00662     if( fabs(m_dY) < in_dEpsilon )
    00663         m_dY = ( ( m_dY >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
    00664     if( fabs(m_dZ) < in_dEpsilon )
    00665         m_dZ = ( ( m_dZ >= 0 ) ? in_dEpsilon : -in_dEpsilon ) ;
    00666     m_dW = 1;
    00667     return *this;
    00668 }
    00669
    00670
    00671 #endif  // _VECTORW_H_