Ocean
Normalization.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_NORMALIZATION_H
9 #define META_OCEAN_GEOMETRY_NORMALIZATION_H
10 
12 
14 
15 namespace Ocean
16 {
17 
18 namespace Geometry
19 {
20 
21 /**
22  * This class implements functions to normalize geometric data.
23  * @ingroup geometry
24  */
25 class OCEAN_GEOMETRY_EXPORT Normalization
26 {
27  public:
28 
29  /**
30  * Normalizes the given 2D image points so that the root of the mean square distance of the normalized 2D points to the origin is equal to sqrt(2).
31  * This function will return the identity transformation if no normalization can be determined.
32  * @param points The 2D points to normalize, can be invalid if 'number == 0'
33  * @param number The number of points to be normalized, with range [0, infinity)
34  * @param points_T_normalizedPoints Optional resulting transformation allowing to transform the normalized image points back to not-normalized image points
35  * @return The transformation matrix which was used to normalize the image points, will be normalizedPoints_T_points
36  */
37  static SquareMatrix3 calculateNormalizedPoints(Vector2* points, const size_t number, SquareMatrix3* points_T_normalizedPoints = nullptr);
38 
39  /**
40  * Normalizes a given 3x3 transformation matrix which is defined up to a scale factor forcing a 1 in the lower right matrix corner after normalization.
41  * @param transformation The transformation to normalize, with lower right corner not zero
42  * @return The resulting normalized transformation
43  * @tparam T The data type of the scalar to be used, either 'float' or 'double'
44  */
45  template <typename T>
46  static SquareMatrixT3<T> normalizedTransformation(const SquareMatrixT3<T>& transformation);
47 
48  /**
49  * Normalizes a given 3x3 transformation matrix which is defined up to a scale factor forcing a 1 in the lower right matrix corner after normalization.
50  * @param transformation The transformation to normalize, with lower right corner not zero
51  * @tparam T The data type of the scalar to be used, either 'float' or 'double'
52  */
53  template <typename T>
54  static void normalizeTransformation(SquareMatrixT3<T>& transformation);
55 };
56 
57 template <typename T>
59 {
60  ocean_assert(NumericT<T>::isNotEqualEps(transformation[8]));
61 
62  if (NumericT<T>::isNotEqualEps(transformation[8]))
63  {
64  const T factor = T(1) / transformation[8];
65 
66  return SquareMatrixT3<T>(transformation[0] * factor, transformation[1] * factor, transformation[2] * factor,
67  transformation[3] * factor, transformation[4] * factor, transformation[5] * factor,
68  transformation[6] * factor, transformation[7] * factor, 1);
69  }
70 
71  return transformation;
72 }
73 
74 template <typename T>
76 {
77  ocean_assert(NumericT<T>::isNotEqualEps(transformation[8]));
78 
79  if (NumericT<T>::isNotEqualEps(transformation[8]))
80  {
81  transformation *= T(1) / transformation[8];
82  }
83 }
84 
85 }
86 
87 }
88 
89 #endif // META_OCEAN_GEOMETRY_NORMALIZATION_H
This class implements functions to normalize geometric data.
Definition: Normalization.h:26
static SquareMatrix3 calculateNormalizedPoints(Vector2 *points, const size_t number, SquareMatrix3 *points_T_normalizedPoints=nullptr)
Normalizes the given 2D image points so that the root of the mean square distance of the normalized 2...
static void normalizeTransformation(SquareMatrixT3< T > &transformation)
Normalizes a given 3x3 transformation matrix which is defined up to a scale factor forcing a 1 in the...
Definition: Normalization.h:75
static SquareMatrixT3< T > normalizedTransformation(const SquareMatrixT3< T > &transformation)
Normalizes a given 3x3 transformation matrix which is defined up to a scale factor forcing a 1 in the...
Definition: Normalization.h:58
This class provides basic numeric functionalities.
Definition: Numeric.h:57
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15