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