ait-survey

xyz(rgb).pcd2xyzrgb

Jun 27th, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 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. using namespace std;
  10.  
  11. int main (int argc, char** argv)
  12. {
  13.     int r,g,b;
  14.  
  15.     //if(argc!=3)
  16.     //{
  17.             //fprintf(stderr,"Usage: %s\n(1)Input_XYZ_filename\n(2)Output_PCD_filename\n",argv[0]);
  18.             //exit(1);
  19.     //}
  20.    
  21.     if(argc != 3)
  22.     {
  23.         cout << "You need to supply one argument to this program."<<endl;
  24.         cout << "(1)Input_XYZRGB.pcd_filename"<<endl;
  25.         cout << "(2)Output_XYZRGB.xyz_filename"<<endl;
  26.         return -1;
  27.     }
  28.    
  29.     pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  30.     pcl::io::loadPCDFile (argv[1], *cloud);
  31.    
  32.     ofstream ofs;
  33.     ofs.open(argv[2]);
  34.     //pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  35.    
  36.     //Open XYZ file
  37.  
  38.     //std::ifstream ifs(argv[1]);
  39.     //std::string buf;
  40.    
  41.     ////Load XYZ file
  42.     //for(size_t i=0; ifs && getline(ifs, buf); i++)
  43.     //{
  44.            
  45.         //std::cout << buf << std::endl;
  46.         //std::istringstream is(buf);
  47.  
  48.         //pcl::PointXYZRGB pnt;
  49.         //is >> pnt.x
  50.         //>> pnt.y
  51.         //>> pnt.z;
  52.         //cloud->push_back ( pnt );
  53.    
  54.     //}
  55.    
  56.     for(size_t i=0; i < cloud->points.size() ; i++)
  57.     {
  58.         ofs << setprecision(3)
  59.         << fixed << cloud->points[i].x << " "
  60.         << fixed << cloud->points[i].y << " "
  61.         << fixed << cloud->points[i].z << " "
  62.         << (int)cloud->points[i].r << " "
  63.         << (int)cloud->points[i].g << " "
  64.         << (int)cloud->points[i].b << endl;
  65.         //<< fixed << normals->points[i].normal_x << " "
  66.         //<< fixed << normals->points[i].normal_y << " "
  67.         //<< fixed << normals->points[i].normal_z << endl;
  68.     }
  69.  
  70.     //ofs.close();
  71.  
  72.  
  73.     //pcl::io::savePCDFileASCII(argv[2], *cloud);
  74.  
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment