点云显示函数

来源:互联网 发布:武易传奇物品数据库 编辑:程序博客网 时间:2024/04/28 18:09

简单的显示方法:
//*******************************************************
//点云数据的简单显示代码
pcl::visualization::CloudViewer viewer(“Simple Cloud Viewer”);
viewer.showCloud(cl_model); //cl_model是需要显示的点云,定义为pcl::PointCloud::Ptr cl_model(new pcl::PointCloud);
while (!viewer.wasStopped())
{
}
//*******************************************************
//另一种点云显示方式
boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer(“PointsCloud Recognition”));
viewer->addPointCloud(cl_model, “model_cloud”);
viewer->addCoordinateSystem(1.0);
viewer->initCameraParameters();
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
//同一窗口显示多个不同的点云对象
boost::shared_ptr viewportsVis(
pcl::PointCloud::ConstPtr cloud1, pcl::PointCloud::ConstPtr cloud2)
{
// ——————————————————–
// —–Open 3D viewer and add point cloud and normals—–
// ——————————————————–
boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer(“3D Viewer”));
viewer->initCameraParameters();

int v1(0);viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);//创建左边的窗口viewer->setBackgroundColor(0, 0, 0, v1);//设置左边窗口的背景viewer->addText("Radius: 0.1", 10, 10, "v1 text", v1);pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color1(cloud1, 255, 0, 0);viewer->addPointCloud<pcl::PointXYZ>(cloud1, single_color1, "sample cloud1", v1);int v2(0);viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);//创建右边的窗口viewer->setBackgroundColor(0.0, 0.0, 0.0, v2);viewer->addText("Radius: 0.1", 10, 10, "v2 text", v2);pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud2, 0, 255, 0);viewer->addPointCloud<pcl::PointXYZ>(cloud2, single_color, "sample cloud2", v2);viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud1");viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud2");viewer->addCoordinateSystem(1.0);//viewer->addPointCloudNormals<pcl::PointXYZRGB, pcl::Normal>(cloud, normals1, 10, 0.05, "normals1", v1);//viewer->addPointCloudNormals<pcl::PointXYZRGB, pcl::Normal>(cloud, normals2, 10, 0.05, "normals2", v2);return (viewer);

}

// ————–
// —–Help—–
// ————–
void
printUsage(const char* progName)
{
std::cout << “\n\nUsage: ” << progName << ” [options]\n\n”
<< “Options:\n”
<< “——————————————-\n”
<< “-h this help\n”
<< “-s Simple visualisation example\n”
<< “-r RGB colour visualisation example\n”
<< “-c Custom colour visualisation example\n”
<< “-n Normals visualisation example\n”
<< “-a Shapes visualisation example\n”
<< “-v Viewports example\n”
<< “-i Interaction Customization example\n”
<< “\n\n”;
}

boost::shared_ptr simpleVis(pcl::PointCloud::ConstPtr cloud)
{
// ——————————————–
// —–Open 3D viewer and add point cloud—–
// ——————————————–
//创建可视化对象viewer
boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer(“3D Viewer”));
//设置背景为黑色
viewer->setBackgroundColor(0, 0, 0);
//将要显示的点云添加到可视化对象中。
viewer->addPointCloud(cloud, “sample cloud”);
//渲染点云
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, “sample cloud”);
//添加坐标轴
viewer->addCoordinateSystem(1.0);
//初始化相机
viewer->initCameraParameters();
return (viewer);
}

boost::shared_ptr rgbVis(pcl::PointCloud::ConstPtr cloud)
{
// ——————————————–
// —–Open 3D viewer and add point cloud—–
// ——————————————–
boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer(“3D Viewer”));
viewer->setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerRGBField rgb(cloud);
viewer->addPointCloud(cloud, rgb, “sample cloud”);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, “sample cloud”);
viewer->addCoordinateSystem(1.0);
viewer->initCameraParameters();
return (viewer);
}

//
boost::shared_ptr customColourVis(pcl::PointCloud::ConstPtr cloud)
{
// ——————————————–
// —–Open 3D viewer and add point cloud—–
// ——————————————–
boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer(“3D Viewer”));
viewer->setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerCustom single_color(cloud, 0, 255, 0);
viewer->addPointCloud(cloud, single_color, “sample cloud”);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, “sample cloud”);
viewer->addCoordinateSystem(1.0);
viewer->initCameraParameters();
return (viewer);
}

//法线显示
boost::shared_ptr normalsVis(
pcl::PointCloud::ConstPtr cloud, pcl::PointCloud::ConstPtr normals)
{
// ——————————————————–
// —–Open 3D viewer and add point cloud and normals—–
// ——————————————————–
boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer(“3D Viewer”));
viewer->setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerRGBField rgb(cloud);
viewer->addPointCloud(cloud, rgb, “sample cloud”);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, “sample cloud”);
viewer->addPointCloudNormals

原创粉丝点击