MeVisLab Toolbox Reference
mlMatrix6.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_MATRIX6_H
14#define ML_MATRIX6_H
15
17
18// Include system independent file and project settings.
19#include "mlErrorMacros.h"
21#include "mlLinearAlgebraDefs.h"
22
23
25
26#include "mlVector6.h"
27#include <mlErrorOutput.h>
28
29// All declarations of this header will be in the ML_LINEAR_ALGEBRA namespace.
31
32//--------------------------------------------------------------------
34//--------------------------------------------------------------------
35template <class DT>
36class Tmat6 : public FloatingPointMatrix<Tvec6<DT>, 6>
37{
38public:
39
41 typedef DT ComponentType;
42
43 // Builds a 6x6 matrix from 36 zero elements.
45
46 // Builds a matrix that has the argument at the diagonal values, zero otherwise
47 Tmat6(const DT diagValue);
48
49 // Builds a matrix of the six row vectors row0, ..., row5.
51 const Tvec6<DT> &row3, const Tvec6<DT> &row4, const Tvec6<DT> &row5);
52
53 // Copy constructor from the Tmat6 mat.
54 Tmat6(const Tmat6<DT> &m);
55
56 // Constructor from 36 floats given as array mat, read row by row.
57 Tmat6(const float mat[36]);
58
59 // Constructor from 36 doubles given as array mat, read row by row.
60 Tmat6(const double mat[36]);
61
62 // Initializes all matrix elements explicitly with scalars,
63 // filling it row by row.
64 Tmat6(const double in00, const double in01, const double in02, const double in03, const double in04, const double in05,
65 const double in10, const double in11, const double in12, const double in13, const double in14, const double in15,
66 const double in20, const double in21, const double in22, const double in23, const double in24, const double in25,
67 const double in30, const double in31, const double in32, const double in33, const double in34, const double in35,
68 const double in40, const double in41, const double in42, const double in43, const double in44, const double in45,
69 const double in50, const double in51, const double in52, const double in53, const double in54, const double in55);
70
71 // Copies the contents from float array m into *this. m must point to an
72 // array with at least 36 valid entries, read row by row.
73 void setValues(const float m[36]);
74
75 // Copies the contents of *this into float array m. Note that range
76 // and precision of the float values may not be sufficient for
77 // higher precision matrix contents. m must point to an array with
78 // at least 36 accessible entries, written row by row.
79 void getValues(float m[36]) const;
80
81 // Copies the contents from double array m into *this. m must point to an
82 // array with at least 36 valid entries, read row by row.
83 void setValues(const double m[36]);
84
85 // Copies the contents of *this into double array m. m must point to an
86 // array with at least 36 accessible entries, written row by row.
87 void getValues(double m[36]) const;
88
89 // Sets the diagonal matrix with scale on diagonal.
90 void setScaleMatrix(const DT scale);
91
92 // Returns a matrix filled with values val.
93 static Tmat6<DT> getMat(const double val);
94
95 // Sets all values to val.
96 void set(const DT val);
97
100 bool operator<(const Tmat6<DT> &) const { return false; }
101
102 // Assigns from a Tmat6.
104
105 // Adds component wise with a Tmat6.
107
108 // Subtracts component wise by a Tmat6.
110
111 // Multiplies by a scalar constant
112 const Tmat6<DT>& operator*=(const DT d);
113
114 // Divides by a scalar constant.
115 // Division by zero is not handled and must be avoided by caller.
116 const Tmat6<DT>& operator/=(const DT d);
117
118 //-------------------------------------------------
119 // Special functions
120 //-------------------------------------------------
121 // Determines the (sub)determinant of columns given by col1, col2, col3, col4 and col5.
122 DT determinantLower5(const int col1, const int col2, const int col3, const int col4, const int col5) const;
123
124 // Returns the determinant of this matrix.
125 DT det() const;
126
127 // Returns the inverse. Gauss-Jordan elimination with partial pivoting.
128 // If a non-NULL Boolean pointer is passed to isInvertible
129 // then true is returned in *isInvertible in the case of a
130 // successful inversion or false if the inversion is not possible
131 // (function return is the identity then).
132 // If a NULL pointer is passed as isInvertible the matrix must
133 // be invertible, otherwise errors will occur.
134 Tmat6<DT> inverse(bool* isInvertible=nullptr) const;
135
136 // Returns the transposed of this matrix.
138
139 // Returns the identity matrix.
141
142 // Applies the function fct to each component.
144
145}; // end of class *Tmat6*
146
147
148
149
150//---------------------------------------------------------------------
153//---------------------------------------------------------------------
155template <class DT>
157{
158 this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = this->v[5] = Tvec6<DT>(0);
159}
160
161// Constructs a matrix that has the argument at the diagonal values, zero otherwise
162template <class DT>
164{
165 this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] = this->v[4][4] = this->v[5][5] = diagValue;
166 this->v[1][0] = this->v[2][0] = this->v[3][0] = this->v[4][0] = this->v[5][0] = this->v[2][1] = this->v[3][1] = this->v[4][1] = this->v[5][1] = this->v[3][2] = this->v[4][2] = this->v[5][2] = this->v[4][3] = this->v[5][3] = this->v[5][4] = 0;
167 this->v[0][1] = this->v[0][2] = this->v[0][3] = this->v[0][4] = this->v[0][5] = this->v[1][2] = this->v[1][3] = this->v[1][4] = this->v[1][5] = this->v[2][3] = this->v[2][4] = this->v[2][5] = this->v[3][4] = this->v[3][5] = this->v[4][5] = 0;
168}
169
171template <class DT>
173 const Tvec6<DT>& row3, const Tvec6<DT>& row4, const Tvec6<DT>& row5)
174{
175 this->v[0] = row0;
176 this->v[1] = row1;
177 this->v[2] = row2;
178 this->v[3] = row3;
179 this->v[4] = row4;
180 this->v[5] = row5;
181}
182
184template <class DT>
186{
187 this->v[0] = mat.v[0];
188 this->v[1] = mat.v[1];
189 this->v[2] = mat.v[2];
190 this->v[3] = mat.v[3];
191 this->v[4] = mat.v[4];
192 this->v[5] = mat.v[5];
193}
194
196template <class DT>
197inline Tmat6<DT>::Tmat6(const float mat[36])
198{
199 setValues(mat);
200}
201
203template <class DT>
204inline Tmat6<DT>::Tmat6(const double mat[36])
205{
206 setValues(mat);
207}
208
210template <class DT>
211inline Tmat6<DT> Tmat6<DT>::getMat(const double val)
212{
213 return Tmat6<DT>(val, val, val, val, val, val,
214 val, val, val, val, val, val,
215 val, val, val, val, val, val,
216 val, val, val, val, val, val,
217 val, val, val, val, val, val,
218 val, val, val, val, val, val);
219}
220
222template <class DT>
223inline void Tmat6<DT>::set(DT val)
224{
225 this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = this->v[5] = Tvec6<DT>(val);
226}
227
229template <class DT>
231{
232 if (&m != this){
233 this->v[0] = m.v[0];
234 this->v[1] = m.v[1];
235 this->v[2] = m.v[2];
236 this->v[3] = m.v[3];
237 this->v[4] = m.v[4];
238 this->v[5] = m.v[5];
239 }
240
241 return *this;
242}
243
245template <class DT>
247{
248 this->v[0] += m.v[0];
249 this->v[1] += m.v[1];
250 this->v[2] += m.v[2];
251 this->v[3] += m.v[3];
252 this->v[4] += m.v[4];
253 this->v[5] += m.v[5];
254
255 return *this;
256}
257
259template <class DT>
261{
262 this->v[0] -= m.v[0];
263 this->v[1] -= m.v[1];
264 this->v[2] -= m.v[2];
265 this->v[3] -= m.v[3];
266 this->v[4] -= m.v[4];
267 this->v[5] -= m.v[5];
268
269 return *this;
270}
271
273template <class DT>
274inline const Tmat6<DT> & Tmat6<DT>::operator*=(const DT d)
275{
276 this->v[0] *= d;
277 this->v[1] *= d;
278 this->v[2] *= d;
279 this->v[3] *= d;
280 this->v[4] *= d;
281 this->v[5] *= d;
282
283 return *this;
284}
285
287template <class DT>
288inline const Tmat6<DT> & Tmat6<DT>::operator/=(const DT d)
289{
290 if (MLValueIs0WOM(d)){ ML_CHECK_THROW(0); }
291 this->v[0] /= d;
292 this->v[1] /= d;
293 this->v[2] /= d;
294 this->v[3] /= d;
295 this->v[4] /= d;
296 this->v[5] /= d;
297 return *this;
298}
299
300
301//--------------------------------------------------------------------
304//--------------------------------------------------------------------
306template <class DT>
308{
309 return Tmat6<DT>(a) *= static_cast<DT>(-1.0);
310}
311
313template <class DT>
314inline Tmat6<DT> operator+(const Tmat6<DT> &a, const Tmat6<DT> &b)
315{
316 return Tmat6<DT>(a) += b;
317}
318
320template <class DT>
321inline Tmat6<DT> operator-(const Tmat6<DT> &a, const Tmat6<DT> &b)
322{
323 return Tmat6<DT>(a) -= b;
324}
325
327template <class DT>
328inline Tmat6<DT> operator*(const Tmat6<DT> &a, const DT d)
329{
330 return Tmat6<DT>(a) *= d;
331}
332
334template <class DT>
335inline Tmat6<DT> operator*(const DT d, const Tmat6<DT> &a)
336{
337 return Tmat6<DT>(a) *= d;
338}
339
342template <class DT>
343inline Tmat6<DT> operator/(const Tmat6<DT> &a, const DT d)
344{
347 divided /= d;
348 return divided;
349}
351
352//-------------------------------------------------------------------
353//
356//
357//-------------------------------------------------------------------
358
359//-------------------------------------------------------------------
362//-------------------------------------------------------------------
363template <class DT>
364Tmat6<DT>::Tmat6(const double in00, const double in01, const double in02, const double in03, const double in04, const double in05,
365 const double in10, const double in11, const double in12, const double in13, const double in14, const double in15,
366 const double in20, const double in21, const double in22, const double in23, const double in24, const double in25,
367 const double in30, const double in31, const double in32, const double in33, const double in34, const double in35,
368 const double in40, const double in41, const double in42, const double in43, const double in44, const double in45,
369 const double in50, const double in51, const double in52, const double in53, const double in54, const double in55)
370{
371 this->v[0][0]=static_cast<DT>(in00); this->v[0][1]=static_cast<DT>(in01); this->v[0][2]=static_cast<DT>(in02); this->v[0][3]=static_cast<DT>(in03); this->v[0][4]=static_cast<DT>(in04); this->v[0][5]=static_cast<DT>(in05);
372 this->v[1][0]=static_cast<DT>(in10); this->v[1][1]=static_cast<DT>(in11); this->v[1][2]=static_cast<DT>(in12); this->v[1][3]=static_cast<DT>(in13); this->v[1][4]=static_cast<DT>(in14); this->v[1][5]=static_cast<DT>(in15);
373 this->v[2][0]=static_cast<DT>(in20); this->v[2][1]=static_cast<DT>(in21); this->v[2][2]=static_cast<DT>(in22); this->v[2][3]=static_cast<DT>(in23); this->v[2][4]=static_cast<DT>(in24); this->v[2][5]=static_cast<DT>(in25);
374 this->v[3][0]=static_cast<DT>(in30); this->v[3][1]=static_cast<DT>(in31); this->v[3][2]=static_cast<DT>(in32); this->v[3][3]=static_cast<DT>(in33); this->v[3][4]=static_cast<DT>(in34); this->v[3][5]=static_cast<DT>(in35);
375 this->v[4][0]=static_cast<DT>(in40); this->v[4][1]=static_cast<DT>(in41); this->v[4][2]=static_cast<DT>(in42); this->v[4][3]=static_cast<DT>(in43); this->v[4][4]=static_cast<DT>(in44); this->v[4][5]=static_cast<DT>(in45);
376 this->v[5][0]=static_cast<DT>(in50); this->v[5][1]=static_cast<DT>(in51); this->v[5][2]=static_cast<DT>(in52); this->v[5][3]=static_cast<DT>(in53); this->v[5][4]=static_cast<DT>(in54); this->v[5][5]=static_cast<DT>(in55);
377}
378
379
380//--------------------------------------------------------------------
383//--------------------------------------------------------------------
384template <class DT>
385void Tmat6<DT>::setValues(const float m[36])
386{
387 this->v[0][0] = static_cast<DT>(m[ 0]); this->v[0][1] = static_cast<DT>(m[ 1]); this->v[0][2] = static_cast<DT>(m[ 2]); this->v[0][3] = static_cast<DT>(m[ 3]); this->v[0][4] = static_cast<DT>(m[ 4]); this->v[0][5] = static_cast<DT>(m[ 5]);
388 this->v[1][0] = static_cast<DT>(m[ 6]); this->v[1][1] = static_cast<DT>(m[ 7]); this->v[1][2] = static_cast<DT>(m[ 8]); this->v[1][3] = static_cast<DT>(m[ 9]); this->v[1][4] = static_cast<DT>(m[10]); this->v[1][5] = static_cast<DT>(m[11]);
389 this->v[2][0] = static_cast<DT>(m[12]); this->v[2][1] = static_cast<DT>(m[13]); this->v[2][2] = static_cast<DT>(m[14]); this->v[2][3] = static_cast<DT>(m[15]); this->v[2][4] = static_cast<DT>(m[16]); this->v[2][5] = static_cast<DT>(m[17]);
390 this->v[3][0] = static_cast<DT>(m[18]); this->v[3][1] = static_cast<DT>(m[19]); this->v[3][2] = static_cast<DT>(m[20]); this->v[3][3] = static_cast<DT>(m[21]); this->v[3][4] = static_cast<DT>(m[22]); this->v[3][5] = static_cast<DT>(m[23]);
391 this->v[4][0] = static_cast<DT>(m[24]); this->v[4][1] = static_cast<DT>(m[25]); this->v[4][2] = static_cast<DT>(m[26]); this->v[4][3] = static_cast<DT>(m[27]); this->v[4][4] = static_cast<DT>(m[28]); this->v[4][5] = static_cast<DT>(m[29]);
392 this->v[5][0] = static_cast<DT>(m[30]); this->v[5][1] = static_cast<DT>(m[31]); this->v[5][2] = static_cast<DT>(m[32]); this->v[5][3] = static_cast<DT>(m[33]); this->v[5][4] = static_cast<DT>(m[34]); this->v[5][5] = static_cast<DT>(m[35]);
393}
394
395//--------------------------------------------------------------------
400//--------------------------------------------------------------------
401template <class DT>
402void Tmat6<DT>::getValues(float m[36]) const
403{
404 m[ 0] = static_cast<float>(this->v[0][0]); m[ 1] = static_cast<float>(this->v[0][1]); m[ 2] = static_cast<float>(this->v[0][2]); m[ 3] = static_cast<float>(this->v[0][3]); m[ 4] = static_cast<float>(this->v[0][4]); m[ 5] = static_cast<float>(this->v[0][5]);
405 m[ 6] = static_cast<float>(this->v[1][0]); m[ 7] = static_cast<float>(this->v[1][1]); m[ 8] = static_cast<float>(this->v[1][2]); m[ 9] = static_cast<float>(this->v[1][3]); m[10] = static_cast<float>(this->v[1][4]); m[11] = static_cast<float>(this->v[1][5]);
406 m[12] = static_cast<float>(this->v[2][0]); m[13] = static_cast<float>(this->v[2][1]); m[14] = static_cast<float>(this->v[2][2]); m[15] = static_cast<float>(this->v[2][3]); m[16] = static_cast<float>(this->v[2][4]); m[17] = static_cast<float>(this->v[2][5]);
407 m[18] = static_cast<float>(this->v[3][0]); m[19] = static_cast<float>(this->v[3][1]); m[20] = static_cast<float>(this->v[3][2]); m[21] = static_cast<float>(this->v[3][3]); m[22] = static_cast<float>(this->v[3][4]); m[23] = static_cast<float>(this->v[3][5]);
408 m[24] = static_cast<float>(this->v[4][0]); m[25] = static_cast<float>(this->v[4][1]); m[26] = static_cast<float>(this->v[4][2]); m[27] = static_cast<float>(this->v[4][3]); m[28] = static_cast<float>(this->v[4][4]); m[29] = static_cast<float>(this->v[4][5]);
409 m[30] = static_cast<float>(this->v[5][0]); m[31] = static_cast<float>(this->v[5][1]); m[32] = static_cast<float>(this->v[5][2]); m[33] = static_cast<float>(this->v[5][3]); m[34] = static_cast<float>(this->v[5][4]); m[35] = static_cast<float>(this->v[5][5]);
410}
411
412//--------------------------------------------------------------------
415//--------------------------------------------------------------------
416template <class DT>
417void Tmat6<DT>::setValues(const double m[36])
418{
419 this->v[0][0] = static_cast<DT>(m[ 0]); this->v[0][1] = static_cast<DT>(m[ 1]); this->v[0][2] = static_cast<DT>(m[ 2]); this->v[0][3] = static_cast<DT>(m[ 3]); this->v[0][4] = static_cast<DT>(m[ 4]); this->v[0][5] = static_cast<DT>(m[ 5]);
420 this->v[1][0] = static_cast<DT>(m[ 6]); this->v[1][1] = static_cast<DT>(m[ 7]); this->v[1][2] = static_cast<DT>(m[ 8]); this->v[1][3] = static_cast<DT>(m[ 9]); this->v[1][4] = static_cast<DT>(m[10]); this->v[1][5] = static_cast<DT>(m[11]);
421 this->v[2][0] = static_cast<DT>(m[12]); this->v[2][1] = static_cast<DT>(m[13]); this->v[2][2] = static_cast<DT>(m[14]); this->v[2][3] = static_cast<DT>(m[15]); this->v[2][4] = static_cast<DT>(m[16]); this->v[2][5] = static_cast<DT>(m[17]);
422 this->v[3][0] = static_cast<DT>(m[18]); this->v[3][1] = static_cast<DT>(m[19]); this->v[3][2] = static_cast<DT>(m[20]); this->v[3][3] = static_cast<DT>(m[21]); this->v[3][4] = static_cast<DT>(m[22]); this->v[3][5] = static_cast<DT>(m[23]);
423 this->v[4][0] = static_cast<DT>(m[24]); this->v[4][1] = static_cast<DT>(m[25]); this->v[4][2] = static_cast<DT>(m[26]); this->v[4][3] = static_cast<DT>(m[27]); this->v[4][4] = static_cast<DT>(m[28]); this->v[4][5] = static_cast<DT>(m[29]);
424 this->v[5][0] = static_cast<DT>(m[30]); this->v[5][1] = static_cast<DT>(m[31]); this->v[5][2] = static_cast<DT>(m[32]); this->v[5][3] = static_cast<DT>(m[33]); this->v[5][4] = static_cast<DT>(m[34]); this->v[5][5] = static_cast<DT>(m[35]);
425}
426
427//--------------------------------------------------------------------
430//--------------------------------------------------------------------
431template <class DT>
432void Tmat6<DT>::getValues(double m[36]) const
433{
434 m[ 0] = static_cast<double>(this->v[0][0]); m[ 1] = static_cast<double>(this->v[0][1]); m[ 2] = static_cast<double>(this->v[0][2]); m[ 3] = static_cast<double>(this->v[0][3]); m[ 4] = static_cast<double>(this->v[0][4]); m[ 5] = static_cast<double>(this->v[0][5]);
435 m[ 6] = static_cast<double>(this->v[1][0]); m[ 7] = static_cast<double>(this->v[1][1]); m[ 8] = static_cast<double>(this->v[1][2]); m[ 9] = static_cast<double>(this->v[1][3]); m[10] = static_cast<double>(this->v[1][4]); m[11] = static_cast<double>(this->v[1][5]);
436 m[12] = static_cast<double>(this->v[2][0]); m[13] = static_cast<double>(this->v[2][1]); m[14] = static_cast<double>(this->v[2][2]); m[15] = static_cast<double>(this->v[2][3]); m[16] = static_cast<double>(this->v[2][4]); m[17] = static_cast<double>(this->v[2][5]);
437 m[18] = static_cast<double>(this->v[3][0]); m[19] = static_cast<double>(this->v[3][1]); m[20] = static_cast<double>(this->v[3][2]); m[21] = static_cast<double>(this->v[3][3]); m[22] = static_cast<double>(this->v[3][4]); m[23] = static_cast<double>(this->v[3][5]);
438 m[24] = static_cast<double>(this->v[4][0]); m[25] = static_cast<double>(this->v[4][1]); m[26] = static_cast<double>(this->v[4][2]); m[27] = static_cast<double>(this->v[4][3]); m[28] = static_cast<double>(this->v[4][4]); m[29] = static_cast<double>(this->v[4][5]);
439 m[30] = static_cast<double>(this->v[5][0]); m[31] = static_cast<double>(this->v[5][1]); m[32] = static_cast<double>(this->v[5][2]); m[33] = static_cast<double>(this->v[5][3]); m[34] = static_cast<double>(this->v[5][4]); m[35] = static_cast<double>(this->v[5][5]);
440}
441
442
443//-------------------------------------------------------------------
445//-------------------------------------------------------------------
446template <class DT>
447void Tmat6<DT>::setScaleMatrix(const DT scale)
448{
449 this->v[0][0] = scale; this->v[0][1] = 0; this->v[0][2] = 0; this->v[0][3] = 0; this->v[0][4] = 0; this->v[0][5] = 0;
450 this->v[1][0] = 0; this->v[1][1] = scale; this->v[1][2] = 0; this->v[1][3] = 0; this->v[1][4] = 0; this->v[1][5] = 0;
451 this->v[2][0] = 0; this->v[2][1] = 0; this->v[2][2] = scale; this->v[2][3] = 0; this->v[2][4] = 0; this->v[2][5] = 0;
452 this->v[3][0] = 0; this->v[3][1] = 0; this->v[3][2] = 0; this->v[3][3] = scale; this->v[3][4] = 0; this->v[3][5] = 0;
453 this->v[4][0] = 0; this->v[4][1] = 0; this->v[4][2] = 0; this->v[4][3] = 0; this->v[4][4] = scale; this->v[4][5] = 0;
454 this->v[5][0] = 0; this->v[5][1] = 0; this->v[5][2] = 0; this->v[5][3] = 0; this->v[5][4] = 0; this->v[5][5] = scale;
455}
457
458//-------------------------------------------------------------------
461//-------------------------------------------------------------------
462
463//--------------------------------------------------------------------
465//--------------------------------------------------------------------
466template <class DT>
467DT Tmat6<DT>::determinantLower5(const int col1, const int col2, const int col3, const int col4, const int col5) const
468{
469 /* Determinant of 5x5 matrix with given entries */
470 return Tmat5<DT>(this->v[1][col1], this->v[1][col2], this->v[1][col3], this->v[1][col4], this->v[1][col5],
471 this->v[2][col1], this->v[2][col2], this->v[2][col3], this->v[2][col4], this->v[2][col5],
472 this->v[3][col1], this->v[3][col2], this->v[3][col3], this->v[3][col4], this->v[3][col5],
473 this->v[4][col1], this->v[4][col2], this->v[4][col3], this->v[4][col4], this->v[4][col5],
474 this->v[5][col1], this->v[5][col2], this->v[5][col3], this->v[5][col4], this->v[5][col5]).det();
475}
476
477//--------------------------------------------------------------------
479//--------------------------------------------------------------------
480template <class DT>
482{
483 return ( this->v[0][0] * determinantLower5(1, 2, 3, 4, 5)
484 - this->v[0][1] * determinantLower5(0, 2, 3, 4, 5)
485 + this->v[0][2] * determinantLower5(0, 1, 3, 4, 5)
486 - this->v[0][3] * determinantLower5(0, 1, 2, 4, 5)
487 + this->v[0][4] * determinantLower5(0, 1, 2, 3, 5)
488 - this->v[0][5] * determinantLower5(0, 1, 2, 3, 4));
489}
490
491//--------------------------------------------------------------------
499//--------------------------------------------------------------------
500template <class DT>
502{
503 // Epsilon for comparison with 0 in inversion process.
504 static const DT Epsilon = static_cast<DT>(10e-12);
505
506 // Use helper function from tools to invert the matrix.
507 return MLInverseMatHelper(*this,
509 Epsilon,
510 "Tmat6<DT> Tmat6<DT>::inverse(bool* isInvertible) const, matrix not invertable",
511 getIdentity(),
512 6);
513}
514
515
516//-------------------------------------------------------------------
518//-------------------------------------------------------------------
519template <class DT>
521{
522 return Tmat6<DT>(Tvec6<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0], this->v[4][0], this->v[5][0]),
523 Tvec6<DT>(this->v[0][1], this->v[1][1], this->v[2][1], this->v[3][1], this->v[4][1], this->v[5][1]),
524 Tvec6<DT>(this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2], this->v[4][2], this->v[5][2]),
525 Tvec6<DT>(this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3], this->v[4][3], this->v[5][3]),
526 Tvec6<DT>(this->v[0][4], this->v[1][4], this->v[2][4], this->v[3][4], this->v[4][4], this->v[5][4]),
527 Tvec6<DT>(this->v[0][5], this->v[1][5], this->v[2][5], this->v[3][5], this->v[4][5], this->v[5][5]));
528}
529
530//-------------------------------------------------------------------
532//-------------------------------------------------------------------
533template <class DT>
535{
536 return Tmat6<DT>(Tvec6<DT>(1,0,0,0,0,0),
537 Tvec6<DT>(0,1,0,0,0,0),
538 Tvec6<DT>(0,0,1,0,0,0),
539 Tvec6<DT>(0,0,0,1,0,0),
540 Tvec6<DT>(0,0,0,0,1,0),
541 Tvec6<DT>(0,0,0,0,0,1));
542}
543
544//-------------------------------------------------------------------
546//-------------------------------------------------------------------
547template <class DT>
549{
550 this->v[0].apply(fct);
551 this->v[1].apply(fct);
552 this->v[2].apply(fct);
553 this->v[3].apply(fct);
554 this->v[4].apply(fct);
555 this->v[5].apply(fct);
556 return *this;
557}
558
559
561#define _ML_MAT6_RC(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + \
562a[i][3]*b[3][j] + a[i][4]*b[4][j] + a[i][5]*b[5][j]
563//-------------------------------------------------------------------
565//-------------------------------------------------------------------
566template <class DT>
576#undef _ML_MAT6_RC
577
578//-------------------------------------------------------------------
580//-------------------------------------------------------------------
581template <class DT>
582bool operator==(const Tmat6<DT> &a, const Tmat6<DT> &b)
583{
584 return (a[0] == b[0]) &&
585 (a[1] == b[1]) &&
586 (a[2] == b[2]) &&
587 (a[3] == b[3]) &&
588 (a[4] == b[4]) &&
589 (a[5] == b[5]);
590}
591
592//-------------------------------------------------------------------
594//-------------------------------------------------------------------
595template <class DT>
596bool operator!=(const Tmat6<DT> &a, const Tmat6<DT> &b)
597{
598 return !(a == b);
599}
600
602#define _ML_MAT6_RC(i) a[i][0]*v[0] + a[i][1]*v[1] + a[i][2]*v[2] + a[i][3]*v[3] + a[i][4]*v[4] + a[i][5]*v[5]
603//-----------------------------------------------------------------------------------
605//-----------------------------------------------------------------------------------
606template <class DT>
607inline Tvec6<DT> operator*(const Tmat6<DT>& a, const Tvec6<DT>& v)
608{
610}
611#undef _ML_MAT6_RC
612
613//-----------------------------------------------------------------------------------
615//-----------------------------------------------------------------------------------
616template <class DT>
617inline Tvec6<DT> operator*(const Tvec6<DT>& v, const Tmat6<DT>& a)
618{
619 return a.transpose() * v;
620}
622
623
624//-----------------------------------------------------------------------------------
627//-----------------------------------------------------------------------------------
628
638
639
641
642namespace std
643{
644 //-------------------------------------------------------------------
646 //-------------------------------------------------------------------
647 template <class DT>
648 inline std::ostream& operator<<(std::ostream& os, const ML_LA_NAMESPACE::Tmat6<DT> & m)
649 {
650 return os << m[0] << '\n' << m[1] << '\n' << m[2] << '\n' << m[3] << '\n' << m[4] << '\n' << m[5];
651 }
652
653 //-------------------------------------------------------------------
655 //-------------------------------------------------------------------
656 template <class DT>
657 inline std::istream& operator>>(std::istream& is, ML_LA_NAMESPACE::Tmat6<DT> & m)
658 {
659 ML_LA_NAMESPACE::Tmat6<DT> m_tmp;
660
661 is >> m_tmp[0] >> m_tmp[1] >> m_tmp[2] >> m_tmp[3] >> m_tmp[4] >> m_tmp[5];
662 if (is){ m = m_tmp; }
663 return is;
664 }
665}
666
667
668#endif // __mlMatrix6_H
669
670
Base class of all matrix classes which holds the data buffer and provides some general access methods...
VectorT v[size]
The rows constituting the matrix.
A six by six matrix class of six row vectors.
Definition mlMatrix6.h:37
Tmat6()
Builds a 6x6 matrix from 36 0 elements.
Definition mlMatrix6.h:156
Tmat6 transpose() const
Returns the transposed of this matrix.
Definition mlMatrix6.h:520
const Tmat6< DT > & operator*=(const DT d)
Multiplies by a constant.
Definition mlMatrix6.h:274
void setValues(const float m[36])
Copies the contents from float array m into *this.
Definition mlMatrix6.h:385
const Tmat6< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to each component.
Definition mlMatrix6.h:548
static Tmat6< DT > getMat(const double val)
Returns a matrix filled with values val.
Definition mlMatrix6.h:211
Tmat6(const double in00, const double in01, const double in02, const double in03, const double in04, const double in05, const double in10, const double in11, const double in12, const double in13, const double in14, const double in15, const double in20, const double in21, const double in22, const double in23, const double in24, const double in25, const double in30, const double in31, const double in32, const double in33, const double in34, const double in35, const double in40, const double in41, const double in42, const double in43, const double in44, const double in45, const double in50, const double in51, const double in52, const double in53, const double in54, const double in55)
Initializes all matrix elements explicitly with scalars, filling it row by row.
Definition mlMatrix6.h:364
Tmat6(const Tmat6< DT > &m)
Copy constructor from the Tmat6 mat.
Definition mlMatrix6.h:185
void set(const DT val)
Sets all values to val.
Definition mlMatrix6.h:223
void setScaleMatrix(const DT scale)
Sets the diagonal matrix with scale on diagonal.
Definition mlMatrix6.h:447
bool operator<(const Tmat6< DT > &) const
Dummy "lesser than operator" which always returns false.
Definition mlMatrix6.h:100
DT determinantLower5(const int col1, const int col2, const int col3, const int col4, const int col5) const
Determines the (sub)determinant of columns given by col1, col2, col3, col4 and col5.
Definition mlMatrix6.h:467
void getValues(float m[36]) const
Copies the contents of *this into float array m.
Definition mlMatrix6.h:402
DT det() const
Returns the determinant of this matrix.
Definition mlMatrix6.h:481
const Tmat6< DT > & operator+=(const Tmat6< DT > &m)
Adds component wise by a Tmat6.
Definition mlMatrix6.h:246
Tmat6(const double mat[36])
Constructor from 36 doubles given as array mat.
Definition mlMatrix6.h:204
Tmat6(const DT diagValue)
Definition mlMatrix6.h:163
void getValues(double m[36]) const
Copies the contents of *this into m, where m must provide at least 36 accessible entries.
Definition mlMatrix6.h:432
const Tmat6< DT > & operator-=(const Tmat6< DT > &m)
Subtracts component wise by a Tmat6.
Definition mlMatrix6.h:260
Tmat6(const float mat[36])
Constructor from 36 floats given as array mat.
Definition mlMatrix6.h:197
DT ComponentType
A typedef to "export" the type of components.
Definition mlMatrix6.h:41
const Tmat6< DT > & operator=(const Tmat6< DT > &m)
Assignment of a Tmat6.
Definition mlMatrix6.h:230
const Tmat6< DT > & operator/=(const DT d)
Divides by a constant. Division by zero is not handled and must be avoided by caller.
Definition mlMatrix6.h:288
static Tmat6 getIdentity()
Returns the identity matrix.
Definition mlMatrix6.h:534
void setValues(const double m[36])
Copies the contents of m into *this, where m must provide at least 36 accessible entries.
Definition mlMatrix6.h:417
Tmat6< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse.
Definition mlMatrix6.h:501
Tmat6(const Tvec6< DT > &row0, const Tvec6< DT > &row1, const Tvec6< DT > &row2, const Tvec6< DT > &row3, const Tvec6< DT > &row4, const Tvec6< DT > &row5)
Builds a matrix of the six row vectors row0, ..., row5.
Definition mlMatrix6.h:172
A six dimensional vector class for floating point types.
Definition mlVector6.h:46
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0, otherwise false.
#define ML_CHECK_THROW(x)
#define ML_CHECK_FLOAT_THROW(x)
#define _ML_MAT6_RC(i, j)
Internal helper macro to multiply two matrices, do not use.
Definition mlMatrix6.h:561
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double(* MLDblFuncPtr)(double)
A function pointer type to a function which returns a double and takes a double as argument.
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component wise division of lhs by specialized rhs of type MLdouble.
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Return true if yes.
Definition mlMatrix2.h:425
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
bool operator!=(const Tmat2< DT > &a, const Tmat2< DT > &b)
a != b ? Return true if yes.
Definition mlMatrix2.h:433
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component wise subtraction of rhs from lhs.
BASE_TYPE MLInverseMatHelper(const BASE_TYPE &origMat, bool *isInvertible, const typename BASE_TYPE::ComponentType, const char *const ZeroDetErrString, const BASE_TYPE &Identity, const size_t Dim)
Computes an N dimensional inverse from given default parameters.
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
istream & operator>>(istream &is, ml::FloatingPointVector< T, size, DataContainer > &v)
Reads a vector from std::istream.