2525#include " eos/render/render.hpp"
2626#include " eos/render/matrix_projection.hpp"
2727
28- #include " boost/program_options .hpp"
28+ #include < cxxopts .hpp>
2929
3030#include " opencv2/core.hpp"
3131#include " opencv2/imgcodecs.hpp"
3434#include < filesystem>
3535
3636using namespace eos ;
37- namespace po = boost::program_options;
3837using std::cout;
3938using std::endl;
4039using std::string;
@@ -49,43 +48,51 @@ using std::vector;
4948 */
5049int main (int argc, char * argv[])
5150{
51+ cxxopts::Options options (" generate-obj" , " Generates samples from the model and stores them as obj file "
52+ " as well as outputs a frontal rendering of the sample." );
53+ // clang-format off
54+ options.add_options ()
55+ (" h,help" , " display the help message" )
56+ (" m,model" , " an eos .bin Morphable Model file" , cxxopts::value<std::string>(), " filename" )
57+ (" shape-coeffs" , " optional comma-separated list of shape coefficients. Do not use spaces between values. "
58+ " E.g.: '--shape-coeffs 0.0,1.5,-1.0'. All coefficients not specified will be set to zero. "
59+ " If omitted, the mean is used." ,
60+ cxxopts::value<std::vector<float >>())
61+ (" color-coeffs" , " optional comma-separated list of colour coefficients. Do not use spaces between values. "
62+ " E.g.: '--colour-coeffs 0.0,1.0,-0.5'. All coefficients not specified will be set to zero. "
63+ " If omitted, the mean is used." ,
64+ cxxopts::value<std::vector<float >>())
65+ (" o,output" , " name of the output obj file (including .obj). Can be a full path." ,
66+ cxxopts::value<std::string>()->default_value (" output.obj" ), " filename" );
67+ // clang-format on
68+
5269 using std::filesystem::path;
5370 path model_file, output_file;
5471 vector<float > shape_coefficients, color_coefficients;
5572
5673 try
5774 {
58- po::options_description desc (" Allowed options" );
59- // clang-format off
60- desc.add_options ()
61- (" help" , " produce help message" )
62- (" model" , po::value<path>(&model_file)->required (), " an eos .bin Morphable Model file" )
63- (" shape-coeffs" , po::value<vector<float >>(&shape_coefficients)->multitoken (),
64- " optional parameter list of shape coefficients. All not specified will be set to zero. E.g.: "
65- " '--shape-coeffs 0.0 1.5'. If omitted, the mean is used." )
66- (" color-coeffs" , po::value<vector<float >>(&color_coefficients)->multitoken (),
67- " optional parameter list of colour coefficients. All not specified will be set to zero. E.g.: "
68- " '--colour-coeffs 0.0 1.5'. If omitted, the mean is used." )
69- (" output" , po::value<path>(&output_file)->default_value (" output.obj" ),
70- " name of the output obj file (including .obj). Can be a full path." );
71- // clang-format on
72- po::variables_map vm;
73- // disabling short options to allow negative values for the coefficients, e.g. '--shape-coeffs 0.0 -1.5'
74- po::store (
75- po::parse_command_line (argc, argv, desc,
76- po::command_line_style::unix_style ^ po::command_line_style::allow_short),
77- vm);
78- if (vm.count (" help" ))
75+ const auto result = options.parse (argc, argv);
76+ if (result.count (" help" ))
7977 {
80- cout << " Usage: generate-obj [options]" << endl;
81- cout << desc;
78+ std::cout << options.help () << std::endl;
8279 return EXIT_SUCCESS;
8380 }
84- po::notify (vm);
85- } catch (const po::error& e)
81+
82+ model_file = result[" model" ].as <std::string>(); // required (with default)
83+ if (result.count (" shape-coeffs" )) // optional
84+ {
85+ shape_coefficients = result[" shape-coeffs" ].as <std::vector<float >>();
86+ }
87+ if (result.count (" color-coeffs" )) // optional
88+ {
89+ color_coefficients = result[" color-coeffs" ].as <std::vector<float >>();
90+ }
91+ output_file = result[" output" ].as <std::string>(); // required (with default)
92+ } catch (const std::exception& e)
8693 {
87- cout << " Error while parsing command-line arguments: " << e.what () << endl;
88- cout << " Use --help to display a list of options." << endl;
94+ std:: cout << " Error while parsing command-line arguments: " << e.what () << std:: endl;
95+ std:: cout << " Use --help to display a list of options." << std:: endl;
8996 return EXIT_FAILURE;
9097 }
9198
0 commit comments