3 #ifndef __KINECT_FUSION_IMPL_HPP__
4 #define __KINECT_FUSION_IMPL_HPP__
6 #include "KinectFusion.hpp"
11 #include <yarp/os/LogStream.h>
12 #include <yarp/cv/Cv.h>
14 #include "LogComponent.hpp"
25 cv::setUseOptimized(
true);
28 void getCloud(yarp::sig::PointCloudXYZNormalRGBA & cloudWithNormals)
const override
30 cv::UMat points, normals;
33 handle->getCloud(points, normals);
36 cv::Mat _points = points.getMat(cv::ACCESS_FAST);
37 cv::Mat _normals = normals.getMat(cv::ACCESS_FAST);
39 cloudWithNormals.resize(points.rows);
41 for (
auto i = 0; i < points.rows; i++)
43 const auto & point = _points.at<cv::Vec4f>(i);
44 const auto & normal = _normals.at<cv::Vec4f>(i);
45 cloudWithNormals(i) = {{point[0], point[1], point[2]}, {normal[0], normal[1], normal[2]}, 0};
49 void getPoints(yarp::sig::PointCloudXYZ & cloud)
const override
54 handle->getPoints(points);
57 cv::Mat _points = points.getMat(cv::ACCESS_FAST);
58 auto data =
const_cast<const char *
>(
reinterpret_cast<char *
>(_points.data));
60 cloud.fromExternalPC(data, yarp::sig::PointCloudBasicType::PC_XYZ_DATA, _points.rows, 1);
63 void getPose(yarp::sig::Matrix & pose)
const override
66 const auto & affine = handle->getPose().matrix;
71 for (
int i = 0; i < 4; i++)
73 for (
int j = 0; j < 4; j++)
75 pose(i, j) = affine(i, j);
80 bool update(
const yarp::sig::ImageOf<yarp::sig::PixelFloat> & depthFrame,
const yarp::sig::FlexImage & colorFrame)
override
84 auto & nonConstDepthFrame =
const_cast<yarp::sig::ImageOf<yarp::sig::PixelFloat> &
>(depthFrame);
85 cv::Mat mat = yarp::cv::toCvMat(nonConstDepthFrame);
88 mat.convertTo(umat, mat.type(), 1000.0);
90 std::lock_guard lock(mtx);
91 return handle->update(umat);
96 std::lock_guard lock(mtx);
100 void render(yarp::sig::FlexImage & image)
const override
105 handle->render(umat);
108 cv::Mat mat = umat.getMat(cv::ACCESS_FAST);
109 const auto & bgr = yarp::cv::fromCvMat<yarp::sig::PixelBgra>(mat);
115 mutable std::mutex mtx;
118 template <
typename T>
119 T getValue(
const yarp::os::Value & v)
121 if constexpr (std::is_integral_v<T>)
125 else if constexpr (std::is_floating_point_v<T>)
127 return v.asFloat64();
132 static_assert(!
sizeof(T),
"Unsupported type");
136 template <
typename TParams,
typename TRet>
137 void updateParam(TParams & params, TRet TParams::* param,
const yarp::os::Searchable & config,
138 const std::string & name,
const std::string & description)
140 auto && log = yCInfo(KINFU);
143 if (config.check(name, description))
145 params.*param = getValue<TRet>(config.find(name));
152 log << params.*param;
Definition: KinectFusionImpl.hpp:21
Definition: KinectFusion.hpp:18
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:5