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.
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>
35class Tmat4 : public FloatingPointMatrix<Tvec4<DT>, 4>
36{
37public:
38
40 typedef DT ComponentType;
41
42 //---------------------------------------------------------------
43 // Constructors, set and get methods.
44 //---------------------------------------------------------------
45 // Construct matrix from 16 zero elements.
47
48 // Builds a matrix that has the argument at the diagonal values, zero otherwise
49 Tmat4(const DT diagValue);
50
51 // Composes a matrix from the four row vectors row0, row1, row2 and row3.
52 Tmat4(const Tvec4<DT> &row0, const Tvec4<DT> &row1, const Tvec4<DT> &row2, const Tvec4<DT> &row3);
53
54 // Copy constructor from the Tmat4 mat.
56
57 // Constructor from 16 floating point values in an array given by mat, row by row.
58 Tmat4(const float mat[16]);
59
60 // Constructor from 16 double values in an array given by mat, row by row.
61 Tmat4(const double mat[16]);
62
63 // Initializes all matrix elements explicitly with scalars,
64 // filling it row by row.
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
70 // Constructs a matrix from three base vectors n0, ... n3 and a translation t,
71 // all given as COLUMN vectors.
72 Tmat4(const Tvec3<DT> &n0, const Tvec3<DT> &n1, const Tvec3<DT> &n3, const Tvec3<DT> &t);
73
74 // Copies the contents from float array mat into *this, row by row.
75 void setValues(const float mat[16]);
76
77 // Copies the contents of *this into floating point matrix mat, row by row.
78 // Note that range and precision of the float values may not be
79 // sufficient for double or long double matrix contents.
80 void getValues(float mat[16]) const;
81
82 // Copies the contents from double array mat into *this, row by row.
83 void setValues(const double mat[16]);
84
85 // Copies the contents of *this into into double matrix mat, row by row.
86 // Note that range and precision of the double values may not be
87 // sufficient for long double matrix contents.
88 void getValues(double mat[16]) const;
89
90 // Sets a diagonal matrix with scale on diagonal.
91 void setScaleMatrix(const DT scale);
92
95 {
96 return Tvec3<DT>( (*this) * sourceVec.affinePoint(), true);
97 }
98
101
102 //---------------------------------------------------------------
103 // Assignment operators and other simple stuff.
104 //---------------------------------------------------------------
105 // Returns a matrix filled with values val.
106 static Tmat4<DT> getMat(const double val);
107
108 // Sets all values to val.
109 void set(const DT val);
110
113 bool operator<(const Tmat4<DT> &) const { return false; }
114
115 // Assigns from a Tmat4.
117
118 // Increments by a Tmat4.
120
121 // Decrements by a Tmat4.
123
124
125 // Multiplies by a constant d.
126 const Tmat4<DT> &operator*=(const DT d);
127
128 // Divides by a constant d. Division by zero is not handled and must be avoided by caller.
129 const Tmat4<DT> &operator/=(const DT d);
130
131
132 //---------------------------------------------------------------
133 // Special functions
134 //---------------------------------------------------------------
135 // Determines the determinant of a 3x3 matrix given by A,B,C,D,E,F,G,H,I.
136 DT det3(DT A, DT B, DT C, DT D, DT E, DT F, DT G, DT H, DT I) const;
137
138 // Determines the (sub)determinant of columns given by col1, col2 and col3.
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
148 // Returns the determinant of this.
149 DT det() const;
150
151 // Returns the transposed *this.
153
154 // Returns the inverse. Gauss-Jordan elimination with partial pivoting.
155 // If a non-NULL Boolean pointer is passed to isInvertible
156 // then true is returned in *isInvertible in the case of a
157 // successful inversion or false if the inversion is not possible
158 // (function return is the identity then).
159 // If a NULL pointer is passed as isInvertible the matrix must
160 // be invertible, otherwise errors will occur.
161 Tmat4<DT> inverse(bool* isInvertible=nullptr) const;
162
163 // Returns the identity matrix.
165
166 // Applies the function fct to each component.
168
169}; // end of class *mat4*
170
171
172//---------------------------------------------------------------
175//---------------------------------------------------------------
176
178template <class DT>
180{
181 this->v[0] = this->v[1] = this->v[2] = this->v[3] = Tvec4<DT>(0);
182}
183
184// Constructs a matrix that has the argument at the diagonal values, zero otherwise
185template <class DT>
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
194template <class DT>
196{
197 this->v[0] = row0;
198 this->v[1] = row1;
199 this->v[2] = row2;
200 this->v[3] = row3;
201}
202
204template <class DT>
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
214template <class DT>
215inline Tmat4<DT>::Tmat4(const float mat[16])
216{
217 setValues(mat);
218}
219
221template <class DT>
222inline Tmat4<DT>::Tmat4(const double mat[16])
223{
224 setValues(mat);
225}
226
228template <class DT>
229inline 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
237template <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
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
264template <class DT>
265inline 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
271template <class DT>
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
284template <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
295template <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
306template <class DT>
307inline 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
317template <class DT>
318inline 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
328template <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] + \
345a[i][2]*b[2][j] + a[i][3]*b[3][j]
346
351template <class DT>
352inline Tmat4<DT> operator*(const Tmat4<DT> &a, const Tmat4<DT> &b)
353{
354 return Tmat4<DT>(
359 );
360}
361#undef _ML_MAT4_RC
362
363
365template <class DT>
366inline 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
375template <class DT>
376inline bool operator!=(const Tmat4<DT>& a, const Tmat4<DT>& b)
377{
378 return !(a == b);
379}
381
382
383//---------------------------------------------------------------
386//---------------------------------------------------------------
388template <class DT>
390{
391 return Tmat4<DT>(a) *= static_cast<DT>(-1.0);
392}
393
395template <class DT>
396inline Tmat4<DT> operator+(const Tmat4<DT> &a, const Tmat4<DT> &b)
397{
398 return Tmat4<DT>(a) += b;
399}
400
402template <class DT>
403inline Tmat4<DT> operator-(const Tmat4<DT> &a, const Tmat4<DT> &b)
404{
405 return Tmat4<DT>(a) -= b;
406}
407
409template <class DT>
410inline Tmat4<DT> operator*(const Tmat4<DT> &a, const DT d)
411{
412 return Tmat4<DT>(a) *= d;
413}
414
416template <class DT>
417inline Tmat4<DT> operator*(const DT d, const Tmat4<DT> &a)
418{
419 return Tmat4<DT>(a) *= d;
420}
421
424template <class DT>
425inline 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//--------------------------------------------------------------------
442template <class DT>
443inline 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//--------------------------------------------------------------------
470template <class DT>
471Tmat4<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//--------------------------------------------------------------------
485template <class DT>
486void 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//--------------------------------------------------------------------
499template <class DT>
500void 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//--------------------------------------------------------------------
511template <class DT>
512void 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//--------------------------------------------------------------------
525template <class DT>
526void 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//--------------------------------------------------------------------
537template <class DT>
538void 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//--------------------------------------------------------------------
549template <class DT>
550inline 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//--------------------------------------------------------------------
559template <class DT>
560inline 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//--------------------------------------------------------------------
571template <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//--------------------------------------------------------------------
583template <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//--------------------------------------------------------------------
596template <class DT>
601
602//--------------------------------------------------------------------
606//--------------------------------------------------------------------
607template <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//--------------------------------------------------------------------
620//-------------------------------------------------------------------
621template <class DT>
623{
624 const DT c = cos(angleRad);
625 const DT s = sin(angleRad);
626 const DT t = 1.0 - c;
627
628 Axis.normalize();
629 return Tmat4<DT>(Tvec4<DT>(t * Axis[0] * Axis[0] + c,
630 t * Axis[0] * Axis[1] - s * Axis[2],
631 t * Axis[0] * Axis[2] + s * Axis[1],
632 0.0),
633 Tvec4<DT>(t * Axis[0] * Axis[1] + s * Axis[2],
634 t * Axis[1] * Axis[1] + c,
635 t * Axis[1] * Axis[2] - s * Axis[0],
636 0.0),
637 Tvec4<DT>(t * Axis[0] * Axis[2] - s * Axis[1],
638 t * Axis[1] * Axis[2] + s * Axis[0],
639 t * Axis[2] * Axis[2] + c,
640 0.0),
641 Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
642}
643
644//--------------------------------------------------------------------
646//--------------------------------------------------------------------
647template <class DT>
649{
650 return Tmat4<DT>(Tvec4<DT>(scaleVector[0], 0.0, 0.0, 0.0),
651 Tvec4<DT>(0.0, scaleVector[1], 0.0, 0.0),
652 Tvec4<DT>(0.0, 0.0, scaleVector[2], 0.0),
653 Tvec4<DT>(0.0, 0.0, 0.0, 1.0));
654}
655
656//--------------------------------------------------------------------
660//--------------------------------------------------------------------
661template <class DT>
662inline Tmat4<DT> perspective3D(const DT d)
663{
666
667 retVal[0][0] = 1.0;
668 retVal[1][1] = 1.0;
669 retVal[2][2] = 1.0;
670 retVal[3][2] = 1.0/d;
671 retVal[3][3] = 1.0;
672 return retVal;
673}
674
675
676//--------------------------------------------------------------------
684//--------------------------------------------------------------------
685template <class DT>
687{
688 // Epsilon for comparison with 0 in inversion process.
689 static const DT Epsilon = static_cast<DT>(10e-14);
690
691 // Use helper function from tools to invert the matrix.
692 return MLInverseMatHelper(*this,
694 Epsilon,
695 "Tmat4<DT> Tmat4<DT>::inverse(bool* isInvertible) const, matrix not invertable",
696 getIdentity(),
697 4);
698}
700
701
702//-----------------------------------------------------------------------------------
705//-----------------------------------------------------------------------------------
706
716
717
719
720namespace std
721{
722 //-------------------------------------------------------------------
724 //-------------------------------------------------------------------
725 template <class DT>
726 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>
733 inline std::istream &operator>>(std::istream &is, ML_LA_NAMESPACE::Tmat4<DT> &m)
734 {
735 ML_LA_NAMESPACE::Tmat4<DT> m_tmp;
736 is >> m_tmp[0] >> m_tmp[1] >> m_tmp[2] >> m_tmp[3];
737 if (is){ m = m_tmp; }
738 return is;
739 }
741}
742
743#endif // __mlMatrix4_H
744
745
746
747
@ G
@ B
@ A
Letters.
@ H
@ C
@ D
@ E
@ I
@ F
A class to administrate an axis coordinate system drawable in OpenGL.
Definition Axis.h:22
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 four by four matrix class consisting of 4 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
Definition mlMatrix4.h:140
Tvec3< DT > transformPoint(const Tvec3< DT > &sourceVec) const
Transforms the given sourceVec and returns the result vector.
Definition mlMatrix4.h:94
void set(const DT val)
Sets all values to double val.
Definition mlMatrix4.h:265
Tmat4< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse Gauss-Jordan elimination with partial pivoting.
Definition mlMatrix4.h:686
Tmat4(const Tvec3< DT > &n0, const Tvec3< DT > &n1, const Tvec3< DT > &n3, const Tvec3< DT > &t)
Constructs a matrix from three base vectors and translation (as COLUMN vectors)
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 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
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 an MLdouble 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" which 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 of 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, 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 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 of mat into *this, row by row.
Definition mlMatrix4.h:486
const Tmat4< DT > & operator*=(const DT d)
Multiplies by an MLdouble constant d.
Definition mlMatrix4.h:307
Tmat4(const DT diagValue)
Definition mlMatrix4.h:186
const Tmat4< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to all vectors of *this and return the matrix.
Definition mlMatrix4.h:329
void getValues(double mat[16]) const
Copies the contents of *this into 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
Forward declarations to resolve header file dependencies.
Definition mlVector4.h:50
#define ML_CHECK_FLOAT_THROW(x)
#define _ML_MAT4_RC(i, j)
Helper macro only locally defined for Tmat4 matrix multiplication.
Definition mlMatrix4.h:344
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.
Tmat4< DT > scaling3D(const Tvec3< DT > &scaleVector)
Scaling 3D.
Definition mlMatrix4.h:648
Tmat4< DT > perspective3D(const DT d)
Creates a 4x4 homogeneous perspective projection matrix with perspective shortening value given by d ...
Definition mlMatrix4.h:662
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
Tmat4< DT > identity3D()
Returns a 4x4 homogeneous identity3D matrix; synonym for Tmat4<DT>::getIdentity().
Definition mlMatrix4.h:597
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
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:622
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.