TAPs 0.7.7.3
TAPsColMatrix3x3.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsColMatrix3x3.hpp
00003 
00004 ColMatrix3x3 class is a class for a 3-by-3 matrix in column-major order.
00005 
00006 SUKITTI PUNAK   (09/14/2004)
00007 UPDATE          (07/30/2005)
00008 ******************************************************************************/
00009 #ifndef TAPs_COL_MATRIX3X3_H
00010 #define TAPs_COL_MATRIX3X3_H
00011 
00012 #include "TAPsMath.hpp"
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 template <typename T>
00017 class ColMatrix3x3 {
00018 //=============================================================================
00019 private:
00020     // Matrix Elements
00021     //       --                --
00022     //      |  e[0]  e[3]  e[6]  |
00023     //      |  e[1]  e[4]  e[7]  |
00024     //      |  e[2]  e[5]  e[8]  |
00025     //       --                --
00026     T e[9];
00027     //-------------------------------------------------------------------------
00028     // Static Data Members for Data Conversions
00029     static float        g_f[9];
00030     static double       g_d[9];
00031     static long double  g_ld[9];
00032     //-------------------------------------------------------------------------
00033 public:
00034     //-------------------------------------------------------------------------
00035     // Output Operator <<
00036     friend std::ostream & operator<< ( std::ostream &output, ColMatrix3x3<T> const &M )
00037     {
00038         int width = 14;
00039         //output << typeid(*this).name() << "( ";
00040         output  << "ColMatrix3x3<" << typeid(T).name() << "> =\n"
00041                 << "| " << std::setw(width) << M.e[0] 
00042                         << std::setw(width) << M.e[3] 
00043                         << std::setw(width) << M.e[6] << " |\n"
00044                 << "| " << std::setw(width) << M.e[1] 
00045                         << std::setw(width) << M.e[4] 
00046                         << std::setw(width) << M.e[7] << " |\n"
00047                 << "| " << std::setw(width) << M.e[2] 
00048                         << std::setw(width) << M.e[5] 
00049                         << std::setw(width) << M.e[8] << " |\n";
00050         //output << std::endl;
00051         return output;
00052     }
00053     //-------------------------------------------------------------------------
00054     // Constructors and Destructor
00055     ColMatrix3x3 ();        // default constructor (Identity Matrix)
00056     ColMatrix3x3 ( ColMatrix3x3<T> const &M );      // copy constructor
00057     ColMatrix3x3 ( T );                         // constructor
00058     ColMatrix3x3 ( T, T, T, T, T, T, T, T, T ); // constructor
00059     ColMatrix3x3 ( T const af[9] );             // constructor from array
00060     ~ColMatrix3x3 ();                               // destructor
00061     //-------------------------------------------------------------------------
00062     // Member Access
00063     inline T &       operator[] ( int i );
00064     inline T const & operator[] ( int i ) const;
00065     inline T &       operator() ( int r, int c );
00066     inline T const & operator() ( int r, int c ) const;
00067     //-------------------------------------------------------------------------
00068     // Convert to one dimension array
00069     operator const T *() const;
00070     operator T *();
00071     //-------------------------------------------------------------------------
00072     // Useful Functions
00073     inline void SetAllElements ( T );                           // set all elements
00074     inline void SetAllElements ( T, T, T, T, T, T, T, T, T );   // set all elements
00075     inline void SetAllElements ( T const af[9] );               // set all elements
00076     inline void MakeIdentity ();                    // set to identity matrix
00077     inline void MakeDiagonal ( T d );               // set to diagonal matrix
00078     inline void MakeDiagonal ( T const af[3] );     // set to diagonal matrix
00079     inline void MakeZero ();                        // set all elements to zero
00080     //-------------------------------------------------------------------------
00081     // Matrix Operations
00082     inline ColMatrix3x3<T> & Transposed ();
00083     inline ColMatrix3x3<T>   GetTranspose () const;
00084     inline ColMatrix3x3<T> & Inversed ();
00085     ColMatrix3x3<T>   GetInverse () const;
00086     inline T GetDeterminant () const;
00087     //-------------------------------------------------------------------------
00088     // Assignment Overloaded Operator
00089     ColMatrix3x3<T> & operator= ( ColMatrix3x3<T> const &M );
00090     //-------------------------------------------------------------------------
00091     // Unary Overloaded Operators
00092     ColMatrix3x3<T> operator- ();   // negation
00093     //-------------------------------------------------------------------------
00094     // Assign Overloaded Operators
00095     ColMatrix3x3<T> &operator+= ( ColMatrix3x3<T> const &M );   // += with matrix
00096     ColMatrix3x3<T> &operator-= ( ColMatrix3x3<T> const &M );   // -= with matrix
00097     ColMatrix3x3<T> &operator*= ( ColMatrix3x3<T> const &M );   // *= with matrix
00098     ColMatrix3x3<T> &operator*= ( T s );                    // *= with scalar
00099     ColMatrix3x3<T> &operator/= ( T s );                    // /= with scalar
00100     //-------------------------------------------------------------------------
00101     // Binary Overloaded Operators
00102     ColMatrix3x3<T> operator+ ( ColMatrix3x3<T> const &M ) const;   // matrix + matrix
00103     ColMatrix3x3<T> operator- ( ColMatrix3x3<T> const &M ) const;   // matrix - matrix
00104     ColMatrix3x3<T> operator* ( ColMatrix3x3<T> const &M ) const;   // matrix * matrix
00105     ColMatrix3x3<T> operator* ( T s ) const;                    // matrix * scalar
00106     friend inline ColMatrix3x3<T> operator* ( T s, ColMatrix3x3<T> const &M )   // scalar * matrix
00107     {   return M * s;   }
00108     ColMatrix3x3<T> operator/ ( T s ) const;                    // matrix / scalar
00109     inline void MultLeft ( ColMatrix3x3<T> const &M );  // this matrix = matrix M * this matrix
00110     inline void MultRight ( ColMatrix3x3<T> const &M ); // this matrix = this matrix * matrix M
00111     //-------------------------------------------------------------------------
00112     // Static Member Functions for Data Conversions
00113     const float *       GetDataFloat () const;
00114     const double *      GetDataDouble () const;
00115     const long double * GetDataLongDouble () const;
00116     const float *       GetTransposeDataFloat () const;
00117     const double *      GetTransposeDataDouble () const;
00118     const long double * GetTransposeDataLongDouble () const;
00119     //-------------------------------------------------------------------------
00120 }; // END CLASS ColMatrix3x3
00121 //=============================================================================
00122 //-----------------------------------------------------------------------------
00123 // Define ColMatrix3x3s
00124 typedef ColMatrix3x3<int>           ColMatrix3x3i;
00125 typedef ColMatrix3x3<float>         ColMatrix3x3f;
00126 typedef ColMatrix3x3<double>        ColMatrix3x3d;
00127 typedef ColMatrix3x3<long double>   ColMatrix3x3ld;
00128 //=============================================================================
00129 END_NAMESPACE_TAPs
00130 //-----------------------------------------------------------------------------
00131 // Include definition if TAPs_USE_EXPORT is not defined
00132 //#if !defined( TAPs_USE_EXPORT )
00133     #include "TAPsColMatrix3x3.cpp"
00134 //#endif
00135 //-----------------------------------------------------------------------------
00136 #endif
00137 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00138 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines