YARP
Yet Another Robot Platform
Pcl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_PCL_PCL_H
10 #define YARP_PCL_PCL_H
11 
12 #include <pcl/io/pcd_io.h>
13 #include <yarp/sig/PointCloud.h>
14 
15 namespace yarp
16 {
17 namespace pcl
18 {
19 
26 template< class T1, class T2 >
27 inline bool toPCL(const yarp::sig::PointCloud< T1 > &yarpCloud, ::pcl::PointCloud< T2 > &pclCloud)
28 {
29  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::toPcl: T1 and T2 are incompatible");
30  pclCloud.points.resize(yarpCloud.size());
31  pclCloud.width = yarpCloud.width();
32  pclCloud.height = yarpCloud.height();
33  pclCloud.is_dense = yarpCloud.isDense();
34  memcpy((char*)& pclCloud.points.at(0), yarpCloud.getRawData(), yarpCloud.dataSizeBytes());
35  return true;
36 }
37 
44 template< class T1, class T2 >
45 inline bool fromPCL(const ::pcl::PointCloud< T1 > &pclCloud, yarp::sig::PointCloud< T2 > &yarpCloud)
46 {
47  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::fromPCL: T1 and T2 are incompatible");
48  yarpCloud.fromExternalPC((char*) &pclCloud(0,0), yarpCloud.getPointType(), pclCloud.width, pclCloud.height, pclCloud.is_dense);
49  return true;
50 }
51 
58 template< class T1, class T2 >
59 inline int savePCD(const std::string &file_name, const yarp::sig::PointCloud< T1 > &yarpCloud)
60 {
61  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::savePCD: T1 and T2 are incompatible");
62  ::pcl::PointCloud<T2> pclCloud(yarpCloud.width(), yarpCloud.height());
63  yarp::pcl::toPCL< T1, T2 >(yarpCloud, pclCloud);
64  return ::pcl::io::savePCDFile(file_name, pclCloud);
65 }
66 
73 template< class T1, class T2 >
74 inline int loadPCD(const std::string &file_name, yarp::sig::PointCloud<T2> &yarpCloud)
75 {
76  static_assert(sizeof(T1) == sizeof(T2), "yarp::pcl::loadPCD: T1 and T2 are incompatible");
77  ::pcl::PointCloud<T1> pclCloud;
78  int ret = ::pcl::io::loadPCDFile(file_name, pclCloud);
79  yarp::pcl::fromPCL< T1, T2 >(pclCloud, yarpCloud);
80  return ret;
81 }
82 
83 } // namespace pcl
84 } // namespace yarp
85 
86 
87 #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:27
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:236
const char * getRawData() const override
Get the pointer to the data.
Definition: PointCloud.h:85
size_t dataSizeBytes() const override
Get the size of the data in terms of number of bytes.
Definition: PointCloud.h:105
size_t size() const override
Definition: PointCloud.h:110
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:45
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:74
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:59
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:27
The main, catch-all namespace for YARP.
Definition: environment.h:25