Skip to content

Commit 7a917cc

Browse files
committed
Merge branch 'cpp14-optional'
2 parents b29487e + b1d23f3 commit 7a917cc

23 files changed

+1311
-80
lines changed

.travis.yml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
1-
sudo: required
2-
dist: trusty
1+
dist: trusty # Use 'trusty' unless specified otherwise
2+
os: linux # Use Linux unless specified otherwise
3+
sudo: false
34

45
language: cpp
56

6-
env:
7-
- C_COMPILER=gcc-7 CXX_COMPILER=g++-7
8-
- C_COMPILER=clang-5.0 CXX_COMPILER=clang++-5.0
7+
matrix:
8+
include:
9+
- env: C_COMPILER=gcc-7 CXX_COMPILER=g++-7 GENERATOR_NAME="Unix Makefiles"
10+
addons: { apt: { packages: ["g++-7"], sources: ["ubuntu-toolchain-r-test"] } }
911

10-
before_install:
11-
- pyenv global system 3.6 # Workaround for travis-ci/issues/8363
12-
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
13-
- wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
14-
- echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-5.0 main" | sudo tee -a /etc/apt/sources.list
15-
- sudo apt-get update -q
16-
- sudo apt-get install gcc-7 g++-7 -y
17-
- sudo apt-get install clang-5.0 -y
18-
- sudo apt-get install libboost-all-dev libopencv-dev -y
19-
- wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.tar.gz
20-
- tar -xvzf cmake-3.8.2-Linux-x86_64.tar.gz
12+
- env: C_COMPILER=clang-5.0 CXX_COMPILER=clang++-5.0 GENERATOR_NAME="Unix Makefiles"
13+
addons: { apt: { packages: ["g++-7", "clang-5.0"], sources: ["llvm-toolchain-trusty-5.0", "ubuntu-toolchain-r-test"] } }
14+
# g++-7 is needed here - otherwise the build will fail because g++-4.8 libstdc++ is used.
15+
16+
- os: osx
17+
env: C_COMPILER=clang CXX_COMPILER=clang++ GENERATOR_NAME="Xcode"
18+
osx_image: xcode9.2
19+
20+
install:
21+
- |
22+
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
23+
wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.tar.gz
24+
CMAKE_DIR=${TRAVIS_BUILD_DIR}/cmake && mkdir ${CMAKE_DIR}
25+
tar -xvzf cmake-3.8.2-Linux-x86_64.tar.gz --strip-components=1 -C ${CMAKE_DIR} # extract from inside the top-level directory to CMAKE_DIR
26+
export PATH=${CMAKE_DIR}/bin:${PATH}
27+
pyenv global system 3.6 # Workaround for travis-ci/issues/8363
28+
sudo apt-get update -q
29+
sudo apt-get install libboost-all-dev libopencv-dev -y
30+
else
31+
brew install cmake || brew upgrade cmake
32+
brew install boost
33+
/usr/bin/yes | pip2 uninstall numpy # see: travis-ci/issues/6688
34+
brew install opencv
35+
fi
36+
- cmake --version
2137

2238
before_script:
2339
- mkdir build
2440
- cd build
25-
- ../cmake-3.8.2-Linux-x86_64/bin/cmake -DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DEOS_BUILD_EXAMPLES=on -DEOS_BUILD_UTILS=on -DEOS_GENERATE_PYTHON_BINDINGS=on -DPYTHON_EXECUTABLE=`which python3.6` ..
41+
- cmake -G "${GENERATOR_NAME}" -DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_INSTALL_PREFIX=../install -DEOS_BUILD_EXAMPLES=on -DEOS_BUILD_UTILS=on -DEOS_GENERATE_PYTHON_BINDINGS=on -DPYTHON_EXECUTABLE=`which python3.6` ..
2642

2743
script:
28-
- make VERBOSE=1
44+
- cmake --build . --config Release
45+
- cmake --build . --target install --config Release

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ set(HEADERS
112112
${CMAKE_CURRENT_SOURCE_DIR}/include/eos/render/detail/Vertex.hpp
113113
${CMAKE_CURRENT_SOURCE_DIR}/include/eos/video/Keyframe.hpp
114114
${CMAKE_CURRENT_SOURCE_DIR}/include/eos/video/keyframe_merging.hpp
115+
${CMAKE_CURRENT_SOURCE_DIR}/include/eos/cpp17/optional.hpp
116+
${CMAKE_CURRENT_SOURCE_DIR}/include/eos/cpp17/detail/akrzemi1_optional.hpp
117+
${CMAKE_CURRENT_SOURCE_DIR}/include/eos/cpp17/detail/akrzemi1_optional_serialization.hpp
115118
)
116119

