Let's say I have two different ones pcl::PointCloud<pcl::PointXYZL>(although the point type really doesn't matter), c1and c2.
I would like to find the intersection of these two pointclouds. By intersection I mean a pointcloud interconstructed in such a way that a point pifrom is c1inserted into interif (and only if) there is a point pjin c2and
pi.x == pj.x && pi.y == pj.y && pi.z == pj.z
I am currently using the following functions for this:
using namespace pcl;
typedef PointXYZL PointLT;
typedef PointCloud<PointLT> PointLCloudT;
bool contains(PointLCloudT::Ptr c, PointLT p) {
PointLCloudT::iterator it = c->begin();
for (; it != c->end(); ++it) {
if (it->x == p.x && it->y == p.y && it->z == p.z)
return true;
}
return false;
}
PointLCloudT::Ptr intersection(PointLCloudT::Ptr c1,
PointLCloudT::Ptr c2) {
PointLCloudT::Ptr inter;
PointLCloudT::iterator it = c1->begin();
for (; it != c1->end(); ++it) {
if (contains(c2, *it))
inter->push_back(*it);
}
return inter;
}
I would like to know if there is a standard (and possibly more efficient) way to do this?
I did not find anything about this in the official documentation, but maybe I am missing something.
Thank.
source
share