CVB++ 14.1
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
96class AffineMatrix3D final
97{
98 public:
99
101
105 static AffineMatrix3D Identity() noexcept
106 {
107 return AffineMatrix3D(
110 }
111
113
116 AffineMatrix3D() noexcept = default;
117
119
124 AffineMatrix3D(Matrix3D matrix, Vector3D<double> translation) noexcept
125 : matrix_(matrix)
126 , translation_(translation)
127 {
128 }
129
130
132
136 Matrix3D Matrix() const noexcept
137 {
138 return matrix_;
139 }
140
142
146 void SetMatrix(Matrix3D matrix) noexcept
147 {
148 matrix_ = matrix;
149 }
150
152
157 {
158 return translation_;
159 }
160
161
163
167 void SetTranslation(Vector3D<double> translation) noexcept
168 {
169 translation_ = translation;
170 }
171
172
174
178 bool IsTranslation() const noexcept
179 {
180 return matrix_ == Cvb::Matrix3D::Identity();
181 }
182
184
188 double Det() const
189 {
190 return Internal::DoResCallValueOut<double>([&](double & value)
191 {
192 auto thisData = reinterpret_cast<const CExports::CVC3DTransformation*>(this);
193 return CVB_CALL_CAPI(CVC3DTransformationDeterminant(*thisData, value));
194 });
195 }
196
197
199
204 void Invert()
205 {
206 Internal::DoResCall([&]()
207 {
208 auto data = reinterpret_cast<const CExports::CVC3DTransformation*>(this);
209 auto dataInv = reinterpret_cast<CExports::CVC3DTransformation*>(this);
210 return CVB_CALL_CAPI(CVC3DInvertTransformation(*data, *dataInv));
211 });
212 }
213
215
222 {
223 auto result = *this;
224 result.Invert();
225 return result;
226 }
227
229
234 bool operator==(const AffineMatrix3D& transformation) const noexcept
235 {
236 return translation_ == transformation.translation_
237 && matrix_ == transformation.matrix_;
238 }
239
241
246 bool operator!=(const AffineMatrix3D& transformation) const noexcept
247 {
248 return !(*this == transformation);
249 }
250
252
257 AffineMatrix3D& operator +=(const AffineMatrix3D & transformation) noexcept
258 {
259 *this = *this + transformation;
260 return *this;
261 }
262
264
269 AffineMatrix3D& operator -=(const AffineMatrix3D & transformation) noexcept
270 {
271 *this = *this - transformation;
272 return *this;
273 }
274
275
276
278
284 {
285 *this = *this * transformation;
286 return *this;
287 }
288
290
295 AffineMatrix3D& operator *=(const double & value) noexcept
296 {
297 *this = *this *value;
298 return *this;
299 }
300
302
307 AffineMatrix3D& operator /=(const double & value) noexcept
308 {
309 *this = *this / value;
310 return *this;
311 }
312
313
314
315 private:
316
317 Vector3D<double> translation_;
318 Matrix3D matrix_;
319};
320
321
322
323
324inline AffineMatrix3D operator+(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept
325{
326 return AffineMatrix3D(lhs.Matrix() + rhs.Matrix(), lhs.Translation() + rhs.Translation());
327}
328
329inline AffineMatrix3D operator-(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept
330{
331 return AffineMatrix3D(lhs.Matrix() - rhs.Matrix(), lhs.Translation() - rhs.Translation());
332}
333
335{
336
337 return Internal::DoResCallValueOut<AffineMatrix3D>([&](AffineMatrix3D & value)
338 {
339 auto valueData = reinterpret_cast<CExports::CVC3DTransformation*>(&value);
340 auto lhsData = reinterpret_cast<const CExports::CVC3DTransformation*>(&lhs);
341 auto rhsData = reinterpret_cast<const CExports::CVC3DTransformation*>(&rhs);
342 return CVB_CALL_CAPI(CVC3DMultiplyTransformations(*lhsData,
343 *rhsData,
344 *valueData));
345 });
346
347}
348
349
350inline AffineMatrix3D operator*(const AffineMatrix3D & lhs, const double & rhs) noexcept
351{
352 return AffineMatrix3D(lhs.Matrix() * rhs, lhs.Translation() * rhs);
353}
354
355
356inline AffineMatrix3D operator*(const double & lhs, const AffineMatrix3D & rhs) noexcept
357{
358 return rhs * lhs;
359}
360
361
362inline AffineMatrix3D operator/(const AffineMatrix3D & lhs, const double & rhs)
363{
364 return AffineMatrix3D(lhs.Matrix() / rhs, lhs.Translation() / rhs);
365}
366
367
368
369
370
371
372CVB_END_INLINE_NS
373
374}
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition: affine_matrix_3d.hpp:97
AffineMatrix3D Inverse()
Gets the inverse of this transformation if possible.
Definition: affine_matrix_3d.hpp:221
bool operator==(const AffineMatrix3D &transformation) const noexcept
Compares to an other transformation.
Definition: affine_matrix_3d.hpp:234
static AffineMatrix3D Identity() noexcept
The identity element.
Definition: affine_matrix_3d.hpp:105
Vector3D< double > Translation() const noexcept
Gets the translation part of the transformation.
Definition: affine_matrix_3d.hpp:156
Matrix3D Matrix() const noexcept
Gets the matrix part of the transformation.
Definition: affine_matrix_3d.hpp:136
AffineMatrix3D & operator*=(const AffineMatrix3D &transformation)
Multiplies and assigns to this transformation.
Definition: affine_matrix_3d.hpp:283
AffineMatrix3D & operator/=(const double &value) noexcept
Divides each element of this transformation by the given value.
Definition: affine_matrix_3d.hpp:307
AffineMatrix3D() noexcept=default
Default constructor for empty transformation.
bool IsTranslation() const noexcept
Checks if this transformation describes a translation.
Definition: affine_matrix_3d.hpp:178
double Det() const
Transformation determinant.
Definition: affine_matrix_3d.hpp:188
bool operator!=(const AffineMatrix3D &transformation) const noexcept
Compares to an other transformation.
Definition: affine_matrix_3d.hpp:246
void SetTranslation(Vector3D< double > translation) noexcept
Sets the translation part of the transformation.
Definition: affine_matrix_3d.hpp:167
AffineMatrix3D & operator-=(const AffineMatrix3D &transformation) noexcept
Subtracts and assigns to this transformation.
Definition: affine_matrix_3d.hpp:269
void SetMatrix(Matrix3D matrix) noexcept
Sets the matrix part of the transformation.
Definition: affine_matrix_3d.hpp:146
void Invert()
Inverts this transformation in-place if possible.
Definition: affine_matrix_3d.hpp:204
AffineMatrix3D & operator+=(const AffineMatrix3D &transformation) noexcept
Adds and assigns to this affine matrix.
Definition: affine_matrix_3d.hpp:257
Double precision 3x3 matrix class.
Definition: matrix_3d.hpp:60
static Matrix3D Identity() noexcept
The identity element.
Definition: matrix_3d.hpp:68
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:231
AffineMatrix2D operator*(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Multiply two affine matrices.
Definition: affine_matrix_2d.hpp:259
AffineMatrix2D operator/(const AffineMatrix2D &lhs, const double &rhs)
Divide affine matrix by scalar.
Definition: affine_matrix_2d.hpp:315
AffineMatrix2D operator-(const AffineMatrix2D &lhs, const AffineMatrix2D &rhs) noexcept
Subtract two affine matrices.
Definition: affine_matrix_2d.hpp:245