117120
add_library(eos INTERFACE)
@@ -137,6 +140,8 @@ source_group(fitting\\detail REGULAR_EXPRESSION include/eos/fitting/detail/*)
137140
source_group(render REGULAR_EXPRESSION include/eos/render/*)
138141
source_group(render\\detail REGULAR_EXPRESSION include/eos/render/detail/*)
139142
source_group(video REGULAR_EXPRESSION include/eos/video/*)
143+
source_group(cpp17 REGULAR_EXPRESSION include/eos/cpp17/*)
144+
source_group(cpp17\\detail REGULAR_EXPRESSION include/eos/cpp17/detail/*)
140145

141146
# The eos install target:
142147
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include) # our library headers

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# eos: A lightweight header-only 3D Morphable Face Model fitting library in modern C++11/14.
22
[![Latest release](http://img.shields.io/github/release/patrikhuber/eos.svg?style=flat-square)][release]
3-
[![Linux build status of master branch](https://img.shields.io/travis/patrikhuber/eos/master.svg?style=flat-square&label=Linux%3A%20build)][travis]
3+
[![Linux build status of master branch](https://img.shields.io/travis/patrikhuber/eos/master.svg?style=flat-square&label=Linux/macOS%3A%20build)][travis]
44
[![Windows build status of master branch](https://ci.appveyor.com/api/projects/status/gekekpn08cdgqcsk/branch/master?svg=true&passingText=Windows%3A%20build%20passing&failingText=Windows%3A%20build%20failing&pendingText=Windows%3A%20build%20pending)][appveyor]
55
[![Apache License 2.0](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat-square)][license]
66

@@ -28,7 +28,7 @@ An experimental model viewer to visualise 3D Morphable Models and blendshapes is
2828

2929
## Usage
3030

31-
* Tested with the following compilers: >=gcc-7, >=clang-5, Visual Studio 2017 Update 3.
31+
* Tested with the following compilers: >=gcc-7, >=clang-5, >=Visual Studio 2017 15.5, >=Xcode 9.2.
3232
* The library and python bindings are free of any external dependencies. The example applications require Boost (>=1.50.0) and OpenCV (>=2.4.3).
3333

3434
To use the library in your own project, just add the following directories to your include path:

doc/namespaces.doxygen

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@
3232
* @namespace eos::video
3333
* @brief Video keyframe extraction and fusion.
3434
*/
35+
36+
/**
37+
* @namespace eos::cpp17
38+
* @brief Replacement type for std::optional for compilers who don't have it (Apple at the moment).
39+
*/

examples/fit-model-multi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "eos/render/texture_extraction.hpp"
3131
#include "eos/render/render.hpp"
3232
#include "eos/render/draw_utils.hpp"
33+
#include "eos/cpp17/optional.hpp"
3334

3435
#include "opencv2/core/core.hpp"
3536
#include "opencv2/highgui/highgui.hpp"
@@ -40,7 +41,6 @@
4041
#include <vector>
4142
#include <iostream>
4243
#include <fstream>
43-
#include <optional>
4444

4545
using namespace eos;
4646
namespace po = boost::program_options;
@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
248248

249249
std::tie(per_frame_meshes, per_frame_rendering_params) = fitting::fit_shape_and_pose(
250250
morphable_model, blendshapes, per_frame_landmarks, landmark_mapper, image_widths, image_heights, edge_topology,
251-
ibug_contour, model_contour, 5, std::nullopt, 30.0f, std::nullopt, pca_shape_coefficients,
251+
ibug_contour, model_contour, 5, cpp17::nullopt, 30.0f, cpp17::nullopt, pca_shape_coefficients,
252252
blendshape_coefficients, fitted_image_points);
253253

254254
cout << "Final pca shape coefficients: ";

examples/fit-model.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "eos/morphablemodel/MorphableModel.hpp"
2828
#include "eos/render/draw_utils.hpp"
2929
#include "eos/render/texture_extraction.hpp"
30+
#include "eos/cpp17/optional.hpp"
3031

3132
#include "Eigen/Core"
3233

@@ -38,7 +39,6 @@
3839
#include "opencv2/imgproc/imgproc.hpp"
3940

4041
#include <iostream>
41-
#include <optional>
4242
#include <string>
4343
#include <vector>
4444

@@ -160,7 +160,7 @@ int main(int argc, char* argv[])
160160
fitting::RenderingParameters rendering_params;
161161
std::tie(mesh, rendering_params) = fitting::fit_shape_and_pose(
162162
morphable_model, blendshapes, landmarks, landmark_mapper, image.cols, image.rows, edge_topology,
163-
ibug_contour, model_contour, 5, std::nullopt, 30.0f);
163+
ibug_contour, model_contour, 5, cpp17::nullopt, 30.0f);
164164

