CVB++ 15.0
matrix_3d_h.hpp
1#pragma once
2
3#include "_cexports/c_core_3d.h"
4
5#include "global.hpp"
6
7#include "point_3d_h.hpp"
8#include "matrix_3d.hpp"
9
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
15 class Matrix3DH;
16
18
26 inline Matrix3DH operator+(const Matrix3DH &lhs, const Matrix3DH &rhs);
27
29
37 inline Matrix3DH operator-(const Matrix3DH &lhs, const Matrix3DH &rhs);
38
40
43 class Matrix3DH final
44 {
45 public:
47
51 static Matrix3DH Identity() noexcept
52 {
53 return {{1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}};
54 }
55
57
60 Matrix3DH() noexcept = default;
61
63
67 template <std::size_t N>
68 Matrix3DH(const double (&list)[N]) noexcept // NOLINT
69 {
70 static_assert(N == 16, "CVB: Matrix3D must have 16 elements");
71 std::copy(std::begin(list), std::end(list), matrix_.data()->data());
72 }
73
75
79 explicit Matrix3DH(const Matrix3D &matrix) noexcept
80 {
81 *this = {{
82 matrix[0][0],
83 matrix[0][1],
84 matrix[0][2],
85 0.0,
86 matrix[1][0],
87 matrix[1][1],
88 matrix[1][2],
89 0.0,
90 matrix[2][0],
91 matrix[2][1],
92 matrix[2][2],
93 0.0,
94 0.0,
95 0.0,
96 0.0,
97 1.0,
98 }};
99 }
100
102
107 const double *operator[](int row) const noexcept
108 {
109 return matrix_[row].data(); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
110 }
111
113
118 double *operator[](int row) noexcept
119 {
120 return matrix_[row].data(); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
121 }
122
124
130 const double &At(int row, int column) const noexcept
131 {
132 return (*this)[row][column];
133 }
134
136
142 double &At(int row, int column) noexcept
143 {
144 return (*this)[row][column];
145 }
146
148
153 bool operator==(const Matrix3DH &matrix) const noexcept
154 {
155 return matrix_ == matrix.matrix_;
156 }
157
159
164 bool operator!=(const Matrix3DH &matrix) const noexcept
165 {
166 return !(*this == matrix);
167 }
168
170
175 Matrix3DH &operator+=(const Matrix3DH &matrix) noexcept
176 {
177 *this = *this + matrix;
178 return *this;
179 }
180
182
187 Matrix3DH &operator-=(const Matrix3DH &matrix) noexcept
188 {
189 *this = *this - matrix;
190 return *this;
191 }
192
194
199 Matrix3DH &operator*=(const double &value) noexcept
200 {
201 for (auto &line : matrix_)
202 for (auto &element : line)
203 element *= value;
204 return *this;
205 }
206
208
213 Matrix3DH &operator/=(const double &value) noexcept
214 {
215 for (auto &line : matrix_)
216 for (auto &element : line)
217 element /= value;
218 return *this;
219 }
220
221 private:
223 };
224
225 inline Matrix3DH operator+(const Matrix3DH &lhs, const Matrix3DH &rhs)
226 {
227 return {{
228 lhs[0][0] + rhs[0][0],
229 lhs[0][1] + rhs[0][1],
230 lhs[0][2] + rhs[0][2],
231 lhs[0][3] + rhs[0][3],
232 lhs[1][0] + rhs[1][0],
233 lhs[1][1] + rhs[1][1],
234 lhs[1][2] + rhs[1][2],
235 lhs[1][3] + rhs[1][3],
236 lhs[2][0] + rhs[2][0],
237 lhs[2][1] + rhs[2][1],
238 lhs[2][2] + rhs[2][2],
239 lhs[2][3] + rhs[2][3],
240 lhs[3][0] + rhs[3][0],
241 lhs[3][1] + rhs[3][1],
242 lhs[3][2] + rhs[3][2],
243 lhs[3][3] + rhs[3][3],
244 }};
245 }
246
247 inline Matrix3DH operator-(const Matrix3DH &lhs, const Matrix3DH &rhs)
248 {
249 return {{
250 lhs[0][0] - rhs[0][0],
251 lhs[0][1] - rhs[0][1],
252 lhs[0][2] - rhs[0][2],
253 lhs[0][3] - rhs[0][3],
254 lhs[1][0] - rhs[1][0],
255 lhs[1][1] - rhs[1][1],
256 lhs[1][2] - rhs[1][2],
257 lhs[1][3] - rhs[1][3],
258 lhs[2][0] - rhs[2][0],
259 lhs[2][1] - rhs[2][1],
260 lhs[2][2] - rhs[2][2],
261 lhs[2][3] - rhs[2][3],
262 lhs[3][0] - rhs[3][0],
263 lhs[3][1] - rhs[3][1],
264 lhs[3][2] - rhs[3][2],
265 lhs[3][3] - rhs[3][3],
266 }};
267 }
268
270
279 {
280 return {{
281 lhs[0][0] * rhs[0] + lhs[0][1] * rhs[1] + lhs[0][2] * rhs[2] + lhs[0][3] * rhs[3],
282 lhs[1][0] * rhs[0] + lhs[1][1] * rhs[1] + lhs[1][2] * rhs[2] + lhs[1][3] * rhs[3],
283 lhs[2][0] * rhs[0] + lhs[2][1] * rhs[1] + lhs[2][2] * rhs[2] + lhs[2][3] * rhs[3],
284 lhs[3][0] * rhs[0] + lhs[3][1] * rhs[1] + lhs[3][2] * rhs[2] + lhs[3][3] * rhs[3],
285 }};
286 }
287
289
297 inline Matrix3DH operator*(const Matrix3DH &lhs, const double &rhs)
298 {
299 return {{
300 lhs[0][0] * rhs,
301 lhs[0][1] * rhs,
302 lhs[0][2] * rhs,
303 lhs[0][3] * rhs,
304 lhs[1][0] * rhs,
305 lhs[1][1] * rhs,
306 lhs[1][2] * rhs,
307 lhs[1][3] * rhs,
308 lhs[2][0] * rhs,
309 lhs[2][1] * rhs,
310 lhs[2][2] * rhs,
311 lhs[2][3] * rhs,
312 lhs[3][0] * rhs,
313 lhs[3][1] * rhs,
314 lhs[3][2] * rhs,
315 lhs[3][3] * rhs,
316 }};
317 }
318
320
328 inline Matrix3DH operator*(const double &lhs, const Matrix3DH &rhs)
329 {
330 return rhs * lhs;
331 }
332
334
342 inline Matrix3DH operator/(const Matrix3DH &lhs, const double &rhs)
343 {
344 return {{lhs[0][0] / rhs, lhs[0][1] / rhs, lhs[0][2] / rhs, lhs[0][3] / rhs, lhs[1][0] / rhs, lhs[1][1] / rhs,
345 lhs[1][2] / rhs, lhs[1][3] / rhs, lhs[2][0] / rhs, lhs[2][1] / rhs, lhs[2][2] / rhs, lhs[2][3] / rhs,
346 lhs[3][0] / rhs, lhs[3][1] / rhs, lhs[3][2] / rhs, lhs[3][3] / rhs}};
347 }
348
349 CVB_END_INLINE_NS
350
351} // namespace Cvb
T begin(T... args)
Double precision row-major 4x4 matrix.
Definition matrix_3d_h.hpp:44
const double & At(int row, int column) const noexcept
Index based element access.
Definition matrix_3d_h.hpp:130
Matrix3DH operator*(const double &lhs, const Matrix3DH &rhs)
Multiply scalar with matrix .
Definition matrix_3d_h.hpp:328
const double * operator[](int row) const noexcept
Index based element access.
Definition matrix_3d_h.hpp:107
double * operator[](int row) noexcept
Index based element access.
Definition matrix_3d_h.hpp:118
Matrix3DH(const Matrix3D &matrix) noexcept
Create a homogeneous matrix from a matrix.
Definition matrix_3d_h.hpp:79
Matrix3DH & operator/=(const double &value) noexcept
Divides each element of this matrix by the given value.
Definition matrix_3d_h.hpp:213
Matrix3DH() noexcept=default
Default constructor for empty matrix.
Matrix3DH operator/(const Matrix3DH &lhs, const double &rhs)
Divide matrix by scalar.
Definition matrix_3d_h.hpp:342
Matrix3DH & operator-=(const Matrix3DH &matrix) noexcept
Subtracts and assigns to this matrix.
Definition matrix_3d_h.hpp:187
Matrix3DH & operator+=(const Matrix3DH &matrix) noexcept
Adds and assigns to this matrix.
Definition matrix_3d_h.hpp:175
Matrix3DH operator*(const Matrix3DH &lhs, const double &rhs)
Multiply matrix with scalar.
Definition matrix_3d_h.hpp:297
bool operator!=(const Matrix3DH &matrix) const noexcept
Compares to an other matrix.
Definition matrix_3d_h.hpp:164
double & At(int row, int column) noexcept
Index based element access.
Definition matrix_3d_h.hpp:142
Matrix3DH & operator*=(const double &value) noexcept
Multiplies and assigns to this matrix.
Definition matrix_3d_h.hpp:199
Point3DH< double > operator*(const Matrix3DH &lhs, const Point3DH< double > &rhs)
Multiply matrix with 3D point (homogeneous).
Definition matrix_3d_h.hpp:278
static Matrix3DH Identity() noexcept
The identity element.
Definition matrix_3d_h.hpp:51
bool operator==(const Matrix3DH &matrix) const noexcept
Compares to an other matrix.
Definition matrix_3d_h.hpp:153
Double precision 3x3 matrix class.
Definition matrix_3d.hpp:54
Multi-purpose 3D vector class (homogeneous).
Definition point_3d_h.hpp:22
T copy(T... args)
T end(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
AffineMatrix2D operator+(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Add two affine matrices.
Definition affine_matrix_2d.hpp:223
AffineMatrix2D operator-(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Subtract two affine matrices.
Definition affine_matrix_2d.hpp:237