【学习记录】pcd文件可视化

#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>

//int user_data;
//Initialize the viewer including the backgroundcolor,coordinate axis,and others.
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
	//set the backgroundcolor:R,G,B
	viewer.setBackgroundColor(1.0, 1.0, 1.0);//背景为白色

											 /*  pcl::PointXYZ o;
											 o.x = 0;
											 o.y = 0;
											 o.z = 0;
											 viewer.addSphere (o, 5, "sphere",0);*/
											 //viewer.addLine(o,"line",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++;
//}

//Accomplish loading a PCDFile,creating a viewer,and show the cloud at the viewer.
void showTheCloud()
{
	pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
	//load 
	pcl::io::loadPCDFile("Scan00SL100000.pcd", *cloud);

	pcl::visualization::CloudViewer viewer("Cloud Viewer");

	//blocks until the cloud is actually rendered
	viewer.showCloud(cloud);

	//use the following functions to get access to the underlying more advanced/powerful
	//PCLVisualizer

	//This will only get called once
	viewer.runOnVisualizationThreadOnce(viewerOneOff);

	//This will get called once per visualization iteration
	//viewer.runOnVisualizationThread (viewerPsycho);
	while (!viewer.wasStopped())
	{
		//you can also do cool processing here
		//FIXME: Note that this is running in a separate thread from viewerPsycho
		//and you should guard against race conditions yourself...
		//user_data++;
	}
}
//Create a point-cloud object,and generate a PCD File to save the point cloud object.
bool saveThePointCloud()
{
	pcl::PointCloud<pcl::PointXYZ> Cloud;      //定义点云对象
											   // 创建点云
	Cloud.width = 30;
	Cloud.height = 1;
	Cloud.is_dense = false;
	Cloud.points.resize(Cloud.width*Cloud.height);
	srand(unsigned(int(NULL)));
	for (size_t i = 0; i<Cloud.points.size(); ++i)
	{//RAND_MAX = 32767
		if (i<10)
		{
			Cloud.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
			Cloud.points[i].y = 0.0f;
			Cloud.points[i].z = 0.0f;
		}
		else if (i<20)
		{
			Cloud.points[i].x = 0.0f;
			Cloud.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
			Cloud.points[i].z = 0.0f;
		}
		else
		{
			Cloud.points[i].x = 0.0f;
			Cloud.points[i].y = 0.0f;
			Cloud.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
		}
	}
	pcl::io::savePCDFile("pointCloudValueFile.pcd", Cloud);
	pcl::io::savePCDFileASCII("pointCloudFile.pcd", Cloud);
	return true;
}
int main()
{
	if (saveThePointCloud())
	{
		showTheCloud();
	}
	else
	{
		std::cout << "Failed" << endl;
	}
	return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200427090124807.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpeGlidWJheGl1,size_16,color_FFFFFF,t_70#pic_center)

cloudviewer结果是一条线,一帧数据,想把所有数据拼接在一个里。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值