165165
// The 3D head pose can be recovered as follows:
166166
float yaw_angle = glm::degrees(glm::yaw(rendering_params.get_rotation()));

examples/generate-obj.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "eos/core/Image_opencv_interop.hpp"
2222
#include "eos/morphablemodel/MorphableModel.hpp"
2323
#include "eos/render/render.hpp"
24+
#include "eos/cpp17/optional.hpp"
2425

2526
#include "glm/gtc/matrix_transform.hpp"
2627

@@ -107,7 +108,7 @@ int main(int argc, char* argv[])
107108
core::Image4u rendering;
108109
std::tie(rendering, std::ignore) =
109110
render::render(sample_mesh, glm::mat4x4(1.0f), glm::ortho(-130.0f, 130.0f, -130.0f, 130.0f), 512, 512,
110-
std::nullopt, true, false, false);
111+
cpp17::nullopt, true, false, false);
111112
fs::path filename_rendering(output_file);
112113
filename_rendering.replace_extension(".png");
113114
cv::imwrite(filename_rendering.string(), core::to_mat(rendering));

include/eos/core/LandmarkMapper.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
#ifndef LANDMARKMAPPER_HPP_
2323
#define LANDMARKMAPPER_HPP_
2424

25+
#include "eos/cpp17/optional.hpp"
26+
2527
#include "toml.hpp"
2628

27-
#include <optional>
2829
#include <stdexcept>
2930
#include <string>
3031
#include <unordered_map>
@@ -102,7 +103,7 @@ class LandmarkMapper
102103
* @param[in] landmark_name A landmark name to convert.
103104
* @return The mapped landmark name if a mapping exists, an empty optional otherwise.
104105
*/
105-
std::optional<std::string> convert(std::string landmark_name) const
106+
cpp17::optional<std::string> convert(std::string landmark_name) const
106107
{
107108
if (landmark_mappings.empty())
108109
{
@@ -117,7 +118,7 @@ class LandmarkMapper
117118
return converted_landmark->second;
118119
} else
119120
{ // landmark_name does not match the key of any element in the map
120-
return std::nullopt;
121+
return cpp17::nullopt;
121122
}
122123
};
123124

include/eos/core/read_obj.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#define READ_OBJ_HPP_
2424

2525
#include "eos/core/Mesh.hpp"
26+
#include "eos/cpp17/optional.hpp"
2627

2728
#include "Eigen/Core"
2829

2930
#include <cassert>
3031
#include <fstream>
31-
#include <optional>
3232
#include <string>
3333
#include <tuple>
3434
#include <utility>
@@ -103,13 +103,13 @@ void tokenize(const std::string& str, ContainerType& tokens, const std::string&
103103
* Todo: Consider using std::string_view for these instead of const string&.
104104
* And should change to glm::vec3, and just divide by 'w'. As soon as we change the Mesh to vec3.
105105
*/
106-
inline std::pair<Eigen::Vector4f, std::optional<Eigen::Vector3f>> parse_vertex(const std::string& line)
106+
inline std::pair<Eigen::Vector4f, cpp17::optional<Eigen::Vector3f>> parse_vertex(const std::string& line)
107107
{
108108
std::vector<std::string> tokens;
109109
tokenize(line, tokens, " ");
110110
assert(tokens.size() == 3 || tokens.size() == 6); // Maybe we should throw instead?
111111
const Eigen::Vector4f vertex(std::stof(tokens[0]), std::stof(tokens[1]), std::stof(tokens[2]), 1.0);
112-
std::optional<Eigen::Vector3f> vertex_color;
112+
cpp17::optional<Eigen::Vector3f> vertex_color;
113113
if (tokens.size() == 6)
114114
{
115115
vertex_color = Eigen::Vector3f(std::stof(tokens[3]), std::stof(tokens[4]), std::stof(tokens[5]));

0 commit comments

Comments
 (0)