00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkVariableSizeMatrix.h,v $ 00005 Language: C++ 00006 Date: $Date: 2005/10/24 19:48:52 $ 00007 Version: $Revision: 1.6 $ 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 "itkArray.h" 00026 00027 00028 namespace itk 00029 { 00030 00040 template<class T > 00041 class VariableSizeMatrix { 00042 public: 00044 typedef VariableSizeMatrix Self; 00045 00047 typedef T ValueType; 00048 typedef T ComponentType; 00049 00051 typedef vnl_matrix<T> InternalMatrixType; 00052 00054 Array<T> operator*(const Array<T> & vector) const; 00055 00057 Self operator*(const Self & matrix) const; 00058 00060 Self operator+(const Self & matrix) const; 00061 const Self & operator+=(const Self & matrix ); 00063 00065 Self operator-(const Self & matrix) const; 00066 const Self & operator-=(const Self & matrix ); 00068 00070 vnl_matrix<T> operator*(const vnl_matrix<T> & matrix) const; 00071 00073 void operator*=(const Self & matrix); 00074 00076 void operator*=(const vnl_matrix<T> & matrix); 00077 00079 vnl_vector<T> operator*(const vnl_vector<T> & matrix) const; 00080 00082 void operator*=(const T & value) 00083 { m_Matrix *= value; } 00084 00086 Self operator*(const T & value) 00087 { Self result( *this ); 00088 result *= value; 00089 return result; } 00091 00093 void operator/=(const T & value) 00094 { m_Matrix /= value; } 00095 00097 Self operator/(const T & value) 00098 { Self result( *this ); 00099 result /= value; 00100 return result; } 00102 00104 inline T & operator()( unsigned int row, unsigned int col ) 00105 { return m_Matrix(row,col); } 00106 00108 inline const T & operator()( unsigned int row, unsigned int col ) const 00109 { return m_Matrix(row,col); } 00110 00112 inline T * operator[]( unsigned int i ) 00113 { return m_Matrix[i]; } 00114 00116 inline const T * operator[]( unsigned int i ) const 00117 { return m_Matrix[i]; } 00118 00120 inline InternalMatrixType & GetVnlMatrix( void ) 00121 { return m_Matrix; } 00122 00124 inline const InternalMatrixType & GetVnlMatrix( void ) const 00125 { return m_Matrix; } 00126 00128 inline void SetIdentity( void ) 00129 { m_Matrix.set_identity(); } 00130 00132 inline void Fill( const T & value ) 00133 { m_Matrix.fill( value ); } 00134 00136 inline const Self & operator=( const vnl_matrix<T> & matrix); 00137 00139 inline bool operator==( const Self & matrix) const; 00140 inline bool operator!=( const Self & matrix) const; 00142 00144 inline const Self & operator=( const Self & matrix); 00145 00147 inline vnl_matrix<T> GetInverse( void ) const; 00148 00150 inline vnl_matrix<T> GetTranspose( void ) const; 00151 00153 VariableSizeMatrix() : m_Matrix() {}; 00154 00155 VariableSizeMatrix(unsigned int rows, unsigned int cols); 00156 00158 VariableSizeMatrix(const Self & matrix) : m_Matrix( matrix.m_Matrix ) {}; 00159 00161 inline unsigned int Rows() const { return m_Matrix.rows(); } 00162 00164 inline unsigned int Cols() const { return m_Matrix.cols(); } 00165 00167 inline bool SetSize( unsigned int r, unsigned int c) 00168 { return m_Matrix.set_size( r, c ); } 00169 00170 00171 00172 private: 00173 InternalMatrixType m_Matrix; 00174 }; 00175 00176 template< class T > 00177 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 00178 const VariableSizeMatrix<T> & v) 00179 { os << v.GetVnlMatrix(); return os; } 00180 00181 00182 00183 } // end namespace itk 00184 00185 00186 #ifndef ITK_MANUAL_INSTANTIATION 00187 #include "itkVariableSizeMatrix.txx" 00188 #endif 00189 00190 00191 #endif 00192