22#ifndef EOS_RENDER_NORMALS_HPP
23#define EOS_RENDER_NORMALS_HPP
44 const Eigen::Vector3f& v2)
46 Eigen::Vector3f n = (v1 - v0).cross(v2 - v0);
47 return n.normalized();
62 const Eigen::Vector4f& v2)
64 Eigen::Vector4f n = (v1 - v0).cross3(v2 - v0);
65 return n.head<3>().normalized();
77inline std::vector<Eigen::Vector3f>
79 const std::vector<std::array<int, 3>>& triangle_vertex_indices)
81 std::vector<Eigen::Vector3f> face_normals;
82 for (
const auto& tvi : triangle_vertex_indices)
84 const auto face_normal =
compute_face_normal(vertices[tvi[0]], vertices[tvi[1]], vertices[tvi[2]]);
85 face_normals.push_back(face_normal);
101inline std::vector<Eigen::Vector3f>
103 const std::vector<std::array<int, 3>>& triangle_vertex_indices,
104 const std::vector<Eigen::Vector3f>& face_normals)
106 std::vector<Eigen::Vector3f> per_vertex_normals;
108 for (
int i = 0; i < vertices.size(); ++i)
110 per_vertex_normals.emplace_back(Eigen::Vector3f(0.0f, 0.0f, 0.0f));
114 for (
int i = 0; i < triangle_vertex_indices.size(); ++i)
116 const auto& tvi = triangle_vertex_indices[i];
118 per_vertex_normals[tvi[0]] += face_normals[i];
119 per_vertex_normals[tvi[1]] += face_normals[i];
120 per_vertex_normals[tvi[2]] += face_normals[i];
124 for (
auto& n : per_vertex_normals)
128 return per_vertex_normals;
std::vector< Eigen::Vector3f > compute_face_normals(const std::vector< Eigen::Vector3f > &vertices, const std::vector< std::array< int, 3 > > &triangle_vertex_indices)
Definition: normals.hpp:78
Eigen::Vector3f compute_face_normal(const Eigen::Vector3f &v0, const Eigen::Vector3f &v1, const Eigen::Vector3f &v2)
Definition: normals.hpp:43
std::vector< Eigen::Vector3f > compute_vertex_normals(const std::vector< Eigen::Vector3f > &vertices, const std::vector< std::array< int, 3 > > &triangle_vertex_indices, const std::vector< Eigen::Vector3f > &face_normals)
Definition: normals.hpp:102
core::Image4u render(const core::Mesh &mesh, const Eigen::Matrix4f &model_view_matrix, const Eigen::Matrix4f &projection_matrix, int viewport_width, int viewport_height, bool enable_backface_culling=false, bool enable_near_clipping=true, bool enable_far_clipping=true)
Definition: render.hpp:52
Namespace containing all of eos's 3D model fitting functionality.