Skip to content

Commit a194097

Browse files
committed
Use an optional<string> to represent the optional isomap coordinates file in load_scm_model
This is more explicit than using an empty string.
1 parent dcda3f0 commit a194097

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

include/eos/morphablemodel/io/cvssp.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define EOS_IO_CVSSP_HPP
2424

2525
#include "eos/morphablemodel/MorphableModel.hpp"
26+
#include "eos/cpp17/optional.hpp"
2627

2728
#include "Eigen/Core"
2829

@@ -60,7 +61,8 @@ std::vector<std::array<double, 2>> load_isomap(std::string isomap_file);
6061
* @return The Morphable Model loaded from the file.
6162
* @throws std::runtime_error when reading either of the files fails.
6263
*/
63-
inline MorphableModel load_scm_model(std::string model_filename, std::string isomap_file = std::string())
64+
inline MorphableModel load_scm_model(std::string model_filename,
65+
cpp17::optional<std::string> isomap_file = cpp17::nullopt)
6466
{
6567
using Eigen::MatrixXf;
6668
using Eigen::VectorXf;
@@ -241,9 +243,9 @@ inline MorphableModel load_scm_model(std::string model_filename, std::string iso
241243

242244
// Load the isomap with texture coordinates if a filename has been given:
243245
std::vector<std::array<double, 2>> tex_coords;
244-
if (!isomap_file.empty())
246+
if (isomap_file)
245247
{
246-
tex_coords = load_isomap(isomap_file);
248+
tex_coords = load_isomap(isomap_file.value());
247249
if (shape_model.get_data_dimension() / 3.0f != tex_coords.size())
248250
{
249251
const std::string error_msg("Error, wrong number of texture coordinates. Don't have the same "

utils/scm-to-cereal.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#include "eos/morphablemodel/MorphableModel.hpp"
2121
#include "eos/morphablemodel/io/cvssp.hpp"
22+
#include "eos/cpp17/optional.hpp"
2223

2324
#include "boost/program_options.hpp"
2425

@@ -69,8 +70,12 @@ int main(int argc, char* argv[])
6970
return EXIT_FAILURE;
7071
}
7172

73+
cpp17::optional<std::string> isomapfile_optional =
74+
isomapfile.empty() ? cpp17::nullopt : cpp17::optional<std::string>(isomapfile);
75+
7276
// Load the .scm Morphable Model and save it as cereal model:
73-
morphablemodel::MorphableModel morphable_model = morphablemodel::load_scm_model(scmmodelfile, isomapfile);
77+
morphablemodel::MorphableModel morphable_model =
78+
morphablemodel::load_scm_model(scmmodelfile, isomapfile_optional);
7479

7580
if (save_shape_only)
7681
{

0 commit comments

Comments
 (0)