赞
踩
首先保证你的文件夹下有三个文件cloud_viewer.cpp、CMakeLists.txt、my_point_cloud.pcd
1、Cloud_Viewer.cpp代码:
- #include <vtkAutoInit.h>
- VTK_MODULE_INIT(vtkRenderingOpenGL);
- VTK_MODULE_INIT(vtkInteractionStyle);
- VTK_MODULE_INIT(vtkRenderingFreeType);
-
- #include <pcl/visualization/cloud_viewer.h>
- #include <iostream>
- #include <pcl/io/io.h>
- #include <pcl/io/pcd_io.h>
-
- int user_data;
- void
- viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
- {
- viewer.setBackgroundColor (1.0f, 0.5f, 1.0f);
- pcl::PointXYZ o;
- o.x = 0;
- o.y = 0;
- o.z = 0;
- viewer.addSphere (o, 0.2, "sphere", 0);
- std::cout << "i only run once" << std::endl;
- }
-
- void
- viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
- {
- static unsigned count = 0;
- std::stringstream ss;
- ss << "Once per viewer loop: " << count++;
- viewer.removeShape ("text", 0);
- viewer.addText (ss.str(), 200, 300, "text", 0);
- //FIXME: possible race condition here:
- user_data++;
- }
-
- int
- main ()
- {
- pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
- pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud);
- pcl::visualization::CloudViewer viewer("Cloud Viewer");
- //showCloud函数是同步的,在此处等待直到渲染显示为止
- viewer.showCloud(cloud);
- //该注册函数在可视化时只调用一次
- viewer.runOnVisualizationThreadOnce (viewerOneOff);
- //该注册函数在渲染输出时每次都调用
- viewer.runOnVisualizationThread (viewerPsycho);
- while (!viewer.wasStopped ())
- {
- //在此处可以添加其他处理
- user_data++;
- }
- return 0;
- }
2、CMakeLists.txt文件
- cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
- project(cloud_viewer)
- find_package(PCL 1.2 REQUIRED)
- include_directories(${PCL_INCLUDE_DIRS})
- link_directories(${PCL_LIBRARY_DIRS})
- add_definitions(${PCL_DEFINITIONS})
- add_executable (cloud_viewer cloud_viewer.cpp)
- target_link_libraries (cloud_viewer ${PCL_LIBRARIES})
3、执行显示
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。