这段代码使用 PCL 库提取点云中的叶片索引,并将提取到的索引保存到一个向量中,方便后续处理。代码示例展示了如何遍历点云,提取叶片索引,并最终将它们保存到一个向量中。

pcl::PointIndices newIndices;
std::vector<pcl::PointIndices> newIndicesVector; // 保存提取到的叶片索引

for (const auto& cloud : clouds)//遍历每一条叶片
{
    for (const auto& point : *cloud)//遍历每一条叶片的所有点
    {
        // 访问当前点的坐标和颜色
        PointXYZRGB P1;
        P1.x = point.x;
        P1.y = point.y;
        P1.z = point.z;

        key1 = std::to_string(P1.x) + '_' + std::to_string(P1.y) + '_' + std::to_string(P1.z);
        if (sliceMap00.find(key1) != sliceMap00.end())
        {
            value = sliceMap00[key1].index;
            std::cout << "Key: " << key1 << ", Value: " << value << std::endl;
            newIndices.indices.insert(newIndices.indices.end(), value.indices.begin(), value.indices.end());
        }
    }

    // 将newIndices保存到新的索引
    newIndicesVector.push_back(newIndices);
    // 清空缓存的索引
    newIndices.indices.clear();
}

// 打印提取到的叶片索引
for (size_t i=0; i<newIndicesVector.size(); i++)
{
    std::cout << "New Indices " << i << ": ";
    for (const auto& index : newIndicesVector[i].indices)
    {
        std::cout << index << " ";
    }
    std::cout << std::endl;
}

这段代码在每次循环中,将提取到的叶片索引保存到newIndicesVector中,并在循环结束后打印出来。每次循环前清空newIndices.indices,以保证每一次循环得到的newIndices都是新的。

代码说明:

  1. 使用std::vector<pcl::PointIndices> newIndicesVector来保存提取到的叶片索引。
  2. 在每次循环遍历完一个叶片后,将当前newIndices添加到newIndicesVector中。
  3. 每次循环结束后,清空newIndices.indices,以便保存下一个叶片的索引。

使用场景:

这段代码可以用于将点云中提取的叶片索引进行保存和管理。例如,可以将newIndicesVector用于后续的点云分割、特征提取或其他处理。

扩展:

  1. 可以根据实际需求对sliceMap00的定义进行修改,以便提取不同的叶片索引。
  2. 可以将newIndicesVector保存到文件或数据库中,以便长期保存和使用。

总结:

这段代码实现了从 PCL 点云中提取叶片索引并保存到向量中的功能。通过使用向量,我们可以方便地管理提取到的索引,并在后续的处理中进行使用。


原文地址: https://www.cveoy.top/t/topic/pSET 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录