Как получить все точки из облака точек, находящиеся на поверхности данной сферы
У меня есть облако точек, состоящее из PointXYZRGB. Я определил сферу s
в трехмерном пространстве, следовательно, известны следующие вещи:
- Центр
o
сферыs
как(x, y, z)
- Радиус
r
сферыs
Я хочу получить все точки этого облака точек, которое находится на поверхности данной сферы.
std::vector<PointXYZRGB> getAllSurfacePoints(
pcl::PointCloud<pcl::PointXYZRGB> cloud){
}
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;
}