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

itkVariableSizeMatrix.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVariableSizeMatrix.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/10/14 19:58:32 $
00007   Version:   $Revision: 1.7 $
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 __itkVariableSizeMatrix_h
00018 #define __itkVariableSizeMatrix_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 #include "itkArray.h"
00029 
00030 
00031 namespace itk
00032 {
00033 
00043 template<class T >
00044 class VariableSizeMatrix {
00045 public:
00047   typedef VariableSizeMatrix  Self;
00048 
00050   typedef T ValueType;
00051   typedef T ComponentType;
00052 
00054   typedef vnl_matrix<T>  InternalMatrixType;
00055 
00057   Array<T> operator*(const Array<T> & vector) const;
00058 
00060   Self operator*(const Self & matrix) const;
00061 
00063   Self operator+(const Self & matrix) const;
00064   const Self & operator+=(const Self & matrix );
00066 
00068   Self operator-(const Self & matrix) const;
00069   const Self & operator-=(const Self & matrix );
00071 
00073   vnl_matrix<T> operator*(const vnl_matrix<T> & matrix) const;
00074 
00076   void operator*=(const Self & matrix);
00077 
00079   void operator*=(const vnl_matrix<T> & matrix);
00080 
00082   vnl_vector<T> operator*(const vnl_vector<T> & matrix) const;
00083 
00085   void operator*=(const T & value)
00086     { m_Matrix *= value; }
00087 
00089   Self operator*(const T & value)
00090     { Self result( *this );
00091       result *= value;
00092       return result; }
00094 
00096   void operator/=(const T & value)
00097     { m_Matrix /= value; }
00098 
00100   Self operator/(const T & value)
00101     { Self result( *this );
00102       result /= value;
00103       return result; }
00105 
00107   inline T & operator()( unsigned int row, unsigned int col )
00108     { return m_Matrix(row,col); }
00109 
00111   inline const T & operator()( unsigned int row, unsigned int col ) const
00112     { return m_Matrix(row,col); }
00113 
00115   inline T * operator[]( unsigned int i )
00116     { return m_Matrix[i]; }
00117 
00119   inline const T * operator[]( unsigned int i ) const
00120     { return m_Matrix[i]; }
00121 
00123   inline InternalMatrixType & GetVnlMatrix( void )
00124     { return m_Matrix; }
00125 
00127   inline const InternalMatrixType & GetVnlMatrix( void ) const
00128     { return m_Matrix; }
00129 
00131   inline void SetIdentity( void ) 
00132     { m_Matrix.set_identity(); }
00133 
00135   inline void Fill( const T & value ) 
00136     { m_Matrix.fill( value ); }
00137 
00139   inline const Self & operator=( const vnl_matrix<T> & matrix)
00140   {
00141     m_Matrix = matrix;
00142     return *this;
00143   }
00144 
00146   inline bool operator==( const Self & matrix) const;
00147   inline bool operator!=( const Self & matrix) const
00148   {
00149     return !this->operator==(matrix);
00150   }
00152 
00154   inline const Self & operator=( const Self & matrix)
00155   {
00156     m_Matrix = matrix.m_Matrix;
00157     return *this;
00158   }
00159 
00160 
00162   inline vnl_matrix<T> GetInverse( void ) const
00163   {
00164     vnl_matrix<T> temp = vnl_matrix_inverse<T>( m_Matrix );
00165     return temp;
00166   }
00168 
00169  
00171   inline vnl_matrix<T> GetTranspose( void ) const
00172   {
00173     return m_Matrix.transpose();
00174   }
00175 
00177   VariableSizeMatrix() : m_Matrix() {};
00178 
00179   VariableSizeMatrix(unsigned int rows, unsigned int cols);
00180 
00182   VariableSizeMatrix(const Self & matrix) : m_Matrix( matrix.m_Matrix ) {};
00183 
00185   inline unsigned int Rows() const { return m_Matrix.rows(); } 
00186 
00188   inline unsigned int Cols() const { return m_Matrix.cols(); } 
00189 
00191   inline bool SetSize( unsigned int r, unsigned int c)
00192     {  return m_Matrix.set_size( r, c );  }
00193 
00194  
00195  
00196 private:
00197   InternalMatrixType     m_Matrix;
00198 };
00199 
00200 template< class T >  
00201 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00202                                     const VariableSizeMatrix<T> & v) 
00203                             { os << v.GetVnlMatrix(); return os; }
00204 
00205 
00206   
00210 template<class T>
00211 inline
00212 bool
00213 VariableSizeMatrix<T>
00214 ::operator==( const Self & matrix ) const  
00215 {
00216   if( (matrix.Rows() != this->Rows()) ||
00217       (matrix.Cols() != this->Cols()))
00218     { 
00219     return false;
00220     }
00221   bool equal = true;
00223 
00224   for( unsigned int r=0; r<this->Rows(); r++) 
00225     {
00226     for( unsigned int c=0; c<this->Cols(); c++ ) 
00227       {
00228       if (m_Matrix(r,c) != matrix.m_Matrix(r,c))
00229         {
00230         equal = false;
00231         break;
00232         }
00233       }
00234     }
00235   return equal;
00236 }
00237 
00238 } // end namespace itk
00239   
00240 
00241 #ifndef ITK_MANUAL_INSTANTIATION
00242 #include "itkVariableSizeMatrix.txx"
00243 #endif
00244 
00245 
00246 #endif 
00247 

Generated at Mon Mar 12 03:16:57 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000