Visual Servoing Platform  version 3.6.1 under development (2024-12-07)
vpEigenConversion.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * ViSP <--> Eigen conversion.
32  */
33 
34 #ifndef VP_EIGEN_CONVERSION_H
35 #define VP_EIGEN_CONVERSION_H
36 
37 #include <visp3/core/vpConfig.h>
38 #ifdef VISP_HAVE_EIGEN3
39 #include <Eigen/Dense>
40 #endif
41 #include <visp3/core/vpMatrix.h>
42 
44 {
45 #ifdef VISP_HAVE_EIGEN3
46 /* Eigen to ViSP */
47 VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst);
48 
49 VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpHomogeneousMatrix &dst);
50 
51 template <typename Type>
52 void eigen2visp(const Eigen::Quaternion<Type> &src, vpQuaternionVector &dst)
53 {
54  dst.buildFrom(src.x(), src.y(), src.z(), src.w());
55 }
56 
57 template <typename Type>
58 void eigen2visp(const Eigen::AngleAxis<Type> &src, vpThetaUVector &dst)
59 {
60  const unsigned int val_2 = 2;
61  dst.buildFrom(src.angle() * src.axis()(0), src.angle() * src.axis()(1), src.angle() * src.axis()(val_2));
62 }
63 
64 VISP_EXPORT void eigen2visp(const Eigen::VectorXd &src, vpColVector &dst);
65 
66 VISP_EXPORT void eigen2visp(const Eigen::RowVectorXd &src, vpRowVector &dst);
67 
68 /* ViSP to Eigen */
69 template <typename Derived>
70 void visp2eigen(const vpMatrix &src, Eigen::MatrixBase<Derived> &dst)
71 {
72  dst = Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(src.data, src.getRows(),
73  src.getCols());
74 }
75 
76 template <typename Derived>
77 void visp2eigen(const vpHomogeneousMatrix &src, Eigen::MatrixBase<Derived> &dst)
78 {
79  dst = Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(src.data, src.getRows(),
80  src.getCols());
81 }
82 
83 template <typename Type>
84 void visp2eigen(const vpQuaternionVector &src, Eigen::Quaternion<Type> &dst)
85 {
86  dst.w() = static_cast<Type>(src.w());
87  dst.x() = static_cast<Type>(src.x());
88  dst.y() = static_cast<Type>(src.y());
89  dst.z() = static_cast<Type>(src.z());
90 }
91 
92 template <typename Type>
93 void visp2eigen(const vpThetaUVector &src, Eigen::AngleAxis<Type> &dst)
94 {
95  const unsigned int index_0 = 0;
96  const unsigned int index_1 = 1;
97  const unsigned int index_2 = 2;
98  dst.angle() = static_cast<Type>(src.getTheta());
99  dst.axis()(index_0) = static_cast<Type>(src.getU()[index_0]);
100  dst.axis()(index_1) = static_cast<Type>(src.getU()[index_1]);
101  dst.axis()(index_2) = static_cast<Type>(src.getU()[index_2]);
102 }
103 
104 VISP_EXPORT void visp2eigen(const vpColVector &src, Eigen::VectorXd &dst);
105 
106 VISP_EXPORT void visp2eigen(const vpRowVector &src, Eigen::RowVectorXd &dst);
107 #endif
108 } // namespace VISP_NAMESPACE_NAME
109 #endif
unsigned int getCols() const
Definition: vpArray2D.h:337
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:148
unsigned int getRows() const
Definition: vpArray2D.h:347
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Implementation of a rotation vector as quaternion angle minimal representation.
const double & z() const
Returns the z-component of the quaternion.
vpQuaternionVector & buildFrom(const double &qx, const double &qy, const double &qz, const double &qw)
const double & x() const
Returns the x-component of the quaternion.
const double & y() const
Returns the y-component of the quaternion.
const double & w() const
Returns the w-component of the quaternion.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:124
Implementation of a rotation vector as axis-angle minimal representation.
vpColVector getU() const
vpThetaUVector & buildFrom(const vpHomogeneousMatrix &M)
double getTheta() const
VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst)
void visp2eigen(const vpMatrix &src, Eigen::MatrixBase< Derived > &dst)