diff --git a/CMakeLists.txt b/CMakeLists.txt index ad96ed4e3..954e58e6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/fitting/RenderingParameters.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/fitting/FittingResult.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/render/utils.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/render/normals.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/render/draw_utils.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/render/render.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/eos/render/render_affine.hpp diff --git a/include/eos/render/normals.hpp b/include/eos/render/normals.hpp new file mode 100644 index 000000000..6a33bd3ec --- /dev/null +++ b/include/eos/render/normals.hpp @@ -0,0 +1,80 @@ +/* + * eos - A 3D Morphable Model fitting library written in modern C++11/14. + * + * File: include/eos/render/normals.hpp + * + * Copyright 2014-2019 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_RENDER_NORMALS_HPP +#define EOS_RENDER_NORMALS_HPP + +#include "glm/vec3.hpp" +#include "glm/geometric.hpp" + +#include "Eigen/Core" + +namespace eos { +namespace render { + +/** + * Calculates the normal of a face (or triangle), i.e. the + * per-face normal. Return normal will be normalised. + * Assumes the triangle is given in CCW order, i.e. vertices + * in counterclockwise order on the screen are front-facing. + * + * @param[in] v0 First vertex. + * @param[in] v1 Second vertex. + * @param[in] v2 Third vertex. + * @return The unit-length normal of the given triangle. + */ +inline Eigen::Vector3f compute_face_normal(const Eigen::Vector3f& v0, const Eigen::Vector3f& v1, + const Eigen::Vector3f& v2) +{ + Eigen::Vector3f n = (v1 - v0).cross(v2 - v0); // v0-to-v1 x v0-to-v2 + return n.normalized(); +}; + +// Todo: Doxygen. Actually this is the overload that's probably most used? +inline Eigen::Vector3f compute_face_normal(const Eigen::Vector4f& v0, const Eigen::Vector4f& v1, + const Eigen::Vector4f& v2) +{ + Eigen::Vector4f n = (v1 - v0).cross3(v2 - v0); // v0-to-v1 x v0-to-v2 + return n.head<3>().normalized(); +}; + +/** + * Computes the normal of a face (or triangle), i.e. the + * per-face normal. Return normal will be normalised. + * Assumes the triangle is given in CCW order, i.e. vertices + * in counterclockwise order on the screen are front-facing. + * + * @param[in] v0 First vertex. + * @param[in] v1 Second vertex. + * @param[in] v2 Third vertex. + * @return The unit-length normal of the given triangle. + */ +inline glm::vec3 compute_face_normal(const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2) +{ + glm::vec3 n = glm::cross(v1 - v0, v2 - v0); // v0-to-v1 x v0-to-v2 + n = glm::normalize(n); + return n; +}; + +} /* namespace render */ +} /* namespace eos */ + +#endif /* EOS_RENDER_NORMALS_HPP */ diff --git a/include/eos/render/utils.hpp b/include/eos/render/utils.hpp index 6149e9df0..8d568e92a 100644 --- a/include/eos/render/utils.hpp +++ b/include/eos/render/utils.hpp @@ -22,10 +22,7 @@ #ifndef RENDER_UTILS_HPP_ #define RENDER_UTILS_HPP_ -#include "glm/vec3.hpp" -#include "glm/geometric.hpp" - -#include "Eigen/Core" +#include "glm/vec2.hpp" namespace eos { namespace render { @@ -95,50 +92,6 @@ glm::tvec2 clip_to_screen_space(const T clip_coord_x, const T clip_coord_y return glm::tvec2(x_ss, y_ss); }; -/** - * Calculates the normal of a face (or triangle), i.e. the - * per-face normal. Return normal will be normalised. - * Assumes the triangle is given in CCW order, i.e. vertices - * in counterclockwise order on the screen are front-facing. - * - * @param[in] v0 First vertex. - * @param[in] v1 Second vertex. - * @param[in] v2 Third vertex. - * @return The unit-length normal of the given triangle. - */ -inline Eigen::Vector3f compute_face_normal(const Eigen::Vector3f& v0, const Eigen::Vector3f& v1, - const Eigen::Vector3f& v2) -{ - Eigen::Vector3f n = (v1 - v0).cross(v2 - v0); // v0-to-v1 x v0-to-v2 - return n.normalized(); -}; - -// Todo: Doxygen. Actually this is the overload that's probably most used? -inline Eigen::Vector3f compute_face_normal(const Eigen::Vector4f& v0, const Eigen::Vector4f& v1, - const Eigen::Vector4f& v2) -{ - Eigen::Vector4f n = (v1 - v0).cross3(v2 - v0); // v0-to-v1 x v0-to-v2 - return n.head<3>().normalized(); -}; - -/** - * Computes the normal of a face (or triangle), i.e. the - * per-face normal. Return normal will be normalised. - * Assumes the triangle is given in CCW order, i.e. vertices - * in counterclockwise order on the screen are front-facing. - * - * @param[in] v0 First vertex. - * @param[in] v1 Second vertex. - * @param[in] v2 Third vertex. - * @return The unit-length normal of the given triangle. - */ -inline glm::vec3 compute_face_normal(const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2) -{ - glm::vec3 n = glm::cross(v1 - v0, v2 - v0); // v0-to-v1 x v0-to-v2 - n = glm::normalize(n); - return n; -}; - } /* namespace render */ } /* namespace eos */