QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsmatrix4x4.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmatrix4x4.h
3 --------------------------------------
4 Date : July 2023
5 Copyright : (C) 2023 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMATRIX4X4_H
17#define QGSMATRIX4X4_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
22#include "qgsvector3d.h"
23
24
39class CORE_EXPORT QgsMatrix4x4
40{
41 public:
43 QgsMatrix4x4() { setToIdentity(); }
45 QgsMatrix4x4( double m11, double m12, double m13, double m14,
46 double m21, double m22, double m23, double m24,
47 double m31, double m32, double m33, double m34,
48 double m41, double m42, double m43, double m44 );
49
50 bool operator==( const QgsMatrix4x4 &other ) const
51 {
52 const double *data = *m;
53 const double *otherData = *( other.m );
54 for ( int i = 0; i < 16; ++i, data++, otherData++ )
55 {
56 if ( !qgsDoubleNear( *data, *otherData ) )
57 return false;
58 }
59 return true;
60 }
61
62 bool operator!=( const QgsMatrix4x4 &other ) const
63 {
64 return !( *this == other );
65 }
66
68 const double *constData() const SIP_SKIP { return *m; }
70 double *data() SIP_SKIP { return *m; }
72 QList< double > dataList() const SIP_PYNAME( data ) SIP_HOLDGIL;
73
77 void translate( const QgsVector3D &vector );
78
80 QgsVector3D map( const QgsVector3D &vector ) const SIP_HOLDGIL
81 {
82 return *this * vector;
83 }
84
86 bool isIdentity() const SIP_HOLDGIL;
88 void setToIdentity() SIP_HOLDGIL;
89
90#ifdef SIP_RUN
91 SIP_PYOBJECT __repr__();
92 % MethodCode
93 QString str = QStringLiteral( "<QgsMatrix4x4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)>" )
94 .arg( sipCpp->data()[0] )
95 .arg( sipCpp->data()[4] )
96 .arg( sipCpp->data()[8] )
97 .arg( sipCpp->data()[12] )
98 .arg( sipCpp->data()[1] )
99 .arg( sipCpp->data()[5] )
100 .arg( sipCpp->data()[9] )
101 .arg( sipCpp->data()[13] )
102 .arg( sipCpp->data()[2] )
103 .arg( sipCpp->data()[6] )
104 .arg( sipCpp->data()[10] )
105 .arg( sipCpp->data()[14] )
106 .arg( sipCpp->data()[3] )
107 .arg( sipCpp->data()[7] )
108 .arg( sipCpp->data()[11] )
109 .arg( sipCpp->data()[15] );
110 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
111 % End
112#endif
113
114#ifndef SIP_RUN
115 friend CORE_EXPORT QgsMatrix4x4 operator*( const QgsMatrix4x4 &m1, const QgsMatrix4x4 &m2 );
116 friend CORE_EXPORT QgsVector3D operator*( const QgsMatrix4x4 &matrix, const QgsVector3D &vector );
117#endif
118
119 private:
120 // Matrix data - in column-major order
121 double m[4][4];
122
124 explicit QgsMatrix4x4( int ) { } // cppcheck-suppress uninitMemberVarPrivate
125};
126
128CORE_EXPORT QgsVector3D operator*( const QgsMatrix4x4 &matrix, const QgsVector3D &vector );
130CORE_EXPORT QgsMatrix4x4 operator*( const QgsMatrix4x4 &m1, const QgsMatrix4x4 &m2 );
131
132
133#endif
A simple 4x4 matrix implementation useful for transformation in 3D space.
bool operator==(const QgsMatrix4x4 &other) const
QgsMatrix4x4()
Initializes identity matrix.
bool operator!=(const QgsMatrix4x4 &other) const
double * data()
Returns pointer to the matrix data (stored in column-major order)
const double * constData() const
Returns pointer to the matrix data (stored in column-major order)
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
#define str(x)
Definition qgis.cpp:39
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5958
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#define SIP_HOLDGIL
Definition qgis_sip.h:171
QgsMargins operator*(const QgsMargins &margins, double factor)
Returns a QgsMargins object that is formed by multiplying each component of the given margins by fact...
Definition qgsmargins.h:249
CORE_EXPORT QgsVector3D operator*(const QgsMatrix4x4 &matrix, const QgsVector3D &vector)
Matrix-matrix multiplication (useful to concatenate transforms)