MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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.
20#include "mlLinearAlgebraDefs.h"
21
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.
30
31//---------------------------------------------------------------
33//---------------------------------------------------------------
34template <class DT> class Tmat4 : public FloatingPointMatrix<Tvec4<DT>, 4>
35{
36public:
38 typedef DT ComponentType;
39
40 //---------------------------------------------------------------
41 // Constructors, set, and get methods.
42 //---------------------------------------------------------------
43 // Construct matrix from 16 zero elements.
45
47 Tmat4(const DT diagValue);
48
50 Tmat4(const Tvec4<DT>& row0, const Tvec4<DT>& row1, const Tvec4<DT>& row2, const Tvec4<DT>& row3);
51
54
56 Tmat4(const float mat[16]);
57
59 Tmat4(const double mat[16]);
60
63 Tmat4(const double in00, const double in01, const double in02, const double in03, const double in10,
64 const double in11, const double in12, const double in13, const double in20, const double in21,
65 const double in22, const double in23, const double in30, const double in31, const double in32,
66 const double in33);
67
70 Tmat4(const Tvec3<DT>& n0, const Tvec3<DT>& n1, const Tvec3<DT>& n3, const Tvec3<DT>& t);
71
73 void setValues(const float mat[16]);
74
78 void getValues(float mat[16]) const;
79
81 void setValues(const double mat[16]);
82
86 void getValues(double mat[16]) const;
87
89 void setScaleMatrix(const DT scale);
90
93 {
94 return Tvec3<DT>((*this) * sourceVec.affinePoint(), true);
95 }
96
99
100 //---------------------------------------------------------------
101 // Assignment operators and other simple methods.
102 //---------------------------------------------------------------
104 static Tmat4<DT> getMat(const double val);
105
107 void set(const DT val);
108
111 bool operator<(const Tmat4<DT>&) const
112 {
113 return false;
114 }
115
118
121
124
125
127 const Tmat4<DT>& operator*=(const DT d);
128
130 const Tmat4<DT>& operator/=(const DT d);
131
132
133 //---------------------------------------------------------------
134 // Special functions
135 //---------------------------------------------------------------
137 DT det3(DT A, DT B, DT C, DT D, DT E, DT F, DT G, DT H, DT I) const;
138
140 template <class IDX_TYP> 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], this->v[2][col1], this->v[2][col2],
144 this->v[2][col3], this->v[3][col1], this->v[3][col2], this->v[3][col3]);
145 }
146
148 DT det() const;
149
152
160 Tmat4<DT> inverse(bool* isInvertible = nullptr) const;
161
164
167
168}; // end of class *mat4*
169
170
171//---------------------------------------------------------------
174//---------------------------------------------------------------
175
177template <class DT> inline Tmat4<DT>::Tmat4()
178{
179 this->v[0] = this->v[1] = this->v[2] = this->v[3] = Tvec4<DT>(0);
180}
181
183template <class DT> inline Tmat4<DT>::Tmat4(const DT diagValue)
184{
185 this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] = diagValue;
186 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;
187 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;
188}
189
191template <class DT>
193{
194 this->v[0] = row0;
195 this->v[1] = row1;
196 this->v[2] = row2;
197 this->v[3] = row3;
198}
199
201template <class DT> inline Tmat4<DT>::Tmat4(const Tmat4<DT>& mat)
202{
203 this->v[0] = mat.v[0];
204 this->v[1] = mat.v[1];
205 this->v[2] = mat.v[2];
206 this->v[3] = mat.v[3];
207}
208
210template <class DT> inline Tmat4<DT>::Tmat4(const float mat[16])
211{
212 setValues(mat);
213}
214
216template <class DT> inline Tmat4<DT>::Tmat4(const double mat[16])
217{
218 setValues(mat);
219}
220
222template <class DT> inline Tmat4<DT> Tmat4<DT>::getMat(const double val)
223{
224 return Tmat4<DT>(val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val);
225}
226
227template <class DT> inline Tmat4<DT> Tmat4<DT>::getRotationMatrix() const
228{
229 Tmat4<DT> matrix = *this;
230
231 // delete translation vector
232 matrix[0][3] = matrix[1][3] = matrix[2][3] = 0;
233
234 // normalize direction vectors
236 int i, j;
237 for (i = 0; i < 3; i++) {
238 for (j = 0; j < 3; j++) {
239 dirVec[j] = matrix[j][i];
240 }
241 dirVec.normalize();
242 for (j = 0; j < 3; j++) {
243 matrix[j][i] = dirVec[j];
244 }
245 }
246 return matrix;
247}
248
250template <class DT> inline void Tmat4<DT>::set(const DT val)
251{
252 this->v[0] = this->v[1] = this->v[2] = this->v[3] = Tvec4<DT>(val);
253}
254
256template <class DT> inline const Tmat4<DT>& Tmat4<DT>::operator=(const Tmat4<DT>& m)
257{
258 if (&m != this) {
259 this->v[0] = m.v[0];
260 this->v[1] = m.v[1];
261 this->v[2] = m.v[2];
262 this->v[3] = m.v[3];
263 }
264 return *this;
265}
266
268template <class DT> inline const Tmat4<DT>& Tmat4<DT>::operator+=(const Tmat4<DT>& m)
269{
270 this->v[0] += m.v[0];
271 this->v[1] += m.v[1];
272 this->v[2] += m.v[2];
273 this->v[3] += m.v[3];
274 return *this;
275}
276
278template <class DT> inline const Tmat4<DT>& Tmat4<DT>::operator-=(const Tmat4<DT>& m)
279{
280 this->v[0] -= m.v[0];
281 this->v[1] -= m.v[1];
282 this->v[2] -= m.v[2];
283 this->v[3] -= m.v[3];
284 return *this;
285}
286
288template <class DT> inline const Tmat4<DT>& Tmat4<DT>::operator*=(const DT d)
289{
290 this->v[0] *= d;
291 this->v[1] *= d;
292 this->v[2] *= d;
293 this->v[3] *= d;
294 return *this;
295}
296
298template <class DT> inline const Tmat4<DT>& Tmat4<DT>::operator/=(const DT d)
299{
300 this->v[0] /= d;
301 this->v[1] /= d;
302 this->v[2] /= d;
303 this->v[3] /= d;
304 return *this;
305}
306
308template <class DT> inline const Tmat4<DT>& Tmat4<DT>::apply(MLDblFuncPtr fct)
309{
310 this->v[0].apply(fct);
311 this->v[1].apply(fct);
312 this->v[2].apply(fct);
313 this->v[3].apply(fct);
314 return *this;
315}
317
318//---------------------------------------------------------------
321//---------------------------------------------------------------
323#define _ML_MAT4_RC(i, j) a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j] + a[i][3] * b[3][j]
324
329template <class DT> inline Tmat4<DT> operator*(const Tmat4<DT>& a, const Tmat4<DT>& b)
330{
331 return Tmat4<DT>(Tvec4<DT>(_ML_MAT4_RC(0, 0), _ML_MAT4_RC(0, 1), _ML_MAT4_RC(0, 2), _ML_MAT4_RC(0, 3)),
332 Tvec4<DT>(_ML_MAT4_RC(1, 0), _ML_MAT4_RC(1, 1), _ML_MAT4_RC(1, 2), _ML_MAT4_RC(1, 3)),
333 Tvec4<DT>(_ML_MAT4_RC(2, 0), _ML_MAT4_RC(2, 1), _ML_MAT4_RC(2, 2), _ML_MAT4_RC(2, 3)),
334 Tvec4<DT>(_ML_MAT4_RC(3, 0), _ML_MAT4_RC(3, 1), _ML_MAT4_RC(3, 2), _ML_MAT4_RC(3, 3)));
335}
336#undef _ML_MAT4_RC
337
338
340template <class DT> inline bool operator==(const Tmat4<DT>& a, const Tmat4<DT>& b)
341{
342 return ((a[0] == b[0]) && (a[1] == b[1]) && (a[2] == b[2]) && (a[3] == b[3]));
343}
344
346template <class DT> inline bool operator!=(const Tmat4<DT>& a, const Tmat4<DT>& b)
347{
348 return !(a == b);
349}
351
352
353//---------------------------------------------------------------
356//---------------------------------------------------------------
358template <class DT> inline Tmat4<DT> operator-(const Tmat4<DT>& a)
359{
360 return Tmat4<DT>(a) *= static_cast<DT>(-1.0);
361}
362
364template <class DT> inline Tmat4<DT> operator+(const Tmat4<DT>& a, const Tmat4<DT>& b)
365{
366 return Tmat4<DT>(a) += b;
367}
368
370template <class DT> inline Tmat4<DT> operator-(const Tmat4<DT>& a, const Tmat4<DT>& b)
371{
372 return Tmat4<DT>(a) -= b;
373}
374
376template <class DT> inline Tmat4<DT> operator*(const Tmat4<DT>& a, const DT d)
377{
378 return Tmat4<DT>(a) *= d;
379}
380
382template <class DT> inline Tmat4<DT> operator*(const DT d, const Tmat4<DT>& a)
383{
384 return Tmat4<DT>(a) *= d;
385}
386
389template <class DT> inline Tmat4<DT> operator/(const Tmat4<DT>& a, const DT d)
390{
391 return Tmat4<DT>(a) /= d;
392}
394
395
396//--------------------------------------------------------------------
397//
400//
401//--------------------------------------------------------------------
402
403//--------------------------------------------------------------------
405//--------------------------------------------------------------------
406template <class DT>
407inline Tmat4<DT>::Tmat4(const Tvec3<DT>& n0, const Tvec3<DT>& n1, const Tvec3<DT>& n2, const Tvec3<DT>& t)
408{
409 this->v[0][0] = n0[0];
410 this->v[1][0] = n0[1];
411 this->v[2][0] = n0[2];
412
413 this->v[0][1] = n1[0];
414 this->v[1][1] = n1[1];
415 this->v[2][1] = n1[2];
416
417 this->v[0][2] = n2[0];
418 this->v[1][2] = n2[1];
419 this->v[2][2] = n2[2];
420
421 this->v[0][3] = t[0];
422 this->v[1][3] = t[1];
423 this->v[2][3] = t[2];
424
425 this->v[3][0] = 0;
426 this->v[3][1] = 0;
427 this->v[3][2] = 0;
428 this->v[3][3] = 1;
429}
430
431//--------------------------------------------------------------------
433//--------------------------------------------------------------------
434template <class DT> Tmat4<DT>::Tmat4(const double in00, const double in01, const double in02, const double in03,
435 const double in10, const double in11, const double in12, const double in13,
436 const double in20, const double in21, const double in22, const double in23,
437 const double in30, const double in31, const double in32, const double in33)
438{
439 this->v[0][0] = static_cast<DT>(in00);
440 this->v[0][1] = static_cast<DT>(in01);
441 this->v[0][2] = static_cast<DT>(in02);
442 this->v[0][3] = static_cast<DT>(in03);
443 this->v[1][0] = static_cast<DT>(in10);
444 this->v[1][1] = static_cast<DT>(in11);
445 this->v[1][2] = static_cast<DT>(in12);
446 this->v[1][3] = static_cast<DT>(in13);
447 this->v[2][0] = static_cast<DT>(in20);
448 this->v[2][1] = static_cast<DT>(in21);
449 this->v[2][2] = static_cast<DT>(in22);
450 this->v[2][3] = static_cast<DT>(in23);
451 this->v[3][0] = static_cast<DT>(in30);
452 this->v[3][1] = static_cast<DT>(in31);
453 this->v[3][2] = static_cast<DT>(in32);
454 this->v[3][3] = static_cast<DT>(in33);
455}
456
457//--------------------------------------------------------------------
459//--------------------------------------------------------------------
460template <class DT> void Tmat4<DT>::setValues(const float mat[16])
461{
462 this->v[0][0] = mat[0];
463 this->v[0][1] = mat[1];
464 this->v[0][2] = mat[2];
465 this->v[0][3] = mat[3];
466 this->v[1][0] = mat[4];
467 this->v[1][1] = mat[5];
468 this->v[1][2] = mat[6];
469 this->v[1][3] = mat[7];
470 this->v[2][0] = mat[8];
471 this->v[2][1] = mat[9];
472 this->v[2][2] = mat[10];
473 this->v[2][3] = mat[11];
474 this->v[3][0] = mat[12];
475 this->v[3][1] = mat[13];
476 this->v[3][2] = mat[14];
477 this->v[3][3] = mat[15];
478}
479
480//--------------------------------------------------------------------
484//--------------------------------------------------------------------
485template <class DT> void Tmat4<DT>::getValues(float mat[16]) const
486{
487 mat[0] = static_cast<float>(this->v[0][0]);
488 mat[1] = static_cast<float>(this->v[0][1]);
489 mat[2] = static_cast<float>(this->v[0][2]);
490 mat[3] = static_cast<float>(this->v[0][3]);
491 mat[4] = static_cast<float>(this->v[1][0]);
492 mat[5] = static_cast<float>(this->v[1][1]);
493 mat[6] = static_cast<float>(this->v[1][2]);
494 mat[7] = static_cast<float>(this->v[1][3]);
495 mat[8] = static_cast<float>(this->v[2][0]);
496 mat[9] = static_cast<float>(this->v[2][1]);
497 mat[10] = static_cast<float>(this->v[2][2]);
498 mat[11] = static_cast<float>(this->v[2][3]);
499 mat[12] = static_cast<float>(this->v[3][0]);
500 mat[13] = static_cast<float>(this->v[3][1]);
501 mat[14] = static_cast<float>(this->v[3][2]);
502 mat[15] = static_cast<float>(this->v[3][3]);
503}
504
505//--------------------------------------------------------------------
507//--------------------------------------------------------------------
508template <class DT> void Tmat4<DT>::setValues(const double mat[16])
509{
510 this->v[0][0] = static_cast<DT>(mat[0]);
511 this->v[0][1] = static_cast<DT>(mat[1]);
512 this->v[0][2] = static_cast<DT>(mat[2]);
513 this->v[0][3] = static_cast<DT>(mat[3]);
514 this->v[1][0] = static_cast<DT>(mat[4]);
515 this->v[1][1] = static_cast<DT>(mat[5]);
516 this->v[1][2] = static_cast<DT>(mat[6]);
517 this->v[1][3] = static_cast<DT>(mat[7]);
518 this->v[2][0] = static_cast<DT>(mat[8]);
519 this->v[2][1] = static_cast<DT>(mat[9]);
520 this->v[2][2] = static_cast<DT>(mat[10]);
521 this->v[2][3] = static_cast<DT>(mat[11]);
522 this->v[3][0] = static_cast<DT>(mat[12]);
523 this->v[3][1] = static_cast<DT>(mat[13]);
524 this->v[3][2] = static_cast<DT>(mat[14]);
525 this->v[3][3] = static_cast<DT>(mat[15]);
526}
527
528//--------------------------------------------------------------------
532//--------------------------------------------------------------------
533template <class DT> void Tmat4<DT>::getValues(double mat[16]) const
534{
535 mat[0] = static_cast<double>(this->v[0][0]);
536 mat[1] = static_cast<double>(this->v[0][1]);
537 mat[2] = static_cast<double>(this->v[0][2]);
538 mat[3] = static_cast<double>(this->v[0][3]);
539 mat[4] = static_cast<double>(this->v[1][0]);
540 mat[5] = static_cast<double>(this->v[1][1]);
541 mat[6] = static_cast<double>(this->v[1][2]);
542 mat[7] = static_cast<double>(this->v[1][3]);
543 mat[8] = static_cast<double>(this->v[2][0]);
544 mat[9] = static_cast<double>(this->v[2][1]);
545 mat[10] = static_cast<double>(this->v[2][2]);
546 mat[11] = static_cast<double>(this->v[2][3]);
547 mat[12] = static_cast<double>(this->v[3][0]);
548 mat[13] = static_cast<double>(this->v[3][1]);
549 mat[14] = static_cast<double>(this->v[3][2]);
550 mat[15] = static_cast<double>(this->v[3][3]);
551}
552
553//--------------------------------------------------------------------
555//--------------------------------------------------------------------
556template <class DT> void Tmat4<DT>::setScaleMatrix(const DT scale)
557{
558 this->v[0][0] = scale;
559 this->v[0][1] = 0;
560 this->v[0][2] = 0;
561 this->v[0][3] = 0;
562 this->v[1][0] = 0;
563 this->v[1][1] = scale;
564 this->v[1][2] = 0;
565 this->v[1][3] = 0;
566 this->v[2][0] = 0;
567 this->v[2][1] = 0;
568 this->v[2][2] = scale;
569 this->v[2][3] = 0;
570 this->v[3][0] = 0;
571 this->v[3][1] = 0;
572 this->v[3][2] = 0;
573 this->v[3][3] = scale;
574}
575
576//--------------------------------------------------------------------
578//--------------------------------------------------------------------
579template <class DT> inline DT Tmat4<DT>::det3(const DT A, const DT B, const DT C, const DT D, const DT E, const DT F,
580 const DT G, const DT H, const DT I) const
581{
582 /* Determinant of 3x3 matrix with given entries */
583 return ((A * E * I + B * F * G + C * D * H) - (A * F * H + B * D * I + C * E * G));
584}
585
586//--------------------------------------------------------------------
588//--------------------------------------------------------------------
589template <class DT> inline DT Tmat4<DT>::det() const
590{
591 return (this->v[0][0] * determinantLower3(1u, 2u, 3u) - this->v[0][1] * determinantLower3(0u, 2u, 3u) +
592 this->v[0][2] * determinantLower3(0u, 1u, 3u) - this->v[0][3] * determinantLower3(0u, 1u, 2u));
593}
594
595//--------------------------------------------------------------------
597//--------------------------------------------------------------------
598template <class DT> inline Tmat4<DT> Tmat4<DT>::transpose() const
599{
600 return Tmat4<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0], this->v[0][1], this->v[1][1],
601 this->v[2][1], this->v[3][1], this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2],
602 this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3]);
603}
604
605//--------------------------------------------------------------------
607//--------------------------------------------------------------------
608template <class DT> inline Tmat4<DT> Tmat4<DT>::getIdentity()
609{
610 return Tmat4<DT>(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
611}
612
613//--------------------------------------------------------------------
616//--------------------------------------------------------------------
617template <class DT> Tmat4<DT> identity3D()
618{
619 return Tmat4<DT>::getIdentity();
620}
621
622//--------------------------------------------------------------------
626//--------------------------------------------------------------------
627template <class DT> inline Tmat4<DT> translation3D(const Tvec3<DT>& v)
628{
629 return Tmat4<DT>(Tvec4<DT>(1.0, 0.0, 0.0, v[0]), Tvec4<DT>(0.0, 1.0, 0.0, v[1]), Tvec4<DT>(0.0, 0.0, 1.0, v[2]),
630 Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
631}
632
633//--------------------------------------------------------------------
636//-------------------------------------------------------------------
637template <class DT> Tmat4<DT> rotation3D(Tvec3<DT> Axis, const DT angleRad)
638{
639 const DT c = cos(angleRad);
640 const DT s = sin(angleRad);
641 const DT t = 1.0 - c;
642
643 Axis.normalize();
644 return Tmat4<DT>(Tvec4<DT>(t * Axis[0] * Axis[0] + c, t * Axis[0] * Axis[1] - s * Axis[2],
645 t * Axis[0] * Axis[2] + s * Axis[1], 0.0),
646 Tvec4<DT>(t * Axis[0] * Axis[1] + s * Axis[2], t * Axis[1] * Axis[1] + c,
647 t * Axis[1] * Axis[2] - s * Axis[0], 0.0),
648 Tvec4<DT>(t * Axis[0] * Axis[2] - s * Axis[1], t * Axis[1] * Axis[2] + s * Axis[0],
649 t * Axis[2] * Axis[2] + c, 0.0),
650 Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
651}
652
653//--------------------------------------------------------------------
655//--------------------------------------------------------------------
656template <class DT> inline Tmat4<DT> scaling3D(const Tvec3<DT>& scaleVector)
657{
658 return Tmat4<DT>(Tvec4<DT>(scaleVector[0], 0.0, 0.0, 0.0), Tvec4<DT>(0.0, scaleVector[1], 0.0, 0.0),
659 Tvec4<DT>(0.0, 0.0, scaleVector[2], 0.0), Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
660}
661
662//--------------------------------------------------------------------
666//--------------------------------------------------------------------
667template <class DT> inline Tmat4<DT> perspective3D(const DT d)
668{
671
672 retVal[0][0] = 1.0;
673 retVal[1][1] = 1.0;
674 retVal[2][2] = 1.0;
675 retVal[3][2] = 1.0 / d;
676 retVal[3][3] = 1.0;
677 return retVal;
678}
679
680
681//--------------------------------------------------------------------
689//--------------------------------------------------------------------
690template <class DT> Tmat4<DT> Tmat4<DT>::inverse(bool* isInvertible) const
691{
692 // Epsilon for comparison with 0 in inversion process.
693 static const DT Epsilon = static_cast<DT>(10e-14);
694
695 // Use helper function from tools to invert the matrix.
697 "Tmat4<DT> Tmat4<DT>::inverse(bool* isInvertible) const, matrix not invertable",
698 getIdentity(), 4);
699}
701
702
703//-----------------------------------------------------------------------------------
706//-----------------------------------------------------------------------------------
707
717
718
720
721namespace std
722{
723 //-------------------------------------------------------------------
725 //-------------------------------------------------------------------
726 template <class DT> inline std::ostream& operator<<(std::ostream& os, const ML_LA_NAMESPACE::Tmat4<DT>& m)
727 {
728 return os << m[0] << '\n' << m[1] << '\n' << m[2] << '\n' << m[3];
729 }
730
731 // Input from stream.
732 template <class DT> 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) {
737 m = m_tmp;
738 }
739 return is;
740 }
742} // namespace std
743
744#endif // __mlMatrix4_H
@ G
@ B
@ A
Letters.
@ H
@ C
@ D
@ E
@ I
@ F
A class to administrate an axis coordinate system drawable in OpenGL.
Definition Axis.h:23
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.
A 4x4 matrix class consisting of four row vectors.
Definition mlMatrix4.h:35
Tmat4(const double mat[16])
Constructor from 16 double values in an array given by mat, row by row.
Definition mlMatrix4.h:216
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
Tvec3< DT > transformPoint(const Tvec3< DT > &sourceVec) const
Transforms the given sourceVec and returns the result vector.
Definition mlMatrix4.h:92
void set(const DT val)
Sets all values to val.
Definition mlMatrix4.h:250
Tmat4< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse.
Definition mlMatrix4.h:690
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, ... n3 and a translation t, all given as column vecto...
Definition mlMatrix4.h:407
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:192
void getValues(float mat[16]) const
Copies the contents of *this into floating point matrix mat, row by row.
Definition mlMatrix4.h:485
Tmat4(const float mat[16])
Constructor from 16 floating point values in an array given by mat, row by row.
Definition mlMatrix4.h:210
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:298
static Tmat4< DT > getIdentity()
Returns the identity matrix.
Definition mlMatrix4.h:608
DT det() const
Returns the determinant of this.
Definition mlMatrix4.h:589
bool operator<(const Tmat4< DT > &) const
Dummy 'lesser than operator' that always returns false.
Definition mlMatrix4.h:111
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:579
void setValues(const double mat[16])
Copies the contents from double array mat into *this, row by row.
Definition mlMatrix4.h:508
Tmat4< DT > transpose() const
Returns the transposed *this.
Definition mlMatrix4.h:598
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:434
static Tmat4< DT > getMat(const double val)
Returns a matrix filled with values val.
Definition mlMatrix4.h:222
const Tmat4< DT > & operator=(const Tmat4< DT > &m)
Assigns from a Tmat4.
Definition mlMatrix4.h:256
Tmat4(const Tmat4< DT > &mat)
Copy constructor from the Tmat4 mat.
Definition mlMatrix4.h:201
Tmat4< DT > getRotationMatrix() const
Returns the rotational part of the matrix (removes scaling and translation).
Definition mlMatrix4.h:227
void setScaleMatrix(const DT scale)
Sets a diagonal matrix with [ scale on the diagonal.
Definition mlMatrix4.h:556
const Tmat4< DT > & operator+=(const Tmat4< DT > &m)
Increments by a Tmat4.
Definition mlMatrix4.h:268
void setValues(const float mat[16])
Copies the contents from float array mat into *this, row by row.
Definition mlMatrix4.h:460
const Tmat4< DT > & operator*=(const DT d)
Multiplies by a constant d.
Definition mlMatrix4.h:288
Tmat4(const DT diagValue)
Builds a matrix that has the argument diagValue as the diagonal values, zero otherwise.
Definition mlMatrix4.h:183
const Tmat4< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to each component.
Definition mlMatrix4.h:308
void getValues(double mat[16]) const
Copies the contents of *this into into double matrix mat, row by row.
Definition mlMatrix4.h:533
const Tmat4< DT > & operator-=(const Tmat4< DT > &m)
Decrements by a Tmat4.
Definition mlMatrix4.h:278
DT ComponentType
A typedef to 'export' the type of components.
Definition mlMatrix4.h:38
Tmat4()
Constructs a matrix from 16 zero elements.
Definition mlMatrix4.h:177
Forward declarations to resolve header file dependencies.
Definition mlVector3.h:66
Forward declarations to resolve header file dependencies.
Definition mlVector4.h:49
#define ML_CHECK_FLOAT_THROW(x)
#define _ML_MAT4_RC(i, j)
Helper macro only locally defined for Tmat4 matrix multiplication.
Definition mlMatrix4.h:323
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double(* MLDblFuncPtr)(double)
A function pointer type to a function that 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.
Tmat4< DT > scaling3D(const Tvec3< DT > &scaleVector)
Scaling 3D.
Definition mlMatrix4.h:656
Tmat4< DT > perspective3D(const DT d)
Creates a 4x4 homogeneous perspective projection matrix with perspective shortening value given by d ...
Definition mlMatrix4.h:667
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Returns true if yes.
Definition mlMatrix2.h:399
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 ? Returns true if yes.
Definition mlMatrix2.h:405
Tmat4< DT > identity3D()
Returns a 4x4 homogeneous identity3D matrix; synonym for Tmat4<DT>::getIdentity().
Definition mlMatrix4.h:617
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:627
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.
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:637
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.