CVB++ 15.0
affine_matrix_3d.hpp
1#pragma once
2
3
4
5#include "_cexports/c_core_3d.h"
6
7#include "global.hpp"
8#include "matrix_3d.hpp"
9#include "point_3d.hpp"
10
11namespace Cvb
12{
13
14CVB_BEGIN_INLINE_NS
15
17
37{
40
43
45 double Syx = 0;
46
48 double Syz = 0;
49
51 double InclinationX = 0;
52
54 double InclinationZ = 0;
55
58 : RotationAngles(Vector3D<double>(0,0,0))
59 , Scale(Factors3D(1,1,1))
60 , Syx(0)
61 , Syz(0)
62 , InclinationX(0)
63 , InclinationZ(0)
64 {
65 }
66};
67
68class AffineMatrix3D;
69
70
72
80inline AffineMatrix3D operator+(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept;
81
83
91inline AffineMatrix3D operator-(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept;
92
93
95
103inline AffineMatrix3D operator*(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs);
104
105
106
108
116inline AffineMatrix3D operator*(const AffineMatrix3D & lhs, const double & rhs) noexcept;
117
119
127inline AffineMatrix3D operator*(const double & lhs, const AffineMatrix3D & rhs) noexcept;
128
130
138inline AffineMatrix3D operator/(const AffineMatrix3D & lhs, const double & rhs);
139
140
141
143
146class AffineMatrix3D final
147{
148 public:
149
151
155 static AffineMatrix3D Identity() noexcept
156 {
157 return AffineMatrix3D(
160 }
161
163
166 AffineMatrix3D() noexcept = default;
167
169
174 AffineMatrix3D(Matrix3D matrix, Vector3D<double> translation) noexcept
175 : matrix_(matrix)
176 , translation_(translation)
177 {
178 }
179
180
182
186 Matrix3D Matrix() const noexcept
187 {
188 return matrix_;
189 }
190
192
196 void SetMatrix(Matrix3D matrix) noexcept
197 {
198 matrix_ = matrix;
199 }
200
202
207 {
208 return translation_;
209 }
210
211
213
217 void SetTranslation(Vector3D<double> translation) noexcept
218 {
219 translation_ = translation;
220 }
221
222
224
228 bool IsTranslation() const noexcept
229 {
230 return matrix_ == Cvb::Matrix3D::Identity();
231 }
232
234
238 double Det() const
239 {
240 return Internal::DoResCallValueOut<double>([&](double & value)
241 {
242 auto thisData = reinterpret_cast<const CExports::CVC3DTransformation*>(this);
243 return CVB_CALL_CAPI(CVC3DTransformationDeterminant(*thisData, value));
244 });
245 }
246
247
249
254 void Invert()
255 {
256 Internal::DoResCall([&]()
257 {
258 auto data = reinterpret_cast<const CExports::CVC3DTransformation*>(this);
259 auto dataInv = reinterpret_cast<CExports::CVC3DTransformation*>(this);
260 return CVB_CALL_CAPI(CVC3DInvertTransformation(*data, *dataInv));
261 });
262 }
263
265
272 {
273 auto result = *this;
274 result.Invert();
275 return result;
276 }
277
279
284 bool operator==(const AffineMatrix3D& transformation) const noexcept
285 {
286 return translation_ == transformation.translation_
287 && matrix_ == transformation.matrix_;
288 }
289
291
296 bool operator!=(const AffineMatrix3D& transformation) const noexcept
297 {
298 return !(*this == transformation);
299 }
300
302
307 AffineMatrix3D& operator +=(const AffineMatrix3D & transformation) noexcept
308 {
309 *this = *this + transformation;
310 return *this;
311 }
312
314
319 AffineMatrix3D& operator -=(const AffineMatrix3D & transformation) noexcept
320 {
321 *this = *this - transformation;
322 return *this;
323 }
324
325
326
328
334 {
335 *this = *this * transformation;
336 return *this;
337 }
338
340
345 AffineMatrix3D& operator *=(const double & value) noexcept
346 {
347 *this = *this *value;
348 return *this;
349 }
350
352
357 AffineMatrix3D& operator /=(const double & value) noexcept
358 {
359 *this = *this / value;
360 return *this;
361 }
362
363
364
365 private:
366
367 Vector3D<double> translation_;
368 Matrix3D matrix_;
369};
370
371
372
373
374inline AffineMatrix3D operator+(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept
375{
376 return AffineMatrix3D(lhs.Matrix() + rhs.Matrix(), lhs.Translation() + rhs.Translation());
377}
378
379inline AffineMatrix3D operator-(const AffineMatrix3D & lhs, const AffineMatrix3D & rhs) noexcept
380{
381 return AffineMatrix3D(lhs.Matrix() - rhs.Matrix(), lhs.Translation() - rhs.Translation());
382}
383
385{
386
387 return Internal::DoResCallValueOut<AffineMatrix3D>([&](AffineMatrix3D & value)
388 {
389 auto valueData = reinterpret_cast<CExports::CVC3DTransformation*>(&value);
390 auto lhsData = reinterpret_cast<const CExports::CVC3DTransformation*>(&lhs);
391 auto rhsData = reinterpret_cast<const CExports::CVC3DTransformation*>(&rhs);
392 return CVB_CALL_CAPI(CVC3DMultiplyTransformations(*lhsData,
393 *rhsData,
394 *valueData));
395 });
396
397}
398
399
400inline AffineMatrix3D operator*(const AffineMatrix3D & lhs, const double & rhs) noexcept
401{
402 return AffineMatrix3D(lhs.Matrix() * rhs, lhs.Translation() * rhs);
403}
404
405
406inline AffineMatrix3D operator*(const double & lhs, const AffineMatrix3D & rhs) noexcept
407{
408 return rhs * lhs;
409}
410
411
412inline AffineMatrix3D operator/(const AffineMatrix3D & lhs, const double & rhs)
413{
414 return AffineMatrix3D(lhs.Matrix() / rhs, lhs.Translation() / rhs);
415}
416
417
418
419
420
421
422CVB_END_INLINE_NS
423
424} // namespace Cvb
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition: affine_matrix_3d.hpp:147
AffineMatrix3D Inverse()
Gets the inverse of this transformation if possible.
Definition: affine_matrix_3d.hpp:271
bool operator==(const AffineMatrix3D &transformation) const noexcept
Compares to an other transformation.
Definition: affine_matrix_3d.hpp:284
static AffineMatrix3D Identity() noexcept
The identity element.
Definition: affine_matrix_3d.hpp:155
Vector3D< double > Translation() const noexcept
Gets the translation part of the transformation.
Definition: affine_matrix_3d.hpp:206
Matrix3D Matrix() const noexcept
Gets the matrix part of the transformation.
Definition: affine_matrix_3d.hpp:186
AffineMatrix3D & operator*=(const AffineMatrix3D &transformation)
Multiplies and assigns to this transformation.
Definition: affine_matrix_3d.hpp:333
AffineMatrix3D & operator/=(const double &value) noexcept
Divides each element of this transformation by the given value.
Definition: affine_matrix_3d.hpp:357
AffineMatrix3D() noexcept=default
Default constructor for empty transformation.
bool IsTranslation() const noexcept
Checks if this transformation describes a translation.
Definition: affine_matrix_3d.hpp:228
double Det() const
Transformation determinant.
Definition: affine_matrix_3d.hpp:238
bool operator!=(const AffineMatrix3D &transformation) const noexcept
Compares to an other transformation.
Definition: affine_matrix_3d.hpp:296
void SetTranslation(Vector3D< double > translation) noexcept
Sets the translation part of the transformation.
Definition: affine_matrix_3d.hpp:217
AffineMatrix3D & operator-=(const AffineMatrix3D &transformation) noexcept
Subtracts and assigns to this transformation.
Definition: affine_matrix_3d.hpp:319
void SetMatrix(Matrix3D matrix) noexcept
Sets the matrix part of the transformation.
Definition: affine_matrix_3d.hpp:196
void Invert()
Inverts this transformation in-place if possible.
Definition: affine_matrix_3d.hpp:254
AffineMatrix3D & operator+=(const AffineMatrix3D &transformation) noexcept
Adds and assigns to this affine matrix.
Definition: affine_matrix_3d.hpp:307
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
Parameters of a 3D affine transformation matrix correcting an inclined laser plane.
Definition: affine_matrix_3d.hpp:37
Vector3D< double > RotationAngles
Rotation angles about x, y and z in [degree].
Definition: affine_matrix_3d.hpp:39
double InclinationZ
Inclination of laser plane (rotation about z axis) in [degree].
Definition: affine_matrix_3d.hpp:54
double Syx
Shear Syx (induced by InclinationZ).
Definition: affine_matrix_3d.hpp:45
double InclinationX
Inclination of laser plane (rotation about x axis) in [degree].
Definition: affine_matrix_3d.hpp:51
Factors3D Scale
Scale factors.
Definition: affine_matrix_3d.hpp:42
AffineTransformationParameters()
Creates a new AffineTransformationParameters object with default values.
Definition: affine_matrix_3d.hpp:57
double Syz
Shear Syz (induced by InclinationX).
Definition: affine_matrix_3d.hpp:48
Factor components to be applied in the 3D domain.
Definition: core_3d.hpp:17