From 4bbc57d75f7759f919126fd25adb92cea0919741 Mon Sep 17 00:00:00 2001 From: Patrik Huber Date: Sun, 15 Dec 2024 10:13:26 +0000 Subject: [PATCH] Replaced boost::program_options with cxxopts in utils/scm-to-cereal --- utils/CMakeLists.txt | 5 ++- utils/scm-to-cereal.cpp | 69 +++++++++++++++++++++-------------------- vcpkg.json | 1 + 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 2d8f3906..94f8cfa1 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,9 +1,8 @@ -set(Boost_NO_WARN_NEW_VERSIONS ON) # Supress "New Boost version may have incorrect dependencies or import targets" warning -find_package(Boost 1.71.0 REQUIRED COMPONENTS program_options) +find_package(cxxopts CONFIG REQUIRED) # Converts a CVSSP .scm Morphable Model to a cereal binary file: add_executable(scm-to-cereal scm-to-cereal.cpp) -target_link_libraries(scm-to-cereal PRIVATE eos Boost::program_options) +target_link_libraries(scm-to-cereal PRIVATE cxxopts::cxxopts eos) # Install targets: install(TARGETS scm-to-cereal DESTINATION bin) diff --git a/utils/scm-to-cereal.cpp b/utils/scm-to-cereal.cpp index 50a07e0b..89805e5f 100644 --- a/utils/scm-to-cereal.cpp +++ b/utils/scm-to-cereal.cpp @@ -20,61 +20,64 @@ #include "eos/morphablemodel/MorphableModel.hpp" #include "eos/morphablemodel/io/cvssp.hpp" -#include "boost/program_options.hpp" +#include #include #include -using namespace eos; -namespace po = boost::program_options; -using std::cout; -using std::endl; - /** * Reads a CVSSP .scm Morphable Model file and converts it * to a cereal binary file. */ int main(int argc, char* argv[]) { - std::string scmmodelfile, isomapfile, outputfile; + cxxopts::Options options("scm-to-cereal", + "Convert a CVSSP .scm morphable model file to an eos (Cereal) .bin file."); + // clang-format off + options.add_options() + ("h,help", "display the help message") + ("m,model", "a CVSSP .scm Morphable Model file", + cxxopts::value()) + ("t,isomap", "optional text file containing CVSSP texture mapping coordinates", + cxxopts::value()) + ("s,shape-only", "save only the shape-model part of the full 3DMM", + cxxopts::value()->default_value("false")->implicit_value("true")) + ("o,output", "output filename for the Morphable Model in cereal binary format", + cxxopts::value()->default_value("converted_model.bin")); + // clang-format on + + std::string scmmodelfile, outputfile; + std::optional isomapfile; bool save_shape_only; + try { - po::options_description desc("Allowed options"); - // clang-format off - desc.add_options() - ("help,h", "display the help message") - ("model,m", po::value(&scmmodelfile)->required(), - "a CVSSP .scm Morphable Model file") - ("isomap,t", po::value(&isomapfile), - "optional text file containing CVSSP texture mapping coordinates") - ("shape-only,s", po::value(&save_shape_only)->default_value(false)->implicit_value(true), - "save only the shape-model part of the full 3DMM") - ("output,o", po::value(&outputfile)->required()->default_value("converted_model.bin"), - "output filename for the Morphable Model in cereal binary format"); - // clang-format on - po::variables_map vm; - po::store(po::command_line_parser(argc, argv).options(desc).run(), vm); - if (vm.count("help")) + const auto result = options.parse(argc, argv); + if (result.count("help")) { - cout << "Usage: scm-to-cereal [options]" << endl; - cout << desc; + std::cout << options.help() << std::endl; return EXIT_SUCCESS; } - po::notify(vm); - } catch (const po::error& e) + + scmmodelfile = result["model"].as(); // required + if (result.count("isomap")) // optional + { + isomapfile = result["isomap"].as(); + } + save_shape_only = result["shape-only"].as(); // optional + outputfile = result["output"].as(); // required + } catch (const std::exception& e) { - cout << "Error while parsing command-line arguments: " << e.what() << endl; - cout << "Use --help to display a list of options." << endl; + std::cout << "Error while parsing command-line arguments: " << e.what() << std::endl; + std::cout << "Use --help to display a list of options." << std::endl; return EXIT_FAILURE; } - std::optional isomapfile_optional = - isomapfile.empty() ? std::nullopt : std::optional(isomapfile); + using namespace eos; // Load the .scm Morphable Model and save it as cereal model: morphablemodel::MorphableModel morphable_model = - morphablemodel::load_scm_model(scmmodelfile, isomapfile_optional); + morphablemodel::load_scm_model(scmmodelfile, isomapfile); if (save_shape_only) { @@ -88,6 +91,6 @@ int main(int argc, char* argv[]) morphablemodel::save_model(morphable_model, outputfile); } - cout << "Saved converted model as " << outputfile << "." << endl; + std::cout << "Saved converted model as " << outputfile << "." << std::endl; return EXIT_SUCCESS; } diff --git a/vcpkg.json b/vcpkg.json index 7f1a5b88..9308bcc4 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -4,6 +4,7 @@ "version": "1.5.0", "dependencies": [ "boost-program-options", + "cxxopts", { "name": "opencv4", "features": [ "jpeg", "png" ],