Skip to content

Commit

Permalink
CLI11 in raw2vol
Browse files Browse the repository at this point in the history
  • Loading branch information
kerautret committed May 25, 2020
1 parent dfd1334 commit 5e6fb8e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 57 deletions.
95 changes: 40 additions & 55 deletions converters/raw2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@
#include <DGtal/images/Image.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;
using namespace Z3i;

namespace po = boost::program_options;

/**
@page raw2vol raw2vol
@brief Converts a 8-bit raw file to vol.
Expand All @@ -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:
Expand Down Expand Up @@ -89,58 +93,39 @@ 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<std::string>(), "Input raw file." )
( "output,o", po::value<string>(),"Output vol filename." )
( "x,x", po::value<unsigned int>(),"x extent." )
( "y,y", po::value<unsigned int >(),"y extent." )
( "z,z", po::value<unsigned int>(),"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."<<std::endl
<< std::endl << "Basic usage: "<<std::endl
<< "\traw2vol -x 128 -y 128 -z 128 --input <RawFileName> --output <VolOutputFileName> "<<std::endl
<< general_opt << "\n";
return 0;
}

//Parse options
if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
std::string filename = vm["input"].as<std::string>();
if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
std::string outputFileName = vm["output"].as<std::string>();
if ( ! ( vm.count ( "x" ) ) ) missingParam ( "--x" );
unsigned int x = vm["x"].as<unsigned int>();
if ( ! ( vm.count ( "y" ) ) ) missingParam ( "--y" );
unsigned int y = vm["y"].as<unsigned int>();
if ( ! ( vm.count ( "z" ) ) ) missingParam ( "--z" );
unsigned int z = vm["z"].as<unsigned int>();


// parse command line using CLI ----------------------------------------------
CLI::App app;
std::string inputFileName;
std::string outputFileName {"result.vol"};
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 <RawFileName> --output <VolOutputFileName>");
app.add_option("-i,--input,1", inputFileName, "Input raw file." )
->required()
->check(CLI::ExistingFile);
app.add_option("-o,--output,2",outputFileName,"Output vol filename.", true);
app.add_option("--x,-x", x, "x extent." )
->required();
app.add_option("--y,-y", y, "y extent." )
->required();
app.add_option("--z,-z", z, "z extent." )
->required();


app.get_formatter()->column_width(40);
CLI11_PARSE(app, argc, argv);
// END parse command line using CLI ----------------------------------------------


typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> 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."<<std::endl;
return 1;
return EXIT_FAILURE;
}
}
2 changes: 0 additions & 2 deletions converters/vol2raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ int main(int argc, char**argv)
CLI::App app;
std::string inputFileName;
std::string outputFileName {"result.raw"};
DGtal::int64_t rescaleInputMin {0};
DGtal::int64_t rescaleInputMax {255};

app.description("Convert a vol to a 8-bit raw file.\n Example: vol2raw ${DGtal}/examples/samples/lobster.vol res.raw \n");
app.add_option("-i,--input,1", inputFileName, "vol file (.vol, .longvol .p3d, .pgm3d and if WITH_ITK is selected: dicom, dcm, mha, mhd). For longvol, dicom, dcm, mha or mhd formats, the input values are linearly scaled between 0 and 255." )
Expand Down

0 comments on commit 5e6fb8e

Please sign in to comment.