我有一个由PointXYZRGB组成的点云。我在3D空间中定义了一个球体s
,因此知道了以下内容 -
o
范围s
作为(x, y, z)
r
s
醇>
我希望得到这个点云的所有点,它位于给定球体的表面上。
std::vector<PointXYZRGB> getAllSurfacePoints(
pcl::PointCloud<pcl::PointXYZRGB> cloud){
}
答案 0 :(得分:1)
尝试调用此函数一次以删除内部点,然后再次删除外部点。
pcl::PointCloud<pcl::PointXYZI>::Ptr
passThroughFilterSphere(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud,
pcl::PointXYZI sphereCenterPoint, const double radius, bool remove_outside)
{
pcl::PointCloud<pcl::PointXYZI>::Ptr filteredCloud(new pcl::PointCloud<pcl::PointXYZI>);
float distanceFromSphereCenterPoint;
bool pointIsWithinSphere;
bool addPointToFilteredCloud;
for (int point_i = 0; point_i < cloud->size(); ++point_i)
{
distanceFromSphereCenterPoint = pcl::euclideanDistance(cloud->at(point_i), sphereCenterPoint);
pointIsWithinSphere = distanceFromSphereCenterPoint <= radius;
addPointToFilteredCloud = (!pointIsWithinSphere && remove_outside) || (pointIsWithinSphere && !remove_outside);
if (addPointToFilteredCloud){
filteredCloud->push_back(cloud->at(point_i));
}
}
return filteredCloud;
}