DGtalTools  0.9.2
vol2raw.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/VolReader.h>
31 #include <DGtal/io/writers/RawWriter.h>
32 #include <DGtal/helpers/StdDefs.h>
33 #include <DGtal/images/Image.h>
34 #include <DGtal/images/ImageContainerBySTLVector.h>
35 
36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/parsers.hpp>
38 #include <boost/program_options/variables_map.hpp>
39 
40 using namespace std;
41 using namespace DGtal;
42 using namespace Z3i;
43 
44 namespace po = boost::program_options;
45 
76 void missingParam ( std::string param )
77 {
78  trace.error() <<" Parameter: "<<param<<" is required..";
79  trace.info() <<std::endl;
80  exit ( 1 );
81 }
82 
83 
84 int main(int argc, char**argv)
85 {
86 
87  // parse command line ----------------------------------------------
88  po::options_description general_opt ( "Allowed options are: " );
89  general_opt.add_options()
90  ( "help,h", "display this message." )
91  ( "input,i", po::value<std::string>(), "Input vol file." )
92  ( "output,o", po::value<string>(),"Output filename." );
93  bool parseOK=true;
94  po::variables_map vm;
95  try{
96  po::store(po::parse_command_line(argc, argv, general_opt), vm);
97  }catch(const std::exception& ex){
98  parseOK=false;
99  trace.info()<< "Error checking program options: "<< ex.what()<< endl;
100  }
101  po::notify ( vm );
102  if (!parseOK || vm.count ( "help" ) ||argc<=1 )
103  {
104  trace.info() << "Convert a vol to a 8-bit raw file."<<std::endl
105  << std::endl << "Basic usage: "<<std::endl
106  << "\tvol2raw --input <volFileName> --o <RawOutputFileName> "<<std::endl
107  << general_opt << "\n";
108  return 0;
109  }
110 
111  //Parse options
112  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
113  std::string filename = vm["input"].as<std::string>();
114  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
115  std::string outputFileName = vm["output"].as<std::string>();
116 
117  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
118 
119  MyImageC imageC = VolReader< MyImageC >::importVol ( filename );
120  bool res = RawWriter< MyImageC >::exportRaw8(outputFileName, imageC);
121  trace.info() << "Raw export done, image dimensions: " << imageC.domain().upperBound()[0]-imageC.domain().lowerBound()[0]+1
122  << " " << imageC.domain().upperBound()[1]-imageC.domain().lowerBound()[1]+1
123  << " " << imageC.domain().upperBound()[2]-imageC.domain().lowerBound()[2]+1 << std::endl;
124 
125  if (res) return 0; else return 1;
126 }
STL namespace.