CVB++ 14.0
affine_matrix_3d.hpp
1#pragma once
2
3
4
5#include "_cexports/c_core_3d.h"
6
7#include "global.hpp"
8
9
10#include "point_3d.hpp"
11#include "matrix_3d.hpp"
12
13namespace Cvb
14{
15
16CVB_BEGIN_INLINE_NS
17
18class AffineMatrix3D;
19
20
22
30inline AffineMatrix3D operator+(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept;
31
33
41inline AffineMatrix3D operator-(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept;
42
43
45
53inline AffineMatrix3D operator*(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs);
54
55
56
58
66inline AffineMatrix3D operator*(const AffineMatrix3D & lhs, const double & rhs) noexcept;
67
69
77inline AffineMatrix3D operator*(const double & lhs, const AffineMatrix3D & rhs) noexcept;
78
80
88inline AffineMatrix3D operator/(const AffineMatrix3D & lhs, const double & rhs);
89
90
91
93
97class AffineMatrix3D final
98{
99 public:
100
102
106 static AffineMatrix3D Identity() noexcept
107 {
108 return AffineMatrix3D(
111 }
112
114
117 AffineMatrix3D() noexcept = default;
118
120
125 AffineMatrix3D(Matrix3D matrix, Vector3D<double> translation) noexcept
126 : matrix_(matrix)
127 , translation_(translation)
128 {
129 }
130
131
133
137 Matrix3D Matrix() const noexcept
138 {
139 return matrix_;
140 }
141
143
147 void SetMatrix(Matrix3D matrix) noexcept
148 {
149 matrix_ = matrix;
150 }
151
153
158 {
159 return translation_;
160 }
161
162
164
168 void SetTranslation(Vector3D<double> translation) noexcept
169 {
170 translation_ = translation;
171 }
172
173
175
179 bool IsTranslation() const noexcept
180 {
181 return matrix_ == Cvb::Matrix3D::Identity();
182 }
183
185
189 double Det() const
190 {
191 return Internal::DoResCallValueOut<double>([&](double & value)
192 {
193 auto thisData = reinterpret_cast<const CExports::CVC3DTransformation*>(this);
194 return CVB_CALL_CAPI(CVC3DTransformationDeterminant(*thisData, value));
195 });
196 }
197
198
200
205 void Invert()
206 {
207 Internal::DoResCall([&]()
208 {
209 auto data = reinterpret_cast<const CExports::CVC3DTransformation*>(this);
210 auto dataInv = reinterpret_cast<CExports::CVC3DTransformation*>(this);
211 return CVB_CALL_CAPI(CVC3DInvertTransformation(*data, *dataInv));
212 });
213 }
214
216
221 bool operator==(const AffineMatrix3D& transformation) const noexcept
222 {
223 return translation_ == transformation.translation_
224 && matrix_ == transformation.matrix_;
225 }
226
228
233 bool operator!=(const AffineMatrix3D& transformation) const noexcept
234 {
235 return !(*this == transformation);
236 }
237
239
244 AffineMatrix3D& operator +=(const AffineMatrix3D & transformation) noexcept
245 {
246 *this = *this + transformation;
247 return *this;
248 }
249
251
256 AffineMatrix3D& operator -=(const AffineMatrix3D & transformation) noexcept
257 {
258 *this = *this - transformation;
259 return *this;
260 }
261
262
263
265
271 {
272 *this = *this * transformation;
273 return *this;
274 }
275
277
282 AffineMatrix3D& operator *=(const double & value) noexcept
283 {
284 *this = *this *value;
285 return *this;
286 }
287
289
294 AffineMatrix3D& operator /=(const double & value) noexcept
295 {
296 *this = *this / value;
297 return *this;
298 }
299
300
301
302 private:
303
304 Vector3D<double> translation_;
305 Matrix3D matrix_;
306};
307
308
309
310
311inline AffineMatrix3D operator+(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept
312{
313 return AffineMatrix3D(lhs.Matrix() + rhs.Matrix(), lhs.Translation() + rhs.Translation());
314}
315
316inline AffineMatrix3D operator-(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept
317{
318 return AffineMatrix3D(lhs.Matrix() - rhs.Matrix(), lhs.Translation() - rhs.Translation());
319}
320
322{
323
324 return Internal::DoResCallValueOut<AffineMatrix3D>([&](AffineMatrix3D & value)
325 {
326 auto valueData = reinterpret_cast<CExports::CVC3DTransformation*>(&value);
327 auto lhsData = reinterpret_cast<const CExports::CVC3DTransformation*>(&lhs);
328 auto rhsData = reinterpret_cast<const CExports::CVC3DTransformation*>(&rhs);
329 return CVB_CALL_CAPI(CVC3DMultiplyTransformations(*lhsData,
330 *rhsData,
331 *valueData));
332 });
333
334}
335
336
337inline AffineMatrix3D operator*(const AffineMatrix3D & lhs, const double & rhs) noexcept
338{
339 return AffineMatrix3D(lhs.Matrix() * rhs, lhs.Translation() * rhs);
340}
341
342
343inline AffineMatrix3D operator*(const double & lhs, const AffineMatrix3D & rhs) noexcept
344{
345 return rhs * lhs;
346}
347
348
349inline AffineMatrix3D operator/(const AffineMatrix3D & lhs, const double & rhs)
350{
351 return AffineMatrix3D(lhs.Matrix() / rhs, lhs.Translation() / rhs);
352}
353
354
355
356
357
358
359CVB_END_INLINE_NS
360
361}
Affine transformation matrix for 3D.
Definition: affine_matrix_3d.hpp:98
bool operator==(const AffineMatrix3D &transformation) const noexcept
Compares to an other transformation.
Definition: affine_matrix_3d.hpp:221
static AffineMatrix3D Identity() noexcept
The identity element.
Definition: affine_matrix_3d.hpp:106
Vector3D< double > Translation() const noexcept
Gets the translation part of the transformation.
Definition: affine_matrix_3d.hpp:157
Matrix3D Matrix() const noexcept
Gets the matrix part of the transformation.
Definition: affine_matrix_3d.hpp:137
AffineMatrix3D & operator*=(const AffineMatrix3D &transformation)
Multiplies and assigns to this transformation.
Definition: affine_matrix_3d.hpp:270
AffineMatrix3D & operator/=(const double &value) noexcept
Divides each element of this transformation by the given value.
Definition: affine_matrix_3d.hpp:294
AffineMatrix3D() noexcept=default
Default constructor for empty transformation.
bool IsTranslation() const noexcept
Checks if this transformation describes a translation.
Definition: affine_matrix_3d.hpp:179
double Det() const
Transformation determinant.
Definition: affine_matrix_3d.hpp:189
bool operator!=(const AffineMatrix3D &transformation) const noexcept
Compares to an other transformation.
Definition: affine_matrix_3d.hpp:233
void SetTranslation(Vector3D< double > translation) noexcept
Sets the translation part of the transformation.
Definition: affine_matrix_3d.hpp:168
AffineMatrix3D & operator-=(const AffineMatrix3D &transformation) noexcept
Subtracts and assigns to this transformation.
Definition: affine_matrix_3d.hpp:256
void SetMatrix(Matrix3D matrix) noexcept
Sets the matrix part of the transformation.
Definition: affine_matrix_3d.hpp:147
void Invert()
Inverts this transformation if possible.
Definition: affine_matrix_3d.hpp:205
AffineMatrix3D & operator+=(const AffineMatrix3D &transformation) noexcept
Adds and assigns to this affine matrix.
Definition: affine_matrix_3d.hpp:244
Double precision 3x3 matrix class.
Definition: matrix_3d.hpp:59
static Matrix3D Identity() noexcept
The identity element.
Definition: matrix_3d.hpp:67
Multi-purpose 3D vector class.
Definition: point_3d.hpp:22
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
AffineMatrix2D operator+(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Add two affine matrices.
Definition: affine_matrix_2d.hpp:217
AffineMatrix2D operator*(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Multiply two affine matrices.
Definition: affine_matrix_2d.hpp:245
AffineMatrix2D operator/(const AffineMatrix2D &lhs, const double &rhs)
Divide affine matrix by scalar.
Definition: affine_matrix_2d.hpp:301
AffineMatrix2D operator-(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Subtract two affine matrices.
Definition: affine_matrix_2d.hpp:231