SUGIYAMA

xyzrgb2pcd_argv

Oct 14th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <sstream>
  5.  
  6. #include <pcl/io/pcd_io.h>
  7. #include <pcl/point_types.h>
  8.  
  9.  
  10. int main (int argc, char** argv)
  11. {
  12.     if(argc!=3)
  13.         {
  14.                 fprintf(stderr,"Usage: %s\n(1)Input_XYZRGB_filename\n(2)Output_filename\n",argv[0]);
  15.                 exit(1);
  16.         }
  17.  
  18.     char input_fname[2048];
  19.     char output_fname[2048];
  20.  
  21.     pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  22.    
  23.     //XYZRGBファイルの読み込み (Input XYZRGB file)
  24.    
  25.     //std::ifstream ifs(input_fname);
  26.     std::ifstream ifs(argv[1]);
  27.     std::string buf;
  28.  
  29.     for(size_t i=0; ifs && getline(ifs, buf); i++)
  30.     {
  31.        
  32.         std::cout << buf << std::endl;
  33.         std::istringstream is(buf);
  34.         pcl::PointXYZRGB pnt;
  35.         is >> pnt.x
  36.            >> pnt.y
  37.            >> pnt.z
  38.            >> pnt.r
  39.            >> pnt.g
  40.            >> pnt.b;
  41.         cloud->push_back ( pnt );
  42.  
  43.     }
  44.  
  45.     //pcd(ASCII)ファイルに書き出し Output pcd(ASCII)
  46.     //std::cout << "Output file name:";
  47.     //std::cin >> output_fname;
  48.     //pcl::io::savePCDFileASCII(output_fname, *cloud);
  49.  
  50.     pcl::io::savePCDFileASCII(argv[2], *cloud);
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment