Ocean
ToonUtilities.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_MATH_TOON_UTILITIES_H
9 #define META_OCEAN_MATH_TOON_UTILITIES_H
10 
12 
13 #include <TooN/TooN.h>
14 #include <TooN/se3.h>
15 
16 namespace Ocean
17 {
18 
19 /**
20  * This class implements utilitiy functions for TooN.
21  * @ingroup math
22  */
24 {
25  public:
26 
27  /**
28  * Converts a TooN::SE3 object to an Ocean HomogenousMatrix4 object.
29  * @param toonSE The TooN object to be converted
30  * @return The resulting Ocean object
31  * @tparam TSource The data type of the source matrix elements, e.g., 'float', or 'double'
32  * @tparam TTarget The data type of the target matrix elements, e.g., 'float', or 'double'
33  */
34  template <typename TSource, typename TTarget>
35  static inline HomogenousMatrixT4<TTarget> toHomogenousMatrix4(const TooN::SE3<TSource>& toonSE);
36 
37  /**
38  * Converts an Ocean HomogenousMatrix4 object to a TooN::SE3 object.
39  * @param matrix The Ocean object to convert
40  * @return The resulting TooN object
41  * @tparam TSource The data type of the source matrix elements, e.g., 'float', or 'double'
42  * @tparam TTarget The data type of the target matrix elements, e.g., 'float', or 'double'
43  */
44  template <typename TSource, typename TTarget>
45  static inline TooN::SE3<TTarget> toSE3(const HomogenousMatrixT4<TSource>& matrix);
46 };
47 
48 template <typename TSource, typename TTarget>
49 inline HomogenousMatrixT4<TTarget> ToonUtilities::toHomogenousMatrix4(const TooN::SE3<TSource>& toonSE)
50 {
51  const auto& translation = toonSE.get_translation();
52  const auto& rotationMatrix = toonSE.get_rotation().get_matrix();
53 
54  HomogenousMatrixT4<TTarget> result(true);
55 
56  for (unsigned int r = 0u; r < 3u; ++r)
57  {
58  for (unsigned int c = 0u; c < 3u; ++c)
59  {
60  result(r, c) = TTarget(rotationMatrix(r, c));
61  }
62  }
63 
64  result(0, 3) = TTarget(translation[0]);
65  result(1, 3) = TTarget(translation[1]);
66  result(2, 3) = TTarget(translation[2]);
67 
68  return result;
69 }
70 
71 template <typename TSource, typename TTarget>
72 inline TooN::SE3<TTarget> ToonUtilities::toSE3(const HomogenousMatrixT4<TSource>& matrix)
73 {
74  TooN::Matrix<3, 3, TTarget> toonRotationMatrix;
75 
76  for (unsigned int r = 0u; r < 3u; ++r)
77  {
78  for (unsigned int c = 0u; c < 3u; ++c)
79  {
80  toonRotationMatrix(r, c) = TTarget(matrix(r, c));
81  }
82  }
83 
84  const TooN::Vector<3, TTarget> toonTranslationVector = TooN::makeVector<TTarget>(TTarget(matrix(0, 3)), TTarget(matrix(1, 3)), TTarget(matrix(2, 3)));
85 
86  return TooN::SE3<TTarget>(TooN::SO3<TTarget>(toonRotationMatrix), toonTranslationVector);
87 }
88 
89 }
90 
91 #endif // META_OCEAN_MATH_TOON_UTILITIES_H
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition: HomogenousMatrix4.h:110
This class implements utilitiy functions for TooN.
Definition: ToonUtilities.h:24
static TooN::SE3< TTarget > toSE3(const HomogenousMatrixT4< TSource > &matrix)
Converts an Ocean HomogenousMatrix4 object to a TooN::SE3 object.
Definition: ToonUtilities.h:72
static HomogenousMatrixT4< TTarget > toHomogenousMatrix4(const TooN::SE3< TSource > &toonSE)
Converts a TooN::SE3 object to an Ocean HomogenousMatrix4 object.
Definition: ToonUtilities.h:49
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15