MeVisLab Toolbox Reference
mlMatrix5.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_MATRIX5_H
14 #define ML_MATRIX5_H
15 
17 
18 // Include system independent file and project settings.
19 #include "mlLinearAlgebraSystem.h"
20 #include "mlLinearAlgebraDefs.h"
21 
22 
23 #include "mlFloatingPointMatrix.h"
24 
25 #include "mlVector5.h"
26 
27 #include "mlMatrix4.h"
28 
29 #include <mlErrorMacros.h>
30 #include <mlErrorOutput.h>
31 
32 // All declarations of this header will be in the ML_LINEAR_ALGEBRA namespace.
33 ML_LA_START_NAMESPACE
34 //--------------------------------------------------------------------
36 // This is necessary because we do not known whether vector or
37 // matrix header is included first and we cannot move template
38 // code into C++ file.
39 //--------------------------------------------------------------------
40 template <class DT> class Tvec5;
41 template <class DT> class Tmat4;
43 
44 //--------------------------------------------------------------------
46 //--------------------------------------------------------------------
47 template <class DT>
48 class Tmat5 : public FloatingPointMatrix<Tvec5<DT>, 5>
49 {
50 public:
51 
53  typedef DT ComponentType;
54 
55  // Builds a 5x5 matrix from 25 zero elements.
56  Tmat5();
57 
58  // Builds a matrix that has the argument at the diagonal values, zero otherwise
59  Tmat5(const DT diagValue);
60 
61  // Builds the matrix of the five row vectors row0, ..., row5.
62  Tmat5(const Tvec5<DT> &row0, const Tvec5<DT> &row1, const Tvec5<DT> &row2,
63  const Tvec5<DT> &row3, const Tvec5<DT> &row4);
64 
65  // Copy constructor from the Tmat5 mat.
66  Tmat5(const Tmat5<DT> &mat);
67 
68  // Constructor from 25 floats given as array mat, row by row.
69  Tmat5(const float mat[25]);
70 
71  // Constructor from 25 doubles given as array mat, row by row.
72  Tmat5(const double mat[25]);
73 
74  // Initializes all matrix elements explicitly with scalars,
75  // filling it row by row.
76  Tmat5(const double in00, const double in01, const double in02, const double in03, const double in04,
77  const double in10, const double in11, const double in12, const double in13, const double in14,
78  const double in20, const double in21, const double in22, const double in23, const double in24,
79  const double in30, const double in31, const double in32, const double in33, const double in34,
80  const double in40, const double in41, const double in42, const double in43, const double in44);
81 
82  // Copies the contents from float array m into *this. m must point to an
83  // array with at least 25 valid entries, row by row.
84  void setValues(const float m[25]);
85 
86  // Copies the contents of *this into float array m. Note that range
87  // and precision of the float values may not be sufficient for
88  // higher precision matrix contents. m must point to an array with
89  // at least 25 accessible entries, row by row.
90  void getValues(float m[25]) const;
91 
92  // Copies the contents from double array m into *this. m must point to an
93  // array with at least 25 valid entries, row by row.
94  void setValues(const double m[25]);
95 
96  // Copies the contents of *this into double array m. m must point to an
97  // array with at least 25 accessible entries, row by row.
98  void getValues(double m[25]) const;
99 
100  // Sets the diagonal matrix with scale on diagonal.
101  void setScaleMatrix(const DT scale);
102 
103  // Returns a matrix filled with values val.
104  static Tmat5<DT> getMat(const double val);
105 
106  // Sets all values to val.
107  void set(const DT val);
108 
111  bool operator<(const Tmat5<DT> &) const { return false; }
112 
113  // Assigns from a Tmat5.
114  const Tmat5<DT>& operator=(const Tmat5<DT> &m);
115 
116  // Adds component wise by a Tmat5.
117  const Tmat5<DT>& operator+=(const Tmat5<DT> &m);
118 
119  // Subtracts component wise by a Tmat5.
120  const Tmat5<DT>& operator-=(const Tmat5<DT> &m);
121 
122  // Multiplies by a scalar constant
123  const Tmat5<DT>& operator*=(const DT d);
124 
125  // Divides by a scalar constant.
126  // Division by zero is not handled and must be avoided by caller.
127  const Tmat5<DT>& operator/=(const DT d);
128 
129  //-------------------------------------------------
130  // Special functions
131  //-------------------------------------------------
132  // Determines the (sub)determinant of columns given by col1, col2, col3 and col4.
133  DT determinantLower4(const int col1, const int col2, const int col3, const int col4) const;
134 
135  // Determinant.
136  DT det() const;
137 
138  // Returns the inverse Gauss-Jordan elimination with partial pivoting.
139  // If a non-NULL Boolean pointer is passed to isInvertible
140  // then true is returned in *isInvertible in the case of a
141  // successful inversion or false if the inversion is not possible
142  // (function return is the identity then).
143  // If a NULL pointer is passed as isInvertible the matrix must
144  // be invertible, otherwise errors will occur.
145  Tmat5<DT> inverse(bool* isInvertible=nullptr) const;
146 
147  // Returns the transposed of this matrix.
148  Tmat5 transpose() const;
149 
150  // Returns the identity matrix.
151  static Tmat5 getIdentity();
152 
153  // Applies the function fct to each component.
155 
156 }; // end of class *Tmat5*
157 
158 
159 
160 
161 //---------------------------------------------------------------------
162 // Constructors
163 //---------------------------------------------------------------------
165 template <class DT>
167 {
168  this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = Tvec5<DT>(0);
169 }
170 
171 // Constructs a matrix that has the argument at the diagonal values, zero otherwise
172 template <class DT>
173 inline Tmat5<DT>::Tmat5(const DT diagValue)
174 {
175  this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] = this->v[4][4] = diagValue;
176  this->v[1][0] = this->v[2][0] = this->v[3][0] = this->v[4][0] = this->v[2][1] = this->v[3][1] = this->v[4][1] = this->v[3][2] = this->v[4][2] = this->v[4][3] = 0;
177  this->v[0][1] = this->v[0][2] = this->v[0][3] = this->v[0][4] = this->v[1][2] = this->v[1][3] = this->v[1][4] = this->v[2][3] = this->v[2][4] = this->v[3][4] = 0;
178 }
179 
180 
182 template <class DT>
183 inline Tmat5<DT>::Tmat5(const Tvec5<DT>& row0, const Tvec5<DT>& row1, const Tvec5<DT>& row2,
184  const Tvec5<DT>& row3, const Tvec5<DT>& row4)
185 {
186  this->v[0] = row0;
187  this->v[1] = row1;
188  this->v[2] = row2;
189  this->v[3] = row3;
190  this->v[4] = row4;
191 }
192 
194 template <class DT>
195 inline Tmat5<DT>::Tmat5(const Tmat5<DT> &mat)
196 {
197  this->v[0] = mat.v[0];
198  this->v[1] = mat.v[1];
199  this->v[2] = mat.v[2];
200  this->v[3] = mat.v[3];
201  this->v[4] = mat.v[4];
202 }
203 
205 template <class DT>
206 inline Tmat5<DT>::Tmat5(const float mat[25])
207 {
208  setValues(mat);
209 }
210 
212 template <class DT>
213 inline Tmat5<DT>::Tmat5(const double mat[25])
214 {
215  setValues(mat);
216 }
217 
219 template <class DT>
220 inline Tmat5<DT> Tmat5<DT>::getMat(const double val)
221 {
222  return Tmat5<DT>(val, val, val, val, val,
223  val, val, val, val, val,
224  val, val, val, val, val,
225  val, val, val, val, val,
226  val, val, val, val, val);
227 }
228 
230 template <class DT>
231 inline void Tmat5<DT>::set(const DT val)
232 {
233  this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = Tvec5<DT>(val);
234 }
235 
237 template <class DT>
238 inline const Tmat5<DT> & Tmat5<DT>::operator=(const Tmat5<DT> &m)
239 {
240  if (&m != this){
241  this->v[0] = m.v[0];
242  this->v[1] = m.v[1];
243  this->v[2] = m.v[2];
244  this->v[3] = m.v[3];
245  this->v[4] = m.v[4];
246  }
247 
248  return *this;
249 }
250 
252 template <class DT>
253 inline const Tmat5<DT> & Tmat5<DT>::operator+=(const Tmat5<DT> &m)
254 {
255  this->v[0] += m.v[0];
256  this->v[1] += m.v[1];
257  this->v[2] += m.v[2];
258  this->v[3] += m.v[3];
259  this->v[4] += m.v[4];
260 
261  return *this;
262 }
263 
265 template <class DT>
266 inline const Tmat5<DT> & Tmat5<DT>::operator-=(const Tmat5<DT> &m)
267 {
268  this->v[0] -= m.v[0];
269  this->v[1] -= m.v[1];
270  this->v[2] -= m.v[2];
271  this->v[3] -= m.v[3];
272  this->v[4] -= m.v[4];
273 
274  return *this;
275 }
276 
278 template <class DT>
279 inline const Tmat5<DT> & Tmat5<DT>::operator*=(const DT d)
280 {
281  this->v[0] *= d;
282  this->v[1] *= d;
283  this->v[2] *= d;
284  this->v[3] *= d;
285  this->v[4] *= d;
286 
287  return *this;
288 }
289 
291 template <class DT>
292 inline const Tmat5<DT> & Tmat5<DT>::operator/=(const DT d)
293 {
295  this->v[0] /= d;
296  this->v[1] /= d;
297  this->v[2] /= d;
298  this->v[3] /= d;
299  this->v[4] /= d;
300  return *this;
301 }
302 
303 
304 //--------------------------------------------------------------------
307 //--------------------------------------------------------------------
309 template <class DT>
310 inline Tmat5<DT> operator-(const Tmat5<DT> &a)
311 {
312  return Tmat5<DT>(a) *= static_cast<DT>(-1.0);
313 }
314 
316 template <class DT>
317 inline Tmat5<DT> operator+(const Tmat5<DT> &a, const Tmat5<DT> &b)
318 {
319  return Tmat5<DT>(a) += b;
320 }
321 
323 template <class DT>
324 inline Tmat5<DT> operator-(const Tmat5<DT> &a, const Tmat5<DT> &b)
325 {
326  return Tmat5<DT>(a) -= b;
327 }
328 
330 template <class DT>
331 inline Tmat5<DT> operator*(const Tmat5<DT> &a, const DT d)
332 {
333  return Tmat5<DT>(a) *= d;
334 }
335 
337 template <class DT>
338 inline Tmat5<DT> operator*(const DT d, const Tmat5<DT> &a)
339 {
340  return Tmat5<DT>(a) *= d;
341 }
342 
345 template <class DT>
346 inline Tmat5<DT> operator/(const Tmat5<DT> &a, const DT d)
347 {
348  Tmat5<DT> divided(a);
350  divided /= d;
351  return divided;
352 }
354 
355 //-------------------------------------------------------------------
356 //
357 // Tmat5 member functions
358 //
359 //-------------------------------------------------------------------
360 
361 //-------------------------------------------------------------------
364 //-------------------------------------------------------------------
365 template <class DT>
366 Tmat5<DT>::Tmat5(const double in00, const double in01, const double in02, const double in03, const double in04,
367  const double in10, const double in11, const double in12, const double in13, const double in14,
368  const double in20, const double in21, const double in22, const double in23, const double in24,
369  const double in30, const double in31, const double in32, const double in33, const double in34,
370  const double in40, const double in41, const double in42, const double in43, const double in44)
371 {
372  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);
373  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);
374  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);
375  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);
376  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);
377 }
378 
379 
380 //--------------------------------------------------------------------
383 //--------------------------------------------------------------------
384 template <class DT>
385 void Tmat5<DT>::setValues(const float m[25])
386 {
387  this->v[0][0] = static_cast<DT>(m[ 0]);
388  this->v[0][1] = static_cast<DT>(m[ 1]);
389  this->v[0][2] = static_cast<DT>(m[ 2]);
390  this->v[0][3] = static_cast<DT>(m[ 3]);
391  this->v[0][4] = static_cast<DT>(m[ 4]);
392 
393  this->v[1][0] = static_cast<DT>(m[ 5]);
394  this->v[1][1] = static_cast<DT>(m[ 6]);
395  this->v[1][2] = static_cast<DT>(m[ 7]);
396  this->v[1][3] = static_cast<DT>(m[ 8]);
397  this->v[1][4] = static_cast<DT>(m[ 9]);
398 
399  this->v[2][0] = static_cast<DT>(m[10]);
400  this->v[2][1] = static_cast<DT>(m[11]);
401  this->v[2][2] = static_cast<DT>(m[12]);
402  this->v[2][3] = static_cast<DT>(m[13]);
403  this->v[2][4] = static_cast<DT>(m[14]);
404 
405  this->v[3][0] = static_cast<DT>(m[15]);
406  this->v[3][1] = static_cast<DT>(m[16]);
407  this->v[3][2] = static_cast<DT>(m[17]);
408  this->v[3][3] = static_cast<DT>(m[18]);
409  this->v[3][4] = static_cast<DT>(m[19]);
410 
411  this->v[4][0] = static_cast<DT>(m[20]);
412  this->v[4][1] = static_cast<DT>(m[21]);
413  this->v[4][2] = static_cast<DT>(m[22]);
414  this->v[4][3] = static_cast<DT>(m[23]);
415  this->v[4][4] = static_cast<DT>(m[24]);
416 }
417 
418 //--------------------------------------------------------------------
423 //--------------------------------------------------------------------
424 template <class DT>
425 void Tmat5<DT>::getValues(float m[25]) const
426 {
427  m[ 0] = static_cast<float>(this->v[0][0]);
428  m[ 1] = static_cast<float>(this->v[0][1]);
429  m[ 2] = static_cast<float>(this->v[0][2]);
430  m[ 3] = static_cast<float>(this->v[0][3]);
431  m[ 4] = static_cast<float>(this->v[0][4]);
432 
433  m[ 5] = static_cast<float>(this->v[1][0]);
434  m[ 6] = static_cast<float>(this->v[1][1]);
435  m[ 7] = static_cast<float>(this->v[1][2]);
436  m[ 8] = static_cast<float>(this->v[1][3]);
437  m[ 9] = static_cast<float>(this->v[1][4]);
438 
439  m[10] = static_cast<float>(this->v[2][0]);
440  m[11] = static_cast<float>(this->v[2][1]);
441  m[12] = static_cast<float>(this->v[2][2]);
442  m[13] = static_cast<float>(this->v[2][3]);
443  m[14] = static_cast<float>(this->v[2][4]);
444 
445  m[15] = static_cast<float>(this->v[3][0]);
446  m[16] = static_cast<float>(this->v[3][1]);
447  m[17] = static_cast<float>(this->v[3][2]);
448  m[18] = static_cast<float>(this->v[3][3]);
449  m[19] = static_cast<float>(this->v[3][4]);
450 
451  m[20] = static_cast<float>(this->v[4][0]);
452  m[21] = static_cast<float>(this->v[4][1]);
453  m[22] = static_cast<float>(this->v[4][2]);
454  m[23] = static_cast<float>(this->v[4][3]);
455  m[24] = static_cast<float>(this->v[4][4]);
456 }
457 
458 //--------------------------------------------------------------------
461 //--------------------------------------------------------------------
462 template <class DT>
463 void Tmat5<DT>::setValues(const double m[25])
464 {
465  this->v[0][0] = static_cast<DT>(m[ 0]);
466  this->v[0][1] = static_cast<DT>(m[ 1]);
467  this->v[0][2] = static_cast<DT>(m[ 2]);
468  this->v[0][3] = static_cast<DT>(m[ 3]);
469  this->v[0][4] = static_cast<DT>(m[ 4]);
470 
471  this->v[1][0] = static_cast<DT>(m[ 5]);
472  this->v[1][1] = static_cast<DT>(m[ 6]);
473  this->v[1][2] = static_cast<DT>(m[ 7]);
474  this->v[1][3] = static_cast<DT>(m[ 8]);
475  this->v[1][4] = static_cast<DT>(m[ 9]);
476 
477  this->v[2][0] = static_cast<DT>(m[10]);
478  this->v[2][1] = static_cast<DT>(m[11]);
479  this->v[2][2] = static_cast<DT>(m[12]);
480  this->v[2][3] = static_cast<DT>(m[13]);
481  this->v[2][4] = static_cast<DT>(m[14]);
482 
483  this->v[3][0] = static_cast<DT>(m[15]);
484  this->v[3][1] = static_cast<DT>(m[16]);
485  this->v[3][2] = static_cast<DT>(m[17]);
486  this->v[3][3] = static_cast<DT>(m[18]);
487  this->v[3][4] = static_cast<DT>(m[19]);
488 
489  this->v[4][0] = static_cast<DT>(m[20]);
490  this->v[4][1] = static_cast<DT>(m[21]);
491  this->v[4][2] = static_cast<DT>(m[22]);
492  this->v[4][3] = static_cast<DT>(m[23]);
493  this->v[4][4] = static_cast<DT>(m[24]);
494 }
495 
496 //--------------------------------------------------------------------
499 //--------------------------------------------------------------------
500 template <class DT>
501 void Tmat5<DT>::getValues(double m[25]) const
502 {
503  m[ 0] = static_cast<double>(this->v[0][0]);
504  m[ 1] = static_cast<double>(this->v[0][1]);
505  m[ 2] = static_cast<double>(this->v[0][2]);
506  m[ 3] = static_cast<double>(this->v[0][3]);
507  m[ 4] = static_cast<double>(this->v[0][4]);
508 
509  m[ 5] = static_cast<double>(this->v[1][0]);
510  m[ 6] = static_cast<double>(this->v[1][1]);
511  m[ 7] = static_cast<double>(this->v[1][2]);
512  m[ 8] = static_cast<double>(this->v[1][3]);
513  m[ 9] = static_cast<double>(this->v[1][4]);
514 
515  m[10] = static_cast<double>(this->v[2][0]);
516  m[11] = static_cast<double>(this->v[2][1]);
517  m[12] = static_cast<double>(this->v[2][2]);
518  m[13] = static_cast<double>(this->v[2][3]);
519  m[14] = static_cast<double>(this->v[2][4]);
520 
521  m[15] = static_cast<double>(this->v[3][0]);
522  m[16] = static_cast<double>(this->v[3][1]);
523  m[17] = static_cast<double>(this->v[3][2]);
524  m[18] = static_cast<double>(this->v[3][3]);
525  m[19] = static_cast<double>(this->v[3][4]);
526 
527  m[20] = static_cast<double>(this->v[4][0]);
528  m[21] = static_cast<double>(this->v[4][1]);
529  m[22] = static_cast<double>(this->v[4][2]);
530  m[23] = static_cast<double>(this->v[4][3]);
531  m[24] = static_cast<double>(this->v[4][4]);
532 }
533 
534 
535 //-------------------------------------------------------------------
537 //-------------------------------------------------------------------
538 template <class DT>
539 void Tmat5<DT>::setScaleMatrix(const DT scale)
540 {
541  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;
542  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;
543  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;
544  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;
545  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;
546 }
547 
548 
549 
550 
551 //-------------------------------------------------------------------
554 //-------------------------------------------------------------------
555 
556 //--------------------------------------------------------------------
558 //--------------------------------------------------------------------
559 template <class DT>
560 inline DT Tmat5<DT>::determinantLower4(const int col1, const int col2, const int col3, const int col4) const
561 {
562  /* Determinant of 4x4 matrix with given entries */
563  return Tmat4<DT>(this->v[1][col1], this->v[1][col2], this->v[1][col3], this->v[1][col4],
564  this->v[2][col1], this->v[2][col2], this->v[2][col3], this->v[2][col4],
565  this->v[3][col1], this->v[3][col2], this->v[3][col3], this->v[3][col4],
566  this->v[4][col1], this->v[4][col2], this->v[4][col3], this->v[4][col4]).det();
567 }
568 
569 //--------------------------------------------------------------------
571 //--------------------------------------------------------------------
572 template <class DT>
574 {
575  return ( this->v[0][0] * determinantLower4(1, 2, 3, 4)
576  - this->v[0][1] * determinantLower4(0, 2, 3, 4)
577  + this->v[0][2] * determinantLower4(0, 1, 3, 4)
578  - this->v[0][3] * determinantLower4(0, 1, 2, 4)
579  + this->v[0][4] * determinantLower4(0, 1, 2, 3));
580 }
581 
582 //--------------------------------------------------------------------
590 //--------------------------------------------------------------------
591 template <class DT>
592 Tmat5<DT> Tmat5<DT>::inverse(bool* isInvertible) const
593 {
594  // Epsilon for comparison with 0 in inversion process.
595  static const DT Epsilon = static_cast<DT>(10e-13);
596 
597  // Use helper function from tools to invert the matrix.
598  return MLInverseMatHelper(*this,
599  isInvertible,
600  Epsilon,
601  "Tmat5<DT> Tmat5<DT>::inverse(bool* isInvertible) const, matrix not invertable",
602  getIdentity(),
603  5);
604 }
605 
606 
607 //-------------------------------------------------------------------
609 //-------------------------------------------------------------------
610 template <class DT>
612 {
613  return Tmat5<DT>(Tvec5<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0], this->v[4][0]),
614  Tvec5<DT>(this->v[0][1], this->v[1][1], this->v[2][1], this->v[3][1], this->v[4][1]),
615  Tvec5<DT>(this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2], this->v[4][2]),
616  Tvec5<DT>(this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3], this->v[4][3]),
617  Tvec5<DT>(this->v[0][4], this->v[1][4], this->v[2][4], this->v[3][4], this->v[4][4]));
618 }
619 
620 //-------------------------------------------------------------------
622 //-------------------------------------------------------------------
623 template <class DT>
625 {
626  return Tmat5<DT>(Tvec5<DT>(1,0,0,0,0),
627  Tvec5<DT>(0,1,0,0,0),
628  Tvec5<DT>(0,0,1,0,0),
629  Tvec5<DT>(0,0,0,1,0),
630  Tvec5<DT>(0,0,0,0,1));
631 }
632 
633 //-------------------------------------------------------------------
635 //-------------------------------------------------------------------
636 template <class DT>
638 {
639  this->v[0].apply(fct);
640  this->v[1].apply(fct);
641  this->v[2].apply(fct);
642  this->v[3].apply(fct);
643  this->v[4].apply(fct);
644  return *this;
645 }
646 
647 
649 #define _ML_MAT5_RC(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j] + \
650 a[i][3]*b[3][j] + a[i][4]*b[4][j]
651 //-------------------------------------------------------------------
653 //-------------------------------------------------------------------
654 template <class DT>
656 {
657  return Tmat5<DT>(Tvec5<DT>(_ML_MAT5_RC(0,0), _ML_MAT5_RC(0,1), _ML_MAT5_RC(0,2), _ML_MAT5_RC(0,3), _ML_MAT5_RC(0,4)),
658  Tvec5<DT>(_ML_MAT5_RC(1,0), _ML_MAT5_RC(1,1), _ML_MAT5_RC(1,2), _ML_MAT5_RC(1,3), _ML_MAT5_RC(1,4)),
659  Tvec5<DT>(_ML_MAT5_RC(2,0), _ML_MAT5_RC(2,1), _ML_MAT5_RC(2,2), _ML_MAT5_RC(2,3), _ML_MAT5_RC(2,4)),
660  Tvec5<DT>(_ML_MAT5_RC(3,0), _ML_MAT5_RC(3,1), _ML_MAT5_RC(3,2), _ML_MAT5_RC(3,3), _ML_MAT5_RC(3,4)),
661  Tvec5<DT>(_ML_MAT5_RC(4,0), _ML_MAT5_RC(4,1), _ML_MAT5_RC(4,2), _ML_MAT5_RC(4,3), _ML_MAT5_RC(4,4)));
662 }
663 #undef _ML_MAT5_RC
664 
665 
666 // Note: Multiplications with Vector5 are implemented with/in class Tvec5.
667 
668 
669 //-------------------------------------------------------------------
671 //-------------------------------------------------------------------
672 template <class DT>
673 inline bool operator==(const Tmat5<DT> &a, const Tmat5<DT> &b)
674 {
675  return (a[0] == b[0]) &&
676  (a[1] == b[1]) &&
677  (a[2] == b[2]) &&
678  (a[3] == b[3]) &&
679  (a[4] == b[4]);
680 }
681 
682 //-------------------------------------------------------------------
684 //-------------------------------------------------------------------
685 template <class DT>
686 inline bool operator!=(const Tmat5<DT> &a, const Tmat5<DT> &b)
687 {
688  return !(a == b);
689 }
691 
692 
693 //-----------------------------------------------------------------------------------
696 //-----------------------------------------------------------------------------------
697 
707 
708 
709 #if ML_DEPRECATED_SINCE(3,5,0)
710 
713 
717 ML_DEPRECATED typedef Tmat5<MLfloat> matf5;
721 ML_DEPRECATED typedef Tmat5<MLdouble> matd5;
725 ML_DEPRECATED typedef Tmat5<MLldouble> matld5;
729 ML_DEPRECATED typedef Tmat5<MLdouble> mat5;
731 
732 
733 #endif
734 
735 
736 
737 ML_LA_END_NAMESPACE
738 
739 namespace std
740 {
741  //-------------------------------------------------------------------
743  //-------------------------------------------------------------------
744  template <class DT>
745  inline std::ostream& operator<<(std::ostream& os, const ML_LA_NAMESPACE::Tmat5<DT> & m)
746  {
747  return os << m[0] << '\n' << m[1] << '\n' << m[2] << '\n' << m[3] << '\n' << m[4];
748  }
749 
750  //-------------------------------------------------------------------
752  //-------------------------------------------------------------------
753  template <class DT>
754  inline std::istream& operator>>(std::istream& is, ML_LA_NAMESPACE::Tmat5<DT> & m)
755  {
756  ML_LA_NAMESPACE::Tmat5<DT> m_tmp;
757 
758  is >> m_tmp[0] >> m_tmp[1] >> m_tmp[2] >> m_tmp[3] >> m_tmp[4];
759  if (is){ m = m_tmp; }
760  return is;
761  }
762 }
763 
764 
765 #endif // __mlMatrix5_H
766 
767 
#define ML_DEPRECATED
Definition: CSOGroup.h:371
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.
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component wise division of lhs by specialized rhs of type MLdouble.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
FloatingPointVector< T, size, DataContainer > operator+(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component wise addition of lhs and rhs.
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.
A four by four matrix class consisting of 4 row vectors.
Definition: mlMatrix4.h:36
DT det() const
Returns the determinant of *this.
Definition: mlMatrix4.h:572
A five by five matrix class of five row vectors.
Definition: mlMatrix5.h:49
Tmat5 transpose() const
Returns the transposed of this matrix.
Definition: mlMatrix5.h:611
const Tmat5< DT > & operator+=(const Tmat5< DT > &m)
Adds component wise by a Tmat5.
Definition: mlMatrix5.h:253
const Tmat5< DT > & operator/=(const DT d)
Divide by a constant. Division by zero is not handled and must be avoided by caller.
Definition: mlMatrix5.h:292
void set(const DT val)
Sets all values to val.
Definition: mlMatrix5.h:231
static Tmat5< DT > getMat(const double val)
Returns a matrix filled with values val, row by row.
Definition: mlMatrix5.h:220
static Tmat5 getIdentity()
Returns the identity matrix.
Definition: mlMatrix5.h:624
bool operator<(const Tmat5< DT > &) const
Dummy "lesser than operator" which always returns false.
Definition: mlMatrix5.h:111
Tmat5()
Builds a 5x5 matrix from 25 0 elements.
Definition: mlMatrix5.h:166
DT ComponentType
A typedef to "export" the type of components.
Definition: mlMatrix5.h:53
void setScaleMatrix(const DT scale)
Sets the diagonal matrix with scale on diagonal.
Definition: mlMatrix5.h:539
DT det() const
Returns the determinant of this matrix.
Definition: mlMatrix5.h:573
Tmat5(const float mat[25])
Constructor from 25 floats given as array mat, row by row.
Definition: mlMatrix5.h:206
Tmat5(const Tvec5< DT > &row0, const Tvec5< DT > &row1, const Tvec5< DT > &row2, const Tvec5< DT > &row3, const Tvec5< DT > &row4)
Builds a matrix of the five row vectors row0, ..., row4.
Definition: mlMatrix5.h:183
const Tmat5< DT > & operator=(const Tmat5< DT > &m)
Assigns by a Tmat5.
Definition: mlMatrix5.h:238
void setValues(const float m[25])
Copies the contents from float array m into *this.
Definition: mlMatrix5.h:385
const Tmat5< DT > & operator*=(const DT d)
Multiplies by a constant.
Definition: mlMatrix5.h:279
Tmat5< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse.
Definition: mlMatrix5.h:592
const Tmat5< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to each component.
Definition: mlMatrix5.h:637
Tmat5(const double in00, const double in01, const double in02, const double in03, const double in04, const double in10, const double in11, const double in12, const double in13, const double in14, const double in20, const double in21, const double in22, const double in23, const double in24, const double in30, const double in31, const double in32, const double in33, const double in34, const double in40, const double in41, const double in42, const double in43, const double in44)
Initializes all matrix elements explicitly with scalars, filling it row by row.
Definition: mlMatrix5.h:366
Tmat5(const Tmat5< DT > &mat)
Copy constructor from the Tmat5 mat.
Definition: mlMatrix5.h:195
void getValues(double m[25]) const
Copies the contents of *this into m, where m must provide at least 25 accessible entries,...
Definition: mlMatrix5.h:501
void getValues(float m[25]) const
Copies the contents of *this into float array m.
Definition: mlMatrix5.h:425
const Tmat5< DT > & operator-=(const Tmat5< DT > &m)
Subtracts component wise by a Tmat5.
Definition: mlMatrix5.h:266
Tmat5(const DT diagValue)
Definition: mlMatrix5.h:173
Tmat5(const double mat[25])
Constructor from 25 doubles given as array mat, row by row.
Definition: mlMatrix5.h:213
void setValues(const double m[25])
Copies the contents of m into *this, where m must provide at least 25 accessible entries,...
Definition: mlMatrix5.h:463
DT determinantLower4(const int col1, const int col2, const int col3, const int col4) const
Determines the (sub)determinant of columns given by col1, col2, col3 and col4.
Definition: mlMatrix5.h:560
Forward declarations to resolve header file dependencies.
Definition: mlVector5.h:48
#define ML_CHECK_FLOAT_THROW(x)
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
#define _ML_MAT5_RC(i, j)
Internal helper macro to multiply two matrices, do not use.
Definition: mlMatrix5.h:649
double(* MLDblFuncPtr)(double)
A function pointer type to a function which returns a double and takes a double as argument.
Definition: mlTypeDefs.h:1282
std::istream & operator>>(std::istream &in, ml::Variant &variant)
Definition: mlVariant.h:215
void apply(Fnc &&fnc, const std::tuple< Args... > &tuple)
bool operator!=(const Tmat5< DT > &a, const Tmat5< DT > &b)
a != b ? Return true if yes, otherwise false.
Definition: mlMatrix5.h:686
FloatingPointVector< T, size, DataContainer > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component wise division of *this by scalar value.
FloatingPointVector< T, size, DataContainer > & operator-=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component wise subtraction of buffer from *this.
Tmat5< MLdouble > Matrix5d
A 5x5 matrix of type double.
Definition: mlMatrix5.h:701
Tmat5< MLfloat > Matrix5f
A 5x5 matrix of type float.
Definition: mlMatrix5.h:699
bool operator==(const Tmat5< DT > &a, const Tmat5< DT > &b)
a == b ? Return true if yes, otherwise false.
Definition: mlMatrix5.h:673
Tmat5< MLdouble > Matrix5
The standard 5x5 matrix of type double.
Definition: mlMatrix5.h:705
constexpr Is< T > is(T d)
Tmat5< MLldouble > Matrix5ld
A 5x5 matrix of type long double.
Definition: mlMatrix5.h:703
FloatingPointVector< T, size, DataContainer > & operator+=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component wise addition.
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.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component wise multiplication *this with specialized MLdouble scalar value.