DGtalTools  0.9.4
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 
76 namespace po = boost::program_options;
78 
79 int main( int argc, char** argv )
80 {
82 
83  // parse command line ----------------------------------------------
84  po::options_description general_opt("Allowed options are: ");
85  general_opt.add_options()
86  ("help,h", "display this message")
87  ("input,i", po::value<std::string>(), "volumetric file (.pgm3d, .vol, .longvol) " )
88  ("output,o", po::value<std::string>(), "volumetric file (.pgm3d, .vol, .longvol) " );
89 
90 
91  bool parseOK=true;
92  po::variables_map vm;
93  try{
94  po::store(po::parse_command_line(argc, argv, general_opt), vm);
95  }catch(const std::exception& ex){
96  parseOK=false;
97  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
98  }
99  po::notify(vm);
100  if( !parseOK || vm.count("help")||argc<=1)
101  {
102  std::cout << "Usage: " << argv[0] << " [input] [output]\n"
103  << "Convert volumetric file into volumetric file from different formats (pgm3d, vol, longvol) "
104  << general_opt << "\n";
105  std::cout << "Example:\n"
106  << "convertVol -i ${DGtal}/examples/samples/lobster.vol -o convertedVol.p3d \n";
107  return 0;
108  }
109 
110  if(! vm.count("input")||! vm.count("output"))
111  {
112  trace.error() << " Input and output filename are needed to be defined" << endl;
113  return 0;
114  }
115 
116 
117  string inputFilename = vm["input"].as<std::string>();
118  string outputFilename = vm["output"].as<std::string>();
119 
120  trace.info() << "Reading input file " << inputFilename ;
121  Image3D inputImage = DGtal::GenericReader<Image3D>::import(inputFilename);
122  trace.info() << " [done] " << std::endl ;
123  trace.info() << "Writing output file " << outputFilename ;
124  DGtal::GenericWriter<Image3D>::exportFile(outputFilename, inputImage);
125  trace.info() << " [done] " << std::endl ;
126 
127 
128  return 0;
129 
130 }
131 
132 
133 
134 
STL namespace.
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()