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