merge_pcds.cpp
Go to the documentation of this file.
00001 
00063 #include <boost/program_options.hpp>
00064 
00065 #include <pcl/io/pcd_io.h>
00066 #include <pcl/common/file_io.h>
00067 #include <pcl/point_cloud.h>
00068 #include <pcl/point_types.h>
00069 
00070 using namespace std;
00071 using namespace pcl;
00072 
00073 string out, in_f;
00074 vector<string> in_pcds;
00075 
00076 
00077 void readOptions(int argc, char* argv[])
00078 {
00079   using namespace boost::program_options;
00080   options_description options("Options");
00081   options.add_options()
00082     ("help", "produce help message")
00083     ("out,o", value<string> (&out), "output pcd file name")
00084     ("folder,f", value<string> (&in_f), "input folder containing all pcd files to merge")
00085     ("pcds,p", value<vector<string> > (&in_pcds), "list of input pcds to merge")
00086     ;
00087 
00088   positional_options_description p_opt;
00089   p_opt.add("out", 1);
00090   variables_map vm;
00091   store(command_line_parser(argc, argv).options(options).positional(p_opt).run(), vm);
00092   notify(vm);
00093 
00094   if (vm.count("help") || !vm.count("out"))
00095   {
00096     cout << "\nTool to merge pcd files (of all types) specified by a folder "
00097          << "or given as a list to a single file\n\n";
00098     cout << options << endl;
00099     exit(0);
00100   }
00101 }
00102 
00103 int main(int argc, char** argv)
00104 {
00105   readOptions(argc, argv);
00106   pcl::PCLPointCloud2 cloud_out;
00107   pcl::PCLPointCloud2 cloud_in;
00108   pcl::PCLPointCloud2 cloud_tmp;
00109   if (in_f != "") 
00110   {
00111     vector<string> tmp_in;
00112     getAllPcdFilesInDirectory(in_f, tmp_in);
00113     for(size_t i=0; i<tmp_in.size(); i++)
00114     {
00115       in_pcds.push_back(in_f + tmp_in[i]);
00116     }
00117   }
00118   cout << "PCD files to merge: " << in_pcds.size() << endl;
00119   io::loadPCDFile(in_pcds[0], cloud_out);
00120   for (size_t i=1; i<in_pcds.size(); i++)
00121   {
00122     io::loadPCDFile(in_pcds[i], cloud_in);
00123     cout << "loaded " << cloud_in.width * cloud_in.height << " points..." << endl;
00124     concatenatePointCloud (cloud_in,cloud_out,cloud_tmp);
00125     cout << "copied " << cloud_tmp.width * cloud_tmp.height << " points..." << endl;
00126     cloud_out = cloud_tmp;
00127 
00128   }
00129   io::savePCDFile(out, cloud_out);
00130   cout << "saved " << cloud_out.width * cloud_out.height << " points!" << endl;
00131 
00132   return 0;
00133 }


cob_3d_mapping_tools
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:27