diff --git a/converters/mesh2vol.cpp b/converters/mesh2vol.cpp index 5f17923a..1b944d1f 100644 --- a/converters/mesh2vol.cpp +++ b/converters/mesh2vol.cpp @@ -36,15 +36,13 @@ #include "DGtal/io/Display3D.h" #include "DGtal/io/writers/GenericWriter.h" #include "DGtal/images/ImageContainerBySTLVector.h" -#include -#include -#include + +#include "CLI11.hpp" + using namespace std; using namespace DGtal; -/////////////////////////////////////////////////////////////////////////////// -namespace po = boost::program_options; /** @page mesh2vol @@ -55,14 +53,17 @@ namespace po = boost::program_options; @b Allowed @b options @b are: @code - -h [ --help ] display this message - -i [ --input ] arg mesh file (.off) - -o [ --output ] arg filename of ouput volumetric file (vol, pgm3d, ...) - (auto-generated by argument values if empty) - -m [ --margin ] arg (=0) add volume margin around the mesh bounding box. - -s [ --separation ] arg (=6) voxelization 6-separated or 26-separated. - -r [ --resolution ] digitization domain size (e.g. 128). The mesh will be scaled such that its bounding box maps to [0,resolution)^3. - +ositionals: + 1 TEXT:FILE REQUIRED mesh file (.off). + 2 TEXT=result.vol filename of ouput volumetric file (vol, pgm3d, ...). + +Options: + -h,--help Print this help message and exit + -i,--input TEXT:FILE REQUIRED mesh file (.off). + -o,--output TEXT=result.vol filename of ouput volumetric file (vol, pgm3d, ...). + -m,--margin UINT add volume margin around the mesh bounding box. + -s,--separation UINT:{6,26}=6 voxelization 6-separated or 26-separated. + -r,--resolution UINT=128 digitization domain size (e.g. 128). The mesh will be scaled such that its bounding box maps to [0,resolution)^3. @endcode @b Example: @@ -128,77 +129,35 @@ void voxelizeAndExport(const std::string& inputFilename, int main( int argc, char** argv ) { - // parse command line ---------------------------------------------- - po::options_description general_opt("\nAllowed options are"); - general_opt.add_options() - ("help,h", "display this message") - ("input,i", po::value(), "mesh file (.off) " ) - ("output,o", po::value(), "filename of ouput volumetric file (vol, pgm3d, ...).") - ("margin,m", po::value()->default_value(0), "add volume margin around the mesh bounding box.") - ("separation,s", po::value()->default_value(6), "voxelization 6-separated or 26-separated." ) - ("resolution,r", po::value(), "digitization domain size (e.g. 128). The mesh will be scaled such that its bounding box maps to [0,resolution)^3." ); - - 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) - { - std::cout << "Usage: " << argv[0] << " -i [input]\n" - << "Convert a mesh file into a 26-separated or 6-separated volumetric voxelization in a given resolution grid." - << general_opt << "\n"; - std::cout << "Example:\n" - << "mesh2vol -i ${DGtal}/examples/samples/tref.off -o output.vol --separation 26 --resolution 256 \n"; - return -1; - } - - if( !vm.count("input") ) - { - trace.error() << " Input filename is needed to be defined" << endl; - return -1; - } - - if( vm["separation"].as() != 6 && - vm["separation"].as() != 26 ) - { - trace.error() << " Separation should be 6 or 26" << endl; - return -1; - } - unsigned int margin = vm["margin"].as(); - unsigned int separation = vm["separation"].as(); - unsigned int resolution; - if (vm.count("resolution")) - resolution = vm["resolution"].as(); - else - { - trace.error()<<"Missing output parameter '--resolution'"<(); - string outputFilename; - - if( vm.count("output") ) - outputFilename = vm["output"].as(); +// parse command line using CLI ---------------------------------------------- + CLI::App app; + std::string inputFileName; + std::string outputFileName {"result.vol"}; + unsigned int margin {0}; + unsigned int separation {6}; + unsigned int resolution {128}; + + app.description("Convert a mesh file into a 26-separated or 6-separated volumetric voxelization in a given resolution grid. \n Example:\n mesh2vol -i ${DGtal}/examples/samples/tref.off -o output.vol --separation 26 --resolution 256 "); + + app.add_option("-i,--input,1", inputFileName, "mesh file (.off)." ) + ->required() + ->check(CLI::ExistingFile); + app.add_option("-o,--output,2", outputFileName, "filename of ouput volumetric file (vol, pgm3d, ...).",true); + app.add_option("-m,--margin", margin, "add volume margin around the mesh bounding box."); + app.add_option("-s,--separation", separation, "voxelization 6-separated or 26-separated.", true) + -> check(CLI::IsMember({6, 26})); + app.add_option("-r,--resolution", resolution,"digitization domain size (e.g. 128). The mesh will be scaled such that its bounding box maps to [0,resolution)^3.", true); + + + app.get_formatter()->column_width(40); + CLI11_PARSE(app, argc, argv); + // END parse command line using CLI ---------------------------------------------- + + if (separation==6) + voxelizeAndExport<6>(inputFileName, outputFileName, resolution, margin); else - { - trace.error()<<"Missing output parameter '--output'"<(inputFilename, outputFilename, resolution, margin); - else if(separation == 26) - voxelizeAndExport<26>(inputFilename, outputFilename, resolution, margin); - - return 0; + voxelizeAndExport<26>(inputFileName, outputFileName, resolution, margin); + return EXIT_SUCCESS; }