From a431780520772f514dc984524b1b1467d647688a Mon Sep 17 00:00:00 2001 From: Kerautret Date: Mon, 25 May 2020 09:44:33 +0200 Subject: [PATCH] CLI11 in raw2vol --- converters/raw2vol.cpp | 97 ++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 55 deletions(-) diff --git a/converters/raw2vol.cpp b/converters/raw2vol.cpp index ad58ef3b..d011c305 100644 --- a/converters/raw2vol.cpp +++ b/converters/raw2vol.cpp @@ -36,15 +36,13 @@ #include #include -#include -#include -#include +#include "CLI11.hpp" using namespace std; using namespace DGtal; using namespace Z3i; -namespace po = boost::program_options; + /** @page raw2vol raw2vol @brief Converts a 8-bit raw file to vol. @@ -54,12 +52,18 @@ namespace po = boost::program_options; @b Allowed @b options @b are: @code - -h [ --help ] display this message. - -i [ --input ] arg Input raw file. - -o [ --output ] arg Output vol filename. - -x [ --x ] arg x extent. - -y [ --y ] arg y extent. - -z [ --z ] arg z extent. +Allowed options are: : + +Positionals: + 1 TEXT:FILE REQUIRED Input raw file. + +Options: + -h,--help Print this help message and exit + -i,--input TEXT:FILE REQUIRED Input raw file. + -o,--output TEXT=result.vol Output vol filename. + --x UINT REQUIRED x extent. + --y UINT REQUIRED y extent. + --z UINT REQUIRED z extent. @endcode @b Example: @@ -89,58 +93,41 @@ void missingParam ( std::string param ) int main(int argc, char**argv) { - // parse command line ---------------------------------------------- - po::options_description general_opt ( "Allowed options are: " ); - general_opt.add_options() - ( "help,h", "display this message." ) - ( "input,i", po::value(), "Input raw file." ) - ( "output,o", po::value(),"Output vol filename." ) - ( "x,x", po::value(),"x extent." ) - ( "y,y", po::value(),"y extent." ) - ( "z,z", po::value(),"z extent." ); - - bool parseOK=true; - po::variables_map vm; - try{ - po::store(po::parse_command_line(argc, argv, general_opt), vm); - }catch(const std::exception& ex){ - parseOK=false; - trace.info()<< "Error checking program options: "<< ex.what()<< endl; - } - - po::notify ( vm ); - if (!parseOK || vm.count ( "help" ) ||argc<=1 ) - { - trace.info() << "Converts a 8-bit raw file to vol."< --output "<(); - if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" ); - std::string outputFileName = vm["output"].as(); - if ( ! ( vm.count ( "x" ) ) ) missingParam ( "--x" ); - unsigned int x = vm["x"].as(); - if ( ! ( vm.count ( "y" ) ) ) missingParam ( "--y" ); - unsigned int y = vm["y"].as(); - if ( ! ( vm.count ( "z" ) ) ) missingParam ( "--z" ); - unsigned int z = vm["z"].as(); - +// parse command line using CLI ---------------------------------------------- + CLI::App app; + std::string inputFileName; + std::string outputFileName {"result.vol"}; + DGtal::int64_t rescaleInputMin {0}; + DGtal::int64_t rescaleInputMax {255}; + unsigned int x, y, z; + app.description("Converts a 8-bit raw file to vol.\n Basic example:\n \t raw2vol -x 128 -y 128 -z 128 --input --output "); + app.add_option("-i,--input,1", inputFileName, "Input raw file." ) + ->required() + ->check(CLI::ExistingFile); + app.add_option("-o,--output",outputFileName,"Output vol filename.", true); + app.add_option("--x", x, "x extent." ) + ->required(); + app.add_option("--y", x, "y extent." ) + ->required(); + app.add_option("--z", x, "z extent." ) + ->required(); + + + app.get_formatter()->column_width(40); + CLI11_PARSE(app, argc, argv); + // END parse command line using CLI ---------------------------------------------- + + typedef ImageContainerBySTLVector MyImageC; - - MyImageC imageC = RawReader< MyImageC >::importRaw8 ( filename, Z3i::Vector(x,y,z) ); + MyImageC imageC = RawReader< MyImageC >::importRaw8 ( inputFileName, Z3i::Vector(x,y,z)); bool res = VolWriter< MyImageC>::exportVol(outputFileName, imageC); if (res) - return 0; + return EXIT_SUCCESS; else { trace.error()<< "Error while exporting the volume."<