Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMatrix.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMatrix.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/01/18 22:10:03 $
00007   Version:   $Revision: 1.24 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkMatrix_h
00018 #define __itkMatrix_h
00019 
00020 
00021 #include "itkPoint.h"
00022 #include "itkVector.h"
00023 #include "itkCovariantVector.h"
00024 #include "vnl/vnl_matrix_fixed.h"
00025 #include "vnl/algo/vnl_matrix_inverse.h"
00026 #include "vnl/vnl_transpose.h"
00027 #include "vnl/vnl_matrix.h"
00028 
00029 
00030 namespace itk
00031 {
00032 
00041 template<class T, unsigned int NRows=3, unsigned int NColumns=3>
00042 class Matrix {
00043 public:
00045   typedef Matrix  Self;
00046 
00048   typedef T ValueType;
00049   typedef T ComponentType;
00050 
00052   itkStaticConstMacro(RowDimensions,    unsigned int, NRows);
00053   itkStaticConstMacro(ColumnDimensions, unsigned int, NColumns);
00055 
00057   typedef vnl_matrix_fixed<T,NRows,NColumns>  InternalMatrixType;
00058 
00060   Vector<T,NRows> operator*(const Vector<T,NColumns> & vector) const;
00061 
00063   Point<T,NRows> operator*(const Point<T,NColumns> & vector) const;
00064 
00066   CovariantVector<T,NRows> 
00067   operator*(const CovariantVector<T,NColumns> & vector) const;
00068 
00070   Self operator*(const Self & matrix) const;
00071 
00073   Self operator+(const Self & matrix) const;
00074   const Self & operator+=(const Self & matrix );
00076 
00078   Self operator-(const Self & matrix) const;
00079   const Self & operator-=(const Self & matrix );
00081 
00083   vnl_matrix<T> operator*(const vnl_matrix<T> & matrix) const;
00084 
00086   void operator*=(const Self & matrix);
00087 
00089   void operator*=(const vnl_matrix<T> & matrix);
00090 
00092   vnl_vector<T> operator*(const vnl_vector<T> & matrix) const;
00093 
00095   void operator*=(const T & value)
00096     { m_Matrix *= value; }
00097 
00099   Self operator*(const T & value)
00100     { Self result( *this );
00101       result *= value;
00102       return result; }
00104 
00106   void operator/=(const T & value)
00107     { m_Matrix /= value; }
00108 
00110   Self operator/(const T & value)
00111     { Self result( *this );
00112       result /= value;
00113       return result; }
00115 
00116 
00118   inline T & operator()( unsigned int row, unsigned int col )
00119     { return m_Matrix(row,col); }
00120 
00122   inline const T & operator()( unsigned int row, unsigned int col ) const
00123     { return m_Matrix(row,col); }
00124 
00126   inline T * operator[]( unsigned int i )
00127     { return m_Matrix[i]; }
00128 
00130   inline const T * operator[]( unsigned int i ) const
00131     { return m_Matrix[i]; }
00132 
00134   inline InternalMatrixType & GetVnlMatrix( void )
00135     { return m_Matrix; }
00136 
00138   inline const InternalMatrixType & GetVnlMatrix( void ) const
00139     { return m_Matrix; }
00140 
00142   inline void SetIdentity( void ) 
00143     { m_Matrix.set_identity(); }
00144 
00146   inline void Fill( const T & value ) 
00147     { m_Matrix.fill( value ); }
00148 
00150   inline const Self & operator=( const vnl_matrix<T> & matrix)
00151   {
00152     m_Matrix = matrix;
00153     return *this;
00154   }
00155 
00157   inline Matrix(const vnl_matrix<T> & matrix) {
00158     this->operator=(matrix);
00159   }
00160 
00162   inline bool operator==( const Self & matrix) const
00163   {
00164     bool equal = true;
00165     for( unsigned int r=0; r<NRows; r++) 
00166       {
00167       for( unsigned int c=0; c<NColumns; c++ ) 
00168         {
00169         if (m_Matrix(r,c) != matrix.m_Matrix(r,c))
00170           {
00171           equal = false;
00172           break;
00173           }
00174         }
00175       }
00176     return equal;
00177   }
00178   inline bool operator!=( const Self & matrix) const
00179   {
00180     return !this->operator==(matrix);
00181   }
00183 
00184 
00186   inline const Self & operator=( const Self & matrix)
00187   {
00188     m_Matrix = matrix.m_Matrix;
00189     return *this;
00190   }
00191 
00193   inline vnl_matrix_fixed<T,NColumns,NRows> GetInverse( void ) const
00194   {
00195     vnl_matrix<T> temp = vnl_matrix_inverse<T>( m_Matrix );
00196     return temp;
00197   }
00199 
00201   inline vnl_matrix_fixed<T,NColumns,NRows> GetTranspose( void ) const
00202   {
00203     return m_Matrix.transpose();
00204   }
00205 
00207   Matrix() : m_Matrix(NumericTraits<T>::Zero) {};
00208 
00210   Matrix(const Self & matrix) : m_Matrix( matrix.m_Matrix ) {};
00211 
00212 private:
00213   InternalMatrixType     m_Matrix;
00214 
00215 };
00216 
00217 template< class T, unsigned int NRows, unsigned int NColumns >  
00218 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00219                                     const Matrix<T,NRows,NColumns> & v) 
00220                             { os << v.GetVnlMatrix(); return os; }
00221 
00222 
00223   
00224 } // end namespace itk
00225 
00226 // Define instantiation macro for this template.
00227 #define ITK_TEMPLATE_Matrix(_, EXPORT, x, y) namespace itk { \
00228   _(3(class EXPORT Matrix< ITK_TEMPLATE_3 x >)) \
00229   namespace Templates { typedef Matrix< ITK_TEMPLATE_3 x > Matrix##y; } \
00230   }
00231 
00232 #if ITK_TEMPLATE_EXPLICIT
00233 # include "Templates/itkMatrix+-.h"
00234 #endif
00235 
00236 #if ITK_TEMPLATE_TXX
00237 # include "itkMatrix.txx"
00238 #endif
00239 
00240 #endif 
00241 

Generated at Sun Sep 23 13:27:27 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000