diff --git a/examples/fit-model-multi.cpp b/examples/fit-model-multi.cpp index c20b152e7..ba1fd236f 100644 --- a/examples/fit-model-multi.cpp +++ b/examples/fit-model-multi.cpp @@ -30,7 +30,6 @@ #include "eos/render/texture_extraction.hpp" #include "eos/render/render.hpp" #include "eos/render/opencv/draw_utils.hpp" -#include "eos/cpp17/optional.hpp" #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" @@ -43,6 +42,7 @@ #include #include #include +#include using namespace eos; namespace po = boost::program_options; @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) std::tie(per_frame_meshes, per_frame_rendering_params) = fitting::fit_shape_and_pose( morphable_model, blendshapes, per_frame_landmarks, landmark_mapper, image_widths, image_heights, edge_topology, - ibug_contour, model_contour, 5, cpp17::nullopt, 30.0f, cpp17::nullopt, pca_shape_coefficients, + ibug_contour, model_contour, 5, std::nullopt, 30.0f, std::nullopt, pca_shape_coefficients, blendshape_coefficients, fitted_image_points); cout << "Final pca shape coefficients: "; diff --git a/include/eos/core/LandmarkMapper.hpp b/include/eos/core/LandmarkMapper.hpp index a99016d95..152127951 100644 --- a/include/eos/core/LandmarkMapper.hpp +++ b/include/eos/core/LandmarkMapper.hpp @@ -22,14 +22,13 @@ #ifndef EOS_LANDMARKMAPPER_HPP #define EOS_LANDMARKMAPPER_HPP -#include "eos/cpp17/optional.hpp" - #include "toml.hpp" #include #include #include #include +#include namespace eos { namespace core { @@ -114,7 +113,7 @@ class LandmarkMapper * @param[in] landmark_name A landmark name to convert. * @return The mapped landmark name if a mapping exists, an empty optional otherwise. */ - cpp17::optional convert(std::string landmark_name) const + std::optional convert(std::string landmark_name) const { if (landmark_mappings.empty()) { @@ -129,7 +128,7 @@ class LandmarkMapper return converted_landmark->second; } else { // landmark_name does not match the key of any element in the map - return cpp17::nullopt; + return std::nullopt; } }; @@ -170,9 +169,9 @@ class LandmarkMapper * vertex indices. * @return An optional int with the vertex index. */ -inline cpp17::optional +inline std::optional get_vertex_index(const std::string landmark_name, const core::LandmarkMapper& landmark_mapper, - const cpp17::optional>& landmark_definitions) + const std::optional>& landmark_definitions) { const auto converted_name = landmark_mapper.convert(landmark_name); if (!converted_name) @@ -198,11 +197,11 @@ get_vertex_index(const std::string landmark_name, const core::LandmarkMapper& la vertex_idx = found_vertex_idx->second; } else { - return cpp17::nullopt; + return std::nullopt; } } else { - return cpp17::nullopt; + return std::nullopt; } } return vertex_idx; diff --git a/include/eos/cpp17/detail/akrzemi1_optional.hpp b/include/eos/cpp17/detail/akrzemi1_optional.hpp deleted file mode 100644 index 000709472..000000000 --- a/include/eos/cpp17/detail/akrzemi1_optional.hpp +++ /dev/null @@ -1,1049 +0,0 @@ -// Copyright (C) 2011 - 2012 Andrzej Krzemienski. -// -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// The idea and interface is based on Boost.Optional library -// authored by Fernando Luis Cacciola Carballal - -# ifndef EOS_AKRZEMI1_OPTIONAL_HPP_ -# define EOS_AKRZEMI1_OPTIONAL_HPP_ - -# include -# include -# include -# include -# include -# include -# include - -# define TR2_OPTIONAL_REQUIRES(...) typename std::enable_if<__VA_ARGS__::value, bool>::type = false - -# if defined __GNUC__ // NOTE: GNUC is also defined for Clang -# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# endif -# -# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# endif -# -# if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# endif -# endif -# -# if defined __clang_major__ -# if (__clang_major__ == 3 && __clang_minor__ >= 5) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# elif (__clang_major__ > 3) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# endif -# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2) -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# endif -# endif -# -# if defined _MSC_VER -# if (_MSC_VER >= 1900) -# define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# endif -# endif - -# if defined __clang__ -# if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif -# elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif - - -# if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1 -# define OPTIONAL_CONSTEXPR_INIT_LIST constexpr -# else -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0 -# define OPTIONAL_CONSTEXPR_INIT_LIST -# endif - -# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L) -# define OPTIONAL_HAS_MOVE_ACCESSORS 1 -# else -# define OPTIONAL_HAS_MOVE_ACCESSORS 0 -# endif - -# // In C++11 constexpr implies const, so we need to make non-const members also non-constexpr -# if (defined __cplusplus) && (__cplusplus == 201103L) -# define OPTIONAL_MUTABLE_CONSTEXPR -# else -# define OPTIONAL_MUTABLE_CONSTEXPR constexpr -# endif - -namespace akrzemi1 { - -// BEGIN workaround for missing is_trivially_destructible -# if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it: it is already there -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - template - using is_trivially_destructible = std::has_trivial_destructor; -# endif -// END workaround for missing is_trivially_destructible - -# if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___) - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - - -// workaround for missing traits in GCC and CLANG -template -struct is_nothrow_move_constructible -{ - constexpr static bool value = std::is_nothrow_constructible::value; -}; - - -template -struct is_assignable -{ - template - constexpr static bool has_assign(...) { return false; } - - template () = std::declval(), true)) > - // the comma operator is necessary for the cases where operator= returns void - constexpr static bool has_assign(bool) { return true; } - - constexpr static bool value = has_assign(true); -}; - - -template -struct is_nothrow_move_assignable -{ - template - struct has_nothrow_move_assign { - constexpr static bool value = false; - }; - - template - struct has_nothrow_move_assign { - constexpr static bool value = noexcept( std::declval() = std::declval() ); - }; - - constexpr static bool value = has_nothrow_move_assign::value>::value; -}; -// end workaround - - -# endif - - - -// 20.5.4, optional for object types -template class optional; - -// 20.5.5, optional for lvalue reference types -template class optional; - - -// workaround: std utility functions aren't constexpr yet -template inline constexpr T&& constexpr_forward(typename std::remove_reference::type& t) noexcept -{ - return static_cast(t); -} - -template inline constexpr T&& constexpr_forward(typename std::remove_reference::type&& t) noexcept -{ - static_assert(!std::is_lvalue_reference::value, "!!"); - return static_cast(t); -} - -template inline constexpr typename std::remove_reference::type&& constexpr_move(T&& t) noexcept -{ - return static_cast::type&&>(t); -} - - -#if defined NDEBUG -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) -#else -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR))) -#endif - - -namespace detail_ -{ - -// static_addressof: a constexpr version of addressof -template -struct has_overloaded_addressof -{ - template - constexpr static bool has_overload(...) { return false; } - - template ().operator&()) > - constexpr static bool has_overload(bool) { return true; } - - constexpr static bool value = has_overload(true); -}; - -template )> -constexpr T* static_addressof(T& ref) -{ - return &ref; -} - -template )> -T* static_addressof(T& ref) -{ - return std::addressof(ref); -} - - -// the call to convert(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A -template -constexpr U convert(U v) { return v; } - -} // namespace detail - - -constexpr struct trivial_init_t{} trivial_init{}; - - -// 20.5.6, In-place construction -constexpr struct in_place_t{} in_place{}; - - -// 20.5.7, Disengaged state indicator -struct nullopt_t -{ - struct init{}; - constexpr explicit nullopt_t(init){} -}; -constexpr nullopt_t nullopt{nullopt_t::init()}; - - -// 20.5.8, class bad_optional_access -class bad_optional_access : public std::logic_error { -public: - explicit bad_optional_access(const std::string& what_arg) : logic_error{what_arg} {} - explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} {} -}; - - -template -union storage_t -{ - unsigned char dummy_; - T value_; - - constexpr storage_t( trivial_init_t ) noexcept : dummy_() {}; - - template - constexpr storage_t( Args&&... args ) : value_(constexpr_forward(args)...) {} - - ~storage_t(){} -}; - - -template -union constexpr_storage_t -{ - unsigned char dummy_; - T value_; - - constexpr constexpr_storage_t( trivial_init_t ) noexcept : dummy_() {}; - - template - constexpr constexpr_storage_t( Args&&... args ) : value_(constexpr_forward(args)...) {} - - ~constexpr_storage_t() = default; -}; - - -template -struct optional_base -{ - bool init_; - storage_t storage_; - - constexpr optional_base() noexcept : init_(false), storage_(trivial_init) {}; - - explicit constexpr optional_base(const T& v) : init_(true), storage_(v) {} - - explicit constexpr optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} - - template explicit optional_base(in_place_t, Args&&... args) - : init_(true), storage_(constexpr_forward(args)...) {} - - template >)> - explicit optional_base(in_place_t, std::initializer_list il, Args&&... args) - : init_(true), storage_(il, std::forward(args)...) {} - - ~optional_base() { if (init_) storage_.value_.T::~T(); } -}; - - -template -struct constexpr_optional_base -{ - bool init_; - constexpr_storage_t storage_; - - constexpr constexpr_optional_base() noexcept : init_(false), storage_(trivial_init) {}; - - explicit constexpr constexpr_optional_base(const T& v) : init_(true), storage_(v) {} - - explicit constexpr constexpr_optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} - - template explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) - : init_(true), storage_(constexpr_forward(args)...) {} - - template >)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(in_place_t, std::initializer_list il, Args&&... args) - : init_(true), storage_(il, std::forward(args)...) {} - - ~constexpr_optional_base() = default; -}; - -template -using OptionalBase = typename std::conditional< - std::is_trivially_destructible::value, // if possible - constexpr_optional_base::type>, // use base with trivial destructor - optional_base::type> ->::type; - - - -template -class optional : private OptionalBase -{ - static_assert( !std::is_same::type, nullopt_t>::value, "bad T" ); - static_assert( !std::is_same::type, in_place_t>::value, "bad T" ); - - - constexpr bool initialized() const noexcept { return OptionalBase::init_; } - typename std::remove_const::type* dataptr() { return std::addressof(OptionalBase::storage_.value_); } - constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase::storage_.value_); } - -# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 - constexpr const T& contained_val() const& { return OptionalBase::storage_.value_; } -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && { return std::move(OptionalBase::storage_.value_); } - OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & { return OptionalBase::storage_.value_; } -# else - T& contained_val() & { return OptionalBase::storage_.value_; } - T&& contained_val() && { return std::move(OptionalBase::storage_.value_); } -# endif -# else - constexpr const T& contained_val() const { return OptionalBase::storage_.value_; } - T& contained_val() { return OptionalBase::storage_.value_; } -# endif - - void clear() noexcept { - if (initialized()) dataptr()->T::~T(); - OptionalBase::init_ = false; - } - - template - void initialize(Args&&... args) noexcept(noexcept(T(std::forward(args)...))) - { - assert(!OptionalBase::init_); - ::new (static_cast(dataptr())) T(std::forward(args)...); - OptionalBase::init_ = true; - } - - template - void initialize(std::initializer_list il, Args&&... args) noexcept(noexcept(T(il, std::forward(args)...))) - { - assert(!OptionalBase::init_); - ::new (static_cast(dataptr())) T(il, std::forward(args)...); - OptionalBase::init_ = true; - } - -public: - typedef T value_type; - - // 20.5.5.1, constructors - constexpr optional() noexcept : OptionalBase() {}; - constexpr optional(nullopt_t) noexcept : OptionalBase() {}; - - optional(const optional& rhs) - : OptionalBase() - { - if (rhs.initialized()) { - ::new (static_cast(dataptr())) T(*rhs); - OptionalBase::init_ = true; - } - } - - optional(optional&& rhs) noexcept(std::is_nothrow_move_constructible::value) - : OptionalBase() - { - if (rhs.initialized()) { - ::new (static_cast(dataptr())) T(std::move(*rhs)); - OptionalBase::init_ = true; - } - } - - constexpr optional(const T& v) : OptionalBase(v) {} - - constexpr optional(T&& v) : OptionalBase(constexpr_move(v)) {} - - template - explicit constexpr optional(in_place_t, Args&&... args) - : OptionalBase(in_place_t{}, constexpr_forward(args)...) {} - - template >)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(in_place_t, std::initializer_list il, Args&&... args) - : OptionalBase(in_place_t{}, il, constexpr_forward(args)...) {} - - // 20.5.4.2, Destructor - ~optional() = default; - - // 20.5.4.3, assignment - optional& operator=(nullopt_t) noexcept - { - clear(); - return *this; - } - - optional& operator=(const optional& rhs) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(*rhs); - else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs; - return *this; - } - - optional& operator=(optional&& rhs) - noexcept(std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(std::move(*rhs)); - else if (initialized() == true && rhs.initialized() == true) contained_val() = std::move(*rhs); - return *this; - } - - template - auto operator=(U&& v) - -> typename std::enable_if - < - std::is_same::type, T>::value, - optional& - >::type - { - if (initialized()) { contained_val() = std::forward(v); } - else { initialize(std::forward(v)); } - return *this; - } - - - template - void emplace(Args&&... args) - { - clear(); - initialize(std::forward(args)...); - } - - template - void emplace(std::initializer_list il, Args&&... args) - { - clear(); - initialize(il, std::forward(args)...); - } - - // 20.5.4.4, Swap - void swap(optional& rhs) noexcept(std::is_nothrow_move_constructible::value && noexcept(swap(std::declval(), std::declval()))) - { - if (initialized() == true && rhs.initialized() == false) { rhs.initialize(std::move(**this)); clear(); } - else if (initialized() == false && rhs.initialized() == true) { initialize(std::move(*rhs)); rhs.clear(); } - else if (initialized() == true && rhs.initialized() == true) { using std::swap; swap(**this, *rhs); } - } - - // 20.5.4.5, Observers - - explicit constexpr operator bool() const noexcept { return initialized(); } - constexpr bool has_value() const noexcept { return initialized(); } - - constexpr T const* operator ->() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr()); - } - -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - - OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() { - assert (initialized()); - return dataptr(); - } - - constexpr T const& operator *() const& { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); - } - - OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & { - assert (initialized()); - return contained_val(); - } - - OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && { - assert (initialized()); - return constexpr_move(contained_val()); - } - - constexpr T const& value() const& { - return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); - } - - OPTIONAL_MUTABLE_CONSTEXPR T& value() & { - return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); - } - - OPTIONAL_MUTABLE_CONSTEXPR T&& value() && { - if (!initialized()) throw bad_optional_access("bad optional access"); - return std::move(contained_val()); - } - -# else - - T* operator ->() { - assert (initialized()); - return dataptr(); - } - - constexpr T const& operator *() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); - } - - T& operator *() { - assert (initialized()); - return contained_val(); - } - - constexpr T const& value() const { - return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); - } - - T& value() { - return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); - } - -# endif - -# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 - - template - constexpr T value_or(V&& v) const& - { - return *this ? **this : detail_::convert(constexpr_forward(v)); - } - -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - - template - OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) && - { - return *this ? constexpr_move(const_cast&>(*this).contained_val()) : detail_::convert(constexpr_forward(v)); - } - -# else - - template - T value_or(V&& v) && - { - return *this ? constexpr_move(const_cast&>(*this).contained_val()) : detail_::convert(constexpr_forward(v)); - } - -# endif - -# else - - template - constexpr T value_or(V&& v) const - { - return *this ? **this : detail_::convert(constexpr_forward(v)); - } - -# endif - - // 20.6.3.6, modifiers - void reset() noexcept { clear(); } -}; - - -template -class optional -{ - static_assert( !std::is_same::value, "bad T" ); - static_assert( !std::is_same::value, "bad T" ); - T* ref; - -public: - - // 20.5.5.1, construction/destruction - constexpr optional() noexcept : ref(nullptr) {} - - constexpr optional(nullopt_t) noexcept : ref(nullptr) {} - - constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) {} - - optional(T&&) = delete; - - constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {} - - explicit constexpr optional(in_place_t, T& v) noexcept : ref(detail_::static_addressof(v)) {} - - explicit optional(in_place_t, T&&) = delete; - - ~optional() = default; - - // 20.5.5.2, mutation - optional& operator=(nullopt_t) noexcept { - ref = nullptr; - return *this; - } - - // optional& operator=(const optional& rhs) noexcept { - // ref = rhs.ref; - // return *this; - // } - - // optional& operator=(optional&& rhs) noexcept { - // ref = rhs.ref; - // return *this; - // } - - template - auto operator=(U&& rhs) noexcept - -> typename std::enable_if - < - std::is_same::type, optional>::value, - optional& - >::type - { - ref = rhs.ref; - return *this; - } - - template - auto operator=(U&& rhs) noexcept - -> typename std::enable_if - < - !std::is_same::type, optional>::value, - optional& - >::type - = delete; - - void emplace(T& v) noexcept { - ref = detail_::static_addressof(v); - } - - void emplace(T&&) = delete; - - - void swap(optional& rhs) noexcept - { - std::swap(ref, rhs.ref); - } - - // 20.5.5.3, observers - constexpr T* operator->() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref); - } - - constexpr T& operator*() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref); - } - - constexpr T& value() const { - return ref ? *ref : (throw bad_optional_access("bad optional access"), *ref); - } - - explicit constexpr operator bool() const noexcept { - return ref != nullptr; - } - - constexpr bool has_value() const noexcept { - return ref != nullptr; - } - - template - constexpr typename std::decay::type value_or(V&& v) const - { - return *this ? **this : detail_::convert::type>(constexpr_forward(v)); - } - - // x.x.x.x, modifiers - void reset() noexcept { ref = nullptr; } -}; - - -template -class optional -{ - static_assert( sizeof(T) == 0, "optional rvalue references disallowed" ); -}; - - -// 20.5.8, Relational operators -template constexpr bool operator==(const optional& x, const optional& y) -{ - return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y; -} - -template constexpr bool operator!=(const optional& x, const optional& y) -{ - return !(x == y); -} - -template constexpr bool operator<(const optional& x, const optional& y) -{ - return (!y) ? false : (!x) ? true : *x < *y; -} - -template constexpr bool operator>(const optional& x, const optional& y) -{ - return (y < x); -} - -template constexpr bool operator<=(const optional& x, const optional& y) -{ - return !(y < x); -} - -template constexpr bool operator>=(const optional& x, const optional& y) -{ - return !(x < y); -} - - -// 20.5.9, Comparison with nullopt -template constexpr bool operator==(const optional& x, nullopt_t) noexcept -{ - return (!x); -} - -template constexpr bool operator==(nullopt_t, const optional& x) noexcept -{ - return (!x); -} - -template constexpr bool operator!=(const optional& x, nullopt_t) noexcept -{ - return bool(x); -} - -template constexpr bool operator!=(nullopt_t, const optional& x) noexcept -{ - return bool(x); -} - -template constexpr bool operator<(const optional&, nullopt_t) noexcept -{ - return false; -} - -template constexpr bool operator<(nullopt_t, const optional& x) noexcept -{ - return bool(x); -} - -template constexpr bool operator<=(const optional& x, nullopt_t) noexcept -{ - return (!x); -} - -template constexpr bool operator<=(nullopt_t, const optional&) noexcept -{ - return true; -} - -template constexpr bool operator>(const optional& x, nullopt_t) noexcept -{ - return bool(x); -} - -template constexpr bool operator>(nullopt_t, const optional&) noexcept -{ - return false; -} - -template constexpr bool operator>=(const optional&, nullopt_t) noexcept -{ - return true; -} - -template constexpr bool operator>=(nullopt_t, const optional& x) noexcept -{ - return (!x); -} - - - -// 20.5.10, Comparison with T -template constexpr bool operator==(const optional& x, const T& v) -{ - return bool(x) ? *x == v : false; -} - -template constexpr bool operator==(const T& v, const optional& x) -{ - return bool(x) ? v == *x : false; -} - -template constexpr bool operator!=(const optional& x, const T& v) -{ - return bool(x) ? *x != v : true; -} - -template constexpr bool operator!=(const T& v, const optional& x) -{ - return bool(x) ? v != *x : true; -} - -template constexpr bool operator<(const optional& x, const T& v) -{ - return bool(x) ? *x < v : true; -} - -template constexpr bool operator>(const T& v, const optional& x) -{ - return bool(x) ? v > *x : true; -} - -template constexpr bool operator>(const optional& x, const T& v) -{ - return bool(x) ? *x > v : false; -} - -template constexpr bool operator<(const T& v, const optional& x) -{ - return bool(x) ? v < *x : false; -} - -template constexpr bool operator>=(const optional& x, const T& v) -{ - return bool(x) ? *x >= v : false; -} - -template constexpr bool operator<=(const T& v, const optional& x) -{ - return bool(x) ? v <= *x : false; -} - -template constexpr bool operator<=(const optional& x, const T& v) -{ - return bool(x) ? *x <= v : true; -} - -template constexpr bool operator>=(const T& v, const optional& x) -{ - return bool(x) ? v >= *x : true; -} - - -// Comparison of optional with T -template constexpr bool operator==(const optional& x, const T& v) -{ - return bool(x) ? *x == v : false; -} - -template constexpr bool operator==(const T& v, const optional& x) -{ - return bool(x) ? v == *x : false; -} - -template constexpr bool operator!=(const optional& x, const T& v) -{ - return bool(x) ? *x != v : true; -} - -template constexpr bool operator!=(const T& v, const optional& x) -{ - return bool(x) ? v != *x : true; -} - -template constexpr bool operator<(const optional& x, const T& v) -{ - return bool(x) ? *x < v : true; -} - -template constexpr bool operator>(const T& v, const optional& x) -{ - return bool(x) ? v > *x : true; -} - -template constexpr bool operator>(const optional& x, const T& v) -{ - return bool(x) ? *x > v : false; -} - -template constexpr bool operator<(const T& v, const optional& x) -{ - return bool(x) ? v < *x : false; -} - -template constexpr bool operator>=(const optional& x, const T& v) -{ - return bool(x) ? *x >= v : false; -} - -template constexpr bool operator<=(const T& v, const optional& x) -{ - return bool(x) ? v <= *x : false; -} - -template constexpr bool operator<=(const optional& x, const T& v) -{ - return bool(x) ? *x <= v : true; -} - -template constexpr bool operator>=(const T& v, const optional& x) -{ - return bool(x) ? v >= *x : true; -} - -// Comparison of optional with T -template constexpr bool operator==(const optional& x, const T& v) -{ - return bool(x) ? *x == v : false; -} - -template constexpr bool operator==(const T& v, const optional& x) -{ - return bool(x) ? v == *x : false; -} - -template constexpr bool operator!=(const optional& x, const T& v) -{ - return bool(x) ? *x != v : true; -} - -template constexpr bool operator!=(const T& v, const optional& x) -{ - return bool(x) ? v != *x : true; -} - -template constexpr bool operator<(const optional& x, const T& v) -{ - return bool(x) ? *x < v : true; -} - -template constexpr bool operator>(const T& v, const optional& x) -{ - return bool(x) ? v > *x : true; -} - -template constexpr bool operator>(const optional& x, const T& v) -{ - return bool(x) ? *x > v : false; -} - -template constexpr bool operator<(const T& v, const optional& x) -{ - return bool(x) ? v < *x : false; -} - -template constexpr bool operator>=(const optional& x, const T& v) -{ - return bool(x) ? *x >= v : false; -} - -template constexpr bool operator<=(const T& v, const optional& x) -{ - return bool(x) ? v <= *x : false; -} - -template constexpr bool operator<=(const optional& x, const T& v) -{ - return bool(x) ? *x <= v : true; -} - -template constexpr bool operator>=(const T& v, const optional& x) -{ - return bool(x) ? v >= *x : true; -} - - -// 20.5.12, Specialized algorithms -template -void swap(optional& x, optional& y) noexcept(noexcept(x.swap(y))) -{ - x.swap(y); -} - - -template -constexpr optional::type> make_optional(T&& v) -{ - return optional::type>(constexpr_forward(v)); -} - -template -constexpr optional make_optional(std::reference_wrapper v) -{ - return optional(v.get()); -} - - -} // namespace akrzemi1 - -namespace std -{ - template - struct hash> - { - typedef typename hash::result_type result_type; - typedef akrzemi1::optional argument_type; - - constexpr result_type operator()(argument_type const& arg) const { - return arg ? std::hash{}(*arg) : result_type{}; - } - }; - - template - struct hash> - { - typedef typename hash::result_type result_type; - typedef akrzemi1::optional argument_type; - - constexpr result_type operator()(argument_type const& arg) const { - return arg ? std::hash{}(*arg) : result_type{}; - } - }; -} - -# undef TR2_OPTIONAL_REQUIRES -# undef TR2_OPTIONAL_ASSERTED_EXPRESSION - -# endif //EOS_AKRZEMI1_OPTIONAL_HPP_ diff --git a/include/eos/cpp17/detail/akrzemi1_optional_serialization.hpp b/include/eos/cpp17/detail/akrzemi1_optional_serialization.hpp deleted file mode 100644 index 066290b91..000000000 --- a/include/eos/cpp17/detail/akrzemi1_optional_serialization.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * eos - A 3D Morphable Model fitting library written in modern C++11/14. - * - * File: include/eos/cpp17/detail/akrzemi1_optional_serialization.hpp - * - * Copyright 2018 Patrik Huber - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#ifndef EOS_AKRZEMI1_OPTIONAL_SERIALIZATION_HPP_ -#define EOS_AKRZEMI1_OPTIONAL_SERIALIZATION_HPP_ - -#include "eos/cpp17/detail/akrzemi1_optional.hpp" - -#include "cereal/cereal.hpp" - -namespace cereal { - -//! Saving for akrzemi1::optional -template -inline void CEREAL_SAVE_FUNCTION_NAME(Archive& ar, const akrzemi1::optional& optional) -{ - if (!optional) - { - ar(CEREAL_NVP_("nullopt", true)); - } else - { - ar(CEREAL_NVP_("nullopt", false), CEREAL_NVP_("data", *optional)); - } -} - -//! Loading for akrzemi1::optional -template -inline void CEREAL_LOAD_FUNCTION_NAME(Archive& ar, akrzemi1::optional& optional) -{ - bool nullopt; - ar(CEREAL_NVP_("nullopt", nullopt)); - - if (nullopt) - { - optional = akrzemi1::nullopt; - } else - { - T value; - ar(CEREAL_NVP_("data", value)); - optional = std::move(value); - } -} - -} // namespace cereal - -#endif /* EOS_AKRZEMI1_OPTIONAL_SERIALIZATION_HPP_ */ diff --git a/include/eos/cpp17/optional.hpp b/include/eos/cpp17/optional.hpp deleted file mode 100644 index ea52007ce..000000000 --- a/include/eos/cpp17/optional.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * eos - A 3D Morphable Model fitting library written in modern C++11/14. - * - * File: include/eos/cpp17/optional.hpp - * - * Copyright 2018 Patrik Huber - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#ifndef EOS_OPTIONAL_HPP_ -#define EOS_OPTIONAL_HPP_ - -#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) - #include - namespace eos { - namespace cpp17 { - using ::std::optional; - using ::std::nullopt; - } - } -#else - #include "eos/cpp17/detail/akrzemi1_optional.hpp" - namespace eos { - namespace cpp17 { - using ::akrzemi1::optional; - using ::akrzemi1::nullopt; - } - } -#endif - -#endif /* EOS_OPTIONAL_HPP_ */ diff --git a/include/eos/cpp17/optional_serialization.hpp b/include/eos/cpp17/optional_serialization.hpp deleted file mode 100644 index caa7b059c..000000000 --- a/include/eos/cpp17/optional_serialization.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * eos - A 3D Morphable Model fitting library written in modern C++11/14. - * - * File: include/eos/cpp17/optional_serialization.hpp - * - * Copyright 2018 Patrik Huber - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#ifndef EOS_OPTIONAL_SERIALIZATION_HPP_ -#define EOS_OPTIONAL_SERIALIZATION_HPP_ - -#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) - #include "cereal/types/optional.hpp" -#else - #include "eos/cpp17/detail/akrzemi1_optional_serialization.hpp" -#endif - -#endif /* EOS_OPTIONAL_SERIALIZATION_HPP_ */ diff --git a/include/eos/fitting/RenderingParameters.hpp b/include/eos/fitting/RenderingParameters.hpp index 765b53311..13c9a47e0 100644 --- a/include/eos/fitting/RenderingParameters.hpp +++ b/include/eos/fitting/RenderingParameters.hpp @@ -25,11 +25,10 @@ #include "eos/fitting/orthographic_camera_estimation_linear.hpp" #include "eos/fitting/rotation_angles.hpp" #include "eos/render/matrix_projection.hpp" -#include "eos/cpp17/optional.hpp" -#include "eos/cpp17/optional_serialization.hpp" #include "eos/fitting/detail/eigen_quaternion_cerealisation.hpp" #include "cereal/cereal.hpp" +#include "cereal/types/optional.hpp" #include "cereal/archives/json.hpp" #include "Eigen/Core" @@ -37,6 +36,7 @@ #include #include #include +#include namespace eos { namespace fitting { @@ -192,7 +192,7 @@ class RenderingParameters return ea; }; - void set_translation(float t_x, float t_y, cpp17::optional t_z = cpp17::nullopt) + void set_translation(float t_x, float t_y, std::optional t_z = std::nullopt) { this->t_x = t_x; this->t_y = t_y; @@ -208,7 +208,7 @@ class RenderingParameters return {t_x, t_y, t_z.value_or(0.0f)}; }; - cpp17::optional get_fov_y() const + std::optional get_fov_y() const { return fov_y; }; @@ -277,10 +277,10 @@ class RenderingParameters float t_x; float t_y; - cpp17::optional t_z; + std::optional t_z; - cpp17::optional fov_y; // Field of view in the y direction. Degree or radians? Only for certain - // camera types. Should it go into Frustum? + std::optional fov_y; // Field of view in the y direction. Degree or radians? Only for certain + // camera types. Should it go into Frustum? int screen_width; // (why) do we need these? int screen_height; diff --git a/include/eos/fitting/fitting.hpp b/include/eos/fitting/fitting.hpp index b5dc5f209..783b086d7 100644 --- a/include/eos/fitting/fitting.hpp +++ b/include/eos/fitting/fitting.hpp @@ -34,13 +34,13 @@ #include "eos/fitting/contour_correspondence.hpp" #include "eos/fitting/closest_edge_fitting.hpp" #include "eos/fitting/RenderingParameters.hpp" -#include "eos/cpp17/optional.hpp" #include "Eigen/Core" #include #include #include +#include namespace eos { namespace fitting { @@ -71,7 +71,7 @@ inline Eigen::VectorXf fit_shape(Eigen::Matrix affine_camera_matrix const std::vector& blendshapes, const std::vector& image_points, const std::vector& vertex_indices, float lambda, - cpp17::optional num_coefficients_to_fit, + std::optional num_coefficients_to_fit, std::vector& pca_shape_coefficients, std::vector& blendshape_coefficients) { @@ -142,7 +142,7 @@ inline Eigen::VectorXf fit_shape(Eigen::Matrix affine_camera_matrix const std::vector& blendshapes, const std::vector& image_points, const std::vector& vertex_indices, float lambda = 3.0f, - cpp17::optional num_coefficients_to_fit = cpp17::optional()) + std::optional num_coefficients_to_fit = std::optional()) { std::vector unused; return fit_shape(affine_camera_matrix, morphable_model, blendshapes, image_points, vertex_indices, lambda, @@ -171,8 +171,8 @@ inline std::vector fit_expressions(const morphablemodel::ExpressionModel& expression_model, const Eigen::VectorXf& face_instance, const Eigen::Matrix& affine_camera_matrix, const std::vector& landmarks, const std::vector& vertex_ids, - cpp17::optional lambda_expressions = cpp17::optional(), - cpp17::optional num_expression_coefficients_to_fit = cpp17::optional()) + std::optional lambda_expressions = std::optional(), + std::optional num_expression_coefficients_to_fit = std::optional()) { std::vector expression_coefficients; if (cpp17::holds_alternative(expression_model)) @@ -210,7 +210,7 @@ fit_expressions(const morphablemodel::ExpressionModel& expression_model, const E * starting values in the fitting. When the function returns, they contain the coefficients from * the last iteration. * - * Use render::Mesh fit_shape_and_pose(const morphablemodel::MorphableModel&, const std::vector&, const core::LandmarkCollection&, const core::LandmarkMapper&, int, int, const morphablemodel::EdgeTopology&, const fitting::ContourLandmarks&, const fitting::ModelContour&, int, cpp17::optional, float). + * Use render::Mesh fit_shape_and_pose(const morphablemodel::MorphableModel&, const std::vector&, const core::LandmarkCollection&, const core::LandmarkMapper&, int, int, const morphablemodel::EdgeTopology&, const fitting::ContourLandmarks&, const fitting::ModelContour&, int, std::optional, float). * for a simpler overload with reasonable defaults and no optional output. * * \p num_iterations: Results are good for even a single iteration. For single-image fitting and @@ -251,8 +251,8 @@ inline std::pair fit_shape_and_pose( const core::LandmarkCollection& landmarks, const core::LandmarkMapper& landmark_mapper, int image_width, int image_height, const morphablemodel::EdgeTopology& edge_topology, const fitting::ContourLandmarks& contour_landmarks, const fitting::ModelContour& model_contour, - int num_iterations, cpp17::optional num_shape_coefficients_to_fit, float lambda_identity, - cpp17::optional num_expression_coefficients_to_fit, cpp17::optional lambda_expressions, + int num_iterations, std::optional num_shape_coefficients_to_fit, float lambda_identity, + std::optional num_expression_coefficients_to_fit, std::optional lambda_expressions, std::vector& pca_shape_coefficients, std::vector& expression_coefficients, std::vector& fitted_image_points) { @@ -319,7 +319,7 @@ inline std::pair fit_shape_and_pose( // and get the corresponding model points (mean if given no initial coeffs, from the computed shape otherwise): for (int i = 0; i < landmarks.size(); ++i) { - const cpp17::optional vertex_idx = core::get_vertex_index( + const std::optional vertex_idx = core::get_vertex_index( landmarks[i].name, landmark_mapper, morphable_model.get_landmark_definitions()); if (!vertex_idx) // vertex index not defined for the current landmark { @@ -452,7 +452,7 @@ inline std::pair fit_shape_and_pose( * * If you want to access the values of shape or blendshape coefficients, or want to set starting * values for them, use the following overload to this function: - * std::pair fit_shape_and_pose(const morphablemodel::MorphableModel&, const std::vector&, const core::LandmarkCollection&, const core::LandmarkMapper&, int, int, const morphablemodel::EdgeTopology&, const fitting::ContourLandmarks&, const fitting::ModelContour&, int, cpp17::optional, float, cpp17::optional, std::vector&, std::vector&, std::vector&) + * std::pair fit_shape_and_pose(const morphablemodel::MorphableModel&, const std::vector&, const core::LandmarkCollection&, const core::LandmarkMapper&, int, int, const morphablemodel::EdgeTopology&, const fitting::ContourLandmarks&, const fitting::ModelContour&, int, std::optional, float, std::optional, std::vector&, std::vector&, std::vector&) * * Todo: Add a convergence criterion. * @@ -483,9 +483,9 @@ inline std::pair fit_shape_and_pose( const core::LandmarkCollection& landmarks, const core::LandmarkMapper& landmark_mapper, int image_width, int image_height, const morphablemodel::EdgeTopology& edge_topology, const fitting::ContourLandmarks& contour_landmarks, const fitting::ModelContour& model_contour, - int num_iterations = 5, cpp17::optional num_shape_coefficients_to_fit = cpp17::nullopt, - float lambda_identity = 50.0f, cpp17::optional num_expression_coefficients_to_fit = cpp17::nullopt, - cpp17::optional lambda_expressions = cpp17::nullopt) + int num_iterations = 5, std::optional num_shape_coefficients_to_fit = std::nullopt, + float lambda_identity = 50.0f, std::optional num_expression_coefficients_to_fit = std::nullopt, + std::optional lambda_expressions = std::nullopt) { std::vector pca_coeffs; std::vector blendshape_coeffs; @@ -541,8 +541,8 @@ inline std::pair fit_shape_and_pose( inline std::pair fit_shape_and_pose( const morphablemodel::MorphableModel& morphable_model, const std::vector& image_points, const std::vector& vertex_indices, int image_width, int image_height, int num_iterations, - cpp17::optional num_shape_coefficients_to_fit, float lambda_identity, - cpp17::optional num_expression_coefficients_to_fit, cpp17::optional lambda_expressions, + std::optional num_shape_coefficients_to_fit, float lambda_identity, + std::optional num_expression_coefficients_to_fit, std::optional lambda_expressions, std::vector& pca_shape_coefficients, std::vector& expression_coefficients, std::vector& fitted_image_points) { @@ -693,8 +693,8 @@ inline std::pair fit_shape_and_pose( inline std::pair fit_shape_and_pose( const morphablemodel::MorphableModel& morphable_model, const std::vector& image_points, const std::vector& vertex_indices, int image_width, int image_height, int num_iterations, - cpp17::optional num_shape_coefficients_to_fit, float lambda_identity, - cpp17::optional num_expression_coefficients_to_fit, cpp17::optional lambda_expressions) + std::optional num_shape_coefficients_to_fit, float lambda_identity, + std::optional num_expression_coefficients_to_fit, std::optional lambda_expressions) { std::vector pca_coeffs; std::vector blendshape_coeffs; @@ -750,8 +750,8 @@ inline std::pair fit_shape_and_pose( const morphablemodel::MorphableModel& morphable_model, const core::LandmarkCollection& landmarks, const core::LandmarkMapper& landmark_mapper, int image_width, int image_height, int num_iterations, - cpp17::optional num_shape_coefficients_to_fit, float lambda_identity, - cpp17::optional num_expression_coefficients_to_fit, cpp17::optional lambda_expressions, + std::optional num_shape_coefficients_to_fit, float lambda_identity, + std::optional num_expression_coefficients_to_fit, std::optional lambda_expressions, std::vector& pca_shape_coefficients, std::vector& expression_coefficients, std::vector& fitted_image_points) { @@ -784,7 +784,7 @@ inline std::pair fit_shape_and_pose( // and get the corresponding model points (mean if given no initial coeffs, from the computed shape otherwise): for (int i = 0; i < landmarks.size(); ++i) { - const cpp17::optional vertex_idx = core::get_vertex_index( + const std::optional vertex_idx = core::get_vertex_index( landmarks[i].name, landmark_mapper, morphable_model.get_landmark_definitions()); if (!vertex_idx) // vertex index not defined for the current landmark { @@ -822,8 +822,8 @@ inline std::pair fit_shape_and_pose( inline std::pair fit_shape_and_pose( const morphablemodel::MorphableModel& morphable_model, const core::LandmarkCollection& landmarks, const core::LandmarkMapper& landmark_mapper, int image_width, int image_height, int num_iterations, - cpp17::optional num_shape_coefficients_to_fit, float lambda_identity, - cpp17::optional num_expression_coefficients_to_fit, cpp17::optional lambda_expressions) + std::optional num_shape_coefficients_to_fit, float lambda_identity, + std::optional num_expression_coefficients_to_fit, std::optional lambda_expressions) { std::vector pca_coeffs; std::vector blendshape_coeffs; diff --git a/include/eos/fitting/linear_shape_fitting.hpp b/include/eos/fitting/linear_shape_fitting.hpp index 40f49582a..a719a238c 100644 --- a/include/eos/fitting/linear_shape_fitting.hpp +++ b/include/eos/fitting/linear_shape_fitting.hpp @@ -23,7 +23,6 @@ #define EOS_LINEAR_SHAPE_FITTING_HPP #include "eos/morphablemodel/PcaModel.hpp" -#include "eos/cpp17/optional.hpp" #include "Eigen/Core" #include "Eigen/QR" @@ -32,6 +31,7 @@ #include #include #include +#include namespace eos { namespace fitting { @@ -61,9 +61,9 @@ inline std::vector fit_shape_to_landmarks_linear( const morphablemodel::PcaModel& shape_model, Eigen::Matrix affine_camera_matrix, const std::vector& landmarks, const std::vector& vertex_ids, Eigen::VectorXf base_face = Eigen::VectorXf(), float lambda = 3.0f, - cpp17::optional num_coefficients_to_fit = cpp17::optional(), - cpp17::optional detector_standard_deviation = cpp17::optional(), - cpp17::optional model_standard_deviation = cpp17::optional()) + std::optional num_coefficients_to_fit = std::optional(), + std::optional detector_standard_deviation = std::optional(), + std::optional model_standard_deviation = std::optional()) { assert(landmarks.size() == vertex_ids.size()); @@ -181,9 +181,9 @@ fit_shape_to_landmarks_linear_multi(const morphablemodel::PcaModel& shape_model, const std::vector>& vertex_ids, std::vector base_faces = std::vector(), float lambda = 3.0f, - cpp17::optional num_coefficients_to_fit = cpp17::optional(), - cpp17::optional detector_standard_deviation = cpp17::optional(), - cpp17::optional model_standard_deviation = cpp17::optional()) + std::optional num_coefficients_to_fit = std::optional(), + std::optional detector_standard_deviation = std::optional(), + std::optional model_standard_deviation = std::optional()) { assert(affine_camera_matrices.size() == landmarks.size() && landmarks.size() == vertex_ids.size()); // same number of instances (i.e. images/frames) for each of them diff --git a/include/eos/fitting/multi_image_fitting.hpp b/include/eos/fitting/multi_image_fitting.hpp index 7aab8e176..0529e9420 100644 --- a/include/eos/fitting/multi_image_fitting.hpp +++ b/include/eos/fitting/multi_image_fitting.hpp @@ -34,13 +34,13 @@ #include "eos/fitting/contour_correspondence.hpp" #include "eos/fitting/closest_edge_fitting.hpp" #include "eos/fitting/RenderingParameters.hpp" -#include "eos/cpp17/optional.hpp" #include "Eigen/Core" #include #include #include +#include namespace eos { namespace fitting { @@ -93,8 +93,8 @@ inline std::pair, std::vector image_width, std::vector image_height, const morphablemodel::EdgeTopology& edge_topology, const fitting::ContourLandmarks& contour_landmarks, const fitting::ModelContour& model_contour, int num_iterations, - cpp17::optional num_shape_coefficients_to_fit, float lambda, - cpp17::optional initial_rendering_params, + std::optional num_shape_coefficients_to_fit, float lambda, + std::optional initial_rendering_params, std::vector& pca_shape_coefficients, std::vector>& blendshape_coefficients, std::vector>& fitted_image_points) { @@ -374,7 +374,7 @@ fit_shape_and_pose(const morphablemodel::MorphableModel& morphable_model, std::vector image_height, const morphablemodel::EdgeTopology& edge_topology, const fitting::ContourLandmarks& contour_landmarks, const fitting::ModelContour& model_contour, int num_iterations = 5, - cpp17::optional num_shape_coefficients_to_fit = cpp17::nullopt, float lambda = 30.0f) + std::optional num_shape_coefficients_to_fit = std::nullopt, float lambda = 30.0f) { using std::vector; vector pca_shape_coefficients; @@ -383,7 +383,7 @@ fit_shape_and_pose(const morphablemodel::MorphableModel& morphable_model, return fit_shape_and_pose(morphable_model, blendshapes, landmarks, landmark_mapper, image_width, image_height, edge_topology, contour_landmarks, model_contour, num_iterations, - num_shape_coefficients_to_fit, lambda, cpp17::nullopt, pca_shape_coefficients, + num_shape_coefficients_to_fit, lambda, std::nullopt, pca_shape_coefficients, blendshape_coefficients, fitted_image_points); }; diff --git a/include/eos/fitting/orthographic_camera_estimation_linear.hpp b/include/eos/fitting/orthographic_camera_estimation_linear.hpp index 9659c930d..418cc4ac1 100644 --- a/include/eos/fitting/orthographic_camera_estimation_linear.hpp +++ b/include/eos/fitting/orthographic_camera_estimation_linear.hpp @@ -22,8 +22,6 @@ #ifndef EOS_ORTHOGRAPHIC_CAMERA_ESTIMATION_LINEAR_HPP #define EOS_ORTHOGRAPHIC_CAMERA_ESTIMATION_LINEAR_HPP -#include "eos/cpp17/optional.hpp" - #include "Eigen/Core" #include "Eigen/Dense" #include "Eigen/SVD" @@ -31,6 +29,7 @@ #include #include +#include namespace eos { namespace fitting { @@ -71,7 +70,7 @@ struct ScaledOrthoProjectionParameters */ inline ScaledOrthoProjectionParameters estimate_orthographic_projection_linear( std::vector image_points, std::vector model_points, - bool is_viewport_upsidedown, cpp17::optional viewport_height = cpp17::nullopt) + bool is_viewport_upsidedown, std::optional viewport_height = std::nullopt) { using Eigen::Matrix; assert(image_points.size() == model_points.size()); @@ -81,7 +80,7 @@ inline ScaledOrthoProjectionParameters estimate_orthographic_projection_linear( if (is_viewport_upsidedown) { - if (viewport_height == cpp17::nullopt) + if (viewport_height == std::nullopt) { throw std::runtime_error( "Error: If is_viewport_upsidedown is set to true, viewport_height needs to be given."); diff --git a/include/eos/morphablemodel/MorphableModel.hpp b/include/eos/morphablemodel/MorphableModel.hpp index 314edebf3..2b344fe0f 100644 --- a/include/eos/morphablemodel/MorphableModel.hpp +++ b/include/eos/morphablemodel/MorphableModel.hpp @@ -26,7 +26,6 @@ #include "eos/morphablemodel/PcaModel.hpp" #include "eos/morphablemodel/Blendshape.hpp" #include "eos/morphablemodel/ExpressionModel.hpp" -#include "eos/cpp17/optional.hpp" #include "eos/cpp17/variant.hpp" #include "cereal/access.hpp" @@ -34,7 +33,7 @@ #include "cereal/types/array.hpp" #include "cereal/types/vector.hpp" #include "cereal/types/unordered_map.hpp" -#include "eos/cpp17/optional_serialization.hpp" +#include "cereal/types/optional.hpp" #include "eos/cpp17/variant_serialization.hpp" #include "eos/morphablemodel/io/eigen_cerealisation.hpp" #include "cereal/archives/binary.hpp" @@ -50,6 +49,7 @@ #include #include #include +#include namespace eos { namespace morphablemodel { @@ -87,7 +87,7 @@ class MorphableModel */ MorphableModel( PcaModel shape_model, PcaModel color_model, - cpp17::optional> landmark_definitions = cpp17::nullopt, + std::optional> landmark_definitions = std::nullopt, std::vector> texture_coordinates = std::vector>(), std::vector> texture_triangle_indices = std::vector>()) : shape_model(shape_model), color_model(color_model), landmark_definitions(landmark_definitions), @@ -107,7 +107,7 @@ class MorphableModel */ MorphableModel( PcaModel shape_model, ExpressionModel expression_model, PcaModel color_model, - cpp17::optional> landmark_definitions = cpp17::nullopt, + std::optional> landmark_definitions = std::nullopt, std::vector> texture_coordinates = std::vector>(), std::vector> texture_triangle_indices = std::vector>()) : shape_model(shape_model), color_model(color_model), landmark_definitions(landmark_definitions), @@ -173,7 +173,7 @@ class MorphableModel // blendshapes, there's nothing to add. if (get_expression_model_type() == ExpressionModelType::PcaModel) { - shape += cpp17::get(expression_model.value()).get_mean(); + shape += std::get(expression_model.value()).get_mean(); } core::Mesh mesh; @@ -316,7 +316,7 @@ class MorphableModel // Get a sample of the expression model, depending on whether it's a PcaModel or Blendshapes: if (get_expression_model_type() == ExpressionModelType::PcaModel) { - const auto& pca_expression_model = cpp17::get(expression_model.value()); + const auto& pca_expression_model = std::get(expression_model.value()); assert(pca_expression_model.get_data_dimension() == shape_model.get_data_dimension()); if (expression_coefficients.empty()) { @@ -327,7 +327,7 @@ class MorphableModel } } else if (get_expression_model_type() == ExpressionModelType::Blendshapes) { - const auto& expression_blendshapes = cpp17::get(expression_model.value()); + const auto& expression_blendshapes = std::get(expression_model.value()); assert(expression_blendshapes.size() > 0); assert(expression_blendshapes[0].deformation.rows() == shape_model.get_data_dimension()); if (expression_coefficients.empty()) @@ -411,7 +411,7 @@ class MorphableModel * The landmark definitions define mappings from a set of global landmark identifiers, like for * example "eye.right.outer_corner", to the model's respective vertex indices. */ - void set_landmark_definitions(cpp17::optional> landmark_definitions) + void set_landmark_definitions(std::optional> landmark_definitions) { this->landmark_definitions = landmark_definitions; }; @@ -455,10 +455,10 @@ class MorphableModel { return ExpressionModelType::None; } - if (cpp17::holds_alternative(expression_model.value())) + if (std::holds_alternative(expression_model.value())) { return ExpressionModelType::Blendshapes; - } else if (cpp17::holds_alternative(expression_model.value())) + } else if (std::holds_alternative(expression_model.value())) { return ExpressionModelType::PcaModel; } else @@ -471,14 +471,14 @@ class MorphableModel }; private: - PcaModel shape_model; ///< A PCA model of the shape - PcaModel color_model; ///< A PCA model of vertex colour information - cpp17::optional expression_model; ///< Blendshapes or PcaModel - cpp17::optional> landmark_definitions; ///< A set of landmark - ///< definitions for the - ///< model, mapping from - ///< identifiers to vertex - ///< numbers + PcaModel shape_model; ///< A PCA model of the shape + PcaModel color_model; ///< A PCA model of vertex colour information + std::optional expression_model; ///< Blendshapes or PcaModel + std::optional> landmark_definitions; ///< A set of landmark + ///< definitions for the + ///< model, mapping from + ///< identifiers to vertex + ///< numbers std::vector> texture_coordinates; ///< uv-coordinates for every vertex std::vector> texture_triangle_indices; ///< Triangulation for the uv-coordinates diff --git a/include/eos/render/FragmentShader.hpp b/include/eos/render/FragmentShader.hpp index 194452a91..4a1653839 100644 --- a/include/eos/render/FragmentShader.hpp +++ b/include/eos/render/FragmentShader.hpp @@ -24,10 +24,11 @@ #include "eos/render/detail/Vertex.hpp" #include "eos/render/detail/texturing.hpp" -#include "eos/cpp17/optional.hpp" #include "Eigen/Core" +#include + // Fragment shaders are a more accurate name for the same functionality as Pixel shaders. They aren't pixels // yet, since the output still has to past several tests (depth, alpha, stencil) as well as the fact that one // may be using anti-aliasing, which renders one-fragment-to-one-pixel non-true. @@ -65,7 +66,7 @@ class VertexColoringFragmentShader Eigen::Vector4 shade_triangle_pixel(int x, int y, const detail::Vertex& point_a, const detail::Vertex& point_b, const detail::Vertex& point_c, const Eigen::Vector3& lambda, - const cpp17::optional& texture, float dudx, float dudy, + const std::optional& texture, float dudx, float dudy, float dvdx, float dvdy) { // attributes interpolation @@ -98,7 +99,7 @@ class TexturingFragmentShader Eigen::Vector4 shade_triangle_pixel(int x, int y, const detail::Vertex& point_a, const detail::Vertex& point_b, const detail::Vertex& point_c, const Eigen::Vector3& lambda, - const cpp17::optional& texture, float dudx, float dudy, + const std::optional& texture, float dudx, float dudy, float dvdx, float dvdy) { Eigen::Vector2 texcoords_persp = @@ -173,7 +174,7 @@ class ExtractionFragmentShader Eigen::Vector4 shade_triangle_pixel(int x, int y, const detail::Vertex& point_a, const detail::Vertex& point_b, const detail::Vertex& point_c, const Eigen::Vector3& lambda, - const cpp17::optional& texture, float dudx, float dudy, + const std::optional& texture, float dudx, float dudy, float dvdx, float dvdy) { const auto corrected_lambda = compute_inverse_perspectively_correct_lambda( diff --git a/include/eos/render/Rasterizer.hpp b/include/eos/render/Rasterizer.hpp index 1e0b871fb..ef4fce0dd 100644 --- a/include/eos/render/Rasterizer.hpp +++ b/include/eos/render/Rasterizer.hpp @@ -29,11 +29,11 @@ #include "eos/render/detail/Vertex.hpp" #include "eos/render/detail/plane.hpp" #include "eos/render/detail/utils.hpp" -#include "eos/cpp17/optional.hpp" #include "Eigen/Core" #include +#include namespace eos { namespace render { @@ -65,7 +65,7 @@ class Rasterizer */ template void raster_triangle(const detail::Vertex& point_a, const detail::Vertex& point_b, - const detail::Vertex& point_c, const cpp17::optional& texture) + const detail::Vertex& point_c, const std::optional& texture) { // We already calculated this in the culling/clipping stage. Maybe we should save/cache it after all. const auto boundingBox = detail::calculate_clipped_bounding_box( diff --git a/include/eos/render/SoftwareRenderer.hpp b/include/eos/render/SoftwareRenderer.hpp index 579360944..0e6875473 100644 --- a/include/eos/render/SoftwareRenderer.hpp +++ b/include/eos/render/SoftwareRenderer.hpp @@ -27,7 +27,6 @@ #include "eos/render/transforms.hpp" #include "eos/render/detail/Vertex.hpp" #include "eos/render/Texture.hpp" -#include "eos/cpp17/optional.hpp" #include "Eigen/Core" @@ -35,6 +34,7 @@ #include #include #include +#include /** * @file include/eos/render/SoftwareRenderer.hpp @@ -97,7 +97,7 @@ class SoftwareRenderer template core::Image4u render(const core::Mesh& mesh, const Eigen::Matrix4& model_view_matrix, const Eigen::Matrix4& projection_matrix, - const cpp17::optional& texture = cpp17::nullopt) + const std::optional& texture = std::nullopt) { // The number of vertices has to be equal for both shape and colour, or, alternatively, it has to be a // shape-only model: @@ -374,7 +374,7 @@ class SoftwareRenderer }; public: // Todo: these should go private in the final implementation - cpp17::optional texture = cpp17::nullopt; + std::optional texture = std::nullopt; bool enable_backface_culling = false; bool enable_near_clipping = true; diff --git a/include/eos/render/ray_triangle_intersect.hpp b/include/eos/render/ray_triangle_intersect.hpp index ac6315e17..cc1b280d0 100644 --- a/include/eos/render/ray_triangle_intersect.hpp +++ b/include/eos/render/ray_triangle_intersect.hpp @@ -22,11 +22,10 @@ #ifndef EOS_RAY_TRIANGLE_INTERSECT_HPP #define EOS_RAY_TRIANGLE_INTERSECT_HPP -#include "eos/cpp17/optional.hpp" - #include "Eigen/Core" #include +#include namespace eos { namespace render { @@ -53,7 +52,7 @@ namespace render { * discarded. * @return Whether the ray intersects the triangle, and if yes, including the distance. */ -inline std::pair> +inline std::pair> ray_triangle_intersect(const Eigen::Vector3f& ray_origin, const Eigen::Vector3f& ray_direction, const Eigen::Vector3f& v0, const Eigen::Vector3f& v1, const Eigen::Vector3f& v2, bool enable_backculling) @@ -73,24 +72,24 @@ ray_triangle_intersect(const Eigen::Vector3f& ray_origin, const Eigen::Vector3f& // If det is negative, the triangle is back-facing. // If det is close to 0, the ray misses the triangle. if (det < epsilon) - return {false, cpp17::nullopt}; + return {false, std::nullopt}; } else { // If det is close to 0, the ray and triangle are parallel. if (std::abs(det) < epsilon) - return {false, cpp17::nullopt}; + return {false, std::nullopt}; } const float inv_det = 1 / det; const Vector3f tvec = ray_origin - v0; const auto u = tvec.dot(pvec) * inv_det; if (u < 0 || u > 1) - return {false, cpp17::nullopt}; + return {false, std::nullopt}; const Vector3f qvec = tvec.cross(v0v1); const auto v = ray_direction.dot(qvec) * inv_det; if (v < 0 || u + v > 1) - return {false, cpp17::nullopt}; + return {false, std::nullopt}; const auto t = v0v2.dot(qvec) * inv_det;