Visual Servoing Platform version 3.5.0
vpEigenConversion.cpp
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
37#include <visp3/core/vpEigenConversion.h>
38
39namespace vp {
40#ifdef VISP_HAVE_EIGEN3
41/* Eigen to ViSP */
42void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst)
43{
44 dst.resize(static_cast<unsigned int>(src.rows()), static_cast<unsigned int>(src.cols()), false, false);
45 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(&dst.data[0], src.rows(), src.cols()) = src;
46}
47
48void eigen2visp(const Eigen::MatrixXd &src, vpHomogeneousMatrix &dst)
49{
50 if (src.rows() != 4 || src.cols() != 4) {
51 throw vpException(vpException::dimensionError, "Input Eigen Matrix must be of size (4,4)!");
52 }
53
54 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(&dst.data[0], src.rows(), src.cols()) = src;
55}
56
57void eigen2visp(const Eigen::VectorXd &src, vpColVector &dst)
58{
59 dst.resize(static_cast<unsigned int>(src.rows()));
60#if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300)
61 for (Eigen::DenseIndex i = 0; i < src.rows(); i++) {
62#else
63 for (Eigen::Index i = 0; i < src.rows(); i++) {
64#endif
65 dst[static_cast<unsigned int>(i)] = src(i);
66 }
67}
68
69void eigen2visp(const Eigen::RowVectorXd &src, vpRowVector &dst)
70{
71 dst.resize(static_cast<unsigned int>(src.cols()));
72#if (VP_VERSION_INT(EIGEN_WORLD_VERSION, EIGEN_MAJOR_VERSION, EIGEN_MINOR_VERSION) < 0x030300)
73 for (Eigen::DenseIndex i = 0; i < src.cols(); i++) {
74#else
75 for (Eigen::Index i = 0; i < src.cols(); i++) {
76#endif
77 dst[static_cast<unsigned int>(i)] = src(i);
78 }
79}
80
81void visp2eigen(const vpColVector &src, Eigen::VectorXd &dst)
82{
83 dst = Eigen::VectorXd::Map(src.data, src.size());
84}
85
86void visp2eigen(const vpRowVector &src, Eigen::RowVectorXd &dst)
87{
88 dst = Eigen::RowVectorXd::Map(src.data, src.size());
89}
90#endif
91}
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:145
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition: vpArray2D.h:304
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:291
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:310
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ dimensionError
Bad dimension.
Definition: vpException.h:95
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:154
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:116
void resize(unsigned int i, bool flagNullify=true)
Definition: vpRowVector.h:271
void visp2eigen(const vpMatrix &src, Eigen::MatrixBase< Derived > &dst)
VISP_EXPORT void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst)