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: 2007-11-05 00:34:00 $
00007   Version:   $Revision: 1.8 $
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   Self & operator- ();
00074 
00076   vnl_matrix<T> operator*(const vnl_matrix<T> & matrix) const;
00077 
00079   void operator*=(const Self & matrix);
00080 
00082   void operator*=(const vnl_matrix<T> & matrix);
00083 
00085   vnl_vector<T> operator*(const vnl_vector<T> & matrix) const;
00086 
00088   void operator*=(const T & value)
00089     { m_Matrix *= value; }
00090 
00092   Self operator*(const T & value)
00093     {
00094     Self result( *this );
00095     result *= value;
00096     return result;
00097     }
00099 
00101   void operator/=(const T & value)
00102     {
00103     m_Matrix /= value;
00104     }
00105 
00107   Self operator/(const T & value)
00108     {
00109     Self result( *this );
00110     result /= value;
00111     return result;
00112     }
00114 
00116   inline T & operator()( unsigned int row, unsigned int col )
00117     {
00118     return m_Matrix(row,col);
00119     }
00120 
00122   inline const T & operator()( unsigned int row, unsigned int col ) const
00123     {
00124     return m_Matrix(row,col);
00125     }
00126 
00128   inline T * operator[]( unsigned int i )
00129     {
00130     return m_Matrix[i];
00131     }
00132 
00134   inline const T * operator[]( unsigned int i ) const
00135     {
00136     return m_Matrix[i];
00137     }
00138 
00140   inline InternalMatrixType & GetVnlMatrix( void )
00141     {
00142     return m_Matrix;
00143     }
00144 
00146   inline const InternalMatrixType & GetVnlMatrix( void ) const
00147     {
00148     return m_Matrix;
00149     }
00150 
00152   inline void SetIdentity( void ) 
00153     {
00154     m_Matrix.set_identity();
00155     }
00156 
00158   inline void Fill( const T & value ) 
00159     {
00160     m_Matrix.fill( value );
00161     }
00162 
00164   inline const Self & operator=( const vnl_matrix<T> & matrix)
00165     {
00166     m_Matrix = matrix;
00167     return *this;
00168     }
00169 
00171   inline bool operator==( const Self & matrix) const;
00172   inline bool operator!=( const Self & matrix) const
00173     {
00174     return !this->operator==(matrix);
00175     }
00177 
00179   inline const Self & operator=( const Self & matrix)
00180     {
00181     m_Matrix = matrix.m_Matrix;
00182     return *this;
00183     }
00184 
00185 
00187   inline vnl_matrix<T> GetInverse( void ) const
00188     {
00189     vnl_matrix<T> temp = vnl_matrix_inverse<T>( m_Matrix );
00190     return temp;
00191     }
00193 
00194  
00196   inline vnl_matrix<T> GetTranspose( void ) const
00197     {
00198     return m_Matrix.transpose();
00199     }
00200 
00202   VariableSizeMatrix() : m_Matrix() {};
00203 
00204   VariableSizeMatrix(unsigned int rows, unsigned int cols);
00205 
00207   VariableSizeMatrix(const Self & matrix) : m_Matrix( matrix.m_Matrix ) {};
00208 
00210   inline unsigned int Rows() const { return m_Matrix.rows(); } 
00211 
00213   inline unsigned int Cols() const { return m_Matrix.cols(); } 
00214 
00216   inline bool SetSize( unsigned int r, unsigned int c)
00217     {  return m_Matrix.set_size( r, c );  }
00218 
00219 private:
00220   InternalMatrixType     m_Matrix;
00221 };
00222 
00223 template< class T >  
00224 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00225                                     const VariableSizeMatrix<T> & v) 
00226 {
00227   os << v.GetVnlMatrix(); return os;
00228 }
00229 
00230 
00231   
00235 template<class T>
00236 inline
00237 bool
00238 VariableSizeMatrix<T>
00239 ::operator==( const Self & matrix ) const  
00240 {
00241   if( (matrix.Rows() != this->Rows()) ||
00242       (matrix.Cols() != this->Cols()))
00243     { 
00244     return false;
00245     }
00246   bool equal = true;
00248 
00249   for( unsigned int r=0; r<this->Rows(); r++) 
00250     {
00251     for( unsigned int c=0; c<this->Cols(); c++ ) 
00252       {
00253       if (m_Matrix(r,c) != matrix.m_Matrix(r,c))
00254         {
00255         equal = false;
00256         break;
00257         }
00258       }
00259     }
00260   return equal;
00261 }
00262 
00263 } // end namespace itk
00264   
00265 
00266 #ifndef ITK_MANUAL_INSTANTIATION
00267 #include "itkVariableSizeMatrix.txx"
00268 #endif
00269 
00270 
00271 #endif 
00272 

Generated at Mon Jul 12 2010 20:07:00 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000