3d/matrix.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 #ifndef __mia_3d_matrix_hh
21 #define __mia_3d_matrix_hh
22 
23 #include <vector>
24 #include <memory>
25 
26 #include <mia/3d/vector.hh>
27 #include <mia/core/msgstream.hh>
28 
30 
31 template <typename T>
33 
44 template <typename T>
45 class T3DMatrix: public T3DVector< T3DVector<T> > {
46 
47 
48 public:
49 
50 
51  T3DMatrix();
52 
53 
59  static T3DMatrix<T> diagonal(T value);
60 
66  static T3DMatrix<T> diagonal(const T3DVector<T>& values);
67 
68 
74  template <typename I>
75  T3DMatrix(const T3DMatrix<I>& o);
76 
77 
83  T3DMatrix(const T3DVector< T3DVector<T> >& other);
84 
85 
92  T3DMatrix(const T3DVector< T >& x, const T3DVector< T >& y, const T3DVector< T >& z );
93 
99  T3DMatrix<T>& operator -= (const T3DMatrix<T>& other);
100 
101 
106  void print( std::ostream& os) const;
107 
108 
112  T3DMatrix<T> transposed()const;
113 
114 
118  T get_det() const;
119 
120 
124  int get_rank()const;
125 
136  int get_eigenvalues(T3DVector<T>& v)const;
137 
144 
150 
151 
153  static const T3DMatrix _1;
154 
156  static const T3DMatrix _0;
157 
158 private:
159  void evaluate_ev() const;
160 
161 
162  mutable int m_ev_type; // 0 = not valid
163  mutable T3DVector<T> m_evalues;
164  mutable std::vector<T3DCVector<T>> m_complex_evectors;
165  mutable std::vector<int> m_ev_order;
166 };
167 
168 template <typename T>
169 template <typename I>
171  T3DVector<T3DVector<T> >(T3DVector<T>(o.x),
172  T3DVector<T>(o.y),
173  T3DVector<T>(o.z)),
174  m_ev_type(0)
175 {
176 }
177 
178 template <typename T>
180 {
181  return T3DVector<T>(dot(m.x, x), dot(m.y, x), dot(m.z, x));
182 }
183 
184 template <typename T>
186 {
187  return T3DVector<T>(m.x.x * x.x + m.y.x * x.y + m.z.x * x.z,
188  m.x.y * x.x + m.y.y * x.y + m.z.y * x.z,
189  m.x.z * x.x + m.y.z * x.y + m.z.z * x.z);
190 }
191 
192 
193 template <typename T>
194 std::ostream& operator << (std::ostream& os, const T3DMatrix<T>& m)
195 {
196  m.print(os);
197  return os;
198 }
199 
200 template <typename T>
202 {
203  m_ev_type = 0;
204  this->x -= o.x;
205  this->y -= o.y;
206  this->z -= o.z;
207  return *this;
208 }
209 
210 template <typename T>
212 {
213  return T3DMatrix<T>(T3DVector<T>(m.x.x * x.x.x + m.x.y * x.y.x + m.x.z * x.z.x,
214  m.x.x * x.x.y + m.x.y * x.y.y + m.x.z * x.z.y,
215  m.x.x * x.x.z + m.x.y * x.y.z + m.x.z * x.z.z),
216  T3DVector<T>(m.y.x * x.x.x + m.y.y * x.y.x + m.y.z * x.z.x,
217  m.y.x * x.x.y + m.y.y * x.y.y + m.y.z * x.z.y,
218  m.y.x * x.x.z + m.y.y * x.y.z + m.y.z * x.z.z),
219  T3DVector<T>(m.z.x * x.x.x + m.z.y * x.y.x + m.z.z * x.z.x,
220  m.z.x * x.x.y + m.z.y * x.y.y + m.z.z * x.z.y,
221  m.z.x * x.x.z + m.z.y * x.y.z + m.z.z * x.z.z));
222 }
223 
226 
229 
230 
231 template <typename T>
233  T3DVector< T >(0,1,0),
234  T3DVector< T >(0,0,1));
235 
236 template <typename T>
238 
239 extern template class EXPORT_3D T3DMatrix<float>;
240 extern template class EXPORT_3D T3DMatrix<double>;
241 
242 
244 
245 #endif
T3DMatrix< T > & operator-=(const T3DMatrix< T > &other)
Definition: 3d/matrix.hh:201
T3DVector< T > z
vector element
Definition: 3d/vector.hh:55
int get_eigenvalues(T3DVector< T > &v) const
static const T3DMatrix _0
The zero matrix.
Definition: 3d/matrix.hh:156
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
static T3DMatrix< T > diagonal(T value)
T3DMatrix< float > C3DFMatrix
a simple 3x3 matrix with single precision floating point values
Definition: 3d/matrix.hh:225
T3DMatrix< T > transposed() const
T3DCVector< T > get_complex_eigenvector(int i) const
#define EXPORT_3D
Definition: defines3d.hh:44
T3DMatrix< double > C3DDMatrix
a simple 3x3 matrix with double precision floating point values
Definition: 3d/matrix.hh:228
int get_rank() const
T3DVector< T > y
vector element
Definition: 3d/vector.hh:53
T3DVector< T > operator*(const T3DMatrix< T > &m, const T3DVector< T > &x)
Definition: 3d/matrix.hh:179
T3DVector< T > get_real_eigenvector(int i) const
double EXPORT_GSL dot(const gsl_vector *lhs, const gsl_vector *rhs)
void print(std::ostream &os) const
A simple 3D vector type.
Definition: 3d/vector.hh:48
T get_det() const
a simple 3x3 matrix
Definition: 3d/matrix.hh:45
T3DVector< T > x
vector element
Definition: 3d/vector.hh:51
static const T3DMatrix _1
The unity matrix.
Definition: 3d/matrix.hh:153
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36