3#ifndef __YARP_CLOUD_UTILS_PCL_HPP__
4#define __YARP_CLOUD_UTILS_PCL_HPP__
9#include <pcl/point_cloud.h>
10#include <pcl/point_types.h>
11#include <pcl/PolygonMesh.h>
12#include <pcl/common/io.h>
14#include "YarpCloudUtils-pcl-traits.hpp"
23 typename pcl::PointCloud<T>::ConstPtr getCloud()
const;
26 typename pcl::PointCloud<T>::Ptr & setCloud();
29 const typename pcl::PointCloud<T>::Ptr & useCloud()
const;
31 pcl::PolygonMesh::ConstPtr getMesh()
const;
33 pcl::PolygonMesh::Ptr & setMesh();
36 template <
typename T1,
typename T2>
37 static auto initializeCloudPointer(
const typename pcl::PointCloud<T1>::ConstPtr & in);
39 pcl::PointCloud<pcl::PointXYZ>::Ptr xyz;
40 pcl::PointCloud<pcl::PointXYZRGB>::Ptr xyz_rgb;
41 pcl::PointCloud<pcl::PointXYZI>::Ptr xyzi;
42 pcl::PointCloud<pcl::InterestPoint>::Ptr xyz_interest;
43 pcl::PointCloud<pcl::PointNormal>::Ptr xyz_normal;
44 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr xyz_rgb_normal;
45 pcl::PointCloud<pcl::PointXYZINormal>::Ptr xyzi_normal;
46 pcl::PolygonMesh::Ptr mesh;
51template <
typename T1,
typename T2>
52inline auto cloud_container::initializeCloudPointer(
const typename pcl::PointCloud<T1>::ConstPtr & in)
54 if constexpr (!std::is_same_v<T1, T2>)
56 if constexpr (!pcl_is_convertible<T1, T2>::value)
58 std::string name_lhs = pcl_descriptor<T1>::name;
59 std::string name_rhs = pcl_descriptor<T2>::name;
60 throw std::runtime_error(
"illegal conversion from " + name_lhs +
" to " + name_rhs);
63 auto out = pcl::make_shared<pcl::PointCloud<T2>>();
64 pcl::copyPointCloud(*in, *out);
76typename pcl::PointCloud<T>::ConstPtr cloud_container::getCloud()
const
80 return initializeCloudPointer<pcl::PointXYZ, T>(xyz);
84 return initializeCloudPointer<pcl::PointXYZRGB, T>(xyz_rgb);
88 return initializeCloudPointer<pcl::PointXYZI, T>(xyzi);
90 else if (xyz_interest)
92 return initializeCloudPointer<pcl::InterestPoint, T>(xyz_interest);
96 return initializeCloudPointer<pcl::PointNormal, T>(xyz_normal);
98 else if (xyz_rgb_normal)
100 return initializeCloudPointer<pcl::PointXYZRGBNormal, T>(xyz_rgb_normal);
102 else if (xyzi_normal)
104 return initializeCloudPointer<pcl::PointXYZINormal, T>(xyzi_normal);
108 throw std::runtime_error(
"cloud pointer was not initialized");
115pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud_container::setCloud<pcl::PointXYZ>()
117 xyz = pcl::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
122pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud_container::setCloud<pcl::PointXYZRGB>()
124 xyz_rgb = pcl::make_shared<pcl::PointCloud<pcl::PointXYZRGB>>();
129pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud_container::setCloud<pcl::PointXYZI>()
131 xyzi = pcl::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
136pcl::PointCloud<pcl::InterestPoint>::Ptr & cloud_container::setCloud<pcl::InterestPoint>()
138 xyz_interest = pcl::make_shared<pcl::PointCloud<pcl::InterestPoint>>();
143pcl::PointCloud<pcl::PointNormal>::Ptr & cloud_container::setCloud<pcl::PointNormal>()
145 xyz_normal = pcl::make_shared<pcl::PointCloud<pcl::PointNormal>>();
150pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud_container::setCloud<pcl::PointXYZRGBNormal>()
152 xyz_rgb_normal = pcl::make_shared<pcl::PointCloud<pcl::PointXYZRGBNormal>>();
153 return xyz_rgb_normal;
157pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud_container::setCloud<pcl::PointXYZINormal>()
159 xyzi_normal = pcl::make_shared<pcl::PointCloud<pcl::PointXYZINormal>>();
166const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud_container::useCloud<pcl::PointXYZ>()
const
172const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud_container::useCloud<pcl::PointXYZRGB>()
const
178const pcl::PointCloud<pcl::PointXYZI>::Ptr & cloud_container::useCloud<pcl::PointXYZI>()
const
184const pcl::PointCloud<pcl::InterestPoint>::Ptr & cloud_container::useCloud<pcl::InterestPoint>()
const
190const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud_container::useCloud<pcl::PointNormal>()
const
196const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud_container::useCloud<pcl::PointXYZRGBNormal>()
const
198 return xyz_rgb_normal;
202const pcl::PointCloud<pcl::PointXYZINormal>::Ptr & cloud_container::useCloud<pcl::PointXYZINormal>()
const
209inline pcl::PolygonMesh::ConstPtr cloud_container::getMesh()
const
217 throw std::runtime_error(
"mesh pointer was not initialized");
221inline pcl::PolygonMesh::Ptr & cloud_container::setMesh()
223 mesh = pcl::make_shared<pcl::PolygonMesh>();