Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __cmtkMatrix4x4_h_included_
00034 #define __cmtkMatrix4x4_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <Base/cmtkTypes.h>
00039 #include <Base/cmtkFixedVector.h>
00040 #include <Base/cmtkMatrix3x3.h>
00041
00042 #include <System/cmtkConsole.h>
00043 #include <System/cmtkSmartPtr.h>
00044
00045 namespace
00046 cmtk
00047 {
00048
00051
00053 template<class T=Types::Coordinate>
00054 class Matrix4x4
00055 {
00056 public:
00058 typedef Matrix4x4<T> Self;
00059
00061 typedef SmartPointer<Self> SmartPtr;
00062
00064 static const Self IdentityMatrix;
00065
00070 Matrix4x4();
00071
00073 Matrix4x4( const Matrix3x3<T>& other );
00074
00079 Matrix4x4( const T *const values )
00080 {
00081 if ( values ) this->Set( values );
00082 }
00083
00085 template<class T2>
00086 Matrix4x4( const T2 (&matrix)[4][4] )
00087 {
00088 for ( size_t j = 0; j < 4; ++j )
00089 for ( size_t i = 0; i < 4; ++i )
00090 this->Matrix[j][i] = matrix[j][i];
00091 }
00092
00094 Self& Set( const T *const values );
00095
00097 const Self GetInverse() const;
00098
00100 Self GetTranspose() const;
00101
00103 T* operator[]( const size_t i ) { return &this->Matrix[i][0]; }
00104
00106 const T* operator[]( const size_t i ) const { return &this->Matrix[i][0]; }
00107
00109 Self& Compose( const Types::Coordinate params[15], const bool logScaleFactors = false );
00110
00112 bool Decompose( Types::Coordinate params[12], const Types::Coordinate *center = NULL, const bool logScaleFactors = false ) const;
00113
00115 Self& operator*=( const Self& other );
00116
00118 const Self operator*( const Self& other ) const;
00119
00121 Self& operator=( const Matrix3x3<T>& other );
00122
00125 Self& ChangeCoordinateSystem( const FixedVector<3,T>& newX, const FixedVector<3,T>& newY );
00126
00128 static Self RotateX( const T angle );
00129
00131 static Self RotateY( const T angle );
00132
00134 static Self RotateZ( const T angle );
00135
00137 T FrobeniusNorm() const;
00138
00140 void Print( Console& console ) const
00141 {
00142 for ( int j = 0; j < 4; ++j )
00143 {
00144 for ( int i = 0; i < 4; ++i )
00145 console.printf( "%f\t", (float)this->Matrix[j][i] );
00146 console << "\n";
00147 }
00148 }
00149
00150 private:
00152 T Matrix[4][4];
00153 };
00154
00155 template<typename T> const Matrix4x4<T> Matrix4x4<T>::IdentityMatrix;
00156
00158 template<class T,class T2>
00159 FixedVector<3,T2>&
00160 operator*=( FixedVector<3,T2>& u, const Matrix4x4<T>& M )
00161 {
00162 return u = u*M;
00163 }
00164
00166 template<class T,class T2>
00167 FixedVector<3,T2>
00168 operator*( const FixedVector<3,T2>& u, const Matrix4x4<T>& M )
00169 {
00170 FixedVector<3,T2> v;
00171 for ( int idx=0; idx<3; ++idx )
00172 v[idx] = u[0]*M[0][idx] + u[1]*M[1][idx] + u[2]*M[2][idx] + M[3][idx];
00173 return v;
00174 }
00175
00177 template<class T>
00178 inline
00179 Console& operator<< ( Console& stream, const Matrix4x4<T>& m )
00180 {
00181 stream << "4x4 Matrix:\n";
00182 for ( int i = 0; i < 4; ++i )
00183 {
00184 for ( int j = 0; j < 4; ++j )
00185 stream << "[" << i << "][" << j << "]=" << m[i][j] << "\t";
00186 stream << "\n";
00187 }
00188 return stream;
00189 }
00190
00192
00193 }
00194
00195 #endif // #ifndef __cmtkMatrix4x4_h_included_