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> 36 #include <boost/program_options/options_description.hpp> 37 #include <boost/program_options/parsers.hpp> 38 #include <boost/program_options/variables_map.hpp> 41 using namespace DGtal;
44 namespace po = boost::program_options;
76 void missingParam ( std::string param )
78 trace.error() <<
" Parameter: "<<param<<
" is required..";
79 trace.info() <<std::endl;
84 int main(
int argc,
char**argv)
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." );
96 po::store(po::parse_command_line(argc, argv, general_opt), vm);
97 }
catch(
const std::exception& ex){
99 trace.info()<<
"Error checking program options: "<< ex.what()<< endl;
102 if (!parseOK || vm.count (
"help" ) ||argc<=1 )
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";
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>();
117 typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
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;
125 if (res)
return 0;
else return 1;