8#include <RobotsIO/Utils/TransformYarpPort.h>
10#include <opencv2/core/eigen.hpp>
12#include <yarp/cv/Cv.h>
13#include <yarp/eigen/Eigen.h>
14#include <yarp/sig/Vector.h>
17using namespace RobotsIO::Utils;
18using namespace yarp::cv;
19using namespace yarp::eigen;
20using namespace yarp::sig;
25 rgb_out_(port_prefix +
"/rgb:o"),
26 depth_segmentation_out_(port_prefix +
"/depth_segmentation:o"),
27 provide_rgb_(provide_rgb),
28 provide_depth_segmentation_(provide_depth_segmentation)
32TransformYarpPort:: ~TransformYarpPort()
36Eigen::Transform<double, 3, Affine> TransformYarpPort::transform()
48bool TransformYarpPort::freeze(
const bool blocking)
50 yarp::sig::Vector* data_yarp = receive_data(blocking);
51 transform_received_ = (data_yarp !=
nullptr);
53 if (!transform_received_)
56 bool invalid_pose =
true;
57 for (std::size_t i = 0; i < 7; i++)
58 invalid_pose &= ((*data_yarp)(i) == 0.0);
62 transform_ = Translation<double, 3>(toEigen(*data_yarp).head<3>());
63 AngleAxisd rotation((*data_yarp)(6), toEigen(*data_yarp).segment<3>(3));
64 transform_.rotate(rotation);
67 if (data_yarp->size() > 7)
71 if (data_yarp->size() == (7 + 6 + 8 * 3))
73 else if (data_yarp->size() == (7 + 8 * 3))
76 throw(std::runtime_error(log_name_ +
"::freeze(). Error: the data stream carries a wrong number of items"));
78 Eigen::VectorXd bbox_points_data = toEigen(*data_yarp).segment<24>(offset);
79 bbox_points_.resize(3, 8);
80 for (std::size_t i = 0; i < 8; i++)
81 bbox_points_.col(i) = bbox_points_data.segment<3>(3 * i);
99 cv_rgb_out_ = image.clone();
100 yarp_rgb_out_ = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(cv_rgb_out_);
102 rgb_out_.send_data(yarp_rgb_out_);
108 if (!provide_depth_segmentation_)
112 cv::eigen2cv(depth, depth_temp);
113 cv_depth_out_ = depth_temp.clone();
119 cv_segmentation_out_ = segmentation.clone();
121 yarp_depth_segmentation_out_.image_mono = yarp::cv::fromCvMat<PixelMono>(cv_segmentation_out_);
122 yarp_depth_segmentation_out_.image_float = yarp::cv::fromCvMat<PixelFloat>(cv_depth_out_);
124 depth_segmentation_out_.send_data(yarp_depth_segmentation_out_);
130 return transform_received_;