一、简单的cloudviewer
#include<pcl/visualiization/cloud_viewer.h>
void foo()
{
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
pcl::visualization::CloudViewer viewer(“Simple Cloud Viewer”);
viewer.showCloud(cloud);
while(!viewer.wasStopped())
{
}
#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(125,0,255);
pcl::PointXYZ o;
o.x=0;
o.y=0;
o.z=0;
viewer.addSphere(o,0.5,12,13,24,"sphere",0); //添加球体
// viewer.addText("Radius:0.5",0.4,0.3,1.0,2,3,"wtjtest");
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);
user_data++;
}
int main()
{
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile("data/1.pcd", *cloud);
pcl::visualization::CloudViewer viewer("Cloud Viewer");
viewer.showCloud(cloud);
viewer.runOnVisualizationThreadOnce(viewerOneOff);
viewer.runOnVisualizationThread(viewerPsycho);
while(!viewer.wasStopped())
{
user_data++;
}
return 0;
}
#include <iostream>
#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>
// --------------
// -----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<pcl::visualization::PCLVisualizer> simpleVis (pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud)
{
// --------------------------------------------
// -----Open 3D viewer and add point cloud-----
// --------------------------------------------
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
//创建视窗对象并给标题(3D viewer),将它定义为boost::shared_ptr 智能共享指针,可以保证该指针在整个程序全局使用,而不引起内存错误。
viewer->setBackgroundColor (12,13,24);
//设置背景色
viewer->addPointCloud<pcl::PointXYZ> (cloud, "sample cloud");
//important,将点云添加到视窗对象,并定义唯一的ID号,如更新点云的ID号,先调用removePointCloud(),并提供需要更新的点云的ID号
viewer->setPointC