ait-survey

xyzrgbnormal2pcd

Sep 23rd, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. /***********************************************************************************************
  2. Read file
  3. Output File : PCD file format
  4.  
  5. XYZRGBNormal 2 PCD
  6.  
  7. *************************************************************************************************/
  8.  
  9.  
  10. #include <iostream>
  11. #include <iomanip>
  12. #include <fstream>
  13. #include <sstream>
  14.  
  15. #include <pcl/io/pcd_io.h>
  16. #include <pcl/point_types.h>
  17.  
  18.  
  19. int main (int argc, char** argv)
  20. {
  21.     if(argc!=3)
  22.         {
  23.                 fprintf(stderr,"Usage: %s\n(1)Input_XYZRGBNormal_filename\n(2)Output_Text_Filename\n",argv[0]);
  24.                 exit(1);
  25.         }
  26.  
  27.     pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBNormal>);
  28.    
  29.     //XYZRGBNormalファイルの読み込み
  30.    
  31.     //std::ifstream ifs(input_fname);
  32.     //std:ifstream Input file stream class
  33.     std::ifstream ifs(argv[1]);
  34.    
  35.     //std:strings Strings are objects that represent sequences of characters.
  36.     std::string buf;
  37.  
  38.     for(size_t i=0; ifs && getline(ifs, buf); i++)
  39.     {
  40.        
  41.         std::cout << buf << std::endl;
  42.         std::istringstream is(buf);
  43.         pcl::PointXYZRGBNormal pnt;
  44.         is >> pnt.x
  45.            >> pnt.y
  46.            >> pnt.z
  47.            >> r
  48.            >> g
  49.            >> b
  50.            >> pnt.normal_x
  51.            >> pnt.normal_y
  52.            >> pnt.normal_z
  53.            >> pnt.curvature;
  54.         pnt.r= (uint8_t)r;
  55.                 pnt.g= (uint8_t)g;
  56.                 pnt.b= (uint8_t)b;
  57.         cloud->push_back ( pnt );
  58.  
  59.     }
  60.  
  61.     //pcdファイルに書き出し
  62.     //std::cout << "Output file name:";
  63.     //std::cin >> output_fname;
  64.    
  65.     pcl::io::savePCDFileASCII(argv[2], *cloud);
  66.  
  67.     //pcl::io::savePCDFileASCII(output_fname, *cloud);
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment