GCC Code Coverage Report


Directory: ./
File: libs/geometry/eigen/helper.hpp
Date: 2024-04-24 14:25:45
Exec Total Coverage
Lines: 6 6 100.0%
Branches: 4 4 100.0%

Line Branch Exec Source
1 /************************************************************************
2 *
3 * Copyright (C) 2017-2024 IRCAD France
4 * Copyright (C) 2017-2018 IHU Strasbourg
5 *
6 * This file is part of Sight.
7 *
8 * Sight is free software: you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Sight is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
20 *
21 ***********************************************************************/
22
23 #pragma once
24
25 #include <sight/geometry/eigen/config.hpp>
26
27 #include <data/matrix4.hpp>
28
29 #include <Eigen/Core>
30
31 namespace sight::geometry::eigen::helper
32 {
33
34 /**
35 * @brief rvec_tvec_t is a std::pair of Eigen::Vector3d that handles Rotation and Translation Vectors (Rvec, Tvec)
36 * The first element is the rotation vector (Rvec)
37 * The second element is the translation vector (Tvec)
38 */
39 using rvec_tvec_t = std::pair<Eigen::Vector3d, Eigen::Vector3d>;
40 using EigenMatrix = Eigen::Matrix<double, 4, 4, Eigen::RowMajor>;
41 /**
42 * @brief Convert from an Eigen float 4x4 Matrix to a data::matrix4
43 * @param _mat : the eigen matrix
44 * @return a pointer to a data::matrix4
45 */
46 SIGHT_GEOMETRY_EIGEN_API data::matrix4::sptr from_eigen(const Eigen::Matrix4f& _mat);
47
48 /**
49 * @brief Convert from an Eigen double 4x4 Matrix to a data::matrix4
50 * @param _mat : the eigen matrix
51 * @return a pointer to a data::matrix4
52 */
53 SIGHT_GEOMETRY_EIGEN_API data::matrix4::sptr from_eigen(const Eigen::Matrix4d& _mat);
54
55 /**
56 * @brief Transform a eigen 4x4 matrix to a rvec tvec representation
57 * @param _mat : input matrix
58 * @return std::pair of Eigen::Vector3d (see rvec_tvec_t)
59 */
60 SIGHT_GEOMETRY_EIGEN_API rvec_tvec_t eigen_mat_to_rvec_tvec(const Eigen::Matrix4d& _mat);
61
62 /**
63 * @brief Transform rvec tvec representation to a eigen 4x4 matrix
64 * @param _mat : input data::matrix4
65 * @return std::pair of Eigen::Vector3d (see rvec_tvec_t)
66 */
67 SIGHT_GEOMETRY_EIGEN_API rvec_tvec_t f4s_mat_to_rvec_tvec(const data::matrix4::csptr _mat);
68 /**
69 * @brief toEigen
70 * @param _farray of float (16 values)
71 * @return eigen Matrix (double)
72 */
73 SIGHT_GEOMETRY_EIGEN_API EigenMatrix to_eigen(const std::array<float, 16>& _farray);
74
75 /**
76 * @brief toEigen
77 * @param _farray of double (16 values)
78 * @return eigen Matrix (double)
79 */
80 SIGHT_GEOMETRY_EIGEN_API EigenMatrix to_eigen(const std::array<double, 16>& _farray);
81
82 /**
83 * @brief Transform rvec tvec representation to a eigen 4x4 matrix
84 * @param _farray input matrix
85 * @return std::pair of Eigen::Vector3d (see rvec_tvec_t)
86 */
87 SIGHT_GEOMETRY_EIGEN_API rvec_tvec_t float16_to_rvec_tvec(const std::array<float, 16>& _farray);
88
89 /**
90 * @brief Transform a data::matrix4::sptr to a eigen 4x4 matrix
91 * @param _trf input matrix to transform
92 * @return the corresponding eigen 4x4 matrix
93 */
94 template<class T = double>
95 82 Eigen::Matrix<T, 4, 4, Eigen::RowMajor> to_eigen(const data::matrix4::csptr _trf)
96 {
97 82 Eigen::Matrix<T, 4, 4> mat;
98
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 82 times.
410 for(unsigned int r = 0 ; r < 4 ; ++r)
99 {
100
2/2
✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 328 times.
1640 for(unsigned int c = 0 ; c < 4 ; ++c)
101 {
102 1312 mat(r, c) = static_cast<T>((*_trf)(r, c));
103 }
104 }
105
106 82 return mat;
107 }
108
109 } // namespace sight::geometry::eigen::helper
110