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-2015 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 
42 template <typename T>
43 class T3DMatrix: public T3DVector< T3DVector<T> > {
44 
45 
46 public:
47 
48  T3DMatrix();
49 
50 
56  static T3DMatrix<T> diagonal(T value);
57 
63  static T3DMatrix<T> diagonal(const T3DVector<T>& values);
64 
65 
71  template <typename I>
72  T3DMatrix(const T3DMatrix<I>& o);
73 
74 
80  T3DMatrix(const T3DVector< T3DVector<T> >& other);
81 
82 
89  T3DMatrix(const T3DVector< T >& x, const T3DVector< T >& y, const T3DVector< T >& z );
90 
96  T3DMatrix<T>& operator -= (const T3DMatrix<T>& other);
97 
98 
103  void print( std::ostream& os) const;
104 
105 
109  T3DMatrix<T> transposed()const;
110 
111 
115  T get_det() const;
116 
117 
121  int get_rank()const;
122 
132  int get_eigenvalues(C3DFVector& v)const;
133 
139  C3DFVector get_eigenvector(int i)const;
140 
141 
143  static const T3DMatrix _1;
144 
146  static const T3DMatrix _0;
147 
148 private:
149  void evaluate_ev() const;
150 
151 
152  mutable int m_ev_type; // 0 = not valid
153  mutable C3DFVector m_evalues;
154  mutable std::vector<C3DFVector> m_evectors;
155  mutable std::vector<int> m_ev_order;
156 };
157 
158 template <typename T>
159 template <typename I>
161  T3DVector<T3DVector<T> >(T3DVector<T>(o.x),
162  T3DVector<T>(o.y),
163  T3DVector<T>(o.z)),
164  m_ev_type(0)
165 {
166 }
167 
168 template <typename T>
170 {
171  return T3DVector<T>(dot(m.x, x), dot(m.y, x), dot(m.z, x));
172 }
173 
174 template <typename T>
176 {
177  return T3DVector<T>(m.x.x * x.x + m.y.x * x.y + m.z.x * x.z,
178  m.x.y * x.x + m.y.y * x.y + m.z.y * x.z,
179  m.x.z * x.x + m.y.z * x.y + m.z.z * x.z);
180 }
181 
182 
183 template <typename T>
184 std::ostream& operator << (std::ostream& os, const T3DMatrix<T>& m)
185 {
186  m.print(os);
187  return os;
188 }
189 
190 template <typename T>
192 {
193  m_ev_type = 0;
194  this->x -= o.x;
195  this->y -= o.y;
196  this->z -= o.z;
197  return *this;
198 }
199 
200 template <typename T>
202 {
203  return T3DMatrix<T>(T3DVector<T>(m.x.x * x.x.x + m.x.y * x.y.x + m.x.z * x.z.x,
204  m.x.x * x.x.y + m.x.y * x.y.y + m.x.z * x.z.y,
205  m.x.x * x.x.z + m.x.y * x.y.z + m.x.z * x.z.z),
206  T3DVector<T>(m.y.x * x.x.x + m.y.y * x.y.x + m.y.z * x.z.x,
207  m.y.x * x.x.y + m.y.y * x.y.y + m.y.z * x.z.y,
208  m.y.x * x.x.z + m.y.y * x.y.z + m.y.z * x.z.z),
209  T3DVector<T>(m.z.x * x.x.x + m.z.y * x.y.x + m.z.z * x.z.x,
210  m.z.x * x.x.y + m.z.y * x.y.y + m.z.z * x.z.y,
211  m.z.x * x.x.z + m.z.y * x.y.z + m.z.z * x.z.z));
212 }
213 
216 
219 
220 
221 template <typename T>
223  T3DVector< T >(0,1,0),
224  T3DVector< T >(0,0,1));
225 
226 template <typename T>
228 
229 extern template class EXPORT_3D T3DMatrix<float>;
230 extern template class EXPORT_3D T3DMatrix<double>;
231 
232 
234 
235 #endif
T3DMatrix< T > & operator-=(const T3DMatrix< T > &other)
Definition: 3d/matrix.hh:191
T3DMatrix< T > transposed() const
T3DVector< T > z
vector element
Definition: 3d/vector.hh:55
static const T3DMatrix _0
The zero matrix.
Definition: 3d/matrix.hh:146
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:43
static T3DMatrix< T > diagonal(T value)
T3DMatrix< float > C3DFMatrix
a simple 3x3 matrix with single precision floating point values
Definition: 3d/matrix.hh:215
#define EXPORT_3D
Definition: defines3d.hh:44
int get_rank() const
T3DMatrix< double > C3DDMatrix
a simple 3x3 matrix with double precision floating point values
Definition: 3d/matrix.hh:218
int get_eigenvalues(C3DFVector &v) 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:169
void print(std::ostream &os) const
C3DFVector get_eigenvector(int i) const
A simple 3D vector type.
Definition: 3d/vector.hh:48
T dot(const T2DVector< T > &a, const T2DVector< T > &b)
Definition: 2d/vector.hh:395
a simple 3x3 matrix
Definition: 3d/matrix.hh:43
T3DVector< T > x
vector element
Definition: 3d/vector.hh:51
T get_det() const
static const T3DMatrix _1
The unity matrix.
Definition: 3d/matrix.hh:143
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46