Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TMatrix44.h
Go to the documentation of this file.
1
20
21#pragma once
22#include <math/TVector3D.h>
23#include <string>
24
25namespace sf
26{
27
28// Forward declaration.
29template<typename T>
30class TQuaternion;
31
35template<typename T>
37{
38 public:
42 typedef T value_type;
43
47 TMatrix44() = default;
48
52 TMatrix44(T m00, T m01, T m02, T m03, T m10, T m11, T m12, T m13, T m20, T m21, T m22, T m23, T m30, T m31, T m32, T m33);
53
57 TMatrix44(std::initializer_list<T[4]> list);
58
62 // ReSharper disable once CppNonExplicitConvertingConstructor
63 TMatrix44(const std::string& str);
64
68 explicit TMatrix44(const T[4][4]);
69
73 explicit TMatrix44(const T*);
74
79 explicit TMatrix44(const TVector3D<T>& v);
80
85 TMatrix44(T tilt, T pan, T roll);
86
91
95 TMatrix44(TMatrix44&&) noexcept;
96
106
112 T determinant(bool only_3x3 = true) const;
113
119
127
133
139
144 TMatrix44& assign(const T[4][4]);
145
150 TMatrix44& assign(const T*);
151
156 TMatrix44& transposeAssign(const T[4][4]);
157
161 TMatrix44& operator=(const TMatrix44&);
165 TMatrix44& operator=(TMatrix44&& m) noexcept;
166
172 TMatrix44& operator*=(const TMatrix44&);
173
179 TVector3D<T> operator^(const TVector3D<T>&) const;
180
186 TVector3D<T> operator*(const TVector3D<T>&) const;
187
193
198 const value_type* data() const;
199
204 // ReSharper disable once CppNonExplicitConversionOperator
205 operator T*();
206
211 // ReSharper disable once CppNonExplicitConversionOperator
212 operator const T*() const;
213
220 bool isEqual(const TMatrix44& m, T tol = tolerance) const;
221
226 bool isRotational() const;
227
232 bool operator==(const TMatrix44&) const;
233
238 bool operator!=(const TMatrix44&) const;
239
243 void copyTo(T[4][4], bool column_order = false) const;
244
248 void copyTo(T*, bool column_order = false) const;
249
260 TMatrix44& setTiltPanRoll(T tilt, T pan, T roll);
261
269 void getTiltPanRoll(T& tilt, T& pan, T& roll) const;
270
278 TMatrix44& rotate(T angle, const TVector3D<T>& vec, bool only = true);
279
289 TMatrix44& rotate(T angle, T x, T y, T z, bool only = true);
290
300 TMatrix44 rotated(T angle, T x, T y, T z, bool only = true) const;
301
309 TMatrix44 rotated(T angle, const TVector3D<T>& vec, bool only = true) const;
310
318 void setPerspectiveProjection(T near_plane, T far_plane, T fov);
319
325
331
337
342 TMatrix44 rotated(const TMatrix44& m) const;
343
350 TVector3D<T> transformed(const TVector3D<T>& v, bool translate) const;
351
356
363 TMatrix44& translate(const TVector3D<T>& v, bool only = true);
364
373 TMatrix44& translate(T x, T y, T z, bool only = true);
374
381 TMatrix44 translated(const TVector3D<T>& v, bool only = true) const;
382
391 TMatrix44 translated(T x, T y, T z, bool only = true) const;
392
398
404
409 TMatrix44& setTranslation(T x, T y, T z);
410
418 TMatrix44& scale(T factor, bool translation = true);
419
429 TMatrix44& scale(T x, T y, T z, bool translation = true);
430
438 TMatrix44& scale(TVector3D<T> factor, bool translation = true);
439
443 enum EAxis : unsigned int
444 {
446 axisX = 0,
448 axisY = 1,
450 axisZ = 2,
453 };
454
461
468 TMatrix44 orbit(T horizontal, T vertical) const;
469
474
481 void setElement(unsigned int row, unsigned int column, T value);
482
489 T element(unsigned int row, unsigned int column) const;
490
497 T& element(unsigned int row, unsigned int column);
498
506 T& operator()(int row, int column);
507
515 T operator()(int row, int column) const;
516
522 template<typename R>
523 void toOpenGL(R* matrix) const;
524
532 template<typename R>
533 std::array<R, 16> toOpenGL() const;
534
542 template<typename R>
543 TMatrix44& fromOpenGL(const R* matrix);
544
551
557
567 TMatrix44& setOrientationXY(const TVector3D<T>& x_axis, const TVector3D<T>& y_axis, bool x_dominant = false);
568
578 TMatrix44& setOrientationZY(const TVector3D<T>& z_axis, const TVector3D<T>& y_axis, bool z_dominant = false);
579
586 TMatrix44& insertGIGRotXYZ(T rx, T ry, T rz);
587
591 std::string toString(int digits = 0) const;
592
601 TMatrix44& fromString(const std::string& s, bool ignore_err = false) noexcept(false);
602
608 static constexpr auto tolerance = TVector3D<T>::tolerance;
609
610 protected:
616 {
617 T array[4 * 4];
618 T mtx[4][4];
619 } _data = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
620};
621
629template<typename T>
631
639template<typename T>
640std::ostream& operator<<(std::ostream& os, const TMatrix44<T>& mtx);
641
649template<typename T>
650std::istream& operator>>(std::istream& is, TMatrix44<T>& mtx) noexcept(false);
651
652}// namespace sf
653
654#ifndef __JETBRAINS_IDE__
655 // Include all inlined functions and template implementations.
656 #include <math/TMatrix44.hpp>
657#endif
Generic 4 x 4 matrix template.
Definition TMatrix44.h:37
TVector3D< T > getTranslation() const
Gets translation part of matrix.
TMatrix44 translated(const TVector3D< T > &v, bool only=true) const
Same as translate() but does not change this matrix only returns the translated one.
TMatrix44 orbit(T horizontal, T vertical) const
Gets transformation of rotation around the local x- and y-axis of the current matrix.
TMatrix44 & rotate(T angle, const TVector3D< T > &vec, bool only=true)
Applies rotation on the current matrix around a vector.
TMatrix44 & setTiltPanRoll(T tilt, T pan, T roll)
Sets/resets rotation part of the matrix according to tilt pan roll and does not touch the translation...
TMatrix44 multiplied(const TMatrix44 &m) const
Same as multiply() but returns the changed matrix and does not affect this matrix.
TMatrix44 rotated(T angle, T x, T y, T z, bool only=true) const
Same as rotate() but only returns the changed matrix and does not affect this matrix.
TMatrix44 & insertGIGRotXYZ(T rx, T ry, T rz)
Another way of applying rotation to the matrix.
TMatrix44 & translate(const TVector3D< T > &v, bool only=true)
Adds a translation to this instance using a 3D vector.
bool isEqual(const TMatrix44 &m, T tol=tolerance) const
Compares the passed matrix within the set tolerance.
TMatrix44 & assign(const T[4][4])
Assigns the 4x4 array structure to this matrix.
TMatrix44 transposed() const
Get a transposed matrix of this instance.
TMatrix44 & transpose()
Transpose this matrix.
TMatrix44(std::initializer_list< T[4]> list)
Constructor using an initializer list.
T & operator()(int row, int column)
Function operator for row column value manipulations. This is different from the element() method.
TMatrix44(const T *)
Initialization constructor for 16 floating point values.
TMatrix44 & fromOpenGL(const R *matrix)
Assigns a column-major matrix array compatible with the OpenGL standard. Essentially converts from an...
TMatrix44 & multiply(const TMatrix44 &m)
Multiplies this matrix with the passed one so that the given matrix is applied on the matrix axes.
T value_type
Type accessible when implemented.
Definition TMatrix44.h:42
TMatrix44(const TVector3D< T > &v)
Construct from a translation vector. Construct a translation transformation from a given 3D Vector.
TMatrix44 & resetOrientation()
Resets the orientation and leaves the translation as is.
TMatrix44 & unit()
Set or resets this instance as a unit/identity matrix. A unit matrix, also known as the identity matr...
T & element(unsigned int row, unsigned int column)
Gets the element reference specified by the row and column.
TMatrix44(T tilt, T pan, T roll)
Constructs a matrix from rotations for each axis.
value_type * data()
Gets the pointer to the array of this matrix.
TMatrix44 & transposeAssign(const T[4][4])
Assigns the transposed 4x4 array structure to this matrix.
T element(unsigned int row, unsigned int column) const
Gets the element specified by the row and column.
TVector3D< T > transformed(const TVector3D< T > &v, bool translate) const
Applies the matrix rotation up on a 3D-vector.
void copyTo(T[4][4], bool column_order=false) const
Copies the matrix to a 4x4 array in row or column order.
TMatrix44 inverse() const
Gets the inverted version of this instance. Call the method invert() to do this.
TMatrix44(const std::string &str)
Constructor using a string as function TMatrix44::fromString().
T operator()(int row, int column) const
Gets the element from row and column index. This is different from the element() method.
EAxis
Enumerate for identifying a matrix axis.
Definition TMatrix44.h:444
@ axisZ
Z-axis of the matrix.
Definition TMatrix44.h:450
@ axisX
X-axis of the matrix.
Definition TMatrix44.h:446
@ axisT
Translation axis of the matrix.
Definition TMatrix44.h:452
@ axisY
Y-axis of the matrix.
Definition TMatrix44.h:448
void toOpenGL(R *matrix) const
Copies this matrix to a column-major matrix array compatible with OpenGL standard....
TMatrix44 & scale(T factor, bool translation=true)
Multiplies this matrix by the given factor. Leave the matrix translation vector alone.
TQuaternion< T > quaternion() const
Convert the rotation matrix part to identity/unit quaternion. Calls TQuaternion::fromMatrix().
TMatrix44 & fromString(const std::string &s, bool ignore_err=false) noexcept(false)
Gets matrix values from the string representation formed like '({1,2,3,4},{11,12,13,...
TVector3D< T > getAxis(EAxis axis) const
Gets the given axis of matrix as a 3D vector.
void setPerspectiveProjection(T near_plane, T far_plane, T fov)
Sets the projection for this matrix.
bool isRotational() const
Determines if the matrix is a rotation matrix.
std::array< R, 16 > toOpenGL() const
Gets a column-major matrix array buffer compatible with OpenGL standard. Essentially converts from a ...
void getTiltPanRoll(T &tilt, T &pan, T &roll) const
Translates rotation part of matrix to tilt, pan and roll values.
TMatrix44 & clearTranslation()
Zero's or clears translation part of this instance.
TMatrix44 & setOrientationXY(const TVector3D< T > &x_axis, const TVector3D< T > &y_axis, bool x_dominant=false)
Set orientation using two vectors X and Y which spans a surface having a dominant axis....
T determinant(bool only_3x3=true) const
Gets the determinant from this instance.
TMatrix44(const TMatrix44 &)
Copy constructor.
TMatrix44 & invert()
Inverts this matrix.
TMatrix44(const T[4][4])
Initialization constructor for 4x4 floating point values.
TMatrix44 & setOrientationZY(const TVector3D< T > &z_axis, const TVector3D< T > &y_axis, bool z_dominant=false)
Set orientation using two vectors Z and Y which spans a surface having a dominant axis....
TMatrix44()=default
Default constructor which is by default a unit-matrix.
TMatrix44 & setTranslation(const TVector3D< T > &v)
Sets translation part of this matrix.
std::string toString(int digits=0) const
Gets the string representation of the matrix formed like '({m00,m01,m02,m03},{m10,...
TMatrix44(T m00, T m01, T m02, T m03, T m10, T m11, T m12, T m13, T m20, T m21, T m22, T m23, T m30, T m31, T m32, T m33)
Initialization constructor for 16 single floating point values.
TMatrix44(TMatrix44 &&) noexcept
Move constructor.
void setElement(unsigned int row, unsigned int column, T value)
Sets the element specified by the row and column.
union sf::TMatrix44::data_type _data
static constexpr auto tolerance
Tolerance for when comparing in the equal operator.
Definition TMatrix44.h:608
TMatrix44 orientation() const
Gets the orientation part of matrix.
Generic type Quaternion.
Definition TQuaternion.h:14
3-dimensional vector for math operations.
Definition TVector3D.h:17
Definition Application.h:10
_GII_FUNC std::istream & operator>>(std::istream &is, ResultData &)
Stream operator for setting up this instance with a setup std::string.
TMatrix44< T > operator*(const TMatrix44< T > &lm, const TMatrix44< T > &rm)
Multiplies to matrices into a single one.
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.
_MISC_FUNC int digits(double value)
Returns the amount of digits which are significant for the value. When the value is 12300....
Storage union of the 4x4 matrix as array and 4 x4 array. It is initialized as a unit-matrix.
Definition TMatrix44.h:616
T mtx[4][4]
Definition TMatrix44.h:618
T array[4 *4]
Definition TMatrix44.h:617