Skip to content

Commit

Permalink
CLI11 in ofs2off
Browse files Browse the repository at this point in the history
  • Loading branch information
kerautret committed May 25, 2020
1 parent 596b949 commit 87f7c19
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 59 deletions.
88 changes: 32 additions & 56 deletions converters/ofs2off.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
#include "DGtal/io/Display3D.h"
#include "DGtal/shapes/Mesh.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;
Expand All @@ -51,9 +50,13 @@ using namespace DGtal;
@b Allowed @b options @b are:
@code
-h [ --help ] display this message
-i [ --input ] arg ofs file (.ofs)
-o [ --output ] arg ofs file (.off)
Positionals:
1 TEXT:FILE REQUIRED ofs file (.ofs).
Options:
-h,--help Print this help message and exit
-i,--input TEXT:FILE REQUIRED ofs file (.ofs).
-o,--output TEXT ofs file (.off)
@endcode
@b Example:
Expand All @@ -66,59 +69,32 @@ using namespace DGtal;
*/


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

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>(), "ofs file (.ofs) " )
("output,o", po::value<std::string>(), "ofs file (.off) " );


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] << " [input] [output]\n"
<< "Convert OFS file into OFF mesh format"
<< general_opt << "\n";
return 0;
}

if(! vm.count("input")||! vm.count("output"))
{
trace.error() << " Input and output filename are needed to be defined" << endl;
return 0;
}


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

// We store the colors
Mesh<Z3i::RealPoint> anImportedMesh(true);
bool import = anImportedMesh << inputFilename;
bool exported = anImportedMesh >> outputFilename;
if(!import || !exported){
trace.info() << "Conversion failed: " << (exported? "Reading OFS failed. ": "Export OFF failed. ") << std::endl;
return 0;
}



// parse command line using CLI ----------------------------------------------
CLI::App app;
std::string inputFileName;
std::string outputFileName {"result.off"};

app.description("Convert OFS file into OFF mesh format.");
app.add_option("-i,--input,1", inputFileName, "ofs file (.ofs)." )
->required()
->check(CLI::ExistingFile);
app.add_option("-o,--output,2", outputFileName, "ofs file (.off)");

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

// We store the colors
Mesh<Z3i::RealPoint> anImportedMesh(true);
bool import = anImportedMesh << inputFileName;
bool exported = anImportedMesh >> outputFileName;
if(!import || !exported){
trace.info() << "Conversion failed: " << (exported? "Reading OFS failed. ": "Export OFF failed. ") << std::endl;
return 0;
}
trace.info() << "[done]. "<< std::endl;

return 0;

}
8 changes: 5 additions & 3 deletions converters/vol2raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ 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." )
->required()
Expand All @@ -115,8 +117,8 @@ int main(int argc, char**argv)
typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char> MyImageC;
typedef DGtal::functors::Rescaling<DGtal::int64_t ,unsigned char > RescalFCT;
MyImageC imageC = GenericReader< MyImageC >::importWithValueFunctor( inputFileName ,RescalFCT(rescaleInputMin,
rescaleInputMax,
0, 255) );
rescaleInputMax,
0, 255) );

bool res = RawWriter< MyImageC >::exportRaw8(outputFileName, imageC);
trace.info() << "Raw export done, image dimensions: " << imageC.domain().upperBound()[0]-imageC.domain().lowerBound()[0]+1
Expand Down

0 comments on commit 87f7c19

Please sign in to comment.