MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlMatrix6.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_MATRIX6_H
14#define ML_MATRIX6_H
15
17
18// Include system independent file and project settings.
19#include "mlErrorMacros.h"
21#include "mlLinearAlgebraDefs.h"
22
23
25
26#include "mlVector6.h"
27#include <mlErrorOutput.h>
28
29// All declarations of this header will be in the ML_LINEAR_ALGEBRA namespace.
31
32//--------------------------------------------------------------------
34//--------------------------------------------------------------------
35template <class DT> class Tmat6 : public FloatingPointMatrix<Tvec6<DT>, 6>
36{
37public:
39 typedef DT ComponentType;
40
43
45 Tmat6(const DT diagValue);
46
47 // Builds a matrix of the six row vectors row0, ..., row5.
48 Tmat6(const Tvec6<DT>& row0, const Tvec6<DT>& row1, const Tvec6<DT>& row2, const Tvec6<DT>& row3,
49 const Tvec6<DT>& row4, const Tvec6<DT>& row5);
50
52 Tmat6(const Tmat6<DT>& m);
53
55 Tmat6(const float mat[36]);
56
58 Tmat6(const double mat[36]);
59
62 Tmat6(const double in00, const double in01, const double in02, const double in03, const double in04,
63 const double in05, const double in10, const double in11, const double in12, const double in13,
64 const double in14, const double in15, const double in20, const double in21, const double in22,
65 const double in23, const double in24, const double in25, const double in30, const double in31,
66 const double in32, const double in33, const double in34, const double in35, const double in40,
67 const double in41, const double in42, const double in43, const double in44, const double in45,
68 const double in50, const double in51, const double in52, const double in53, const double in54,
69 const double in55);
70
73 void setValues(const float m[36]);
74
79 void getValues(float m[36]) const;
80
83 void setValues(const double m[36]);
84
87 void getValues(double m[36]) const;
88
90 void setScaleMatrix(const DT scale);
91
93 static Tmat6<DT> getMat(const double val);
94
96 void set(const DT val);
97
100 bool operator<(const Tmat6<DT>&) const
101 {
102 return false;
103 }
104
107
110
113
115 const Tmat6<DT>& operator*=(const DT d);
116
119 const Tmat6<DT>& operator/=(const DT d);
120
121 //-------------------------------------------------
122 // Special functions
123 //-------------------------------------------------
125 DT determinantLower5(const int col1, const int col2, const int col3, const int col4, const int col5) const;
126
128 DT det() const;
129
137 Tmat6<DT> inverse(bool* isInvertible = nullptr) const;
138
141
144
147
148}; // end of class *Tmat6*
149
150
151//---------------------------------------------------------------------
154//---------------------------------------------------------------------
156template <class DT> inline Tmat6<DT>::Tmat6()
157{
158 this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = this->v[5] = Tvec6<DT>(0);
159}
160
162template <class DT> inline Tmat6<DT>::Tmat6(const DT diagValue)
163{
164 this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] = this->v[4][4] = this->v[5][5] = diagValue;
165 this->v[1][0] = this->v[2][0] = this->v[3][0] = this->v[4][0] = this->v[5][0] = this->v[2][1] = this->v[3][1] =
166 this->v[4][1] = this->v[5][1] = this->v[3][2] = this->v[4][2] = this->v[5][2] = this->v[4][3] = this->v[5][3] =
167 this->v[5][4] = 0;
168 this->v[0][1] = this->v[0][2] = this->v[0][3] = this->v[0][4] = this->v[0][5] = this->v[1][2] = this->v[1][3] =
169 this->v[1][4] = this->v[1][5] = this->v[2][3] = this->v[2][4] = this->v[2][5] = this->v[3][4] = this->v[3][5] =
170 this->v[4][5] = 0;
171}
172
174template <class DT> inline Tmat6<DT>::Tmat6(const Tvec6<DT>& row0, const Tvec6<DT>& row1, const Tvec6<DT>& row2,
175 const Tvec6<DT>& row3, const Tvec6<DT>& row4, const Tvec6<DT>& row5)
176{
177 this->v[0] = row0;
178 this->v[1] = row1;
179 this->v[2] = row2;
180 this->v[3] = row3;
181 this->v[4] = row4;
182 this->v[5] = row5;
183}
184
186template <class DT> inline Tmat6<DT>::Tmat6(const Tmat6<DT>& mat)
187{
188 this->v[0] = mat.v[0];
189 this->v[1] = mat.v[1];
190 this->v[2] = mat.v[2];
191 this->v[3] = mat.v[3];
192 this->v[4] = mat.v[4];
193 this->v[5] = mat.v[5];
194}
195
197template <class DT> inline Tmat6<DT>::Tmat6(const float mat[36])
198{
199 setValues(mat);
200}
201
203template <class DT> inline Tmat6<DT>::Tmat6(const double mat[36])
204{
205 setValues(mat);
206}
207
209template <class DT> inline Tmat6<DT> Tmat6<DT>::getMat(const double val)
210{
211 return Tmat6<DT>(val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val,
212 val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val);
213}
214
216template <class DT> inline void Tmat6<DT>::set(DT val)
217{
218 this->v[0] = this->v[1] = this->v[2] = this->v[3] = this->v[4] = this->v[5] = Tvec6<DT>(val);
219}
220
222template <class DT> inline const Tmat6<DT>& Tmat6<DT>::operator=(const Tmat6<DT>& m)
223{
224 if (&m != this) {
225 this->v[0] = m.v[0];
226 this->v[1] = m.v[1];
227 this->v[2] = m.v[2];
228 this->v[3] = m.v[3];
229 this->v[4] = m.v[4];
230 this->v[5] = m.v[5];
231 }
232
233 return *this;
234}
235
237template <class DT> inline const Tmat6<DT>& Tmat6<DT>::operator+=(const Tmat6<DT>& m)
238{
239 this->v[0] += m.v[0];
240 this->v[1] += m.v[1];
241 this->v[2] += m.v[2];
242 this->v[3] += m.v[3];
243 this->v[4] += m.v[4];
244 this->v[5] += m.v[5];
245
246 return *this;
247}
248
250template <class DT> inline const Tmat6<DT>& Tmat6<DT>::operator-=(const Tmat6<DT>& m)
251{
252 this->v[0] -= m.v[0];
253 this->v[1] -= m.v[1];
254 this->v[2] -= m.v[2];
255 this->v[3] -= m.v[3];
256 this->v[4] -= m.v[4];
257 this->v[5] -= m.v[5];
258
259 return *this;
260}
261
263template <class DT> inline const Tmat6<DT>& Tmat6<DT>::operator*=(const DT d)
264{
265 this->v[0] *= d;
266 this->v[1] *= d;
267 this->v[2] *= d;
268 this->v[3] *= d;
269 this->v[4] *= d;
270 this->v[5] *= d;
271
272 return *this;
273}
274
276template <class DT> inline const Tmat6<DT>& Tmat6<DT>::operator/=(const DT d)
277{
278 if (MLValueIs0WOM(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 this->v[5] /= d;
287 return *this;
288}
289
290
291//--------------------------------------------------------------------
294//--------------------------------------------------------------------
296template <class DT> inline Tmat6<DT> operator-(const Tmat6<DT>& a)
297{
298 return Tmat6<DT>(a) *= static_cast<DT>(-1.0);
299}
300
302template <class DT> inline Tmat6<DT> operator+(const Tmat6<DT>& a, const Tmat6<DT>& b)
303{
304 return Tmat6<DT>(a) += b;
305}
306
308template <class DT> inline Tmat6<DT> operator-(const Tmat6<DT>& a, const Tmat6<DT>& b)
309{
310 return Tmat6<DT>(a) -= b;
311}
312
314template <class DT> inline Tmat6<DT> operator*(const Tmat6<DT>& a, const DT d)
315{
316 return Tmat6<DT>(a) *= d;
317}
318
320template <class DT> inline Tmat6<DT> operator*(const DT d, const Tmat6<DT>& a)
321{
322 return Tmat6<DT>(a) *= d;
323}
324
327template <class DT> inline Tmat6<DT> operator/(const Tmat6<DT>& a, const DT d)
328{
331 divided /= d;
332 return divided;
333}
335
336//-------------------------------------------------------------------
337//
340//
341//-------------------------------------------------------------------
342
343//-------------------------------------------------------------------
346//-------------------------------------------------------------------
347template <class DT> Tmat6<DT>::Tmat6(const double in00, const double in01, const double in02, const double in03,
348 const double in04, const double in05, const double in10, const double in11,
349 const double in12, const double in13, const double in14, const double in15,
350 const double in20, const double in21, const double in22, const double in23,
351 const double in24, const double in25, const double in30, const double in31,
352 const double in32, const double in33, const double in34, const double in35,
353 const double in40, const double in41, const double in42, const double in43,
354 const double in44, const double in45, const double in50, const double in51,
355 const double in52, const double in53, const double in54, const double in55)
356{
357 this->v[0][0] = static_cast<DT>(in00);
358 this->v[0][1] = static_cast<DT>(in01);
359 this->v[0][2] = static_cast<DT>(in02);
360 this->v[0][3] = static_cast<DT>(in03);
361 this->v[0][4] = static_cast<DT>(in04);
362 this->v[0][5] = static_cast<DT>(in05);
363 this->v[1][0] = static_cast<DT>(in10);
364 this->v[1][1] = static_cast<DT>(in11);
365 this->v[1][2] = static_cast<DT>(in12);
366 this->v[1][3] = static_cast<DT>(in13);
367 this->v[1][4] = static_cast<DT>(in14);
368 this->v[1][5] = static_cast<DT>(in15);
369 this->v[2][0] = static_cast<DT>(in20);
370 this->v[2][1] = static_cast<DT>(in21);
371 this->v[2][2] = static_cast<DT>(in22);
372 this->v[2][3] = static_cast<DT>(in23);
373 this->v[2][4] = static_cast<DT>(in24);
374 this->v[2][5] = static_cast<DT>(in25);
375 this->v[3][0] = static_cast<DT>(in30);
376 this->v[3][1] = static_cast<DT>(in31);
377 this->v[3][2] = static_cast<DT>(in32);
378 this->v[3][3] = static_cast<DT>(in33);
379 this->v[3][4] = static_cast<DT>(in34);
380 this->v[3][5] = static_cast<DT>(in35);
381 this->v[4][0] = static_cast<DT>(in40);
382 this->v[4][1] = static_cast<DT>(in41);
383 this->v[4][2] = static_cast<DT>(in42);
384 this->v[4][3] = static_cast<DT>(in43);
385 this->v[4][4] = static_cast<DT>(in44);
386 this->v[4][5] = static_cast<DT>(in45);
387 this->v[5][0] = static_cast<DT>(in50);
388 this->v[5][1] = static_cast<DT>(in51);
389 this->v[5][2] = static_cast<DT>(in52);
390 this->v[5][3] = static_cast<DT>(in53);
391 this->v[5][4] = static_cast<DT>(in54);
392 this->v[5][5] = static_cast<DT>(in55);
393}
394
395
396//--------------------------------------------------------------------
399//--------------------------------------------------------------------
400template <class DT> void Tmat6<DT>::setValues(const float m[36])
401{
402 this->v[0][0] = static_cast<DT>(m[0]);
403 this->v[0][1] = static_cast<DT>(m[1]);
404 this->v[0][2] = static_cast<DT>(m[2]);
405 this->v[0][3] = static_cast<DT>(m[3]);
406 this->v[0][4] = static_cast<DT>(m[4]);
407 this->v[0][5] = static_cast<DT>(m[5]);
408 this->v[1][0] = static_cast<DT>(m[6]);
409 this->v[1][1] = static_cast<DT>(m[7]);
410 this->v[1][2] = static_cast<DT>(m[8]);
411 this->v[1][3] = static_cast<DT>(m[9]);
412 this->v[1][4] = static_cast<DT>(m[10]);
413 this->v[1][5] = static_cast<DT>(m[11]);
414 this->v[2][0] = static_cast<DT>(m[12]);
415 this->v[2][1] = static_cast<DT>(m[13]);
416 this->v[2][2] = static_cast<DT>(m[14]);
417 this->v[2][3] = static_cast<DT>(m[15]);
418 this->v[2][4] = static_cast<DT>(m[16]);
419 this->v[2][5] = static_cast<DT>(m[17]);
420 this->v[3][0] = static_cast<DT>(m[18]);
421 this->v[3][1] = static_cast<DT>(m[19]);
422 this->v[3][2] = static_cast<DT>(m[20]);
423 this->v[3][3] = static_cast<DT>(m[21]);
424 this->v[3][4] = static_cast<DT>(m[22]);
425 this->v[3][5] = static_cast<DT>(m[23]);
426 this->v[4][0] = static_cast<DT>(m[24]);
427 this->v[4][1] = static_cast<DT>(m[25]);
428 this->v[4][2] = static_cast<DT>(m[26]);
429 this->v[4][3] = static_cast<DT>(m[27]);
430 this->v[4][4] = static_cast<DT>(m[28]);
431 this->v[4][5] = static_cast<DT>(m[29]);
432 this->v[5][0] = static_cast<DT>(m[30]);
433 this->v[5][1] = static_cast<DT>(m[31]);
434 this->v[5][2] = static_cast<DT>(m[32]);
435 this->v[5][3] = static_cast<DT>(m[33]);
436 this->v[5][4] = static_cast<DT>(m[34]);
437 this->v[5][5] = static_cast<DT>(m[35]);
438}
439
440//--------------------------------------------------------------------
445//--------------------------------------------------------------------
446template <class DT> void Tmat6<DT>::getValues(float m[36]) const
447{
448 m[0] = static_cast<float>(this->v[0][0]);
449 m[1] = static_cast<float>(this->v[0][1]);
450 m[2] = static_cast<float>(this->v[0][2]);
451 m[3] = static_cast<float>(this->v[0][3]);
452 m[4] = static_cast<float>(this->v[0][4]);
453 m[5] = static_cast<float>(this->v[0][5]);
454 m[6] = static_cast<float>(this->v[1][0]);
455 m[7] = static_cast<float>(this->v[1][1]);
456 m[8] = static_cast<float>(this->v[1][2]);
457 m[9] = static_cast<float>(this->v[1][3]);
458 m[10] = static_cast<float>(this->v[1][4]);
459 m[11] = static_cast<float>(this->v[1][5]);
460 m[12] = static_cast<float>(this->v[2][0]);
461 m[13] = static_cast<float>(this->v[2][1]);
462 m[14] = static_cast<float>(this->v[2][2]);
463 m[15] = static_cast<float>(this->v[2][3]);
464 m[16] = static_cast<float>(this->v[2][4]);
465 m[17] = static_cast<float>(this->v[2][5]);
466 m[18] = static_cast<float>(this->v[3][0]);
467 m[19] = static_cast<float>(this->v[3][1]);
468 m[20] = static_cast<float>(this->v[3][2]);
469 m[21] = static_cast<float>(this->v[3][3]);
470 m[22] = static_cast<float>(this->v[3][4]);
471 m[23] = static_cast<float>(this->v[3][5]);
472 m[24] = static_cast<float>(this->v[4][0]);
473 m[25] = static_cast<float>(this->v[4][1]);
474 m[26] = static_cast<float>(this->v[4][2]);
475 m[27] = static_cast<float>(this->v[4][3]);
476 m[28] = static_cast<float>(this->v[4][4]);
477 m[29] = static_cast<float>(this->v[4][5]);
478 m[30] = static_cast<float>(this->v[5][0]);
479 m[31] = static_cast<float>(this->v[5][1]);
480 m[32] = static_cast<float>(this->v[5][2]);
481 m[33] = static_cast<float>(this->v[5][3]);
482 m[34] = static_cast<float>(this->v[5][4]);
483 m[35] = static_cast<float>(this->v[5][5]);
484}
485
486//--------------------------------------------------------------------
489//--------------------------------------------------------------------
490template <class DT> void Tmat6<DT>::setValues(const double m[36])
491{
492 this->v[0][0] = static_cast<DT>(m[0]);
493 this->v[0][1] = static_cast<DT>(m[1]);
494 this->v[0][2] = static_cast<DT>(m[2]);
495 this->v[0][3] = static_cast<DT>(m[3]);
496 this->v[0][4] = static_cast<DT>(m[4]);
497 this->v[0][5] = static_cast<DT>(m[5]);
498 this->v[1][0] = static_cast<DT>(m[6]);
499 this->v[1][1] = static_cast<DT>(m[7]);
500 this->v[1][2] = static_cast<DT>(m[8]);
501 this->v[1][3] = static_cast<DT>(m[9]);
502 this->v[1][4] = static_cast<DT>(m[10]);
503 this->v[1][5] = static_cast<DT>(m[11]);
504 this->v[2][0] = static_cast<DT>(m[12]);
505 this->v[2][1] = static_cast<DT>(m[13]);
506 this->v[2][2] = static_cast<DT>(m[14]);
507 this->v[2][3] = static_cast<DT>(m[15]);
508 this->v[2][4] = static_cast<DT>(m[16]);
509 this->v[2][5] = static_cast<DT>(m[17]);
510 this->v[3][0] = static_cast<DT>(m[18]);
511 this->v[3][1] = static_cast<DT>(m[19]);
512 this->v[3][2] = static_cast<DT>(m[20]);
513 this->v[3][3] = static_cast<DT>(m[21]);
514 this->v[3][4] = static_cast<DT>(m[22]);
515 this->v[3][5] = static_cast<DT>(m[23]);
516 this->v[4][0] = static_cast<DT>(m[24]);
517 this->v[4][1] = static_cast<DT>(m[25]);
518 this->v[4][2] = static_cast<DT>(m[26]);
519 this->v[4][3] = static_cast<DT>(m[27]);
520 this->v[4][4] = static_cast<DT>(m[28]);
521 this->v[4][5] = static_cast<DT>(m[29]);
522 this->v[5][0] = static_cast<DT>(m[30]);
523 this->v[5][1] = static_cast<DT>(m[31]);
524 this->v[5][2] = static_cast<DT>(m[32]);
525 this->v[5][3] = static_cast<DT>(m[33]);
526 this->v[5][4] = static_cast<DT>(m[34]);
527 this->v[5][5] = static_cast<DT>(m[35]);
528}
529
530//--------------------------------------------------------------------
533//--------------------------------------------------------------------
534template <class DT> void Tmat6<DT>::getValues(double m[36]) const
535{
536 m[0] = static_cast<double>(this->v[0][0]);
537 m[1] = static_cast<double>(this->v[0][1]);
538 m[2] = static_cast<double>(this->v[0][2]);
539 m[3] = static_cast<double>(this->v[0][3]);
540 m[4] = static_cast<double>(this->v[0][4]);
541 m[5] = static_cast<double>(this->v[0][5]);
542 m[6] = static_cast<double>(this->v[1][0]);
543 m[7] = static_cast<double>(this->v[1][1]);
544 m[8] = static_cast<double>(this->v[1][2]);
545 m[9] = static_cast<double>(this->v[1][3]);
546 m[10] = static_cast<double>(this->v[1][4]);
547 m[11] = static_cast<double>(this->v[1][5]);
548 m[12] = static_cast<double>(this->v[2][0]);
549 m[13] = static_cast<double>(this->v[2][1]);
550 m[14] = static_cast<double>(this->v[2][2]);
551 m[15] = static_cast<double>(this->v[2][3]);
552 m[16] = static_cast<double>(this->v[2][4]);
553 m[17] = static_cast<double>(this->v[2][5]);
554 m[18] = static_cast<double>(this->v[3][0]);
555 m[19] = static_cast<double>(this->v[3][1]);
556 m[20] = static_cast<double>(this->v[3][2]);
557 m[21] = static_cast<double>(this->v[3][3]);
558 m[22] = static_cast<double>(this->v[3][4]);
559 m[23] = static_cast<double>(this->v[3][5]);
560 m[24] = static_cast<double>(this->v[4][0]);
561 m[25] = static_cast<double>(this->v[4][1]);
562 m[26] = static_cast<double>(this->v[4][2]);
563 m[27] = static_cast<double>(this->v[4][3]);
564 m[28] = static_cast<double>(this->v[4][4]);
565 m[29] = static_cast<double>(this->v[4][5]);
566 m[30] = static_cast<double>(this->v[5][0]);
567 m[31] = static_cast<double>(this->v[5][1]);
568 m[32] = static_cast<double>(this->v[5][2]);
569 m[33] = static_cast<double>(this->v[5][3]);
570 m[34] = static_cast<double>(this->v[5][4]);
571 m[35] = static_cast<double>(this->v[5][5]);
572}
573
574
575//-------------------------------------------------------------------
577//-------------------------------------------------------------------
578template <class DT> void Tmat6<DT>::setScaleMatrix(const DT scale)
579{
580 this->v[0][0] = scale;
581 this->v[0][1] = 0;
582 this->v[0][2] = 0;
583 this->v[0][3] = 0;
584 this->v[0][4] = 0;
585 this->v[0][5] = 0;
586 this->v[1][0] = 0;
587 this->v[1][1] = scale;
588 this->v[1][2] = 0;
589 this->v[1][3] = 0;
590 this->v[1][4] = 0;
591 this->v[1][5] = 0;
592 this->v[2][0] = 0;
593 this->v[2][1] = 0;
594 this->v[2][2] = scale;
595 this->v[2][3] = 0;
596 this->v[2][4] = 0;
597 this->v[2][5] = 0;
598 this->v[3][0] = 0;
599 this->v[3][1] = 0;
600 this->v[3][2] = 0;
601 this->v[3][3] = scale;
602 this->v[3][4] = 0;
603 this->v[3][5] = 0;
604 this->v[4][0] = 0;
605 this->v[4][1] = 0;
606 this->v[4][2] = 0;
607 this->v[4][3] = 0;
608 this->v[4][4] = scale;
609 this->v[4][5] = 0;
610 this->v[5][0] = 0;
611 this->v[5][1] = 0;
612 this->v[5][2] = 0;
613 this->v[5][3] = 0;
614 this->v[5][4] = 0;
615 this->v[5][5] = scale;
616}
618
619//-------------------------------------------------------------------
622//-------------------------------------------------------------------
623
624//--------------------------------------------------------------------
626//--------------------------------------------------------------------
627template <class DT>
628DT Tmat6<DT>::determinantLower5(const int col1, const int col2, const int col3, const int col4, const int col5) const
629{
630 /* Determinant of 5x5 matrix with given entries */
631 return Tmat5<DT>(this->v[1][col1], this->v[1][col2], this->v[1][col3], this->v[1][col4], this->v[1][col5],
632 this->v[2][col1], this->v[2][col2], this->v[2][col3], this->v[2][col4], this->v[2][col5],
633 this->v[3][col1], this->v[3][col2], this->v[3][col3], this->v[3][col4], this->v[3][col5],
634 this->v[4][col1], this->v[4][col2], this->v[4][col3], this->v[4][col4], this->v[4][col5],
635 this->v[5][col1], this->v[5][col2], this->v[5][col3], this->v[5][col4], this->v[5][col5])
636 .det();
637}
638
639//--------------------------------------------------------------------
641//--------------------------------------------------------------------
642template <class DT> DT Tmat6<DT>::det() const
643{
644 return (this->v[0][0] * determinantLower5(1, 2, 3, 4, 5) - this->v[0][1] * determinantLower5(0, 2, 3, 4, 5) +
645 this->v[0][2] * determinantLower5(0, 1, 3, 4, 5) - this->v[0][3] * determinantLower5(0, 1, 2, 4, 5) +
646 this->v[0][4] * determinantLower5(0, 1, 2, 3, 5) - this->v[0][5] * determinantLower5(0, 1, 2, 3, 4));
647}
648
649//--------------------------------------------------------------------
657//--------------------------------------------------------------------
658template <class DT> Tmat6<DT> Tmat6<DT>::inverse(bool* isInvertible) const
659{
660 // Epsilon for comparison with 0 in inversion process.
661 static const DT Epsilon = static_cast<DT>(10e-12);
662
663 // Use helper function from tools to invert the matrix.
665 "Tmat6<DT> Tmat6<DT>::inverse(bool* isInvertible) const, matrix not invertable",
666 getIdentity(), 6);
667}
668
669
670//-------------------------------------------------------------------
672//-------------------------------------------------------------------
673template <class DT> Tmat6<DT> Tmat6<DT>::transpose() const
674{
675 return Tmat6<DT>(Tvec6<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0], this->v[4][0], this->v[5][0]),
676 Tvec6<DT>(this->v[0][1], this->v[1][1], this->v[2][1], this->v[3][1], this->v[4][1], this->v[5][1]),
677 Tvec6<DT>(this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2], this->v[4][2], this->v[5][2]),
678 Tvec6<DT>(this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3], this->v[4][3], this->v[5][3]),
679 Tvec6<DT>(this->v[0][4], this->v[1][4], this->v[2][4], this->v[3][4], this->v[4][4], this->v[5][4]),
680 Tvec6<DT>(this->v[0][5], this->v[1][5], this->v[2][5], this->v[3][5], this->v[4][5], this->v[5][5]));
681}
682
683//-------------------------------------------------------------------
685//-------------------------------------------------------------------
687{
688 return Tmat6<DT>(Tvec6<DT>(1, 0, 0, 0, 0, 0), Tvec6<DT>(0, 1, 0, 0, 0, 0), Tvec6<DT>(0, 0, 1, 0, 0, 0),
689 Tvec6<DT>(0, 0, 0, 1, 0, 0), Tvec6<DT>(0, 0, 0, 0, 1, 0), Tvec6<DT>(0, 0, 0, 0, 0, 1));
690}
691
692//-------------------------------------------------------------------
694//-------------------------------------------------------------------
695template <class DT> const Tmat6<DT>& Tmat6<DT>::apply(MLDblFuncPtr fct)
696{
697 this->v[0].apply(fct);
698 this->v[1].apply(fct);
699 this->v[2].apply(fct);
700 this->v[3].apply(fct);
701 this->v[4].apply(fct);
702 this->v[5].apply(fct);
703 return *this;
704}
705
706
708#define _ML_MAT6_RC(i, j) \
709 a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j] + a[i][3] * b[3][j] + a[i][4] * b[4][j] + a[i][5] * b[5][j]
710//-------------------------------------------------------------------
712//-------------------------------------------------------------------
713template <class DT> Tmat6<DT> operator*(const Tmat6<DT>& a, const Tmat6<DT>& b)
714{
715 return Tmat6<DT>(Tvec6<DT>(_ML_MAT6_RC(0, 0), _ML_MAT6_RC(0, 1), _ML_MAT6_RC(0, 2), _ML_MAT6_RC(0, 3),
716 _ML_MAT6_RC(0, 4), _ML_MAT6_RC(0, 5)),
717 Tvec6<DT>(_ML_MAT6_RC(1, 0), _ML_MAT6_RC(1, 1), _ML_MAT6_RC(1, 2), _ML_MAT6_RC(1, 3),
718 _ML_MAT6_RC(1, 4), _ML_MAT6_RC(1, 5)),
719 Tvec6<DT>(_ML_MAT6_RC(2, 0), _ML_MAT6_RC(2, 1), _ML_MAT6_RC(2, 2), _ML_MAT6_RC(2, 3),
720 _ML_MAT6_RC(2, 4), _ML_MAT6_RC(2, 5)),
721 Tvec6<DT>(_ML_MAT6_RC(3, 0), _ML_MAT6_RC(3, 1), _ML_MAT6_RC(3, 2), _ML_MAT6_RC(3, 3),
722 _ML_MAT6_RC(3, 4), _ML_MAT6_RC(3, 5)),
723 Tvec6<DT>(_ML_MAT6_RC(4, 0), _ML_MAT6_RC(4, 1), _ML_MAT6_RC(4, 2), _ML_MAT6_RC(4, 3),
724 _ML_MAT6_RC(4, 4), _ML_MAT6_RC(4, 5)),
725 Tvec6<DT>(_ML_MAT6_RC(5, 0), _ML_MAT6_RC(5, 1), _ML_MAT6_RC(5, 2), _ML_MAT6_RC(5, 3),
726 _ML_MAT6_RC(5, 4), _ML_MAT6_RC(5, 5)));
727}
728#undef _ML_MAT6_RC
729
730//-------------------------------------------------------------------
732//-------------------------------------------------------------------
733template <class DT> bool operator==(const Tmat6<DT>& a, const Tmat6<DT>& b)
734{
735 return (a[0] == b[0]) && (a[1] == b[1]) && (a[2] == b[2]) && (a[3] == b[3]) && (a[4] == b[4]) && (a[5] == b[5]);
736}
737
738//-------------------------------------------------------------------
740//-------------------------------------------------------------------
741template <class DT> bool operator!=(const Tmat6<DT>& a, const Tmat6<DT>& b)
742{
743 return !(a == b);
744}
745
747#define _ML_MAT6_RC(i) \
748 a[i][0] * v[0] + a[i][1] * v[1] + a[i][2] * v[2] + a[i][3] * v[3] + a[i][4] * v[4] + a[i][5] * v[5]
749//-----------------------------------------------------------------------------------
751//-----------------------------------------------------------------------------------
752template <class DT> inline Tvec6<DT> operator*(const Tmat6<DT>& a, const Tvec6<DT>& v)
753{
755}
756#undef _ML_MAT6_RC
757
758//-----------------------------------------------------------------------------------
760//-----------------------------------------------------------------------------------
761template <class DT> inline Tvec6<DT> operator*(const Tvec6<DT>& v, const Tmat6<DT>& a)
762{
763 return a.transpose() * v;
764}
766
767
768//-----------------------------------------------------------------------------------
771//-----------------------------------------------------------------------------------
772
782
783
785
786namespace std
787{
788 //-------------------------------------------------------------------
790 //-------------------------------------------------------------------
791 template <class DT> inline std::ostream& operator<<(std::ostream& os, const ML_LA_NAMESPACE::Tmat6<DT>& m)
792 {
793 return os << m[0] << '\n' << m[1] << '\n' << m[2] << '\n' << m[3] << '\n' << m[4] << '\n' << m[5];
794 }
795
796 //-------------------------------------------------------------------
798 //-------------------------------------------------------------------
799 template <class DT> inline std::istream& operator>>(std::istream& is, ML_LA_NAMESPACE::Tmat6<DT>& m)
800 {
801 ML_LA_NAMESPACE::Tmat6<DT> m_tmp;
802
803 is >> m_tmp[0] >> m_tmp[1] >> m_tmp[2] >> m_tmp[3] >> m_tmp[4] >> m_tmp[5];
804 if (is) {
805 m = m_tmp;
806 }
807 return is;
808 }
809} // namespace std
810
811
812#endif // __mlMatrix6_H
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 6x6 matrix class of six row vectors.
Definition mlMatrix6.h:36
Tmat6()
Builds a 6x6 matrix from 36 zero elements.
Definition mlMatrix6.h:156
Tmat6 transpose() const
Returns the transposed of this matrix.
Definition mlMatrix6.h:673
const Tmat6< DT > & operator*=(const DT d)
Multiplies by a scalar constant d.
Definition mlMatrix6.h:263
void setValues(const float m[36])
Copies the contents from float array m into *this.
Definition mlMatrix6.h:400
const Tmat6< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to each component.
Definition mlMatrix6.h:695
static Tmat6< DT > getMat(const double val)
Returns a matrix filled with values val.
Definition mlMatrix6.h:209
Tmat6(const double in00, const double in01, const double in02, const double in03, const double in04, const double in05, const double in10, const double in11, const double in12, const double in13, const double in14, const double in15, const double in20, const double in21, const double in22, const double in23, const double in24, const double in25, const double in30, const double in31, const double in32, const double in33, const double in34, const double in35, const double in40, const double in41, const double in42, const double in43, const double in44, const double in45, const double in50, const double in51, const double in52, const double in53, const double in54, const double in55)
Initializes all matrix elements explicitly with scalars, filling it row by row.
Definition mlMatrix6.h:347
Tmat6(const Tmat6< DT > &m)
Copy constructor from the Tmat6 mat.
Definition mlMatrix6.h:186
void set(const DT val)
Sets all values to val.
Definition mlMatrix6.h:216
void setScaleMatrix(const DT scale)
Sets the diagonal matrix with scale on the diagonal.
Definition mlMatrix6.h:578
bool operator<(const Tmat6< DT > &) const
Dummy 'lesser than operator' that always returns false.
Definition mlMatrix6.h:100
DT determinantLower5(const int col1, const int col2, const int col3, const int col4, const int col5) const
Determines the (sub)determinant of columns given by col1, col2, col3, col4, and col5.
Definition mlMatrix6.h:628
void getValues(float m[36]) const
Copies the contents of *this into float array m.
Definition mlMatrix6.h:446
DT det() const
Returns the determinant of this matrix.
Definition mlMatrix6.h:642
const Tmat6< DT > & operator+=(const Tmat6< DT > &m)
Adds component-wise with a Tmat6.
Definition mlMatrix6.h:237
Tmat6(const double mat[36])
Constructor from 36 doubles given as array mat, read row by row.
Definition mlMatrix6.h:203
Tmat6(const DT diagValue)
Builds a matrix that has the argument diagValue as the diagonal values, zero otherwise.
Definition mlMatrix6.h:162
void getValues(double m[36]) const
Copies the contents of *this into double array m.
Definition mlMatrix6.h:534
const Tmat6< DT > & operator-=(const Tmat6< DT > &m)
Subtracts component-wise by a Tmat6.
Definition mlMatrix6.h:250
Tmat6(const float mat[36])
Constructor from 36 floats given as array mat, read row by row.
Definition mlMatrix6.h:197
DT ComponentType
A typedef to 'export' the type of components.
Definition mlMatrix6.h:39
const Tmat6< DT > & operator=(const Tmat6< DT > &m)
Assigns from a Tmat6.
Definition mlMatrix6.h:222
const Tmat6< DT > & operator/=(const DT d)
Divides by a scalar constant d.
Definition mlMatrix6.h:276
static Tmat6 getIdentity()
Returns the identity matrix.
Definition mlMatrix6.h:686
void setValues(const double m[36])
Copies the contents from double array m into *this.
Definition mlMatrix6.h:490
Tmat6< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse.
Definition mlMatrix6.h:658
Tmat6(const Tvec6< DT > &row0, const Tvec6< DT > &row1, const Tvec6< DT > &row2, const Tvec6< DT > &row3, const Tvec6< DT > &row4, const Tvec6< DT > &row5)
Builds a matrix of the six row vectors row0, ..., row5.
Definition mlMatrix6.h:174
A six dimensional vector class for floating point types.
Definition mlVector6.h:45
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0; otherwise, it returns false.
#define ML_CHECK_THROW(x)
#define ML_CHECK_FLOAT_THROW(x)
#define _ML_MAT6_RC(i, j)
Internal helper macro to multiply two matrices, do not use.
Definition mlMatrix6.h:708
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.
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
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component-wise subtraction of rhs from lhs.
BASE_TYPE MLInverseMatHelper(const BASE_TYPE &origMat, bool *isInvertible, const typename BASE_TYPE::ComponentType, const char *const ZeroDetErrString, const BASE_TYPE &Identity, const size_t Dim)
Computes an N dimensional inverse from given default parameters.
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
istream & operator>>(istream &is, ml::FloatingPointVector< T, size, DataContainer > &v)
Reads a vector from std::istream.