DGtalTools  0.9.2
convertVol.cpp
1 
29 #include <iostream>
31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 
34 #include "DGtal/io/readers/GenericReader.h"
35 #include "DGtal/io/writers/GenericWriter.h"
36 
37 
38 #include <boost/program_options/options_description.hpp>
39 #include <boost/program_options/parsers.hpp>
40 #include <boost/program_options/variables_map.hpp>
41 
42 using namespace std;
43 using namespace DGtal;
44 
71 namespace po = boost::program_options;
73 
74 int main( int argc, char** argv )
75 {
76  typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char> Image3D;
77 
78  // parse command line ----------------------------------------------
79  po::options_description general_opt("Allowed options are: ");
80  general_opt.add_options()
81  ("help,h", "display this message")
82  ("input,i", po::value<std::string>(), "volumetric file (.pgm3d, .vol, .longvol) " )
83  ("output,o", po::value<std::string>(), "volumetric file (.pgm3d, .vol, .longvol) " );
84 
85 
86  bool parseOK=true;
87  po::variables_map vm;
88  try{
89  po::store(po::parse_command_line(argc, argv, general_opt), vm);
90  }catch(const std::exception& ex){
91  parseOK=false;
92  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
93  }
94  po::notify(vm);
95  if( !parseOK || vm.count("help")||argc<=1)
96  {
97  std::cout << "Usage: " << argv[0] << " [input] [output]\n"
98  << "Convert volumetric file into volumetric file from different formats (pgm3d, vol, longvol) "
99  << general_opt << "\n";
100  std::cout << "Example:\n"
101  << "convertVol -i ${DGtal}/examples/samples/lobster.vol -o convertedVol.p3d \n";
102  return 0;
103  }
104 
105  if(! vm.count("input")||! vm.count("output"))
106  {
107  trace.error() << " Input and output filename are needed to be defined" << endl;
108  return 0;
109  }
110 
111 
112  string inputFilename = vm["input"].as<std::string>();
113  string outputFilename = vm["output"].as<std::string>();
114 
115  trace.info() << "Reading input file " << inputFilename ;
116  Image3D inputImage = DGtal::GenericReader<Image3D>::import(inputFilename);
117  trace.info() << " [done] " << std::endl ;
118  trace.info() << "Writing output file " << outputFilename ;
119  DGtal::GenericWriter<Image3D>::exportFile(outputFilename, inputImage);
120  trace.info() << " [done] " << std::endl ;
121 
122 
123  return 0;
124 
125 }
126 
127 
128 
129 
STL namespace.