ppm_to_pcd.cpp
Go to the documentation of this file.
00001 
00063 // Boost:
00064 #include <boost/program_options.hpp>
00065 // PCL:
00066 #include <pcl/point_types.h>
00067 #include <pcl/io/pcd_io.h>
00068 
00069 #include "cob_3d_mapping_common/io.h"
00070 
00071 using namespace std;
00072 using namespace pcl;
00073 
00074 vector<string> file_i(2, "");
00075 string file_o = "";
00076 bool remove_undef = false;
00077 
00078 
00079 void readOptions(int argc, char* argv[])
00080 {
00081   using namespace boost::program_options;
00082   options_description options("Options");
00083   options.add_options()
00084     ("help", "produce help message")
00085     ("rm_undef,R", "remove points labeled as undefined from point cloud")
00086     ("in", value< vector<string> >(&file_i), "input files, first ppm, second pcd")
00087     ("out", value<string> (&file_o), "output pcd file")
00088     ;
00089 
00090   positional_options_description p_opt;
00091   p_opt.add("in", 2).add("out", 1);
00092   variables_map vm;
00093   store(command_line_parser(argc, argv).options(options).positional(p_opt).run(), vm);
00094   notify(vm);
00095 
00096   if (vm.count("help"))
00097   {
00098     cout << "Reads a .ppm image and maps the color values on a point cloud" << endl;
00099     cout << options << endl;
00100     exit(0);
00101   }
00102   if (vm.count("rm_undef"))
00103   {
00104     remove_undef = true;
00105   }
00106   if (file_o == "")
00107   {
00108     cout << "no output file defined " << endl << options << endl;
00109     exit(0);
00110   }
00111   if (file_i[0] == "" || file_i[1] == "")
00112   {
00113     cout << "no input files defined " << endl << options << endl;
00114     exit(0);
00115   }
00116 }
00117 
00121 int main(int argc, char** argv)
00122 {
00123   readOptions(argc, argv);
00124 
00125   PointCloud<PointXYZ>::Ptr p(new PointCloud<PointXYZ>());
00126   PointCloud<PointXYZRGB>::Ptr pc(new PointCloud<PointXYZRGB>());
00127 
00128   PCDReader r;
00129   if (r.read(file_i[1], *p) == -1) return(0);
00130   copyPointCloud<PointXYZ, PointXYZRGB>(*p, *pc);
00131   pc->height = p->height;
00132   pc->width = p->width;
00133   cob_3d_mapping_common::PPMReader ppmR;
00134   if (ppmR.mapRGB(file_i[0], *pc, remove_undef) == -1)
00135   {
00136     cout << "Mapping error" << endl;
00137     return(0);
00138   }
00139   cout << "Mapped colors to \"" << file_o << "\" (Points: " << pc->points.size() << ", width: "
00140        << pc->width << ", height: " << pc->height << ")" << endl;
00141   PCDWriter w;
00142   io::savePCDFileASCII(file_o, *pc);
00143   return(0);
00144 }


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