1. 程式人生 > >PLC 初學三通道點雲的賦值、顯示和儲存

PLC 初學三通道點雲的賦值、顯示和儲存

 

#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <fstream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h> //PCL對各種格式的點的支援標頭檔案	

//寫個點雲檔案RL0	
pcl::PointCloud<pcl::PointXYZRGB>::Ptr RL0(new pcl::PointCloud<pcl::PointXYZRGB>);
		for (int i = 0; i < pp_l0.size();i++)
		{
			pcl::PointXYZRGB p0;
			p0.x = pp_l0[i].x;
			p0.y = pp_l0[i].y;
			p0.z = pp_l0[i].z;
			p0.r = 0;
			p0.g = 0;
			p0.b = 255;
			RL0->points.push_back(p0);
		}
		RL0->width = RL0->points.size();
		RL0->height = 1;
		RL0->is_dense = false;

//顯示點雲
		boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_TR(new pcl::visualization::PCLVisualizer("3D"));
		viewer_TR->setBackgroundColor(1, 1, 1);		
		viewer_TR->addPointCloud<pcl::PointXYZRGB>(RL0, "RL0");
		viewer_TR->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "RL0");
		viewer_TR->addCoordinateSystem(1.0);
		while (!viewer_TR->wasStopped())																						//視窗停留
		{
			viewer_TR->spinOnce(100);
			boost::this_thread::sleep(boost::posix_time::microseconds(100000));
		}
		RL0->points.clear();
//檔案儲存,有點問題
	path_pcd = "D:/";
	pcl::io::savePCDFile(path_pcd, *RL0);