MeVisLab Toolbox Reference
mlMatrix4.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_MATRIX4_H
14 #define ML_MATRIX4_H
15 
17 
18 // Include system independent file and project settings.
19 #include "mlLinearAlgebraSystem.h"
20 #include "mlLinearAlgebraDefs.h"
21 
22 #include "mlFloatingPointMatrix.h"
23 
24 #include "mlMatrix3.h"
25 #include "mlVector4.h"
26 #include "mlVector3.h"
27 
28 // All declarations of this header will be in the ML_LA_START_NAMESPACE namespace.
29 ML_LA_START_NAMESPACE
30 
31 //---------------------------------------------------------------
33 //---------------------------------------------------------------
34 template <class DT>
35 class Tmat4 : public FloatingPointMatrix<Tvec4<DT>, 4>
36 {
37 public:
38 
40  typedef DT ComponentType;
41 
42  //---------------------------------------------------------------
43  // Constructors, set, and get methods.
44  //---------------------------------------------------------------
45  // Construct matrix from 16 zero elements.
46  Tmat4();
47 
49  Tmat4(const DT diagValue);
50 
52  Tmat4(const Tvec4<DT> &row0, const Tvec4<DT> &row1, const Tvec4<DT> &row2, const Tvec4<DT> &row3);
53 
55  Tmat4(const Tmat4<DT> &mat);
56 
58  Tmat4(const float mat[16]);
59 
61  Tmat4(const double mat[16]);
62 
65  Tmat4(const double in00, const double in01, const double in02, const double in03,
66  const double in10, const double in11, const double in12, const double in13,
67  const double in20, const double in21, const double in22, const double in23,
68  const double in30, const double in31, const double in32, const double in33);
69 
72  Tmat4(const Tvec3<DT> &n0, const Tvec3<DT> &n1, const Tvec3<DT> &n3, const Tvec3<DT> &t);
73 
75  void setValues(const float mat[16]);
76 
80  void getValues(float mat[16]) const;
81 
83  void setValues(const double mat[16]);
84 
88  void getValues(double mat[16]) const;
89 
91  void setScaleMatrix(const DT scale);
92 
94  inline Tvec3<DT> transformPoint(const Tvec3<DT>& sourceVec) const
95  {
96  return Tvec3<DT>( (*this) * sourceVec.affinePoint(), true);
97  }
98 
101 
102  //---------------------------------------------------------------
103  // Assignment operators and other simple methods.
104  //---------------------------------------------------------------
106  static Tmat4<DT> getMat(const double val);
107 
109  void set(const DT val);
110 
113  bool operator<(const Tmat4<DT> &) const { return false; }
114 
116  const Tmat4<DT> &operator=(const Tmat4<DT> &m);
117 
119  const Tmat4<DT> &operator+=(const Tmat4<DT> &m);
120 
122  const Tmat4<DT> &operator-=(const Tmat4<DT> &m);
123 
124 
126  const Tmat4<DT> &operator*=(const DT d);
127 
129  const Tmat4<DT> &operator/=(const DT d);
130 
131 
132  //---------------------------------------------------------------
133  // Special functions
134  //---------------------------------------------------------------
136  DT det3(DT A, DT B, DT C, DT D, DT E, DT F, DT G, DT H, DT I) const;
137 
139  template <class IDX_TYP>
140  inline DT determinantLower3(const IDX_TYP col1, const IDX_TYP col2, const IDX_TYP col3) const
141  {
142  /* Determinant of 3x3 matrix with given entries */
143  return det3(this->v[1][col1], this->v[1][col2], this->v[1][col3],
144  this->v[2][col1], this->v[2][col2], this->v[2][col3],
145  this->v[3][col1], this->v[3][col2], this->v[3][col3]);
146  }
147 
149  DT det() const;
150 
153 
161  Tmat4<DT> inverse(bool* isInvertible=nullptr) const;
162 
165 
168 
169 }; // end of class *mat4*
170 
171 
172 //---------------------------------------------------------------
175 //---------------------------------------------------------------
176 
178 template <class DT>
180 {
181  this->v[0] = this->v[1] = this->v[2] = this->v[3] = Tvec4<DT>(0);
182 }
183 
185 template <class DT>
186 inline Tmat4<DT>::Tmat4(const DT diagValue)
187 {
188  this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] = diagValue;
189  this->v[1][0] = this->v[2][0] = this->v[3][0] = this->v[2][1] = this->v[3][1] = this->v[3][2] = 0;
190  this->v[0][1] = this->v[0][2] = this->v[0][3] = this->v[1][2] = this->v[1][3] = this->v[2][3] = 0;
191 }
192 
194 template <class DT>
195 inline Tmat4<DT>::Tmat4(const Tvec4<DT> &row0, const Tvec4<DT> &row1, const Tvec4<DT> &row2, const Tvec4<DT> &row3)
196 {
197  this->v[0] = row0;
198  this->v[1] = row1;
199  this->v[2] = row2;
200  this->v[3] = row3;
201 }
202 
204 template <class DT>
205 inline Tmat4<DT>::Tmat4(const Tmat4<DT> &mat)
206 {
207  this->v[0] = mat.v[0];
208  this->v[1] = mat.v[1];
209  this->v[2] = mat.v[2];
210  this->v[3] = mat.v[3];
211 }
212 
214 template <class DT>
215 inline Tmat4<DT>::Tmat4(const float mat[16])
216 {
217  setValues(mat);
218 }
219 
221 template <class DT>
222 inline Tmat4<DT>::Tmat4(const double mat[16])
223 {
224  setValues(mat);
225 }
226 
228 template <class DT>
229 inline Tmat4<DT> Tmat4<DT>::getMat(const double val)
230 {
231  return Tmat4<DT>(val, val, val, val,
232  val, val, val, val,
233  val, val, val, val,
234  val, val, val, val);
235 }
236 
237 template <class DT>
239 {
240  Tmat4<DT> matrix = *this;
241 
242  // delete translation vector
243  matrix[0][3] = matrix[1][3] = matrix[2][3] = 0;
244 
245  // normalize direction vectors
246  Tvec3<DT> dirVec;
247  int i, j;
248  for (i = 0; i < 3; i++)
249  {
250  for (j = 0; j < 3; j++)
251  {
252  dirVec[j] = matrix[j][i];
253  }
254  dirVec.normalize();
255  for (j = 0; j < 3; j++)
256  {
257  matrix[j][i] = dirVec[j];
258  }
259  }
260  return matrix;
261 }
262 
264 template <class DT>
265 inline void Tmat4<DT>::set(const DT val)
266 {
267  this->v[0] = this->v[1] = this->v[2] = this->v[3] = Tvec4<DT>(val);
268 }
269 
271 template <class DT>
272 inline const Tmat4<DT> &Tmat4<DT>::operator=(const Tmat4<DT> &m)
273 {
274  if (&m != this){
275  this->v[0] = m.v[0];
276  this->v[1] = m.v[1];
277  this->v[2] = m.v[2];
278  this->v[3] = m.v[3];
279  }
280  return *this;
281 }
282 
284 template <class DT>
286 {
287  this->v[0] += m.v[0];
288  this->v[1] += m.v[1];
289  this->v[2] += m.v[2];
290  this->v[3] += m.v[3];
291  return *this;
292 }
293 
295 template <class DT>
297 {
298  this->v[0] -= m.v[0];
299  this->v[1] -= m.v[1];
300  this->v[2] -= m.v[2];
301  this->v[3] -= m.v[3];
302  return *this;
303 }
304 
306 template <class DT>
307 inline const Tmat4<DT> &Tmat4<DT>::operator*=(const DT d)
308 {
309  this->v[0] *= d;
310  this->v[1] *= d;
311  this->v[2] *= d;
312  this->v[3] *= d;
313  return *this;
314 }
315 
317 template <class DT>
318 inline const Tmat4<DT> &Tmat4<DT>::operator/=(const DT d)
319 {
320  this->v[0] /= d;
321  this->v[1] /= d;
322  this->v[2] /= d;
323  this->v[3] /= d;
324  return *this;
325 }
326 
328 template <class DT>
330 {
331  this->v[0].apply(fct);
332  this->v[1].apply(fct);
333  this->v[2].apply(fct);
334  this->v[3].apply(fct);
335  return *this;
336 }
338 
339 //---------------------------------------------------------------
342 //---------------------------------------------------------------
344 #define _ML_MAT4_RC(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + \
345 a[i][2]*b[2][j] + a[i][3]*b[3][j]
346 
351 template <class DT>
352 inline Tmat4<DT> operator*(const Tmat4<DT> &a, const Tmat4<DT> &b)
353 {
354  return Tmat4<DT>(
355  Tvec4<DT>(_ML_MAT4_RC(0,0), _ML_MAT4_RC(0,1), _ML_MAT4_RC(0,2), _ML_MAT4_RC(0,3)),
356  Tvec4<DT>(_ML_MAT4_RC(1,0), _ML_MAT4_RC(1,1), _ML_MAT4_RC(1,2), _ML_MAT4_RC(1,3)),
357  Tvec4<DT>(_ML_MAT4_RC(2,0), _ML_MAT4_RC(2,1), _ML_MAT4_RC(2,2), _ML_MAT4_RC(2,3)),
359  );
360 }
361 #undef _ML_MAT4_RC
362 
363 
365 template <class DT>
366 inline bool operator==(const Tmat4<DT> &a, const Tmat4<DT> &b)
367 {
368  return ((a[0] == b[0]) &&
369  (a[1] == b[1]) &&
370  (a[2] == b[2]) &&
371  (a[3] == b[3]));
372 }
373 
375 template <class DT>
376 inline bool operator!=(const Tmat4<DT>& a, const Tmat4<DT>& b)
377 {
378  return !(a == b);
379 }
381 
382 
383 //---------------------------------------------------------------
386 //---------------------------------------------------------------
388 template <class DT>
389 inline Tmat4<DT> operator-(const Tmat4<DT> &a)
390 {
391  return Tmat4<DT>(a) *= static_cast<DT>(-1.0);
392 }
393 
395 template <class DT>
396 inline Tmat4<DT> operator+(const Tmat4<DT> &a, const Tmat4<DT> &b)
397 {
398  return Tmat4<DT>(a) += b;
399 }
400 
402 template <class DT>
403 inline Tmat4<DT> operator-(const Tmat4<DT> &a, const Tmat4<DT> &b)
404 {
405  return Tmat4<DT>(a) -= b;
406 }
407 
409 template <class DT>
410 inline Tmat4<DT> operator*(const Tmat4<DT> &a, const DT d)
411 {
412  return Tmat4<DT>(a) *= d;
413 }
414 
416 template <class DT>
417 inline Tmat4<DT> operator*(const DT d, const Tmat4<DT> &a)
418 {
419  return Tmat4<DT>(a) *= d;
420 }
421 
424 template <class DT>
425 inline Tmat4<DT> operator/(const Tmat4<DT> &a, const DT d)
426 {
427  return Tmat4<DT>(a) /= d;
428 }
430 
431 
432 //--------------------------------------------------------------------
433 //
436 //
437 //--------------------------------------------------------------------
438 
439 //--------------------------------------------------------------------
441 //--------------------------------------------------------------------
442 template <class DT>
443 inline Tmat4<DT>::Tmat4(const Tvec3<DT> &n0, const Tvec3<DT> &n1, const Tvec3<DT> &n2, const Tvec3<DT> &t)
444 {
445  this->v[0][0]=n0[0];
446  this->v[1][0]=n0[1];
447  this->v[2][0]=n0[2];
448 
449  this->v[0][1]=n1[0];
450  this->v[1][1]=n1[1];
451  this->v[2][1]=n1[2];
452 
453  this->v[0][2]=n2[0];
454  this->v[1][2]=n2[1];
455  this->v[2][2]=n2[2];
456 
457  this->v[0][3]=t[0];
458  this->v[1][3]=t[1];
459  this->v[2][3]=t[2];
460 
461  this->v[3][0]=0;
462  this->v[3][1]=0;
463  this->v[3][2]=0;
464  this->v[3][3]=1;
465 }
466 
467 //--------------------------------------------------------------------
469 //--------------------------------------------------------------------
470 template <class DT>
471 Tmat4<DT>::Tmat4(const double in00, const double in01, const double in02, const double in03,
472  const double in10, const double in11, const double in12, const double in13,
473  const double in20, const double in21, const double in22, const double in23,
474  const double in30, const double in31, const double in32, const double in33)
475 {
476  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);
477  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);
478  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);
479  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);
480 }
481 
482 //--------------------------------------------------------------------
484 //--------------------------------------------------------------------
485 template <class DT>
486 void Tmat4<DT>::setValues(const float mat[16])
487 {
488  this->v[0][0] = mat[ 0]; this->v[0][1] = mat[ 1]; this->v[0][2] = mat[ 2]; this->v[0][3] = mat[ 3];
489  this->v[1][0] = mat[ 4]; this->v[1][1] = mat[ 5]; this->v[1][2] = mat[ 6]; this->v[1][3] = mat[ 7];
490  this->v[2][0] = mat[ 8]; this->v[2][1] = mat[ 9]; this->v[2][2] = mat[10]; this->v[2][3] = mat[11];
491  this->v[3][0] = mat[12]; this->v[3][1] = mat[13]; this->v[3][2] = mat[14]; this->v[3][3] = mat[15];
492 }
493 
494 //--------------------------------------------------------------------
498 //--------------------------------------------------------------------
499 template <class DT>
500 void Tmat4<DT>::getValues(float mat[16]) const
501 {
502  mat[ 0] = static_cast<float>(this->v[0][0]); mat[ 1] = static_cast<float>(this->v[0][1]); mat[ 2] = static_cast<float>(this->v[0][2]); mat[ 3] = static_cast<float>(this->v[0][3]);
503  mat[ 4] = static_cast<float>(this->v[1][0]); mat[ 5] = static_cast<float>(this->v[1][1]); mat[ 6] = static_cast<float>(this->v[1][2]); mat[ 7] = static_cast<float>(this->v[1][3]);
504  mat[ 8] = static_cast<float>(this->v[2][0]); mat[ 9] = static_cast<float>(this->v[2][1]); mat[10] = static_cast<float>(this->v[2][2]); mat[11] = static_cast<float>(this->v[2][3]);
505  mat[12] = static_cast<float>(this->v[3][0]); mat[13] = static_cast<float>(this->v[3][1]); mat[14] = static_cast<float>(this->v[3][2]); mat[15] = static_cast<float>(this->v[3][3]);
506 }
507 
508 //--------------------------------------------------------------------
510 //--------------------------------------------------------------------
511 template <class DT>
512 void Tmat4<DT>::setValues(const double mat[16])
513 {
514  this->v[0][0] = static_cast<DT>(mat[ 0]); this->v[0][1] = static_cast<DT>(mat[ 1]); this->v[0][2] = static_cast<DT>(mat[ 2]); this->v[0][3] = static_cast<DT>(mat[ 3]);
515  this->v[1][0] = static_cast<DT>(mat[ 4]); this->v[1][1] = static_cast<DT>(mat[ 5]); this->v[1][2] = static_cast<DT>(mat[ 6]); this->v[1][3] = static_cast<DT>(mat[ 7]);
516  this->v[2][0] = static_cast<DT>(mat[ 8]); this->v[2][1] = static_cast<DT>(mat[ 9]); this->v[2][2] = static_cast<DT>(mat[10]); this->v[2][3] = static_cast<DT>(mat[11]);
517  this->v[3][0] = static_cast<DT>(mat[12]); this->v[3][1] = static_cast<DT>(mat[13]); this->v[3][2] = static_cast<DT>(mat[14]); this->v[3][3] = static_cast<DT>(mat[15]);
518 }
519 
520 //--------------------------------------------------------------------
524 //--------------------------------------------------------------------
525 template <class DT>
526 void Tmat4<DT>::getValues(double mat[16]) const
527 {
528  mat[ 0] = static_cast<double>(this->v[0][0]); mat[ 1] = static_cast<double>(this->v[0][1]); mat[ 2] = static_cast<double>(this->v[0][2]); mat[ 3] = static_cast<double>(this->v[0][3]);
529  mat[ 4] = static_cast<double>(this->v[1][0]); mat[ 5] = static_cast<double>(this->v[1][1]); mat[ 6] = static_cast<double>(this->v[1][2]); mat[ 7] = static_cast<double>(this->v[1][3]);
530  mat[ 8] = static_cast<double>(this->v[2][0]); mat[ 9] = static_cast<double>(this->v[2][1]); mat[10] = static_cast<double>(this->v[2][2]); mat[11] = static_cast<double>(this->v[2][3]);
531  mat[12] = static_cast<double>(this->v[3][0]); mat[13] = static_cast<double>(this->v[3][1]); mat[14] = static_cast<double>(this->v[3][2]); mat[15] = static_cast<double>(this->v[3][3]);
532 }
533 
534 //--------------------------------------------------------------------
536 //--------------------------------------------------------------------
537 template <class DT>
538 void Tmat4<DT>::setScaleMatrix(const DT scale)
539 {
540  this->v[0][0] = scale; this->v[0][1] = 0; this->v[0][2] = 0; this->v[0][3] = 0;
541  this->v[1][0] = 0; this->v[1][1] = scale; this->v[1][2] = 0; this->v[1][3] = 0;
542  this->v[2][0] = 0; this->v[2][1] = 0; this->v[2][2] = scale; this->v[2][3] = 0;
543  this->v[3][0] = 0; this->v[3][1] = 0; this->v[3][2] = 0; this->v[3][3] = scale;
544 }
545 
546 //--------------------------------------------------------------------
548 //--------------------------------------------------------------------
549 template <class DT>
550 inline DT Tmat4<DT>::det3(const DT A, const DT B, const DT C, const DT D, const DT E, const DT F, const DT G, const DT H, const DT I) const
551 {
552  /* Determinant of 3x3 matrix with given entries */
553  return ((A*E*I + B*F*G + C*D*H) - (A*F*H + B*D*I + C*E*G));
554 }
555 
556 //--------------------------------------------------------------------
558 //--------------------------------------------------------------------
559 template <class DT>
560 inline DT Tmat4<DT>::det() const
561 {
562  return ( this->v[0][0] * determinantLower3(1u, 2u, 3u)
563  - this->v[0][1] * determinantLower3(0u, 2u, 3u)
564  + this->v[0][2] * determinantLower3(0u, 1u, 3u)
565  - this->v[0][3] * determinantLower3(0u, 1u, 2u));
566 }
567 
568 //--------------------------------------------------------------------
570 //--------------------------------------------------------------------
571 template <class DT>
573 {
574  return Tmat4<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0],
575  this->v[0][1], this->v[1][1], this->v[2][1], this->v[3][1],
576  this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2],
577  this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3]);
578 }
579 
580 //--------------------------------------------------------------------
582 //--------------------------------------------------------------------
583 template <class DT>
585 {
586  return Tmat4<DT>(1, 0, 0, 0,
587  0, 1, 0, 0,
588  0, 0, 1, 0,
589  0, 0, 0, 1);
590 }
591 
592 //--------------------------------------------------------------------
595 //--------------------------------------------------------------------
596 template <class DT>
598 {
599  return Tmat4<DT>::getIdentity();
600 }
601 
602 //--------------------------------------------------------------------
606 //--------------------------------------------------------------------
607 template <class DT>
609 {
610  return Tmat4<DT>(Tvec4<DT>(1.0, 0.0, 0.0, v[0]),
611  Tvec4<DT>(0.0, 1.0, 0.0, v[1]),
612  Tvec4<DT>(0.0, 0.0, 1.0, v[2]),
613  Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
614 }
615 
616 //--------------------------------------------------------------------
619 //-------------------------------------------------------------------
620 template <class DT>
622 {
623  const DT c = cos(angleRad);
624  const DT s = sin(angleRad);
625  const DT t = 1.0 - c;
626 
627  Axis.normalize();
628  return Tmat4<DT>(Tvec4<DT>(t * Axis[0] * Axis[0] + c,
629  t * Axis[0] * Axis[1] - s * Axis[2],
630  t * Axis[0] * Axis[2] + s * Axis[1],
631  0.0),
632  Tvec4<DT>(t * Axis[0] * Axis[1] + s * Axis[2],
633  t * Axis[1] * Axis[1] + c,
634  t * Axis[1] * Axis[2] - s * Axis[0],
635  0.0),
636  Tvec4<DT>(t * Axis[0] * Axis[2] - s * Axis[1],
637  t * Axis[1] * Axis[2] + s * Axis[0],
638  t * Axis[2] * Axis[2] + c,
639  0.0),
640  Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
641 }
642 
643 //--------------------------------------------------------------------
645 //--------------------------------------------------------------------
646 template <class DT>
647 inline Tmat4<DT> scaling3D(const Tvec3<DT> &scaleVector)
648 {
649  return Tmat4<DT>(Tvec4<DT>(scaleVector[0], 0.0, 0.0, 0.0),
650  Tvec4<DT>(0.0, scaleVector[1], 0.0, 0.0),
651  Tvec4<DT>(0.0, 0.0, scaleVector[2], 0.0),
652  Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
653 }
654 
655 //--------------------------------------------------------------------
659 //--------------------------------------------------------------------
660 template <class DT>
661 inline Tmat4<DT> perspective3D(const DT d)
662 {
663  Tmat4<DT> retVal;
665 
666  retVal[0][0] = 1.0;
667  retVal[1][1] = 1.0;
668  retVal[2][2] = 1.0;
669  retVal[3][2] = 1.0/d;
670  retVal[3][3] = 1.0;
671  return retVal;
672 }
673 
674 
675 //--------------------------------------------------------------------
683 //--------------------------------------------------------------------
684 template <class DT>
685 Tmat4<DT> Tmat4<DT>::inverse(bool* isInvertible) const
686 {
687  // Epsilon for comparison with 0 in inversion process.
688  static const DT Epsilon = static_cast<DT>(10e-14);
689 
690  // Use helper function from tools to invert the matrix.
691  return MLInverseMatHelper(*this,
692  isInvertible,
693  Epsilon,
694  "Tmat4<DT> Tmat4<DT>::inverse(bool* isInvertible) const, matrix not invertable",
695  getIdentity(),
696  4);
697 }
699 
700 
701 //-----------------------------------------------------------------------------------
704 //-----------------------------------------------------------------------------------
705 
715 
716 
717 ML_LA_END_NAMESPACE
718 
719 namespace std
720 {
721  //-------------------------------------------------------------------
723  //-------------------------------------------------------------------
724  template <class DT>
725  inline std::ostream &operator<<(std::ostream &os, const ML_LA_NAMESPACE::Tmat4<DT> &m)
726  {
727  return os << m[0] << '\n' << m[1] << '\n' << m[2] << '\n' << m[3];
728  }
729 
730  // Input from stream.
731  template <class DT>
732  inline std::istream &operator>>(std::istream &is, ML_LA_NAMESPACE::Tmat4<DT> &m)
733  {
734  ML_LA_NAMESPACE::Tmat4<DT> m_tmp;
735  is >> m_tmp[0] >> m_tmp[1] >> m_tmp[2] >> m_tmp[3];
736  if (is){ m = m_tmp; }
737  return is;
738  }
740 }
741 
742 #endif // __mlMatrix4_H
743 
744 
745 
746 
@ G
Definition: SoKeyGrabber.h:58
@ B
Definition: SoKeyGrabber.h:53
@ A
Letters.
Definition: SoKeyGrabber.h:52
@ H
Definition: SoKeyGrabber.h:59
@ C
Definition: SoKeyGrabber.h:54
@ D
Definition: SoKeyGrabber.h:55
@ E
Definition: SoKeyGrabber.h:56
@ I
Definition: SoKeyGrabber.h:60
@ F
Definition: SoKeyGrabber.h:57
A class to administrate an axis coordinate system drawable in OpenGL.
Definition: Axis.h:22
Base class of all matrix classes that 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 normalize()
Normalizes the buffer and returns the Euclidean length of vector before normalization,...
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 4x4 matrix class consisting of four row vectors.
Definition: mlMatrix4.h:36
Tmat4(const double mat[16])
Constructor from 16 double values in an array given by mat, row by row.
Definition: mlMatrix4.h:222
DT determinantLower3(const IDX_TYP col1, const IDX_TYP col2, const IDX_TYP col3) const
Determines the (sub)determinant of columns given by col1, col2, and col3.
Definition: mlMatrix4.h:140
void set(const DT val)
Sets all values to val.
Definition: mlMatrix4.h:265
Tmat4< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse.
Definition: mlMatrix4.h:685
Tmat4(const Tvec3< DT > &n0, const Tvec3< DT > &n1, const Tvec3< DT > &n3, const Tvec3< DT > &t)
Constructs a matrix from three base vectors n0, ...
Definition: mlMatrix4.h:443
Tmat4(const Tvec4< DT > &row0, const Tvec4< DT > &row1, const Tvec4< DT > &row2, const Tvec4< DT > &row3)
Composes a matrix from the four row vectors row0, row1, row2, and row3.
Definition: mlMatrix4.h:195
void getValues(float mat[16]) const
Copies the contents of *this into floating point matrix mat, row by row.
Definition: mlMatrix4.h:500
Tvec3< DT > transformPoint(const Tvec3< DT > &sourceVec) const
Transforms the given sourceVec and returns the result vector.
Definition: mlMatrix4.h:94
Tmat4(const float mat[16])
Constructor from 16 floating point values in an array given by mat, row by row.
Definition: mlMatrix4.h:215
const Tmat4< DT > & operator/=(const DT d)
Divides by a constant d. Division by zero is not handled and must be avoided by caller.
Definition: mlMatrix4.h:318
static Tmat4< DT > getIdentity()
Returns the identity matrix.
Definition: mlMatrix4.h:584
DT det() const
Returns the determinant of this.
Definition: mlMatrix4.h:560
bool operator<(const Tmat4< DT > &) const
Dummy 'lesser than operator' that always returns false.
Definition: mlMatrix4.h:113
DT det3(DT A, DT B, DT C, DT D, DT E, DT F, DT G, DT H, DT I) const
Determines the determinant of a 3x3 matrix given by A,B,C,D,E,F,G,H,I.
Definition: mlMatrix4.h:550
void setValues(const double mat[16])
Copies the contents from double array mat into *this, row by row.
Definition: mlMatrix4.h:512
Tmat4< DT > transpose() const
Returns the transposed *this.
Definition: mlMatrix4.h:572
Tmat4(const double in00, const double in01, const double in02, const double in03, const double in10, const double in11, const double in12, const double in13, const double in20, const double in21, const double in22, const double in23, const double in30, const double in31, const double in32, const double in33)
Initializes all matrix elements explicitly with scalars, filling it row by row.
Definition: mlMatrix4.h:471
static Tmat4< DT > getMat(const double val)
Returns a matrix filled with values val.
Definition: mlMatrix4.h:229
const Tmat4< DT > & operator=(const Tmat4< DT > &m)
Assigns from a Tmat4.
Definition: mlMatrix4.h:272
Tmat4(const Tmat4< DT > &mat)
Copy constructor from the Tmat4 mat.
Definition: mlMatrix4.h:205
Tmat4< DT > getRotationMatrix() const
Returns the rotational part of the matrix (removes scaling and translation).
Definition: mlMatrix4.h:238
void setScaleMatrix(const DT scale)
Sets a diagonal matrix with [ scale on the diagonal.
Definition: mlMatrix4.h:538
const Tmat4< DT > & operator+=(const Tmat4< DT > &m)
Increments by a Tmat4.
Definition: mlMatrix4.h:285
void setValues(const float mat[16])
Copies the contents from float array mat into *this, row by row.
Definition: mlMatrix4.h:486
const Tmat4< DT > & operator*=(const DT d)
Multiplies by a constant d.
Definition: mlMatrix4.h:307
Tmat4(const DT diagValue)
Builds a matrix that has the argument diagValue as the diagonal values, zero otherwise.
Definition: mlMatrix4.h:186
const Tmat4< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to each component.
Definition: mlMatrix4.h:329
void getValues(double mat[16]) const
Copies the contents of *this into into double matrix mat, row by row.
Definition: mlMatrix4.h:526
const Tmat4< DT > & operator-=(const Tmat4< DT > &m)
Decrements by a Tmat4.
Definition: mlMatrix4.h:296
DT ComponentType
A typedef to 'export' the type of components.
Definition: mlMatrix4.h:40
Tmat4()
Constructs a matrix from 16 zero elements.
Definition: mlMatrix4.h:179
Forward declarations to resolve header file dependencies.
Definition: mlVector3.h:66
Tvec4< DT > affinePoint() const
Builds a homogeneous Tvec4 point from *this and returns it, i.e., leaves all components unchanged and...
Definition: mlVector3.h:203
Forward declarations to resolve header file dependencies.
Definition: mlVector4.h:50
#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_MAT4_RC(i, j)
Helper macro only locally defined for Tmat4 matrix multiplication.
Definition: mlMatrix4.h:344
double(* MLDblFuncPtr)(double)
A function pointer type to a function that returns a double and takes a double as argument.
Definition: mlTypeDefs.h:1166
std::istream & operator>>(std::istream &in, ml::Variant &variant)
Definition: mlVariant.h:215
void apply(Fnc &&fnc, const std::tuple< Args... > &tuple)
Tmat4< DT > translation3D(const Tvec3< DT > &v)
Returns a 4x4 homogeneous translation matrix with default identity matrix contents and the upper thre...
Definition: mlMatrix4.h:608
Tmat4< DT > rotation3D(Tvec3< DT > Axis, const DT angleRad)
Returns a 4x4 homogeneous 3D rotation matrix describing a rotation with angle angleRad around axis Ax...
Definition: mlMatrix4.h:621
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.
Tmat4< DT > scaling3D(const Tvec3< DT > &scaleVector)
Scaling 3D.
Definition: mlMatrix4.h:647
bool operator==(const Tmat4< DT > &a, const Tmat4< DT > &b)
a == b ? Returns true if yes.
Definition: mlMatrix4.h:366
Tmat4< MLdouble > Matrix4d
A 4x4 matrix of type double.
Definition: mlMatrix4.h:709
Tmat4< DT > perspective3D(const DT d)
Creates a 4x4 homogeneous perspective projection matrix with perspective shortening value given by d ...
Definition: mlMatrix4.h:661
Tmat4< MLdouble > Matrix4
The standard 4x4 matrix of type double.
Definition: mlMatrix4.h:713
bool operator!=(const Tmat4< DT > &a, const Tmat4< DT > &b)
a != b ? Returns true if yes.
Definition: mlMatrix4.h:376
Tmat4< DT > identity3D()
Returns a 4x4 homogeneous identity3D matrix; synonym for Tmat4<DT>::getIdentity().
Definition: mlMatrix4.h:597
Tmat4< MLldouble > Matrix4ld
A 4x4 matrix of type long double.
Definition: mlMatrix4.h:711
constexpr Is< T > is(T d)
FloatingPointVector< T, size, DataContainer > & operator+=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component-wise addition.
Tmat4< MLfloat > Matrix4f
A 4x4 matrix of type float.
Definition: mlMatrix4.h:707
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.