| IOLink 1.11.0

Loading...
Searching...
No Matches
Matrix.h
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <initializer_list>
6#include <ostream>
7#include <string>
8
9#include <iolink/IOLinkAPI.h>
10#include <iolink/Vector.h>
11
12 namespace iolink
13{
14
20 template <typename ValueType, size_t N>
21 class Matrix
22{
23 public:
27 static Matrix identity();
28
34 static Matrix uniform(ValueType value);
35
40 Matrix();
41
57 explicit Matrix(const ValueType* values);
58
76 Matrix(const ValueType* values, bool isRowMajor);
77
95 explicit Matrix(std::initializer_list<ValueType> init);
96
97 bool operator==(const Matrix& other) const;
98 bool operator!=(const Matrix& other) const;
99
106 ValueType at(size_t row, size_t column) const;
107
114 ValueType operator()(size_t row, size_t column) const;
115
123 void setAt(size_t row, size_t column, ValueType value);
124
128 void transposeInPlace();
129
133 Matrix transpose() const;
134
141 Matrix inverse() const;
142
161 ValueType* data();
162
166 const ValueType* data() const;
167
171 std::string toString() const;
172
173 // ==================== //
174 // Arithmetic operators //
175 // ==================== //
176
177 Matrix operator-() const;
178
179 Matrix& operator+=(const Matrix& m);
180 Matrix& operator-=(const Matrix& m);
181
182 inline Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
183 inline Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
184
185 Matrix& operator*=(ValueType value);
186 Matrix& operator/=(ValueType value);
187
188 inline Matrix operator*(ValueType v) const { return Matrix(*this) *= v; }
189 inline Matrix operator/(ValueType v) const { return Matrix(*this) /= v; }
190
191 Vector<ValueType, N> operator*(const Vector<ValueType, N>& v) const;
192 Matrix operator*(const Matrix& m) const;
193
194 private:
195 std::array<ValueType, N * N> m_data;
196};
197
201 template <typename T, size_t N>
202 inline std::ostream&
203operator<<(std::ostream& os, const Matrix<T, N>& m)
204{
205 os << m.toString();
206 return os;
207}
208
209//=======================//
210// Template declarations //
211//=======================//
212
213 extern template class IOLINK_API_IMPORT Matrix<float, 3>;
214 extern template class IOLINK_API_IMPORT Matrix<double, 3>;
215
216 extern template class IOLINK_API_IMPORT Matrix<float, 4>;
217 extern template class IOLINK_API_IMPORT Matrix<double, 4>;
218
219//======================//
220// Aliases declarations //
221//======================//
222
223 using Matrix3f = Matrix<float, 3>;
224 using Matrix3d = Matrix<double, 3>;
225
226 using Matrix4f = Matrix<float, 4>;
227 using Matrix4d = Matrix<double, 4>;
228
229} // end namespace iolink
iolink::Matrix
An arithmetic square matrix.
Definition Matrix.h:22
iolink::Matrix::Matrix
Matrix(std::initializer_list< ValueType > init)
Create a matrix giving initialization values.
iolink::Matrix::operator()
ValueType operator()(size_t row, size_t column) const
Access an element of the matrix.
iolink::Matrix::transposeInPlace
void transposeInPlace()
Transpose the matrix in place.
iolink::Matrix::data
const ValueType * data() const
Exposes the internal data of the matrix, use it only if you know what you do.
iolink::Matrix::uniform
static Matrix uniform(ValueType value)
Initialize an uniform matrix with an unique value.
iolink::Matrix::Matrix
Matrix()
Default constructor.
iolink::Matrix::setAt
void setAt(size_t row, size_t column, ValueType value)
Set an element of the matrix.
iolink::Matrix::at
ValueType at(size_t row, size_t column) const
Access an element of the matrix.
iolink::Matrix::toString
std::string toString() const
Return a string representation of the matrix.
iolink::Matrix::data
ValueType * data()
Exposes the internal data of the matrix, use it only if you know what you do.
iolink::Matrix::Matrix
Matrix(const ValueType *values)
Constructor with C-array parameter.
iolink::Matrix::inverse
Matrix inverse() const
Return the inverse matrix.
iolink::Matrix::Matrix
Matrix(const ValueType *values, bool isRowMajor)
Constructor with C-array parameter.
iolink::Matrix::identity
static Matrix identity()
Return an identity matrix.
iolink::Matrix::transpose
Matrix transpose() const
Return the transposed matrix.
iolink
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8