DGtalTools  0.9.4
HDF52vol.cpp
1 
28 #include <iostream>
29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/HDF5Reader.h>
31 #include <DGtal/io/writers/VolWriter.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 
75 void missingParam ( std::string param )
76 {
77  trace.error() <<" Parameter: "<<param<<" is required..";
78  trace.info() <<std::endl;
79  exit ( 1 );
80 }
81 
82 
83 int main(int argc, char**argv)
84 {
85 
86  // parse command line ----------------------------------------------
87  po::options_description general_opt ( "Allowed options are: " );
88  general_opt.add_options()
89  ( "help,h", "display this message." )
90  ( "input,i", po::value<std::string>(), "Input HDF5 file." )
91  ( "output,o", po::value<string>(),"Output vol filename." );
92 
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 
102  po::notify ( vm );
103  if (!parseOK || vm.count ( "help" ) ||argc<=1 )
104  {
105  trace.info() << "Convert a 3D 8-bit HDF5 file to vol."<<std::endl
106  << std::endl << "Basic usage: "<<std::endl
107  << "\tHDF52vol --input <HDF5FileName> --output <VolOutputFileName> "<<std::endl
108  << general_opt << "\n";
109  return 0;
110  }
111 
112  //Parse options
113  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
114  std::string filename = vm["input"].as<std::string>();
115  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
116  std::string outputFileName = vm["output"].as<std::string>();
117 
118 
120 
121  MyImageC imageC = HDF5Reader< MyImageC >::importHDF5_3D( filename, "/UInt8Array3D" );
122  bool res = VolWriter< MyImageC>::exportVol(outputFileName, imageC);
123 
124  if (res)
125  return 0;
126  else
127  {
128  trace.error()<< "Error while exporting the volume."<<std::endl;
129  return 1;
130  }
131 }
STL namespace.
Trace trace(traceWriterTerm)
std::ostream & info()
std::ostream & error()