[C++][转载]pcl安装后测试代码

[C++][转载]pcl安装后测试代码,第1张

[C++][转载]pcl安装后测试代码

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main(int argc, char** argv)
{
    srand((unsigned int)time(NULL));
    pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
    // 创建点云数据
    cloud->width = 1000;
    cloud->height = 1;
    cloud->points.resize(cloud->width * cloud->height);
    for (size_t i = 0; i < cloud->points.size(); ++i)
    {
        cloud->points[i].x = 1024.0f * rand() / (RAND_MAX + 1.0f);
        cloud->points[i].y = 1024.0f * rand() / (RAND_MAX + 1.0f);
        cloud->points[i].z = 1024.0f * rand() / (RAND_MAX + 1.0f);
    }
    pcl::octree::OctreePointCloudSearch octree(0.1);
    octree.setInputCloud(cloud);
    octree.addPointsFromInputCloud();
    pcl::PointXYZ searchPoint;
    searchPoint.x = 1024.0f * rand() / (RAND_MAX + 1.0f);
    searchPoint.y = 1024.0f * rand() / (RAND_MAX + 1.0f);
    searchPoint.z = 1024.0f * rand() / (RAND_MAX + 1.0f);
    //半径内近邻搜索
    vectorpointIdxRadiusSearch;
    vectorpointRadiusSquaredDistance;
    float radius = 256.0f * rand() / (RAND_MAX + 1.0f);
    cout << "Neighbors within radius search at (" << searchPoint.x
        << " " << searchPoint.y
        << " " << searchPoint.z
        << ") with radius=" << radius << endl;
    if (octree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0)
    {
        for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
            cout << " " << cloud->points[pointIdxRadiusSearch[i]].x
            << " " << cloud->points[pointIdxRadiusSearch[i]].y
            << " " << cloud->points[pointIdxRadiusSearch[i]].z
            << " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << endl;
    }
    // 初始化点云可视化对象
    boost::shared_ptrviewer(new pcl::visualization::PCLVisualizer("显示点云"));
    viewer->setBackgroundColor(0, 0, 0); //设置背景颜色为黑色
    // 对点云着色可视化 (red).
    pcl::visualization::PointCloudColorHandlerCustomtarget_color(cloud, 255, 0, 0);
    viewer->addPointCloud(cloud, target_color, "target cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "target cloud");
    // 等待直到可视化窗口关闭
    while (!viewer->wasStopped())
    {
        viewer->spinonce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(1000));
    }
    return (0);
}
 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5155559.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存