ait-survey

xyz2pcd

Nov 12th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 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.         int r,g,b;
  13.    
  14.         if(argc!=3)
  15.         {
  16.                 fprintf(stderr,"Usage: %s\n(1)Input_XYZ_filename\n(2)Output_PCD_filename\n",argv[0]);
  17.                 exit(1);
  18.         }
  19.    
  20.    
  21.         pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  22.        
  23.         //Open XYZ file
  24.  
  25.         std::ifstream ifs(argv[1]);
  26.         std::string buf;
  27.    
  28.     //Load XYZ file
  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.        
  35.                 pcl::PointXYZRGB pnt;
  36.                 is >> pnt.x
  37.                 >> pnt.y
  38.                 >> pnt.z;
  39.                 cloud->push_back ( pnt );
  40.        
  41.         }
  42.    
  43.    
  44.         pcl::io::savePCDFileBinary(argv[2], *cloud);
  45.    
  46.         return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment