My Project
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 
49 public:
50 
51 
53 
54 
60  static T3DMatrix<T> diagonal(T value);
61 
67  static T3DMatrix<T> diagonal(const T3DVector<T>& values);
68 
69 
75  template <typename I>
77 
78 
84  T3DMatrix(const T3DVector< T3DVector<T>>& other);
85 
86 
94 
101 
102 
107  void print( std::ostream& os) const;
108 
109 
114 
115 
119  T get_det() const;
120 
121 
125  int get_rank()const;
126 
138 
145 
151 
152 
154  static const T3DMatrix _1;
155 
157  static const T3DMatrix _0;
158 
159 private:
160  void evaluate_ev() const;
161 
162 
163  mutable int m_ev_type; // 0 = not valid
164  mutable T3DVector<T> m_evalues;
165  mutable std::vector<T3DCVector<T>> m_complex_evectors;
166  mutable std::vector<int> m_ev_order;
167 };
168 
169 template <typename T>
170 template <typename I>
172  T3DVector<T3DVector<T>>(T3DVector<T>(o.x),
173  T3DVector<T>(o.y),
174  T3DVector<T>(o.z)),
175  m_ev_type(0)
176 {
177 }
178 
179 template <typename T>
181 {
182  return T3DVector<T>(dot(m.x, x), dot(m.y, x), dot(m.z, x));
183 }
184 
185 template <typename T>
187 {
188  return T3DVector<T>(m.x.x * x.x + m.y.x * x.y + m.z.x * x.z,
189  m.x.y * x.x + m.y.y * x.y + m.z.y * x.z,
190  m.x.z * x.x + m.y.z * x.y + m.z.z * x.z);
191 }
192 
193 
194 template <typename T>
195 std::ostream& operator << (std::ostream& os, const T3DMatrix<T>& m)
196 {
197  m.print(os);
198  return os;
199 }
200 
201 template <typename T>
203 {
204  m_ev_type = 0;
205  this->x -= o.x;
206  this->y -= o.y;
207  this->z -= o.z;
208  return *this;
209 }
210 
211 template <typename T>
213 {
214  return T3DMatrix<T>(T3DVector<T>(m.x.x * x.x.x + m.x.y * x.y.x + m.x.z * x.z.x,
215  m.x.x * x.x.y + m.x.y * x.y.y + m.x.z * x.z.y,
216  m.x.x * x.x.z + m.x.y * x.y.z + m.x.z * x.z.z),
217  T3DVector<T>(m.y.x * x.x.x + m.y.y * x.y.x + m.y.z * x.z.x,
218  m.y.x * x.x.y + m.y.y * x.y.y + m.y.z * x.z.y,
219  m.y.x * x.x.z + m.y.y * x.y.z + m.y.z * x.z.z),
220  T3DVector<T>(m.z.x * x.x.x + m.z.y * x.y.x + m.z.z * x.z.x,
221  m.z.x * x.x.y + m.z.y * x.y.y + m.z.z * x.z.y,
222  m.z.x * x.x.z + m.z.y * x.y.z + m.z.z * x.z.z));
223 }
224 
227 
230 
231 
232 template <typename T>
234  T3DVector< T >(0, 1, 0),
235  T3DVector< T >(0, 0, 1));
236 
237 template <typename T>
239 
240 extern template class EXPORT_3D T3DMatrix<float>;
241 extern template class EXPORT_3D T3DMatrix<double>;
242 
243 
245 
246 #endif
T3DMatrix< float > C3DFMatrix
a simple 3x3 matrix with single precision floating point values
Definition: 3d/matrix.hh:226
T3DMatrix< double > C3DDMatrix
a simple 3x3 matrix with double precision floating point values
Definition: 3d/matrix.hh:229
std::ostream & operator<<(std::ostream &os, const T3DMatrix< T > &m)
Definition: 3d/matrix.hh:195
T3DVector< T > operator*(const T3DMatrix< T > &m, const T3DVector< T > &x)
Definition: 3d/matrix.hh:180
a simple 3x3 matrix
Definition: 3d/matrix.hh:46
T3DVector< T > get_real_eigenvector(int i) const
T get_det() const
static const T3DMatrix _0
The zero matrix.
Definition: 3d/matrix.hh:157
static const T3DMatrix _1
The unity matrix.
Definition: 3d/matrix.hh:154
T3DMatrix(const T3DMatrix< I > &o)
Definition: 3d/matrix.hh:171
T3DMatrix< T > transposed() const
void print(std::ostream &os) const
T3DMatrix< T > & operator-=(const T3DMatrix< T > &other)
Definition: 3d/matrix.hh:202
T3DMatrix(const T3DVector< T3DVector< T >> &other)
T3DMatrix(const T3DVector< T > &x, const T3DVector< T > &y, const T3DVector< T > &z)
static T3DMatrix< T > diagonal(const T3DVector< T > &values)
static T3DMatrix< T > diagonal(T value)
int get_eigenvalues(T3DVector< T > &v) const
T3DCVector< T > get_complex_eigenvector(int i) const
int get_rank() const
A simple 3D vector type.
Definition: 3d/vector.hh:49
T3DVector< T > y
vector element
Definition: 3d/vector.hh:54
T3DVector< T > z
vector element
Definition: 3d/vector.hh:56
T3DVector< T > x
vector element
Definition: 3d/vector.hh:52
#define EXPORT_3D
Definition: defines3d.hh:45
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
double EXPORT_GSL dot(const gsl_vector *lhs, const gsl_vector *rhs)