Ocean
AbsoluteTransformation.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_GEOMETRY_ABSOLUTE_TRANSFORMATION_H
9 #define META_OCEAN_GEOMETRY_ABSOLUTE_TRANSFORMATION_H
10 
12 
14 #include "ocean/math/Vector3.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Geometry
20 {
21 
22 /**
23  * This class provides functions determining the absolute transformation between two point sets.
24  * @ingroup geometry
25  */
26 class OCEAN_GEOMETRY_EXPORT AbsoluteTransformation
27 {
28  public:
29 
30  /**
31  * Defines whether the error term for the scale calculation is in the space of right coordinate system, the left coordinate system, or uses a symmetric formulation
32  */
33  enum class ScaleErrorType
34  {
35  /// Error term for scaling computation is in the units of the right coordinate system (e = || Pright - s * R * Pleft ||^2).
36  RightBiased,
37  /// Error term for scaling computation is in the units of the left coordinate system (e = || (1 / s) * (R^{-1}) * Pright - Pleft ||^2).
38  LeftBiased,
39  /// Error term for scaling computation uses a symmetric formulation (e = || (1 / sqrt(s)) * Pright - sqrt(s) * R * Pleft) ||^2 ). (Recommended by Horn in the general case.)
40  Symmetric
41  };
42 
43  /**
44  * Calculates the absolute transformation between two corresponding 3D point sets.
45  * The implementation follows "Closed-form solution of absolute orientation using unit quaternions, Horn, 1986"<br>
46  * The resulting transformation contains translation and rotation, but no scaling. The scale term can be retrieved optionally -- this allows the transformation to be inverted more reliably.<br>
47  * Beware: This function does not support outliers.
48  * @param left The object points defined in the 'left' coordinate system, must be valid
49  * @param right The object points define in the 'right' coordinate system, one for each object point in the 'left' coordinate system, must be valid
50  * @param correspondences Number of point correspondences, with range [3, infinity)
51  * @param right_T_left Resulting transformation between left and right points, with no scaling.
52  * @param scaleErrorType The error type to use for the scale computation
53  * @param scale If non-null, will be populated with the resulting scale. The caller may want to update the transformation as follows: right_T_left.applyScale(Vector3(*scale, *scale, *scale))
54  * @return True, if succeeded
55  */
56  static bool calculateTransformation(const Vector3* left, const Vector3* right, const size_t correspondences, HomogenousMatrix4& right_T_left, const ScaleErrorType scaleErrorType = ScaleErrorType::RightBiased, Scalar* scale = nullptr);
57 
58  /**
59  * Calculates the absolute transformation between two sets of 6-DOF transformations not containing outliers.
60  * The implementation follows "Comparing two sets of corresponding six degree of freedom data, Shah, 2011"<br>
61  * Beware: This function does not support outliers.
62  * @param leftWorld_T_transformations The individual transformations defined in the left world, must be valid
63  * @param rightWorld_T_transformations The idividual transformations defines in the right world, one for each transformation in the left world, must be valid
64  * @param correspondences The number of given transformation correspondences, with range [1, infinity)
65  * @param rightWorld_T_leftWorld The resulting transformation between the left world and the right world
66  * @param scaleErrorType The error type to use for the scale computation
67  * @param scale If non-null, will be populated with the resulting scale. The caller may want to update the transformation as follows: rightWorld_T_leftWorld.applyScale(Vector3(*scale, *scale, *scale))
68  * @return True, if succeeded
69  */
70  static bool calculateTransformation(const HomogenousMatrix4* leftWorld_T_transformations, const HomogenousMatrix4* rightWorld_T_transformations, const size_t correspondences, HomogenousMatrix4& rightWorld_T_leftWorld, const ScaleErrorType scaleErrorType = ScaleErrorType::RightBiased, Scalar* scale = nullptr);
71 
72  /**
73  * Calculates the absolute transformation between two sets of 6-DOF transformations which may contain outliers.
74  * The implementation follows "Comparing two sets of corresponding six degree of freedom data, Shah, 2011"<br>
75  * @param leftWorld_T_transformations The individual transformations defined in the left world, must be valid
76  * @param rightWorld_T_transformations The idividual transformations defines in the right world, one for each transformation in the left world, must be valid
77  * @param correspondences the number of given transformation correspondences, with range [1, infinity)
78  * @param rightWorld_T_leftWorld The resulting transformation between the left world and the right world
79  * @param inlierRate The rate of inlier in the given input data with range (0, 1)
80  * @param scaleErrorType The error type to use for the scale computation
81  * @param scale If non-null, will be populated with the resulting scale. The caller may want to update the transformation as follows: rightWorld_T_leftWorld.applyScale(Vector3(*scale, *scale, *scale))
82  * @return True, if succeeded
83  */
84  static bool calculateTransformationWithOutliers(const HomogenousMatrix4* leftWorld_T_transformations, const HomogenousMatrix4* rightWorld_T_transformations, const size_t correspondences, HomogenousMatrix4& rightWorld_T_leftWorld, const Scalar inlierRate = Scalar(0.75), const ScaleErrorType scaleErrorType = ScaleErrorType::RightBiased, Scalar* scale = nullptr);
85 
86  protected:
87 
88  /**
89  * Removes the outliers from the set of 6-DOF input transformations.
90  * @param leftWorld_T_transformations The individual transformations defined in the left world, must be valid
91  * @param rightWorld_T_transformations The idividual transformations defines in the right world, one for each transformation in the left world, must be valid
92  * @param correspondences the number of given transformation correspondences, with range [1, infinity)
93  * @param rightWorld_T_leftWorld The transformation between the left world and the right world
94  * @param leftWorld_T_subsetTransformations The resulting inlier transformations for 'leftWorld_T_transformations'
95  * @param rightWorld_T_subsetTransformations The resulting inlier transformations for 'rightWorld_T_transformations'
96  * @return True, if the input data contained some outliers; False, if the input data did not contain any outliers
97  */
98  static bool removeOutliers(const HomogenousMatrix4* leftWorld_T_transformations, const HomogenousMatrix4* rightWorld_T_transformations, const size_t correspondences, const HomogenousMatrix4& rightWorld_T_leftWorld, HomogenousMatrices4& leftWorld_T_subsetTransformations, HomogenousMatrices4& rightWorld_T_subsetTransformations);
99 };
100 
101 }
102 
103 }
104 
105 #endif // META_OCEAN_GEOMETRY_ABSOLUTE_TRANSFORMATION_H
This class provides functions determining the absolute transformation between two point sets.
Definition: AbsoluteTransformation.h:27
ScaleErrorType
Defines whether the error term for the scale calculation is in the space of right coordinate system,...
Definition: AbsoluteTransformation.h:34
static bool calculateTransformation(const HomogenousMatrix4 *leftWorld_T_transformations, const HomogenousMatrix4 *rightWorld_T_transformations, const size_t correspondences, HomogenousMatrix4 &rightWorld_T_leftWorld, const ScaleErrorType scaleErrorType=ScaleErrorType::RightBiased, Scalar *scale=nullptr)
Calculates the absolute transformation between two sets of 6-DOF transformations not containing outli...
static bool calculateTransformation(const Vector3 *left, const Vector3 *right, const size_t correspondences, HomogenousMatrix4 &right_T_left, const ScaleErrorType scaleErrorType=ScaleErrorType::RightBiased, Scalar *scale=nullptr)
Calculates the absolute transformation between two corresponding 3D point sets.
static bool calculateTransformationWithOutliers(const HomogenousMatrix4 *leftWorld_T_transformations, const HomogenousMatrix4 *rightWorld_T_transformations, const size_t correspondences, HomogenousMatrix4 &rightWorld_T_leftWorld, const Scalar inlierRate=Scalar(0.75), const ScaleErrorType scaleErrorType=ScaleErrorType::RightBiased, Scalar *scale=nullptr)
Calculates the absolute transformation between two sets of 6-DOF transformations which may contain ou...
static bool removeOutliers(const HomogenousMatrix4 *leftWorld_T_transformations, const HomogenousMatrix4 *rightWorld_T_transformations, const size_t correspondences, const HomogenousMatrix4 &rightWorld_T_leftWorld, HomogenousMatrices4 &leftWorld_T_subsetTransformations, HomogenousMatrices4 &rightWorld_T_subsetTransformations)
Removes the outliers from the set of 6-DOF input transformations.
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition: HomogenousMatrix4.h:73
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15