基于pcl库遍历出pclPointIndices newIndices1;内的数据的c++代码
以下是基于pcl库遍历出pcl::PointIndices newIndices1内的数据的C++代码示例:
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/point_indices.h>
int main()
{
// 创建一个点云数据
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->width = 100;
cloud->height = 1;
cloud->points.resize(cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size(); ++i)
{
cloud->points[i].x = static_cast<float>(i);
cloud->points[i].y = static_cast<float>(i);
cloud->points[i].z = static_cast<float>(i);
}
// 创建一个PointIndices对象并添加一些索引
pcl::PointIndices newIndices1;
newIndices1.indices.push_back(1);
newIndices1.indices.push_back(3);
newIndices1.indices.push_back(5);
// 遍历newIndices1内的索引并输出对应的点坐标
for (size_t i = 0; i < newIndices1.indices.size(); ++i)
{
int index = newIndices1.indices[i];
pcl::PointXYZ point = cloud->points[index];
std::cout << "Point at index " << index << ": (" << point.x << ", " << point.y << ", " << point.z << ")" << std::endl;
}
return 0;
}
这段代码首先创建了一个点云数据,然后创建了一个pcl::PointIndices对象newIndices1,并向其中添加了一些索引。接下来,代码遍历了newIndices1内的索引,并根据索引获取对应的点坐标,并输出到控制台
原文地址: https://www.cveoy.top/t/topic/iij7 著作权归作者所有。请勿转载和采集!