Windows VS2017安装配置PCL点云库

Windows VS2017安装配置PCL点云库

如需远程调试,可加QQ905733049由专业技术人员远程协助!

运行代码如下:

#include 
#include //标准C++库中的输入输出类相关头文件。
#include 
#include //pcd 读写类相关的头文件。
#include 
#include  //PCL中支持的点类型头文件。
#include  
#include   
#include  

using namespace std;

int main()
{
	typedef struct tagPOINT_3D
	{
		double x;  //mm world coordinate x  
		double y;  //mm world coordinate y  
		double z;  //mm world coordinate z  
		double r;
	}POINT_WORLD;


	/加载txt数据  
	int number_Txt;
	FILE *fp_txt;
	tagPOINT_3D TxtPoint;
	vector m_vTxtPoints;
	fp_txt = fopen("za.txt", "r");
	if (fp_txt)
	{
		while (fscanf(fp_txt, "%lf %lf %lf", &TxtPoint.x, &TxtPoint.y, &TxtPoint.z) != EOF)
		{
			m_vTxtPoints.push_back(TxtPoint);
		}
	}
	else
		cout << "txt数据加载失败!" << endl;
	number_Txt = m_vTxtPoints.size();
	//pcl::PointCloud cloud;
	//这里使用“PointXYZ”是因为我后面给的点云信息是包含的三维坐标,同时还有点云信息包含的rgb颜色信息的或者还有包含rgba颜色和强度信息。
	pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
	// Fill in the cloud data  
	cloud->width = number_Txt;
	cloud->height = 1;
	cloud->is_dense = false;
	cloud->points.resize(cloud->width * cloud->height);
	for (size_t i = 0; i < cloud->points.size(); ++i)
	{
		cloud->points[i].x = m_vTxtPoints[i].x;
		cloud->points[i].y = m_vTxtPoints[i].y;
		cloud->points[i].z = m_vTxtPoints[i].z;
	}
	pcl::io::savePCDFileASCII("txt2pcd_bunny1.pcd", *cloud);
	std::cerr << "Saved " << cloud->points.size() << " data points to txt2pcd.pcd." << std::endl;

	//for (size_t i = 0; i < cloud.points.size(); ++i)
	//  std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

	//PCL Visualizer
	// Viewer  
	pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
	viewer.addPointCloud(cloud);
	viewer.setBackgroundColor(0, 0, 0);

	viewer.spin();
	system("pause");
	return 0;

}

运行结果:

Windows VS2017安装配置PCL点云库_第1张图片

你可能感兴趣的:(Windows VS2017安装配置PCL点云库)