KWStyle - itkVariableSizeMatrix.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkVariableSizeMatrix.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:49 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkVariableSizeMatrix_h
18 #define __itkVariableSizeMatrix_h
19
20
21 #include "itkPoint.h"
22 #include "itkVector.h"
23 #include "itkCovariantVector.h"
24 #include "vnl/vnl_matrix_fixed.h"
25 #include "itkArray.h"
26
27
28 namespace itk
29 {
30
31 /** \class VariableSizeMatrix
32  * \brief A templated class holding a M x N size Matrix
33  * This class contains a vnl_matrix in order 
34  * to make all the vnl mathematical methods available. This class is meant to be
35  * used when the matrix length cannot be determined at compile time.
36  *
37  * \ingroup DataRepresentation
38  */
39
40 template<class T >
41 class VariableSizeMatrix {
42 public:
43   /** Standard class typedefs. */
44   typedef VariableSizeMatrix  Self;
45
46   /** Component value type */
47   typedef T ValueType;
48   typedef T ComponentType;
49
50   /** Internal matrix type */
51   typedef vnl_matrix<T>  InternalMatrixType;
52
53   /** Matrix by Vector multiplication.  */
54   Array<T> operator*(const Array<T> & vector) const;
55  
56   /** Matrix by Matrix multiplication.  */
57   Self operator*(const Self & matrix) const;
58  
59   /** Matrix addition.  */
60   Self operator+(const Self & matrix) const;
61   const Self & operator+=(const Self & matrix );
62  
63   /** Matrix addition.  */
64   Self operator-(const Self & matrix) const;
65   const Self & operator-=(const Self & matrix );
66  
67   /** Matrix by vnl_matrix multiplication.  */
68   vnl_matrix<T> operator*(const vnl_matrix<T> & matrix) const;
69
70   /** Matrix by Matrix multiplication.  */
71   void operator*=(const Self & matrix);
72  
73   /** Matrix by vnl_matrix multiplication.  */
74   void operator*=(const vnl_matrix<T> & matrix);
75
76   /** Matrix by vnl_vector multiplication.  */
77   vnl_vector<T> operator*(const vnl_vector<T> & matrix) const;
78
79   /** Matrix by scalar multiplication.  */
80   void operator*=(const T & value)
81     { m_Matrix *= value; }
82
83   /** Matrix by scalar multiplication.  */
84   Self operator*(const T & value)
85     { Self result( *this );
86 IND ******result *= value;
87 IND ******return result; }
88
89   /** Matrix by scalar division.  */
90   void operator/=(const T & value)
91     { m_Matrix /= value; }
92   
93   /** Matrix by scalar division.  */
94   Self operator/(const T & value)
95     { Self result( *this );
96 IND ******result /= value;
97 IND ******return result; }
98
99 IND ***/** Return an element of the matrix. */
100   inline T & operator()( unsigned int row, unsigned int col )
101     { return m_Matrix(row,col); }
102
103   /** Return an element of the matrix. */
104   inline const T & operator()( unsigned int row, unsigned int col ) const
105     { return m_Matrix(row,col); }
106
107   /** Return a row of the matrix. */
108   inline T * operator[]( unsigned int i )
109     { return m_Matrix[i]; }
110
111   /** Return a row of the matrix.*/
112   inline const T * operator[]( unsigned int i ) const
113     { return m_Matrix[i]; }
114
115   /** Return the matrix. */
116   inline InternalMatrixType & GetVnlMatrix( void )
117     { return m_Matrix; }
118
119   /** Return the matrix. */
120   inline const InternalMatrixType & GetVnlMatrix( void ) const
121     { return m_Matrix; }
122
123   /** Set the matrix to identity. */
124   inline void SetIdentity( void ) 
125     { m_Matrix.set_identity(); }
126
127   /** Fill the matrix with a value. */
128   inline void Fill( const T & value ) 
129     { m_Matrix.fill( value ); }
130
131   /** Assignment operator. */
132   inline const Self & operator=( const vnl_matrix<T> & matrix);
133
134   /** Comparison operators. */
135   inline bool operator==( const Self & matrix) const;
136   inline bool operator!=( const Self & matrix) const;
137
138   /** Assignment operator. */
139   inline const Self & operator=( const Self & matrix);
140
141   /** Return the inverse matrix. */
142   inline vnl_matrix<T> GetInverse( void ) const;
143  
144   /** Return the transposed matrix. */
145   inline vnl_matrix<T> GetTranspose( void ) const;
146
147   /** Default constructor. */
148   VariableSizeMatrix() : m_Matrix() {};
149   
150   VariableSizeMatrix(unsigned int rows, unsigned int cols);
151
152   /** Copy constructor. */
153   VariableSizeMatrix(const Self & matrix) : m_Matrix( matrix.m_Matrix ) {};
154
155   /** Return number of rows in the matrix */
156   inline unsigned int Rows() const { return m_Matrix.rows(); } 
157   
158   /** Return number of columns in the matrix */
159   inline unsigned int Cols() const { return m_Matrix.cols(); } 
160
161   /** Set the matrix size. Old data lost. Returns true if size changed. */
162   inline bool SetSize( unsigned int r, unsigned int c)
163     {  return m_Matrix.set_size( r, c );  }
164     
165  
166  
167 private:
168   InternalMatrixType     m_Matrix;
169 };
170
171 template< class T >  
172 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
173                                     const VariableSizeMatrix<T> & v) 
174 IND,IND ****************************{ os << v.GetVnlMatrix(); return os; }
175
176
177   
178 // end namespace itk
179   
180
181 #ifndef ITK_MANUAL_INSTANTIATION
182 #include "itkVariableSizeMatrix.txx"
183 #endif
184
185
186 #endif 
187

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:51PM
© Kitware Inc.