KWStyle - itkMatrix.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkMatrix.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:41 $
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 __itkMatrix_h
18 #define __itkMatrix_h
19
20
21 #include "itkPoint.h"
22 #include "itkVector.h"
23 #include "itkCovariantVector.h"
24 #include "vnl/vnl_matrix_fixed.h"
25
26
27 namespace itk
28 {
29
30 /** \class Matrix
31  * \brief A templated class holding a M x N size Matrix
32  * This class contains a vnl_matrix_fixed in order 
33  * to make all the vnl mathematical methods available.
34  *
35  * \ingroup DataRepresentation
36  */
37
38 template<class T, unsigned int NRows=3, unsigned int NColumns=3>
39 class Matrix {
40 public:
41   /** Standard class typedefs. */
42   typedef Matrix  Self;
43
44   /** Component value type */
45   typedef T ValueType;
46   typedef T ComponentType;
47
48   /** Number Of Columns and Rows. */
49   itkStaticConstMacro(RowDimensions,    unsigned int, NRows);
50   itkStaticConstMacro(ColumnDimensions, unsigned int, NColumns);
51
52   /** Internal matrix type */
53   typedef vnl_matrix_fixed<T,NRows,NColumns>  InternalMatrixType;
54
55   /** Matrix by Vector multiplication.  */
56   Vector<T,NRows> operator*(const Vector<T,NColumns> & vector) const;
57  
58   /** Matrix by Point multiplication.  */
59   Point<T,NRows> operator*(const Point<T,NColumns> & vector) const;
60  
61   /** Matrix by CovariantVector multiplication.  */
62   CovariantVector<T,NRows> 
63   operator*(const CovariantVector<T,NColumns> & vector) const;
64   
65   /** Matrix by Matrix multiplication.  */
66   Self operator*(const Self & matrix) const;
67  
68   /** Matrix addition.  */
69   Self operator+(const Self & matrix) const;
70   const Self & operator+=(const Self & matrix );
71  
72   /** Matrix addition.  */
73   Self operator-(const Self & matrix) const;
74   const Self & operator-=(const Self & matrix );
75  
76   /** Matrix by vnl_matrix multiplication.  */
77   vnl_matrix<T> operator*(const vnl_matrix<T> & matrix) const;
78
79   /** Matrix by Matrix multiplication.  */
80   void operator*=(const Self & matrix);
81  
82   /** Matrix by vnl_matrix multiplication.  */
83   void operator*=(const vnl_matrix<T> & matrix);
84
85   /** Matrix by vnl_vector multiplication.  */
86   vnl_vector<T> operator*(const vnl_vector<T> & matrix) const;
87
88   /** Matrix by scalar multiplication.  */
89   void operator*=(const T & value)
90     { m_Matrix *= value; }
91
92   /** Matrix by scalar multiplication.  */
93   Self operator*(const T & value)
94     { Self result( *this );
95 IND ******result *= value;
96 IND ******return result; }
97       
98   /** Matrix by scalar division.  */
99   void operator/=(const T & value)
100     { m_Matrix /= value; }
101   
102   /** Matrix by scalar division.  */
103   Self operator/(const T & value)
104     { Self result( *this );
105 IND ******result /= value;
106 IND ******return result; }
107
108
109   /** Return an element of the matrix. */
110   inline T & operator()( unsigned int row, unsigned int col )
111     { return m_Matrix(row,col); }
112
113   /** Return an element of the matrix. */
114   inline const T & operator()( unsigned int row, unsigned int col ) const
115     { return m_Matrix(row,col); }
116
117   /** Return a row of the matrix. */
118   inline T * operator[]( unsigned int i )
119     { return m_Matrix[i]; }
120
121   /** Return a row of the matrix.*/
122   inline const T * operator[]( unsigned int i ) const
123     { return m_Matrix[i]; }
124
125   /** Return the matrix. */
126   inline InternalMatrixType & GetVnlMatrix( void )
127     { return m_Matrix; }
128
129   /** Return the matrix. */
130   inline const InternalMatrixType & GetVnlMatrix( void ) const
131     { return m_Matrix; }
132
133   /** Set the matrix to identity. */
134   inline void SetIdentity( void ) 
135     { m_Matrix.set_identity(); }
136
137   /** Fill the matrix with a value. */
138   inline void Fill( const T & value ) 
139     { m_Matrix.fill( value ); }
140
141   /** Assignment operator. */
142   inline const Self & operator=( const vnl_matrix<T> & matrix);
143
144   /** Comparison operators. */
145   inline bool operator==( const Self & matrix);
146   inline bool operator!=( const Self & matrix);
147
148   /** Assignment operator. */
149   inline const Self & operator=( const Self & matrix);
150
151   /** Return the inverse matrix. */
152   inline vnl_matrix_fixed<T,NColumns,NRows> GetInverse( void ) const;
153  
154   /** Return the transposed matrix. */
155   inline vnl_matrix_fixed<T,NColumns,NRows> GetTranspose( void ) const;
156
157   /** Default constructor. */
158   Matrix() : m_Matrix(NumericTraits<T>::Zero) {};
159
160   /** Copy constructor. */
161   Matrix(const Self & matrix) : m_Matrix( matrix.m_Matrix ) {};
162  
163 private:
164   InternalMatrixType     m_Matrix;
165
166 };
167
168 template< class T, unsigned int NRows, unsigned int NColumns >  
169 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
170                                     const Matrix<T,NRows,NColumns> & v) 
171 IND,IND ****************************{ os << v.GetVnlMatrix(); return os; }
172
173
174   
175 // end namespace itk
176   
177
178 #ifndef ITK_MANUAL_INSTANTIATION
179 #include "itkMatrix.txx"
180 #endif
181
182
183 #endif 
184

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