Advertisement
SUGIYAMA

☆xyzrgbnormal2pcd

Jan 6th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. /***********************************************************************************************
  2. Read file   : TXT 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.     float r,g,b;
  22.     if(argc!=3)
  23.         {
  24.                 fprintf(stderr,"Usage: %s\n(1)Input_XYZRGBNormal_filename\n(2)Output_Text_Filename\n",argv[0]);
  25.                 exit(1);
  26.         }
  27.  
  28.     pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBNormal>);
  29.    
  30.     //XYZRGBNormalファイルの読み込み
  31.    
  32.     //std::ifstream ifs(input_fname);
  33.     //std:ifstream Input file stream class
  34.     std::ifstream ifs(argv[1]);
  35.    
  36.     //std:strings Strings are objects that represent sequences of characters.
  37.     std::string buf;
  38.  
  39.     for(size_t i=0; ifs && getline(ifs, buf); i++)
  40.     {
  41.        
  42.         std::cout << buf << std::endl;
  43.         std::istringstream is(buf);
  44.         pcl::PointXYZRGBNormal pnt;
  45.         is >> pnt.x
  46.            >> pnt.y
  47.            >> pnt.z
  48.            >> r
  49.            >> g
  50.            >> b
  51.            >> pnt.normal_x
  52.            >> pnt.normal_y
  53.            >> pnt.normal_z
  54.            >> pnt.curvature;
  55.         pnt.r= (uint8_t)r;
  56.                 pnt.g= (uint8_t)g;
  57.                 pnt.b= (uint8_t)b;
  58.         cloud->push_back ( pnt );
  59.  
  60.     }
  61.  
  62.     //pcdファイルに書き出し
  63.     //std::cout << "Output file name:";
  64.     //std::cin >> output_fname;
  65.    
  66.     pcl::io::savePCDFileASCII(argv[2], *cloud);
  67.  
  68.     //pcl::io::savePCDFileASCII(output_fname, *cloud);
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement