RobotsIO
Loading...
Searching...
No Matches
YarpVectorOfProbe.cpp
1/*
2 * Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This software may be modified and distributed under the terms of the
5 * BSD 3-Clause license. See the accompanying LICENSE file for details.
6 */
7
8#include <RobotsIO/Utils/YarpVectorOfProbe.hpp>
9
10using namespace RobotsIO::Utils;
11
12
13template <>
14yarp::sig::VectorOf<double> RobotsIO::Utils::YarpVectorOfProbe<double, Eigen::VectorXd>::convert_from(const Eigen::VectorXd& data)
15{
16 yarp::sig::VectorOf<double> tmp(data.size());
17 yarp::eigen::toEigen(tmp) = data;
18
19 return tmp;
20}
21
22
23template <>
24yarp::sig::VectorOf<double> RobotsIO::Utils::YarpVectorOfProbe<double, Eigen::Transform<double, 3, Eigen::Affine>>::convert_from(const Eigen::Transform<double, 3, Eigen::Affine>& data)
25{
26 /* Assume by default transformation to x-y-z-axis-angle. */
27 yarp::sig::VectorOf<double> tmp(7);
28 yarp::eigen::toEigen(tmp).head<3>() = data.translation();
29
30 Eigen::AngleAxisd axis_angle(data.rotation());
31 yarp::eigen::toEigen(tmp).segment<3>(3) = axis_angle.axis();
32 yarp::eigen::toEigen(tmp)(6) = axis_angle.angle();
33
34 return tmp;
35}
36
37
38template <>
40{
41 /* Assume by default transformation to x-y-z-axis-angle. */
42 yarp::sig::VectorOf<double> tmp(13);
43 yarp::eigen::toEigen(tmp).head<3>() = data.transform.translation();
44
45 Eigen::AngleAxisd axis_angle(data.transform.rotation());
46 yarp::eigen::toEigen(tmp).segment<3>(3) = axis_angle.axis();
47 yarp::eigen::toEigen(tmp)(6) = axis_angle.angle();
48
49 yarp::eigen::toEigen(tmp).segment<3>(7) = data.linear_velocity;
50 yarp::eigen::toEigen(tmp).tail<3>() = data.angular_velocity;
51
52 return tmp;
53}
54
55template <>
56yarp::sig::VectorOf<int> RobotsIO::Utils::YarpVectorOfProbe<int, cv::Rect>::convert_from(const cv::Rect& data)
57{
58 /* Assume by default a top_left x, top_left right, width, height data. */
59 yarp::sig::VectorOf<int> tmp(4);
60 tmp(0) = data.x;
61 tmp(1) = data.y;
62 tmp(2) = data.width;
63 tmp(3) = data.height;
64
65 return tmp;
66}