#include 赞 踩 先看下效果,文章末尾后面有源码下载路径 源码下载地址:https://download.csdn.net/download/aoxuestudy/13966344 Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。
PointCloudLibrary点云库加载pcd文件_point cloud library android
PointCloudLibrary点云库加载pcd文件
// pclCloud_viewer_71.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <iostream>
#include <pcl/point_types.h>
#include <pcl/io/ply_io.h>
#include <pcl/visualization/pcl_visualizer.h>
using namespace std;
using namespace pcl;
using namespace io;
int user_data;
void
viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor(0.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere(o, 0.25, "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::io::loadPCDFile("E:\\PointCloudLibrary\\testSrc\\1 cloud_viewer\\build\\map.pcd", *cloud);
//pcl::io::loadPCDFile("map.pcd", *cloud);
pcl::io::loadPCDFile("E:\\PointCloudLibrary\\testSrc\\1 cloud_viewer\\source\\maize.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;
//改变粒子颜色
PointCloud<PointXYZ>::Ptr cloud(new PointCloud<PointXYZ>);
pcl::io::loadPCDFile("maize.pcd", *cloud);
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud, 0, 255, 255); // green
viewer->addPointCloud<pcl::PointXYZ>(cloud, single_color, "sample cloud");
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
/*boost::this_thread::sleep(boost::posix_time::microseconds(100000));*/
std::this_thread::sleep_for(std::chrono::milliseconds(30));
}
return 0;
}