42 #ifndef QGENERICMATRIX_H 43 #define QGENERICMATRIX_H 45 #include <QtCore/qmetatype.h> 46 #include <QtCore/qdebug.h> 47 #include <QtCore/qdatastream.h> 55 template <
int N,
int M,
typename T>
63 const T&
operator()(
int row,
int column)
const;
83 const T *
data()
const {
return *
m; }
86 #if !defined(Q_NO_TEMPLATE_FRIENDS) 87 template<
int NN,
int MM,
typename TT>
89 template<
int NN,
int MM,
typename TT>
91 template<
int NN,
int M1,
int M2,
typename TT>
93 template<
int NN,
int MM,
typename TT>
95 template<
int NN,
int MM,
typename TT>
97 template<
int NN,
int MM,
typename TT>
99 template<
int NN,
int MM,
typename TT>
108 #if !defined(Q_NO_TEMPLATE_FRIENDS) 109 template <
int NN,
int MM,
typename TT>
114 template <
int N,
int M,
typename T>
120 template <
int N,
int M,
typename T>
123 for (
int col = 0; col < N; ++col)
124 for (
int row = 0; row <
M; ++row)
125 m[col][row] = other.
m[col][row];
128 template <
int N,
int M,
typename T>
131 for (
int col = 0; col < N; ++col)
132 for (
int row = 0; row <
M; ++row)
133 m[col][row] = values[row * N + col];
136 template <
int N,
int M,
typename T>
139 Q_ASSERT(row >= 0 && row < M && column >= 0 && column < N);
140 return m[column][row];
143 template <
int N,
int M,
typename T>
146 Q_ASSERT(row >= 0 && row < M && column >= 0 && column < N);
147 return m[column][row];
150 template <
int N,
int M,
typename T>
153 for (
int col = 0; col < N; ++col) {
154 for (
int row = 0; row <
M; ++row) {
156 if (
m[col][row] != 1.0f)
159 if (
m[col][row] != 0.0f)
167 template <
int N,
int M,
typename T>
170 for (
int col = 0; col < N; ++col) {
171 for (
int row = 0; row <
M; ++row) {
180 template <
int N,
int M,
typename T>
183 for (
int col = 0; col < N; ++col)
184 for (
int row = 0; row <
M; ++row)
188 template <
int N,
int M,
typename T>
192 for (
int row = 0; row <
M; ++row)
193 for (
int col = 0; col < N; ++col)
194 result.
m[row][col] =
m[col][row];
198 template <
int N,
int M,
typename T>
201 for (
int row = 0; row <
M; ++row)
202 for (
int col = 0; col < N; ++col)
203 m[col][row] += other.
m[col][row];
207 template <
int N,
int M,
typename T>
210 for (
int row = 0; row <
M; ++row)
211 for (
int col = 0; col < N; ++col)
212 m[col][row] -= other.
m[col][row];
216 template <
int N,
int M,
typename T>
219 for (
int row = 0; row <
M; ++row)
220 for (
int col = 0; col < N; ++col)
221 m[col][row] *= factor;
225 template <
int N,
int M,
typename T>
228 for (
int row = 0; row <
M; ++row)
229 for (
int col = 0; col < N; ++col) {
230 if (
m[col][row] != other.
m[col][row])
236 template <
int N,
int M,
typename T>
239 for (
int row = 0; row <
M; ++row)
240 for (
int col = 0; col < N; ++col) {
241 if (
m[col][row] != other.
m[col][row])
247 template <
int N,
int M,
typename T>
250 for (
int row = 0; row <
M; ++row)
251 for (
int col = 0; col < N; ++col)
252 m[col][row] /= divisor;
256 template <
int N,
int M,
typename T>
260 for (
int row = 0; row <
M; ++row)
261 for (
int col = 0; col < N; ++col)
262 result.
m[col][row] = m1.
m[col][row] + m2.
m[col][row];
266 template <
int N,
int M,
typename T>
270 for (
int row = 0; row <
M; ++row)
271 for (
int col = 0; col < N; ++col)
272 result.
m[col][row] = m1.
m[col][row] - m2.
m[col][row];
276 template <
int N,
int M1,
int M2,
typename T>
280 for (
int row = 0; row < M2; ++row) {
281 for (
int col = 0; col < M1; ++col) {
283 for (
int j = 0; j < N; ++j)
284 sum += m1.
m[j][row] * m2.
m[col][j];
285 result.
m[col][row] = sum;
291 template <
int N,
int M,
typename T>
295 for (
int row = 0; row <
M; ++row)
296 for (
int col = 0; col < N; ++col)
297 result.
m[col][row] = -matrix.
m[col][row];
301 template <
int N,
int M,
typename T>
305 for (
int row = 0; row <
M; ++row)
306 for (
int col = 0; col < N; ++col)
307 result.
m[col][row] = matrix.
m[col][row] * factor;
311 template <
int N,
int M,
typename T>
315 for (
int row = 0; row <
M; ++row)
316 for (
int col = 0; col < N; ++col)
317 result.
m[col][row] = matrix.
m[col][row] * factor;
321 template <
int N,
int M,
typename T>
325 for (
int row = 0; row <
M; ++row)
326 for (
int col = 0; col < N; ++col)
327 result.
m[col][row] = matrix.
m[col][row] / divisor;
331 template <
int N,
int M,
typename T>
334 for (
int col = 0; col < N; ++col)
335 for (
int row = 0; row <
M; ++row)
336 values[row * N + col] = T(
m[col][row]);
349 #ifndef QT_NO_DEBUG_STREAM 351 template <
int N,
int M,
typename T>
352 QDebug operator<<(QDebug dbg, const QGenericMatrix<N, M, T> &
m)
354 dbg.nospace() <<
"QGenericMatrix<" << N <<
", " <<
M 357 for (
int row = 0; row <
M; ++row) {
358 for (
int col = 0; col < N; ++col)
368 #ifndef QT_NO_DATASTREAM 370 template <
int N,
int M,
typename T>
371 QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M, T> &matrix)
373 for (
int row = 0; row <
M; ++row)
374 for (
int col = 0; col < N; ++col)
375 stream <<
double(matrix(row, col));
379 template <
int N,
int M,
typename T>
383 for (
int row = 0; row <
M; ++row) {
384 for (
int col = 0; col < N; ++col) {
386 matrix(row, col) = T(x);
const T * constData() const
Returns a constant pointer to the raw data of this matrix.
The QDebug class provides an output stream for debugging information.
T * data()
Returns a pointer to the raw data of this matrix.
QGenericMatrix< N, M, T > & operator*=(T factor)
Multiplies all elements of this matrix by factor.
#define QT_END_NAMESPACE
This macro expands to.
QDataStream & operator>>(QDataStream &stream, QGenericMatrix< N, M, T > &matrix)
Reads a NxM matrix from the given stream into the given matrix and returns a reference to the stream...
The QGenericMatrix class is a template class that represents a NxM transformation matrix with N colum...
QMatrix4x3
The QMatrix4x3 type defines a convenient instantiation of the QGenericMatrix template for 4 columns...
bool isIdentity() const
Returns true if this matrix is the identity; false otherwise.
QMatrix3x2
The QMatrix3x2 type defines a convenient instantiation of the QGenericMatrix template for 3 columns...
friend QGenericMatrix< M1, M2, TT > operator*(const QGenericMatrix< NN, M2, TT > &m1, const QGenericMatrix< M1, NN, TT > &m2)
QMatrix2x2
The QMatrix2x2 type defines a convenient instantiation of the QGenericMatrix template for 2 columns...
const T * data() const
Returns a constant pointer to the raw data of this matrix.
void setToIdentity()
Sets this matrix to the identity.
QGenericMatrix< N, M, T > & operator/=(T divisor)
Divides all elements of this matrix by divisor.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QGenericMatrix< N, M, T > & operator-=(const QGenericMatrix< N, M, T > &other)
Subtracts the contents of other from this matrix.
QMatrix2x4
The QMatrix2x4 type defines a convenient instantiation of the QGenericMatrix template for 2 columns...
#define Q_INLINE_TEMPLATE
void fill(T value)
Fills all elements of this matrix with value.
QMatrix2x3
The QMatrix2x3 type defines a convenient instantiation of the QGenericMatrix template for 2 columns...
bool operator==(const QGenericMatrix< N, M, T > &other) const
Returns true if this matrix is identical to other; false otherwise.
QMatrix3x4
The QMatrix3x4 type defines a convenient instantiation of the QGenericMatrix template for 3 columns...
bool operator!=(const QGenericMatrix< N, M, T > &other) const
Returns true if this matrix is not identical to other; false otherwise.
friend QGenericMatrix< NN, MM, TT > operator+(const QGenericMatrix< NN, MM, TT > &m1, const QGenericMatrix< NN, MM, TT > &m2)
const T & operator()(int row, int column) const
Returns a constant reference to the element at position (row, column) in this matrix.
QMatrix4x2
The QMatrix4x2 type defines a convenient instantiation of the QGenericMatrix template for 4 columns...
QMatrix3x3
The QMatrix3x3 type defines a convenient instantiation of the QGenericMatrix template for 3 columns...
The QDataStream class provides serialization of binary data to a QIODevice.
friend QGenericMatrix< NN, MM, TT > operator/(const QGenericMatrix< NN, MM, TT > &matrix, TT divisor)
#define Q_OUTOFLINE_TEMPLATE
QGenericMatrix< M, N, T > transposed() const
Returns this matrix, transposed about its diagonal.
QTextStreamManipulator qSetFieldWidth(int width)
friend QGenericMatrix< NN, MM, TT > operator-(const QGenericMatrix< NN, MM, TT > &m1, const QGenericMatrix< NN, MM, TT > &m2)
void copyDataTo(T *values) const
Retrieves the N * M items in this matrix and copies them to values in row-major order.
QGenericMatrix< N, M, T > & operator+=(const QGenericMatrix< N, M, T > &other)
Adds the contents of other to this matrix.
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)