YARP
Yet Another Robot Platform
Pcl.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_PCL_PCL_H
7 #define YARP_PCL_PCL_H
8 
9 #include <pcl/io/pcd_io.h>
10 #include <yarp/sig/PointCloud.h>
11 
12 namespace yarp
13 {
14 namespace pcl
15 {
16 
23 template< class T1, class T2 >
24 inline bool toPCL(const yarp::sig::PointCloud< T1 > &yarpCloud, ::pcl::PointCloud< T2 > &pclCloud)
25 {
26  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::toPcl: T1 and T2 are incompatible");
27  pclCloud.points.resize(yarpCloud.size());
28  pclCloud.width = yarpCloud.width();
29  pclCloud.height = yarpCloud.height();
30  pclCloud.is_dense = yarpCloud.isDense();
31  memcpy((char*)& pclCloud.points.at(0), yarpCloud.getRawData(), yarpCloud.dataSizeBytes());
32  return true;
33 }
34 
41 template< class T1, class T2 >
42 inline bool fromPCL(const ::pcl::PointCloud< T1 > &pclCloud, yarp::sig::PointCloud< T2 > &yarpCloud)
43 {
44  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::fromPCL: T1 and T2 are incompatible");
45  yarpCloud.fromExternalPC((char*) &pclCloud(0,0), yarpCloud.getPointType(), pclCloud.width, pclCloud.height, pclCloud.is_dense);
46  return true;
47 }
48 
55 template< class T1, class T2 >
56 inline int savePCD(const std::string &file_name, const yarp::sig::PointCloud< T1 > &yarpCloud)
57 {
58  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::savePCD: T1 and T2 are incompatible");
59  ::pcl::PointCloud<T2> pclCloud(yarpCloud.width(), yarpCloud.height());
60  yarp::pcl::toPCL< T1, T2 >(yarpCloud, pclCloud);
61  return ::pcl::io::savePCDFile(file_name, pclCloud);
62 }
63 
70 template< class T1, class T2 >
71 inline int loadPCD(const std::string &file_name, yarp::sig::PointCloud<T2> &yarpCloud)
72 {
73  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::loadPCD: T1 and T2 are incompatible");
74  ::pcl::PointCloud<T1> pclCloud;
75  int ret = ::pcl::io::loadPCDFile(file_name, pclCloud);
76  yarp::pcl::fromPCL< T1, T2 >(pclCloud, yarpCloud);
77  return ret;
78 }
79 
80 } // namespace pcl
81 } // namespace yarp
82 
83 
84 #endif
bool ret
virtual size_t width() const
virtual bool isDense() const
virtual int getPointType() const
virtual size_t height() const
The PointCloud class.
Definition: PointCloud.h:24
virtual void fromExternalPC(const char *source, int type, size_t width, size_t height, bool isDense=true)
Copy the content of an external PointCloud.
Definition: PointCloud.h:233
const char * getRawData() const override
Get the pointer to the data.
Definition: PointCloud.h:82
size_t dataSizeBytes() const override
Get the size of the data in terms of number of bytes.
Definition: PointCloud.h:102
size_t size() const override
Definition: PointCloud.h:107
bool fromPCL(const ::pcl::PointCloud< T1 > &pclCloud, yarp::sig::PointCloud< T2 > &yarpCloud)
Convert a pcl::PointCloud to a yarp::sig::PointCloud object.
Definition: Pcl.h:42
int loadPCD(const std::string &file_name, yarp::sig::PointCloud< T2 > &yarpCloud)
Load a yarp::sig::PointCloud from a PCD file, ASCII format.
Definition: Pcl.h:71
int savePCD(const std::string &file_name, const yarp::sig::PointCloud< T1 > &yarpCloud)
Save a yarp::sig::PointCloud to PCD file, ASCII format.
Definition: Pcl.h:56
bool toPCL(const yarp::sig::PointCloud< T1 > &yarpCloud, ::pcl::PointCloud< T2 > &pclCloud)
Convert a yarp::sig::PointCloud to a pcl::PointCloud object.
Definition: Pcl.h:24
The main, catch-all namespace for YARP.
Definition: dirs.h:16