SUGIYAMA

xyzrgb2pcd

Sep 19th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 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.     char input_fname[2048];
  12.     char output_fname[2048];
  13.  
  14.     //ファイル名の読み込み
  15.     std::cout << "Input file name:";
  16.     std::cin >> input_fname;
  17.  
  18.     pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  19.    
  20.     //XYZファイルの読み込み
  21.    
  22.     std::ifstream ifs(input_fname);
  23.     std::string buf;
  24.  
  25.     for(size_t i=0; ifs && getline(ifs, buf); i++){
  26.        
  27.         std::cout << buf << std::endl;
  28.         std::istringstream is(buf);
  29.         pcl::PointXYZRGB pnt;
  30.         is >> pnt.x
  31.            >> pnt.y
  32.            >> pnt.z
  33.            >> pnt.r
  34.            >> pnt.g
  35.            >> pnt.b;
  36.         cloud->push_back ( pnt );
  37.  
  38.     }
  39.  
  40.     //pcdファイルに書き出し
  41.     std::cout << "Output file name:";
  42.     std::cin >> output_fname;
  43.     pcl::io::savePCDFileASCII(output_fname, *cloud);
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment