代码
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <fstream>
#include <sstream>
int
main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
for (int j = 0; j<8; j++)
{
std::stringstream s;
s << "P" << j << ".pcd";
if (pcl::io::loadPCDFile<pcl::PointXYZ>(s.str(), cloud) == -1) //* load the file
{
PCL_ERROR("Couldn't read file test_pcd.pcd \n");
return (-1);
}
std::cout << "Loaded "
<< cloud.width * cloud.height
<< " data points from test_pcd.pcd with the following fields: "
<< std::endl;
std::fstream fs;
std::stringstream ss;
ss << "P"<<j << ".txt";
fs.open(ss.str(), std::fstream::out);
for (size_t i = 0; i < cloud.points.size(); ++i)
{
std::cout << " " << cloud.points[i].x
<< " " << cloud.points[i].y
<< " " << cloud.points[i].z << std::endl;
fs << cloud.points[i].x << "\t"
<< cloud.points[i].y << "\t"
<< cloud.points[i].z << "\n";
}
fs.close();
}
return (0);
}