MeVisLab Toolbox Reference
mlMatrix3.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_MATRIX3_H
14 #define ML_MATRIX3_H
15 
17 
18 // Include system independent file and project settings.
19 #include "mlLinearAlgebraSystem.h"
20 #include "mlLinearAlgebraDefs.h"
21 #include "mlLinearAlgebraTools.h"
22 
23 #include "mlFloatingPointMatrix.h"
24 
25 #include "mlMatrix2.h"
26 #include "mlVector3.h"
27 
28 #include <cstdlib>
29 // All declarations of this header will be in the ML_LA_NAMESPACE namespace.
30 ML_LA_START_NAMESPACE
31 
32 //--------------------------------------------------------------------
34 //--------------------------------------------------------------------
35 template <class DT>
36 class Tmat3 : public FloatingPointMatrix<Tvec3<DT>, 3>
37 {
38 
39 public:
40 
42  typedef DT ComponentType;
43 
44  // Builds a 3x3 matrix from 9 zero elements.
45  Tmat3();
46 
47  // Builds a matrix that has the argument at the diagonal values, zero otherwise
48  Tmat3(const DT diagValue);
49 
50  // Builds a matrix of the three row vectors row0, row1, row2.
51  Tmat3(const Tvec3<DT> &row0, const Tvec3<DT> &row1, const Tvec3<DT> &row2);
52 
53  // Copy constructor from the Tmat3 mat.
54  Tmat3(const Tmat3<DT> &mat);
55 
56  // Constructor from 9 floating point values in an array given by mat, row by row.
57  Tmat3(const float mat[9]);
58 
59  // Constructor from 9 double values in an array given by mat, row by row.
60  Tmat3(const double mat[9]);
61 
62  // Initializes all matrix elements explicitly with scalars,
63  // filling it row by row.
64  Tmat3(const double in00, const double in01, const double in02,
65  const double in10, const double in11, const double in12,
66  const double in20, const double in21, const double in22);
67 
68  // Copies the contents from float array mat into *this, row by row.
69  void setValues(const float mat[9]);
70 
71  // Copies the contents of *this into float array mat, row by row.
72  // Note that range and precision of the float values may not be
73  // sufficient for the double matrix contents.
74  void getValues(float mat[9]) const;
75 
76  // Copies the contents from double array mat into *this, row by row.
77  void setValues(const double mat[9]);
78 
79  // Copies the contents of *this into double array mat, row by row.
80  void getValues(double mat[9]) const;
81 
82  // Sets the diagonal matrix with scale on diagonal.
83  void setScaleMatrix(const DT scale);
84 
85  // Returns a matrix filled with values val.
86  static Tmat3<DT> getMat(const double val);
87 
88  // Sets all values to val.
89  void set(DT val);
90 
93  bool operator<(const Tmat3<DT> &) const { return false; }
94 
95  // Assigns from a Tmat3
96  const Tmat3<DT> &operator=(const Tmat3<DT> &m);
97 
98  // Increments by a Tmat3.
99  const Tmat3<DT> &operator+=(const Tmat3<DT> &m);
100 
101  // Decrements by a Tmat3
102  const Tmat3<DT> &operator-=(const Tmat3<DT> &m);
103 
104  // Multiplies by a scalar constant
105  const Tmat3<DT> &operator*=(const DT d);
106 
107  // Divides by a scalar constant.
108  // Division by zero is not handled and must be avoided by caller.
109  const Tmat3<DT> &operator/=(const DT d);
110 
111  //-------------------------------------------------
112  // Special functions
113  //-------------------------------------------------
114  // Returns the determinant of this matrix.
115  DT det() const;
116 
117  // Returns the transpose of this matrix.
118  Tmat3 transpose() const;
119 
120  // Returns the identity matrix.
121  static Tmat3 getIdentity();
122 
123  // Returns the inverse. Gauss-Jordan elimination with partial pivoting.
124  // If a non-NULL Boolean pointer is passed to isInvertible
125  // then true is returned in *isInvertible in the case of a
126  // successful inversion or false if the inversion is not possible
127  // (function return is the identity then).
128  // If a NULL pointer is passed as isInvertible the matrix must
129  // be invertible, otherwise errors will occur.
130  Tmat3 inverse(bool* isInvertible=nullptr) const;
131 
132  // Applies the function fct to each component.
134 
135  // Calculates the Jacobi-Decomposition of 3x3 matrix.
136  Tmat3 jacobi(Tvec3<DT> &eVal, int &rots) const;
137 
138 }; // end of class *Tmat3*
139 
140 
141 
142 //---------------------------------------------------------------------
145 //---------------------------------------------------------------------
147 template <class DT>
149 {
150  this->v[0] = this->v[1] = this->v[2] = Tvec3<DT>(0);
151 }
152 
153 // Constructs a matrix that has the argument at the diagonal values, zero otherwise
154 template <class DT>
155 inline Tmat3<DT>::Tmat3(const DT diagValue)
156 {
157  this->v[0][0] = this->v[1][1] = this->v[2][2] = diagValue;
158  this->v[1][0] = this->v[2][0] = this->v[2][1] = 0;
159  this->v[0][1] = this->v[0][2] = this->v[1][2] = 0;
160 }
161 
163 template <class DT>
164 inline Tmat3<DT>::Tmat3(const Tvec3<DT> &row0, const Tvec3<DT> &row1, const Tvec3<DT> &row2)
165 {
166  this->v[0] = row0;
167  this->v[1] = row1;
168  this->v[2] = row2;
169 }
170 
172 template <class DT>
173 inline Tmat3<DT>::Tmat3(const Tmat3<DT> &mat)
174 {
175  this->v[0] = mat.v[0];
176  this->v[1] = mat.v[1];
177  this->v[2] = mat.v[2];
178 }
179 
181 template <class DT>
182 inline Tmat3<DT>::Tmat3(const float mat[9])
183 {
184  setValues(mat);
185 }
186 
188 template <class DT>
189 inline Tmat3<DT>::Tmat3(const double mat[9])
190 {
191  setValues(mat);
192 }
193 
195 template <class DT>
196 inline Tmat3<DT> Tmat3<DT>::getMat(const double val)
197 {
198  return Tmat3<DT>(val, val, val,
199  val, val, val,
200  val, val, val);
201 }
202 
204 template <class DT>
205 inline void Tmat3<DT>::set(DT val)
206 {
207  this->v[0] = this->v[1] = this->v[2] = Tvec3<DT>(val);
208 }
209 
211 template <class DT>
212 inline const Tmat3<DT> &Tmat3<DT>::operator=(const Tmat3<DT> &m)
213 {
214  if (&m != this){
215  this->v[0] = m.v[0];
216  this->v[1] = m.v[1];
217  this->v[2] = m.v[2];
218  }
219 
220  return *this;
221 }
222 
224 template <class DT>
226 {
227  this->v[0] += m.v[0];
228  this->v[1] += m.v[1];
229  this->v[2] += m.v[2];
230 
231  return *this;
232 }
233 
235 template <class DT>
237 {
238  this->v[0] -= m.v[0];
239  this->v[1] -= m.v[1];
240  this->v[2] -= m.v[2];
241 
242  return *this;
243 }
244 
246 template <class DT>
247 inline const Tmat3<DT> &Tmat3<DT>::operator*=(const DT d)
248 {
249  this->v[0] *= d;
250  this->v[1] *= d;
251  this->v[2] *= d;
252 
253  return *this;
254 }
255 
257 template <class DT>
258 inline const Tmat3<DT> &Tmat3<DT>::operator/=(const DT d)
259 {
260  this->v[0] /= d;
261  this->v[1] /= d;
262  this->v[2] /= d;
263  return *this;
264 }
266 
267 
268 //====================================================================
271 //====================================================================
273 template <class DT>
274 inline Tmat3<DT> operator-(const Tmat3<DT> &a)
275 {
276  return Tmat3<DT>(a) *= static_cast<DT>(-1.0);
277 }
278 
280 template <class DT>
281 inline Tmat3<DT> operator+(const Tmat3<DT> &a, const Tmat3<DT> &b)
282 {
283  return Tmat3<DT>(a) += b;
284 }
285 
287 template <class DT>
288 inline Tmat3<DT> operator-(const Tmat3<DT> &a, const Tmat3<DT> &b)
289 {
290  return Tmat3<DT>(a) -= b;
291 }
292 
294 template <class DT>
295 inline Tmat3<DT> operator*(const Tmat3<DT> &a, const DT d)
296 {
297  return Tmat3<DT>(a) *= d;
298 }
299 
301 template <class DT>
302 inline Tmat3<DT> operator*(const DT d, const Tmat3<DT> &a)
303 {
304  return Tmat3<DT>(a) *= d;
305 }
306 
309 template <class DT>
310 inline Tmat3<DT> operator/(const Tmat3<DT> &a, const DT d)
311 {
312  Tmat3<DT> retVal(a);
313  retVal /= d;
314  return retVal;
315 }
317 
318 
319 //-------------------------------------------------------------------
320 //
323 //
324 //-------------------------------------------------------------------
325 
326 //-------------------------------------------------------------------
329 //-------------------------------------------------------------------
330 template <class DT>
331 inline Tmat3<DT>::Tmat3(const double in00, const double in01, const double in02,
332  const double in10, const double in11, const double in12,
333  const double in20, const double in21, const double in22)
334 {
335  this->v[0][0]=static_cast<DT>(in00); this->v[0][1]=static_cast<DT>(in01); this->v[0][2]=static_cast<DT>(in02);
336  this->v[1][0]=static_cast<DT>(in10); this->v[1][1]=static_cast<DT>(in11); this->v[1][2]=static_cast<DT>(in12);
337  this->v[2][0]=static_cast<DT>(in20); this->v[2][1]=static_cast<DT>(in21); this->v[2][2]=static_cast<DT>(in22);
338 }
339 
340 
341 //--------------------------------------------------------------------
343 //--------------------------------------------------------------------
344 template <class DT>
345 inline void Tmat3<DT>::setValues(const float mat[9])
346 {
347  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]);
348  this->v[1][0] = static_cast<DT>(mat[3]); this->v[1][1] = static_cast<DT>(mat[4]); this->v[1][2] = static_cast<DT>(mat[5]);
349  this->v[2][0] = static_cast<DT>(mat[6]); this->v[2][1] = static_cast<DT>(mat[7]); this->v[2][2] = static_cast<DT>(mat[8]);
350 }
351 
352 //--------------------------------------------------------------------
356 //--------------------------------------------------------------------
357 template <class DT>
358 inline void Tmat3<DT>::getValues(float mat[9]) const
359 {
360  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]);
361  mat[3] = static_cast<float>(this->v[1][0]); mat[4] = static_cast<float>(this->v[1][1]); mat[5] = static_cast<float>(this->v[1][2]);
362  mat[6] = static_cast<float>(this->v[2][0]); mat[7] = static_cast<float>(this->v[2][1]); mat[8] = static_cast<float>(this->v[2][2]);
363 }
364 
365 //--------------------------------------------------------------------
367 //--------------------------------------------------------------------
368 template <class DT>
369 inline void Tmat3<DT>::setValues(const double mat[9])
370 {
371  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]);
372  this->v[1][0] = static_cast<DT>(mat[3]); this->v[1][1] = static_cast<DT>(mat[4]); this->v[1][2] = static_cast<DT>(mat[5]);
373  this->v[2][0] = static_cast<DT>(mat[6]); this->v[2][1] = static_cast<DT>(mat[7]); this->v[2][2] = static_cast<DT>(mat[8]);
374 }
375 
376 //--------------------------------------------------------------------
380 //--------------------------------------------------------------------
381 template <class DT>
382 inline void Tmat3<DT>::getValues(double mat[9]) const
383 {
384  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]);
385  mat[3] = static_cast<double>(this->v[1][0]); mat[4] = static_cast<double>(this->v[1][1]); mat[5] = static_cast<double>(this->v[1][2]);
386  mat[6] = static_cast<double>(this->v[2][0]); mat[7] = static_cast<double>(this->v[2][1]); mat[8] = static_cast<double>(this->v[2][2]);
387 }
388 
389 
390 //-------------------------------------------------------------------
392 //-------------------------------------------------------------------
393 template <class DT>
394 inline void Tmat3<DT>::setScaleMatrix(const DT scale)
395 {
396  this->v[0][0]=scale; this->v[0][1]=0; this->v[0][2]=0;
397  this->v[1][0]=0; this->v[1][1]=scale; this->v[1][2]=0;
398  this->v[2][0]=0; this->v[2][1]=0; this->v[2][2]=scale;
399 }
401 
402 
403 //-------------------------------------------------------------------
406 //-------------------------------------------------------------------
407 
409 #define DET3(A,B,C,D,E,F,G,H,I) ((A*E*I + B*F*G + C*D*H) - (A*F*H + B*D*I + C*E*G))
410 //-------------------------------------------------------------------
412 //-------------------------------------------------------------------
413 template <class DT>
415 {
416  return DET3(this->v[0][0], this->v[0][1], this->v[0][2],
417  this->v[1][0], this->v[1][1], this->v[1][2],
418  this->v[2][0], this->v[2][1], this->v[2][2]);
419 }
420 #undef DET3
421 
422 //-------------------------------------------------------------------
424 //-------------------------------------------------------------------
425 template <class DT>
427 {
428  return Tmat3<DT>(Tvec3<DT>(this->v[0][0], this->v[1][0], this->v[2][0]),
429  Tvec3<DT>(this->v[0][1], this->v[1][1], this->v[2][1]),
430  Tvec3<DT>(this->v[0][2], this->v[1][2], this->v[2][2]));
431 }
432 
433 //-------------------------------------------------------------------
435 //-------------------------------------------------------------------
436 template <class DT>
438 {
439  return Tmat3<DT>(Tvec3<DT>(1,0,0),
440  Tvec3<DT>(0,1,0),
441  Tvec3<DT>(0,0,1));
442 }
443 
444 //-------------------------------------------------------------------
446 //-------------------------------------------------------------------
447 template <class DT>
449 {
450  this->v[0].apply(fct);
451  this->v[1].apply(fct);
452  this->v[2].apply(fct);
453  return *this;
454 }
455 
457 #define _ML_MAT3_RC(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j]
458 //-------------------------------------------------------------------
460 //-------------------------------------------------------------------
461 template <class DT>
462 inline Tmat3<DT> operator*(const Tmat3<DT> &a, const Tmat3<DT> &b)
463 {
464  return Tmat3<DT>(Tvec3<DT>(_ML_MAT3_RC(0,0), _ML_MAT3_RC(0,1), _ML_MAT3_RC(0,2)),
465  Tvec3<DT>(_ML_MAT3_RC(1,0), _ML_MAT3_RC(1,1), _ML_MAT3_RC(1,2)),
466  Tvec3<DT>(_ML_MAT3_RC(2,0), _ML_MAT3_RC(2,1), _ML_MAT3_RC(2,2)));
467 
468 }
469 #undef _ML_MAT3_RC
470 
471 //-------------------------------------------------------------------
473 //-------------------------------------------------------------------
474 template <class DT>
475 inline bool operator==(const Tmat3<DT> &a, const Tmat3<DT> &b)
476 {
477  return (a[0] == b[0]) &&
478  (a[1] == b[1]) &&
479  (a[2] == b[2]);
480 }
481 
482 //-------------------------------------------------------------------
484 //-------------------------------------------------------------------
485 template <class DT>
486 inline bool operator!=(const Tmat3<DT> &a, const Tmat3<DT> &b)
487 {
488  return !(a == b);
489 }
490 
491 //-------------------------------------------------------------------
492 //
493 // Special global 2D functions and 3D functions
494 //
495 //-------------------------------------------------------------------
496 
497 //--------------------------------------------------------------------
500 //--------------------------------------------------------------------
501 template <class DT>
503 {
504  return Tmat3<DT>::getIdentity();
505 }
506 
507 //-------------------------------------------------------------------
510 //-------------------------------------------------------------------
511 template <class DT>
513 {
514  return Tmat3<DT>(Tvec3<DT>(1.0, 0.0, v[0]),
515  Tvec3<DT>(0.0, 1.0, v[1]),
516  Tvec3<DT>(0.0, 0.0, 1.0));
517 }
518 
519 //-------------------------------------------------------------------
522 //-------------------------------------------------------------------
523 template <class DT>
524 Tmat3<DT> rotation2D(const Tvec2<DT> &Center, const DT angleDeg)
525 {
526  DT angleRad = angleDeg * M_PI / 180.0;
527  DT c = cos(angleRad);
528  DT s = sin(angleRad);
529 
530  return Tmat3<DT>(Tvec3<DT>(c, -s, Center[0] * (1.0-c) + Center[1] * s),
531  Tvec3<DT>(s, c, Center[1] * (1.0-c) - Center[0] * s),
532  Tvec3<DT>(0.0, 0.0, 1.0));
533 }
534 
535 //-------------------------------------------------------------------
537 //-------------------------------------------------------------------
538 template <class DT>
539 inline Tmat3<DT> scaling2D(const Tvec2<DT> &scaleVector)
540 {
541  return Tmat3<DT>(Tvec3<DT>(scaleVector[0], 0.0, 0.0),
542  Tvec3<DT>(0.0, scaleVector[1], 0.0),
543  Tvec3<DT>(0.0, 0.0, 1.0));
544 }
545 
546 
547 
548 //-------------------------------------------------------------------
560 //-------------------------------------------------------------------
561 template <class DT>
562 Tmat3<DT> Tmat3<DT>::jacobi(Tvec3<DT> &evalues, int &rots) const
563 {
564  Tmat3<DT> evectors (getIdentity());
565 
566  // TODO: Further documentation of the algorithm required!
567 
568  DT sm = 0; // smallest entry
569  DT theta = 0; // angle for Jacobi rotation
570  DT c = 0, s = 0, t = 0; // cosine, sine, tangent of theta
571  DT tau = 0; // sine / (1 + cos)
572  DT h = 0, g = 0; // two scrap values
573  DT thresh = 0; // threshold below which no rotation done
574 
575  int p = 0, q = 0, i = 0, j = 0;
576 
577  // Initialization
578  Tvec3<DT> b (this->v[0][0], this->v[1][1], this->v[2][2]); // diagonal elements
579  Tvec3<DT> z (0, 0, 0);
580  evalues = b;
581 
582  Tmat3<DT> a (*this);
583 
584  rots = 0;
585  for (i = 0; i < 50; i++){ // typical matrices require 6 to 10 sweeps to achieve convergence - hence 50 gives some safety margin
586  sm = 0.0;
587  for (p = 0; p < 2; p++){
588  for (q = p+1; q < 3; q++){
589  sm += std::abs(a.v[p][q]); // sum off-diagonal elements
590  }
591  }
592 
593  if (sm == 0.0){
594  return *(&evectors); // circumvent a code generation bug in Visual Studio 2019 (version 16.5.4)
595  }
596 
597  thresh = (i < 3 ? (.2 * sm / 9) : 0.0);
598 
599  for (p = 0; p < 2; p++) {
600  for (q = p+1; q < 3; q++) { // compute on sweep, i.e. one rotation for each of-diagonal element of the matrix
601 
602  g = 100.0 * std::abs(a.v[p][q]);
603 
604  if ((i > 3) &&
605  (std::abs(evalues[p]) + g == std::abs(evalues[p])) &&
606  (std::abs(evalues[q]) + g == std::abs(evalues[q]))){
607  a.v[p][q] = 0.0; // after three sweeps, skip rotation of small off diagonal elements
608  }
609  else if (std::abs(a.v[p][q]) > thresh) {
610  h = evalues[q] - evalues[p];
611  if (std::abs(h) + g == std::abs(h)){
612  t = a.v[p][q] / h;
613  }
614  else {
615  theta = .5 * h / a.v[p][q];
616  t = 1.0 / (std::abs(theta) + sqrt(1 + theta * theta));
617  if (theta < 0.0){
618  t = -t;
619  }
620  }
621  // End of computing tangent of rotation angle
622 
623  c = 1.0 / sqrt(1.0 + t*t);
624  s = t * c;
625  tau = s / (1.0 + c);
626  h = t * a.v[p][q];
627  z[p] -= h;
628  z[q] += h;
629  evalues[p] -= h;
630  evalues[q] += h;
631  a.v[p][q] = 0.0;
632 
633  for (j = 0; j < p; j++) {
634  g = a.v[j][p];
635  h = a.v[j][q];
636  a.v[j][p] = g - s * (h + g * tau);
637  a.v[j][q] = h + s * (g - h * tau);
638  }
639 
640  for (j = p+1; j < q; j++) {
641  g = a.v[p][j];
642  h = a.v[j][q];
643  a.v[p][j] = g - s * (h + g * tau);
644  a.v[j][q] = h + s * (g - h * tau);
645  }
646 
647  for (j = q+1; j < 3; j++) {
648  g = a.v[p][j];
649  h = a.v[q][j];
650  a.v[p][j] = g - s * (h + g * tau);
651  a.v[q][j] = h + s * (g - h * tau);
652  }
653 
654  for (j = 0; j < 3; j++) {
655  g = evectors.v[j][p];
656  h = evectors.v[j][q];
657  evectors.v[j][p] = g - s * (h + g * tau);
658  evectors.v[j][q] = h + s * (g - h * tau);
659  }
660  } // else if (std::abs(a.v[p][q]) > thresh)
661 
662  rots++;
663 
664  } // for (q = p+1; q < 3; q++)
665  } // for (p = 0; p < 2; p++)
666 
667  for (p = 0; p < 3; p++) {
668  evalues[p] = b[p] += z[p];
669  z[p] = 0;
670  }
671  } // for (i = 0; i < 50; i++)
672  return evectors;
673 }
674 
675 //-------------------------------------------------------------------
683 //-------------------------------------------------------------------
684 template <class DT>
685 Tmat3<DT> Tmat3<DT>::inverse(bool* isInvertible) const
686 {
687  // Epsilon for comparison with 0 in inversion process.
688  static const DT Epsilon = static_cast<DT>(0.);
689 
690  // Use helper function from tools to invert the matrix.
691  return MLInverseMatHelper(*this,
692  isInvertible,
693  Epsilon,
694  "Tmat3<DT> Tmat3<DT>::inverse(bool* isInvertible) const, matrix not invertable",
695  getIdentity(),
696  3);
697 }
698 
699 //-----------------------------------------------------------------------------------
702 //-----------------------------------------------------------------------------------
703 
713 
714 
715 #if ML_DEPRECATED_SINCE(3,5,0)
716 
719 
723 ML_DEPRECATED typedef Tmat3<MLfloat> matf3;
727 ML_DEPRECATED typedef Tmat3<MLdouble> matd3;
731 ML_DEPRECATED typedef Tmat3<MLldouble> matld3;
735 ML_DEPRECATED typedef Tmat3<MLdouble> mat3;
737 
738 
739 #endif
740 
741 
742 
743 ML_LA_END_NAMESPACE
744 
745 namespace std
746 {
747  //-------------------------------------------------------------------
749  //-------------------------------------------------------------------
750  template <class DT>
751  inline std::ostream &operator<<(std::ostream &os, const ML_LA_NAMESPACE::Tmat3<DT> &m)
752  {
753  return os << m[0] << '\n' << m[1] << '\n' << m[2];
754  }
755 
756  //-------------------------------------------------------------------
758  //-------------------------------------------------------------------
759  template <class DT>
760  inline std::istream &operator>>(std::istream &is, ML_LA_NAMESPACE::Tmat3<DT> &m)
761  {
762  ML_LA_NAMESPACE::Tmat3<DT> m_tmp;
763 
764  is >> m_tmp[0] >> m_tmp[1] >> m_tmp[2];
765  if (is){ m = m_tmp; }
766  return is;
767  }
768 }
769 
770 
771 #endif // __mlMatrix3_H
772 
773 
#define ML_DEPRECATED
Definition: CSOGroup.h:371
Base class of all matrix classes which holds the data buffer and provides some general access methods...
VectorT v[size]
The rows constituting the matrix.
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component wise division of lhs by specialized rhs of type MLdouble.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
FloatingPointVector< T, size, DataContainer > operator+(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component wise addition of lhs and rhs.
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component wise subtraction of rhs from lhs.
A three by three matrix class of three row vectors.
Definition: mlMatrix3.h:37
bool operator<(const Tmat3< DT > &) const
Dummy "lesser than operator" which always returns false.
Definition: mlMatrix3.h:93
void setValues(const float mat[9])
Copies the contents of mat into *this, row by row.
Definition: mlMatrix3.h:345
static Tmat3 getIdentity()
Returns the identity matrix.
Definition: mlMatrix3.h:437
static Tmat3< DT > getMat(const double val)
Returns a matrix filled with values val.
Definition: mlMatrix3.h:196
void setScaleMatrix(const DT scale)
Sets a diagonal matrix with scale on diagonal.
Definition: mlMatrix3.h:394
Tmat3(const double in00, const double in01, const double in02, const double in10, const double in11, const double in12, const double in20, const double in21, const double in22)
Initializes all matrix elements explicitly with scalars, filling it row by row.
Definition: mlMatrix3.h:331
const Tmat3< DT > & operator+=(const Tmat3< DT > &m)
Increments by a Tmat3.
Definition: mlMatrix3.h:225
Tmat3(const double mat[9])
Constructor from 9 double values in an array given by mat, row by row.
Definition: mlMatrix3.h:189
const Tmat3< DT > & operator-=(const Tmat3< DT > &m)
Decrements by a Tmat3.
Definition: mlMatrix3.h:236
void getValues(float mat[9]) const
Copies the contents of *this into mat, row by row.
Definition: mlMatrix3.h:358
const Tmat3< DT > & operator*=(const DT d)
Multiplies by a constant.
Definition: mlMatrix3.h:247
void getValues(double mat[9]) const
Copies the contents of *this into mat, row by row.
Definition: mlMatrix3.h:382
Tmat3 transpose() const
Returns the transpose of this matrix.
Definition: mlMatrix3.h:426
Tmat3(const Tmat3< DT > &mat)
Copy constructor from the Tmat3 mat.
Definition: mlMatrix3.h:173
Tmat3(const Tvec3< DT > &row0, const Tvec3< DT > &row1, const Tvec3< DT > &row2)
Builds a matrix of the three row vectors row0, row1, row2.
Definition: mlMatrix3.h:164
Tmat3(const DT diagValue)
Definition: mlMatrix3.h:155
DT ComponentType
A typedef to "export" the type of components.
Definition: mlMatrix3.h:42
const Tmat3< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to each component.
Definition: mlMatrix3.h:448
Tmat3(const float mat[9])
Constructor from 9 floating point values in an array given by mat, row by row.
Definition: mlMatrix3.h:182
void setValues(const double mat[9])
Copies the contents of mat into *this, row by row.
Definition: mlMatrix3.h:369
Tmat3 jacobi(Tvec3< DT > &eVal, int &rots) const
Calculates the Jacobi-Decomposition of 3x3 matrix.
Definition: mlMatrix3.h:562
Tmat3()
Builds a 3x3 matrix from 9 0 elements.
Definition: mlMatrix3.h:148
Tmat3 inverse(bool *isInvertible=nullptr) const
Returns the inverse.
Definition: mlMatrix3.h:685
const Tmat3< DT > & operator=(const Tmat3< DT > &m)
Assigns by a Tmat3.
Definition: mlMatrix3.h:212
const Tmat3< DT > & operator/=(const DT d)
Divides by a constant. Division by zero is not handled and must be avoided by caller.
Definition: mlMatrix3.h:258
void set(DT val)
Sets all values to val.
Definition: mlMatrix3.h:205
DT det() const
Determinant.
Definition: mlMatrix3.h:414
Declaration of float vector type traits:
Definition: mlVector2.h:57
Forward declarations to resolve header file dependencies.
Definition: mlVector3.h:66
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
#define DET3(A, B, C, D, E, F, G, H, I)
Internal helper macro to calculate the determinant of 3x3 matrix with given entries,...
Definition: mlMatrix3.h:409
#define _ML_MAT3_RC(i, j)
Internal helper macro to multiply two matrices, do not use.
Definition: mlMatrix3.h:457
double(* MLDblFuncPtr)(double)
A function pointer type to a function which returns a double and takes a double as argument.
Definition: mlTypeDefs.h:1282
std::istream & operator>>(std::istream &in, ml::Variant &variant)
Definition: mlVariant.h:215
void apply(Fnc &&fnc, const std::tuple< Args... > &tuple)
Tmat3< MLfloat > Matrix3f
A 3x3 matrix of type float.
Definition: mlMatrix3.h:705
Tmat3< DT > translation2D(const Tvec2< DT > &v)
Returns a 2D translation matrix as 3D homogeneous matrix where the translation is located in the righ...
Definition: mlMatrix3.h:512
Tmat3< DT > rotation2D(const Tvec2< DT > &Center, const DT angleDeg)
Returns a 2D rotation matrix as 3D homogeneous matrix where center specifies the center of rotation.
Definition: mlMatrix3.h:524
bool operator==(const Tmat3< DT > &a, const Tmat3< DT > &b)
a == b ? Return true if yes, otherwise false.
Definition: mlMatrix3.h:475
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.
DT abs(DT val)
Tmat3< MLdouble > Matrix3
The standard 3x3 matrix of type double.
Definition: mlMatrix3.h:711
Tmat3< DT > scaling2D(const Tvec2< DT > &scaleVector)
Returns a 2D scale matrix as 3D homogeneous matrix.
Definition: mlMatrix3.h:539
Tmat3< MLldouble > Matrix3ld
A 3x3 matrix of type long double.
Definition: mlMatrix3.h:709
constexpr Is< T > is(T d)
Tmat3< MLdouble > Matrix3d
A 3x3 matrix of type double.
Definition: mlMatrix3.h:707
FloatingPointVector< T, size, DataContainer > & operator+=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component wise addition.
BASE_TYPE MLInverseMatHelper(const BASE_TYPE &origMat, bool *isInvertible, const typename BASE_TYPE::ComponentType, const char *const ZeroDetErrString, const BASE_TYPE &Identity, const size_t Dim)
Computes an N dimensional inverse from given default parameters.
Tmat3< DT > identity2D()
Returns a 3x3 homogeneous identity2D matrix; synonym for Tmat3<DT>::getIdentity().
Definition: mlMatrix3.h:502
bool operator!=(const Tmat3< DT > &a, const Tmat3< DT > &b)
a != b ? Return true if yes, otherwise false.
Definition: mlMatrix3.h:486
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component wise multiplication *this with specialized MLdouble scalar value.