Skip to content

Commit 4bbc57d

Browse files
committed
Replaced boost::program_options with cxxopts in utils/scm-to-cereal
1 parent d18fddf commit 4bbc57d

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

utils/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
set(Boost_NO_WARN_NEW_VERSIONS ON) # Supress "New Boost version may have incorrect dependencies or import targets" warning
2-
find_package(Boost 1.71.0 REQUIRED COMPONENTS program_options)
1+
find_package(cxxopts CONFIG REQUIRED)
32

43
# Converts a CVSSP .scm Morphable Model to a cereal binary file:
54
add_executable(scm-to-cereal scm-to-cereal.cpp)
6-
target_link_libraries(scm-to-cereal PRIVATE eos Boost::program_options)
5+
target_link_libraries(scm-to-cereal PRIVATE cxxopts::cxxopts eos)
76

87
# Install targets:
98
install(TARGETS scm-to-cereal DESTINATION bin)

utils/scm-to-cereal.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,61 +20,64 @@
2020
#include "eos/morphablemodel/MorphableModel.hpp"
2121
#include "eos/morphablemodel/io/cvssp.hpp"
2222

23-
#include "boost/program_options.hpp"
23+
#include <cxxopts.hpp>
2424

2525
#include <string>
2626
#include <iostream>
2727

28-
using namespace eos;
29-
namespace po = boost::program_options;
30-
using std::cout;
31-
using std::endl;
32-
3328
/**
3429
* Reads a CVSSP .scm Morphable Model file and converts it
3530
* to a cereal binary file.
3631
*/
3732
int main(int argc, char* argv[])
3833
{
39-
std::string scmmodelfile, isomapfile, outputfile;
34+
cxxopts::Options options("scm-to-cereal",
35+
"Convert a CVSSP .scm morphable model file to an eos (Cereal) .bin file.");
36+
// clang-format off
37+
options.add_options()
38+
("h,help", "display the help message")
39+
("m,model", "a CVSSP .scm Morphable Model file",
40+
cxxopts::value<std::string>())
41+
("t,isomap", "optional text file containing CVSSP texture mapping coordinates",
42+
cxxopts::value<std::string>())
43+
("s,shape-only", "save only the shape-model part of the full 3DMM",
44+
cxxopts::value<bool>()->default_value("false")->implicit_value("true"))
45+
("o,output", "output filename for the Morphable Model in cereal binary format",
46+
cxxopts::value<std::string>()->default_value("converted_model.bin"));
47+
// clang-format on
48+
49+
std::string scmmodelfile, outputfile;
50+
std::optional<std::string> isomapfile;
4051
bool save_shape_only;
52+
4153
try
4254
{
43-
po::options_description desc("Allowed options");
44-
// clang-format off
45-
desc.add_options()
46-
("help,h", "display the help message")
47-
("model,m", po::value<std::string>(&scmmodelfile)->required(),
48-
"a CVSSP .scm Morphable Model file")
49-
("isomap,t", po::value<std::string>(&isomapfile),
50-
"optional text file containing CVSSP texture mapping coordinates")
51-
("shape-only,s", po::value<bool>(&save_shape_only)->default_value(false)->implicit_value(true),
52-
"save only the shape-model part of the full 3DMM")
53-
("output,o", po::value<std::string>(&outputfile)->required()->default_value("converted_model.bin"),
54-
"output filename for the Morphable Model in cereal binary format");
55-
// clang-format on
56-
po::variables_map vm;
57-
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
58-
if (vm.count("help"))
55+
const auto result = options.parse(argc, argv);
56+
if (result.count("help"))
5957
{
60-
cout << "Usage: scm-to-cereal [options]" << endl;
61-
cout << desc;
58+
std::cout << options.help() << std::endl;
6259
return EXIT_SUCCESS;
6360
}
64-
po::notify(vm);
65-
} catch (const po::error& e)
61+
62+
scmmodelfile = result["model"].as<std::string>(); // required
63+
if (result.count("isomap")) // optional
64+
{
65+
isomapfile = result["isomap"].as<std::string>();
66+
}
67+
save_shape_only = result["shape-only"].as<bool>(); // optional
68+
outputfile = result["output"].as<std::string>(); // required
69+
} catch (const std::exception& e)
6670
{
67-
cout << "Error while parsing command-line arguments: " << e.what() << endl;
68-
cout << "Use --help to display a list of options." << endl;
71+
std::cout << "Error while parsing command-line arguments: " << e.what() << std::endl;
72+
std::cout << "Use --help to display a list of options." << std::endl;
6973
return EXIT_FAILURE;
7074
}
7175

72-
std::optional<std::string> isomapfile_optional =
73-
isomapfile.empty() ? std::nullopt : std::optional<std::string>(isomapfile);
76+
using namespace eos;
7477

7578
// Load the .scm Morphable Model and save it as cereal model:
7679
morphablemodel::MorphableModel morphable_model =
77-
morphablemodel::load_scm_model(scmmodelfile, isomapfile_optional);
80+
morphablemodel::load_scm_model(scmmodelfile, isomapfile);
7881

7982
if (save_shape_only)
8083
{
@@ -88,6 +91,6 @@ int main(int argc, char* argv[])
8891
morphablemodel::save_model(morphable_model, outputfile);
8992
}
9093

91-
cout << "Saved converted model as " << outputfile << "." << endl;
94+
std::cout << "Saved converted model as " << outputfile << "." << std::endl;
9295
return EXIT_SUCCESS;
9396
}

vcpkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.5.0",
55
"dependencies": [
66
"boost-program-options",
7+
"cxxopts",
78
{
89
"name": "opencv4",
910
"features": [ "jpeg", "png" ],

0 commit comments

Comments
 (0)