Skip to content

Commit

Permalink
CLI11 in mesh2vol
Browse files Browse the repository at this point in the history
  • Loading branch information
kerautret committed May 25, 2020
2 parents 87f7c19 + 79ea12a commit 2cafe2d
Showing 1 changed file with 42 additions and 83 deletions.
125 changes: 42 additions & 83 deletions converters/mesh2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@
#include "DGtal/io/Display3D.h"
#include "DGtal/io/writers/GenericWriter.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>

#include "CLI11.hpp"


using namespace std;
using namespace DGtal;

///////////////////////////////////////////////////////////////////////////////
namespace po = boost::program_options;

/**
@page mesh2vol
Expand All @@ -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:
Expand Down Expand Up @@ -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<std::string>(), "mesh file (.off) " )
("output,o", po::value<std::string>(), "filename of ouput volumetric file (vol, pgm3d, ...).")
("margin,m", po::value<unsigned int>()->default_value(0), "add volume margin around the mesh bounding box.")
("separation,s", po::value<unsigned int>()->default_value(6), "voxelization 6-separated or 26-separated." )
("resolution,r", po::value<unsigned int>(), "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<unsigned int>() != 6 &&
vm["separation"].as<unsigned int>() != 26 )
{
trace.error() << " Separation should be 6 or 26" << endl;
return -1;
}
unsigned int margin = vm["margin"].as<unsigned int>();
unsigned int separation = vm["separation"].as<unsigned int>();
unsigned int resolution;
if (vm.count("resolution"))
resolution = vm["resolution"].as<unsigned int>();
else
{
trace.error()<<"Missing output parameter '--resolution'"<<std::endl;
return -1;
}

string inputFilename = vm["input"].as<std::string>();
string outputFilename;

if( vm.count("output") )
outputFilename = vm["output"].as<std::string>();
// 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'"<<std::endl;
return -1;
}


if(separation == 6)
voxelizeAndExport<6>(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;
}

0 comments on commit 2cafe2d

Please sign in to comment.