自学内容网 自学内容网

Octree索引(体素近邻搜索,K近邻搜索,半径内近邻搜索)------PCL

体素近邻搜索

/// <summary>
/// octree 体素近邻搜索
/// </summary>
/// <param name="cloud">索引点云</param>
/// <param name="searchPoint">索引点</param>
/// <param name="resolution">分辨率</param>
/// <returns>返回所有点编号数组</returns>
std::vector<int> PclTool::octreeVoxelSearch(const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, const pcl::PointXYZ searchPoint, const float resolution)
{
    pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution);  // 初始化Octree
    octree.setInputCloud(cloud);        // 设置输入点云 
    octree.addPointsFromInputCloud();   // 构建octree
    std::vector<int> pointIdxVec;       // 存储体素近邻搜索结果向量
    if (octree.voxelSearch(searchPoint, pointIdxVec))  // 执行搜索
    {
        return pointIdxVec;
    }
    else
    {
        return std::vector<int>();
    }
}
  • 分辨率为:1
    在这里插入图片描述

k紧邻搜索

std::vector<int> PclTool::octreeKSearch(const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, const float resolution, const pcl::PointXYZ searchPoint, const unsigned int k)
{
    pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution);  // 初始化Octree
    octree.setInputCloud(cloud);          // 设置输入点云
    octree.addPointsFromInputCloud();     // 构建octree


    std::vector<int> pointIdxNKNSearch;          // 结果点的索引的向量
    std::vector<float> pointNKNSquaredDistance;  // 搜索点与近邻之间的距离的平方

    if (octree.nearestKSearch(searchPoint, k, pointIdxNKNSearch, pointNKNSquaredDistance) > 0)
    {
        return pointIdxNKNSearch;
    }
    else
    {
        return std::vector<int>();
    }

}

在这里插入图片描述

半径内近邻搜索

std::vector<int> PclTool::octreeRadiusSearch(const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, const float resolution, const pcl::PointXYZ searchPoint, const float radius)
{
    pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution);  // 初始化Octree
    octree.setInputCloud(cloud);         // 设置输入点云
    octree.addPointsFromInputCloud();    // 构建octree

    std::vector<int> pointIdxRadiusSearch;
    std::vector<float> pointRadiusSquaredDistance;

    if (octree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0)
    {
        return pointIdxRadiusSearch;
    }
    else
    {
        return std::vector<int>();
    }
}

在这里插入图片描述


原文地址:https://blog.csdn.net/mankeywang/article/details/137728164

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!