YARP
Yet Another Robot Platform
Pcl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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
yarp::sig::PointCloud::fromExternalPC
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
yarp::sig::PointCloudBase::getPointType
virtual int getPointType() const
Definition: PointCloudBase.cpp:102
yarp::sig::PointCloudBase::isDense
virtual bool isDense() const
Definition: PointCloudBase.h:90
yarp::sig::PointCloud::size
size_t size() const override
Definition: PointCloud.h:110
PointCloud.h
yarp::sig::PointCloud::dataSizeBytes
size_t dataSizeBytes() const override
Get the size of the data in terms of number of bytes.
Definition: PointCloud.h:105
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::pcl::loadPCD
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
yarp::sig::PointCloud::getRawData
const char * getRawData() const override
Get the pointer to the data.
Definition: PointCloud.h:85
yarp::pcl::fromPCL
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
yarp::sig::PointCloud
The PointCloud class.
Definition: PointCloud.h:27
yarp::pcl::savePCD
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
yarp::sig::PointCloudBase::height
virtual size_t height() const
Definition: PointCloudBase.cpp:92
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::pcl::toPCL
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
yarp::sig::PointCloudBase::width
virtual size_t width() const
Definition: PointCloudBase.cpp:97