文章目录

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
typedef pcl::PointXYZ PointT;
typedef pcl::PointCloud<PointT> PointCloud;int main()
{PointCloud::Ptr cloud(new PointCloud);std::string filename = "D:/PCL/monkey.ply"; if (filename.substr(filename.find_last_of(".") + 1) == "pcd"){if (pcl::io::loadPCDFile(filename, *cloud) == -1){PCL_ERROR("Couldn't read file %s \n", filename.c_str());return (-1);}}else if (filename.substr(filename.find_last_of(".") + 1) == "ply"){if (pcl::io::loadPLYFile(filename, *cloud) == -1){PCL_ERROR("Couldn't read file %s \n", filename.c_str());return (-1);}}else{std::cerr << "Unsupported file format!" << std::endl;return -1;}std::cout << "Loaded "<< cloud->width * cloud->height<< " data points from " << filename << std::endl;std::string output_filename = "output_cloud.pcd"; if (output_filename.substr(output_filename.find_last_of(".") + 1) == "pcd"){pcl::io::savePCDFile(output_filename, *cloud);}else if (output_filename.substr(output_filename.find_last_of(".") + 1) == "ply"){pcl::io::savePLYFile(output_filename, *cloud);}else{std::cerr << "Unsupported output file format!" << std::endl;return -1;}std::cout << "Saved "<< cloud->width * cloud->height<< " data points to " << output_filename << std::endl;return 0;
}