ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I am making two assumptions in answering this question:
pcl::PCLPointCloud2
data typeFor this, you have several options:
2 | No.2 Revision |
I am making two assumptions an assumption in answering this question:
Next, the answer depends on which "PointCloud2" datatype you are referring to. Both ROS
andTo
merge twopcl::PCLPointCloud2
data typeFor this, you have several options:
Source: pcl::PCLPointCloud2 Struct Reference
To merge two ROS sensor_msgs::PointCloud2 clouds, there aren't any pre-existing functions that will do this for you (unless I missed them) so you have to either convert the point cloud to a PCL type (plenty of online tutorials that will show you how to do that) or you have to do it yourself directly. In C++ this can be done as shown below:
Note: I am assuming here that you are using an unorganized point cloud, in which case the "width" is just the length of the 1D data array. Merging organised point clouds is very different and deserves its own Q&A.
// Merge metadata
MergedCloud.width += Cloud1.width;
// Re-size the merged data array to make space for the new points
uint64_t OriginalSize = MergedCloud.data.size();
MergedCloud.data.resize(MergedCloud.data.size() + Cloud1.data.size());
// Copy the new points from Cloud1 into the second half of the MergedCloud array
std::copy(
Cloud1.data.begin(),
Cloud1.data.end(),
MergedCloud.data.begin() + OriginalSize);