ITK  6.0.0
Insight Toolkit
itkVariableSizeMatrix.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkVariableSizeMatrix_h
19#define itkVariableSizeMatrix_h
20
21#include "itkPoint.h"
22#include "itkCovariantVector.h"
23#include "vnl/vnl_matrix_fixed.h"
24#include "vnl/algo/vnl_matrix_inverse.h"
25#include "vnl/vnl_transpose.h"
26#include "vnl/vnl_matrix.h"
27#include "itkArray.h"
28#include "itkMath.h"
29
30namespace itk
31{
44template <typename T>
45class ITK_TEMPLATE_EXPORT VariableSizeMatrix
46{
47public:
50
52 using ValueType = T;
53 using ComponentType = T;
54
56 using InternalMatrixType = vnl_matrix<T>;
57
60 operator*(const Array<T> & vect) const;
61
63 Self
64 operator*(const Self & matrix) const;
65
67 Self
68 operator+(const Self & matrix) const;
69
70 const Self &
71 operator+=(const Self & matrix);
72
74 Self
75 operator-(const Self & matrix) const;
76
77 const Self &
78 operator-=(const Self & matrix);
79
81 Self &
83
85 vnl_matrix<T>
86 operator*(const vnl_matrix<T> & matrix) const;
87
89 void
90 operator*=(const Self & matrix);
91
93 void
94 operator*=(const vnl_matrix<T> & matrix);
95
97 vnl_vector<T>
98 operator*(const vnl_vector<T> & vc) const;
99
101 void
102 operator*=(const T & value)
103 {
104 m_Matrix *= value;
105 }
106
108 Self
109 operator*(const T & value) const
110 {
111 Self result(*this);
112
113 result *= value;
114 return result;
115 }
116
118 void
119 operator/=(const T & value)
120 {
121 m_Matrix /= value;
122 }
123
125 Self
126 operator/(const T & value) const
127 {
128 Self result(*this);
129
130 result /= value;
131 return result;
132 }
133
135 inline T &
136 operator()(unsigned int row, unsigned int col)
137 {
138 return m_Matrix(row, col);
139 }
140
142 inline const T &
143 operator()(unsigned int row, unsigned int col) const
144 {
145 return m_Matrix(row, col);
146 }
147
149 inline T *
150 operator[](unsigned int i)
151 {
152 return m_Matrix[i];
153 }
154
156 inline const T *
157 operator[](unsigned int i) const
158 {
159 return m_Matrix[i];
160 }
161
163 inline InternalMatrixType &
165 {
166 return m_Matrix;
167 }
168
170 inline const InternalMatrixType &
172 {
173 return m_Matrix;
174 }
175
177 inline void
179 {
180 m_Matrix.set_identity();
181 }
182
184 inline void
185 Fill(const T & value)
186 {
187 m_Matrix.fill(value);
188 }
189
191 inline Self &
192 operator=(const vnl_matrix<T> & matrix)
193 {
194 m_Matrix = matrix;
195 return *this;
196 }
197
199 inline bool
200 operator==(const Self & matrix) const;
201
203
205 inline Self &
206 operator=(const Self & matrix)
207 {
208 m_Matrix = matrix.m_Matrix;
209 return *this;
210 }
211
213 inline vnl_matrix<T>
215 {
216 return vnl_matrix_inverse<T>(m_Matrix).as_matrix();
217 }
218
220 inline vnl_matrix<T>
222 {
223 return m_Matrix.transpose();
224 }
225
228 : m_Matrix()
229 {}
230
231 VariableSizeMatrix(unsigned int rows, unsigned int cols);
232
234 VariableSizeMatrix(const Self & matrix)
235 : m_Matrix(matrix.m_Matrix)
236 {}
237
239 inline unsigned int
240 Rows() const
241 {
242 return m_Matrix.rows();
243 }
244
246 inline unsigned int
247 Cols() const
248 {
249 return m_Matrix.cols();
250 }
251
253 inline bool
254 SetSize(unsigned int r, unsigned int c)
255 {
256 return m_Matrix.set_size(r, c);
257 }
258
259private:
261};
262
263template <typename T>
264std::ostream &
265operator<<(std::ostream & os, const VariableSizeMatrix<T> & v)
266{
267 os << v.GetVnlMatrix();
268 return os;
269}
270
274template <typename T>
275inline bool
277{
278 if ((matrix.Rows() != this->Rows()) || (matrix.Cols() != this->Cols()))
279 {
280 return false;
281 }
282 bool equal = true;
285 for (unsigned int r = 0; r < this->Rows(); ++r)
286 {
287 for (unsigned int c = 0; c < this->Cols(); ++c)
288 {
289 if (Math::NotExactlyEquals(m_Matrix(r, c), matrix.m_Matrix(r, c)))
290 {
291 equal = false;
292 break;
293 }
294 }
295 }
296 return equal;
297}
298} // end namespace itk
299
300#ifndef ITK_MANUAL_INSTANTIATION
301# include "itkVariableSizeMatrix.hxx"
302#endif
303
304#endif
Pixel-wise addition of two images.
Array class with size defined at construction time.
Definition: itkArray.h:48
A templated class holding a M x N size Matrix.
void operator*=(const vnl_matrix< T > &matrix)
const Self & operator+=(const Self &matrix)
bool operator==(const Self &matrix) const
vnl_matrix< T > GetTranspose() const
Array< T > operator*(const Array< T > &vect) const
bool SetSize(unsigned int r, unsigned int c)
VariableSizeMatrix(unsigned int rows, unsigned int cols)
Self operator*(const T &value) const
vnl_matrix< T > operator*(const vnl_matrix< T > &matrix) const
void operator*=(const T &value)
VariableSizeMatrix(const Self &matrix)
vnl_vector< T > operator*(const vnl_vector< T > &vc) const
vnl_matrix< T > InternalMatrixType
Self operator*(const Self &matrix) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
const Self & operator-=(const Self &matrix)
void operator/=(const T &value)
Self operator/(const T &value) const
Self operator+(const Self &matrix) const
Self & operator=(const Self &matrix)
T & operator()(unsigned int row, unsigned int col)
const T & operator()(unsigned int row, unsigned int col) const
const InternalMatrixType & GetVnlMatrix() const
vnl_matrix< T > GetInverse() const
void operator*=(const Self &matrix)
Self & operator=(const vnl_matrix< T > &matrix)
const T * operator[](unsigned int i) const
T * operator[](unsigned int i)
InternalMatrixType & GetVnlMatrix()
Self operator-(const Self &matrix) const
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)