Skip to content

Commit

Permalink
CLI11 in sdp2vol
Browse files Browse the repository at this point in the history
  • Loading branch information
kerautret committed May 24, 2020
1 parent 375e249 commit dfd1334
Showing 1 changed file with 50 additions and 72 deletions.
122 changes: 50 additions & 72 deletions converters/sdp2vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/io/writers/GenericWriter.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 @@ -50,18 +48,19 @@ using namespace DGtal;
@b Allowed @b options @b are:
@code
-h [ --help ] display this message
-i [ --input ] arg Sequence of 3d Discrete points (.sdp)
-o [ --output ] arg Vol file (.vol, .longvol, .pgm3d)
-f [ --foregroundVal ] arg (=128) value which will represent the foreground
object in the resulting image (default 128)
--invertY Invert the Y axis (image flip in the y
direction)
-b [ --backgroundVal ] arg (=0) value which will represent the background
outside the object in the resulting image
(default 0)
-d [ --domain ] arg defines the domain of the resulting image
xmin ymin zmin xmax ymax zmax
Positionals:
1 TEXT:FILE REQUIRED Sequence of 3d Discrete points (.sdp).
2 TEXT Vol file (.vol, .longvol, .pgm3d)
Options:
-h,--help Print this help message and exit
-i,--input TEXT:FILE REQUIRED Sequence of 3d Discrete points (.sdp).
-o,--output TEXT Vol file (.vol, .longvol, .pgm3d)
-f,--foregroundVal INT value which will represent the foreground object in the resulting image (default 128)
-b,--backgroundVal INT value which will represent the background outside the object in the resulting image (default 0)
-d,--domain INT x 6 customizes the domain of the resulting image xmin ymin zmin xmax ymax zmax (computed automatically by default)
--invertY Invert the Y axis (image flip in the y direction)
@endcode
@b Example:
Expand All @@ -74,55 +73,41 @@ using namespace DGtal;
*/


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



int main( int argc, char** argv )
{
typedef ImageContainerBySTLVector < Z3i::Domain, unsigned char > Image3D;

// 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>(), "Sequence of 3d Discrete points (.sdp) " )
("output,o", po::value<std::string>(), "Vol file (.vol, .longvol, .pgm3d) " )
("foregroundVal,f", po::value<int>()->default_value(128), "value which will represent the foreground object in the resulting image (default 128)")
("invertY", "Invert the Y axis (image flip in the y direction)")
("backgroundVal,b", po::value<int>()->default_value(0), "value which will represent the background outside the object in the resulting image (default 0)")
("domain,d", po::value<std::vector <int> >()->multitoken(), "customizes the domain of the resulting image xmin ymin zmin xmax ymax zmax (computed automatically by default) ");

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"))
{
std::cout << "Convert digital set of points into a volumic file.\n";
std::cout << "Usage: " << argv[0] << " [input] [output]\n"
<< general_opt << "\n";
std::cout << "Example:\n"
<< "sdp2vol -i volumePoints.sdp -o volume.vol -d 0 0 0 10 10 10 \n";
return 0;
}
if(! vm.count("input") ||! vm.count("output") )
{
trace.error() << " Input/ output filename and domain are needed to be defined" << endl;
return 0;
}



string inputSDP = vm["input"].as<std::string>();
string outputFilename = vm["output"].as<std::string>();
int foregroundVal = vm["foregroundVal"].as<int>();
int backgroundVal = vm["backgroundVal"].as<int>();

// parse command line using CLI ----------------------------------------------
CLI::App app;
std::string inputSDP;
std::string outputFileName {"result.vol"};
DGtal::int64_t rescaleInputMin {0};
DGtal::int64_t rescaleInputMax {255};

int foregroundVal {128};
int backgroundVal {0};
bool invertY {false};
std::vector<int> domainCoords;

app.description("Convert digital set of points into a volumic file.\n Example:\n sdp2vol -i volumePoints.sdp -o volume.vol -d 0 0 0 10 10 10 \n");
app.add_option("-i,--input,1", inputSDP, "Sequence of 3d Discrete points (.sdp)." )
->required()
->check(CLI::ExistingFile);
app.add_option("-o,--output,2", outputFileName, "Vol file (.vol, .longvol, .pgm3d) ");
app.add_option("-f,--foregroundVal", foregroundVal, "value which will represent the foreground object in the resulting image (default 128)");
app.add_option("-b,--backgroundVal", backgroundVal, "value which will represent the background outside the object in the resulting image (default 0)");
app.add_option("-d,--domain", domainCoords, "customizes the domain of the resulting image xmin ymin zmin xmax ymax zmax (computed automatically by default)")
->expected(6);

app.add_flag("--invertY", invertY, "Invert the Y axis (image flip in the y direction)");


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

vector<unsigned int> vPos;
vPos.push_back(0);
Expand All @@ -134,15 +119,14 @@ int main( int argc, char** argv )

Z3i::Point ptLower;
Z3i::Point ptUpper;


struct BBCompPoints
{
explicit BBCompPoints(unsigned int d): myDim(d){};
bool operator() (const Z3i::Point &p1, const Z3i::Point &p2){return p1[myDim]<p2[myDim];};
unsigned int myDim;
};
if(!vm.count("domain"))
if(domainCoords.size() != 6 )
{
unsigned int marge = 1;
for(unsigned int i=0; i< 4; i++)
Expand All @@ -154,9 +138,8 @@ int main( int argc, char** argv )
}
else
{
std::vector<int> domainCoords= vm["domain"].as<std::vector <int> >();
ptLower = Z3i::Point(domainCoords[3],domainCoords[4], domainCoords[5]);
ptUpper = Z3i::Point(domainCoords[0],domainCoords[1], domainCoords[2]);
ptLower = Z3i::Point(domainCoords[0],domainCoords[1], domainCoords[2]);
ptUpper = Z3i::Point(domainCoords[3],domainCoords[4], domainCoords[5]);
}

Image3D::Domain imageDomain(ptLower, ptUpper);
Expand All @@ -171,7 +154,7 @@ int main( int argc, char** argv )

for(unsigned int i=0; i<vectPoints.size(); i++)
{
if(vm.count("invertY"))
if(invertY)
{
vectPoints[i][1]=ptUpper[1]-vectPoints[i][1];
}
Expand All @@ -185,12 +168,7 @@ int main( int argc, char** argv )
}
}
trace.info()<< "Exporting resulting volumic image ... ";
GenericWriter<Image3D>::exportFile(outputFilename, imageResult);
GenericWriter<Image3D>::exportFile(outputFileName, imageResult);
trace.info() << " [done]"<<std::endl;
return 0;

return EXIT_SUCCESS;
}




0 comments on commit dfd1334

Please sign in to comment.