![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsColMatrix2x2.hpp 00003 00004 ColMatrix2x2 class is a class for a 2-by-2 matrix in column-major order. 00005 00006 SUKITTI PUNAK (09/12/2004) 00007 UPDATE (07/30/2005) 00008 ******************************************************************************/ 00009 #ifndef TAPs_COL_MATRIX2X2_H 00010 #define TAPs_COL_MATRIX2X2_H 00011 00012 #include "TAPsMath.hpp" 00013 00014 BEGIN_NAMESPACE_TAPs 00015 //============================================================================= 00016 template <typename T> 00017 class ColMatrix2x2 { 00018 //============================================================================= 00019 private: 00020 // Matrix Elements 00021 T e[4]; 00022 00023 public: 00024 //------------------------------------------------------------------------- 00025 // Output Operator << 00026 friend std::ostream & operator<< ( std::ostream &output, ColMatrix2x2<T> const &M ) 00027 { 00028 int width = 14; 00029 //output << typeid(*this).name() << "( "; 00030 output << "ColMatrix2x2<" << typeid(T).name() << "> =\n" 00031 << "| " << std::setw(width) << M.e[0] 00032 << std::setw(width) << M.e[2] << " |\n" 00033 << "| " << std::setw(width) << M.e[1] 00034 << std::setw(width) << M.e[3] << " |\n"; 00035 //output << std::endl; 00036 return output; 00037 } 00038 //------------------------------------------------------------------------- 00039 // Constructors and Destructor 00040 ColMatrix2x2 (); // default constructor (Identity Matrix) 00041 ColMatrix2x2 ( ColMatrix2x2<T> const &M ); // copy constructor 00042 ColMatrix2x2 ( T ); // constructor 00043 ColMatrix2x2 ( T, T, T, T ); // constructor 00044 ColMatrix2x2 ( T const af[4] ); // constructor from array 00045 ~ColMatrix2x2 (); // destructor 00046 //------------------------------------------------------------------------- 00047 // Member Access 00048 inline T & operator[] ( int i ); 00049 inline T const & operator[] ( int i ) const; 00050 inline T & operator() ( int r, int c ); 00051 inline T const & operator() ( int r, int c ) const; 00052 //------------------------------------------------------------------------- 00053 // Convert to one dimension array 00054 operator const T *() const; 00055 operator T *(); 00056 //------------------------------------------------------------------------- 00057 // Useful Functions 00058 void SetAllElements ( T ); // set all elements 00059 void SetAllElements ( T, T, T, T ); // set all elements 00060 void SetAllElements ( T const af[4] ); // set all elements 00061 void MakeIdentity (); // set to identity matrix 00062 void MakeDiagonal ( T d ); // set to diagonal matrix 00063 void MakeDiagonal ( T const af[4] ); // set to diagonal matrix 00064 void MakeZero (); // set all elements to zero 00065 //------------------------------------------------------------------------- 00066 // Matrix Operations 00067 ColMatrix2x2<T> & Transposed (); 00068 ColMatrix2x2<T> GetTranspose () const; 00069 ColMatrix2x2<T> & Inversed (); 00070 ColMatrix2x2<T> GetInverse () const; 00071 T GetDeterminant () const; 00072 //------------------------------------------------------------------------- 00073 // Assignment Overloaded Operator 00074 ColMatrix2x2<T> & operator= ( ColMatrix2x2<T> const &M ); 00075 //------------------------------------------------------------------------- 00076 // Unary Overloaded Operators 00077 ColMatrix2x2<T> operator- (); // negation 00078 //------------------------------------------------------------------------- 00079 // Assign Overloaded Operators 00080 ColMatrix2x2<T> &operator+= ( ColMatrix2x2<T> const &M ); // += with matrix 00081 ColMatrix2x2<T> &operator-= ( ColMatrix2x2<T> const &M ); // -= with matrix 00082 ColMatrix2x2<T> &operator*= ( ColMatrix2x2<T> const &M ); // *= with matrix 00083 ColMatrix2x2<T> &operator*= ( T s ); // *= with scalar 00084 ColMatrix2x2<T> &operator/= ( T s ); // /= with scalar 00085 //------------------------------------------------------------------------- 00086 // Binary Overloaded Operators 00087 ColMatrix2x2<T> operator+ ( ColMatrix2x2<T> const &M ) const; // matrix + matrix 00088 ColMatrix2x2<T> operator- ( ColMatrix2x2<T> const &M ) const; // matrix - matrix 00089 ColMatrix2x2<T> operator* ( ColMatrix2x2<T> const &M ) const; // matrix * matrix 00090 ColMatrix2x2<T> operator* ( T s ) const; // matrix * scalar 00091 friend inline ColMatrix2x2<T> operator* ( T s, ColMatrix2x2<T> const &M ) // scalar * matrix 00092 { return M * s; } 00093 ColMatrix2x2<T> operator/ ( T s ) const; // matrix / scalar 00094 inline void MultLeft ( ColMatrix2x2<T> const &M ); // this matrix = matrix M * this matrix 00095 inline void MultRight ( ColMatrix2x2<T> const &M ); // this matrix = this matrix * matrix M 00096 }; // END CLASS ColMatrix2x2 00097 //============================================================================= 00098 //----------------------------------------------------------------------------- 00099 // Define ColMatrix2x2s 00100 typedef ColMatrix2x2<int> ColMatrix2x2i; 00101 typedef ColMatrix2x2<float> ColMatrix2x2f; 00102 typedef ColMatrix2x2<double> ColMatrix2x2d; 00103 typedef ColMatrix2x2<long double> ColMatrix2x2ld; 00104 //============================================================================= 00105 END_NAMESPACE_TAPs 00106 //----------------------------------------------------------------------------- 00107 // Include definition if TAPs_USE_EXPORT is not defined 00108 //#if !defined( TAPs_USE_EXPORT ) 00109 #include "TAPsColMatrix2x2.cpp" 00110 //#endif 00111 //----------------------------------------------------------------------------- 00112 #endif 00113 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00114 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8