22#ifndef EOS_RAY_TRIANGLE_INTERSECT_HPP
23#define EOS_RAY_TRIANGLE_INTERSECT_HPP
25#include "eos/cpp17/optional.hpp"
56inline std::pair<bool, cpp17::optional<float>>
58 const Eigen::Vector3f& v0,
const Eigen::Vector3f& v1,
const Eigen::Vector3f& v2,
59 bool enable_backculling)
61 using Eigen::Vector3f;
62 const float epsilon = 1e-6f;
64 const Vector3f v0v1 = v1 - v0;
65 const Vector3f v0v2 = v2 - v0;
67 const Vector3f pvec = ray_direction.cross(v0v2);
69 const float det = v0v1.dot(pvec);
71 if (enable_backculling)
76 return {
false, cpp17::nullopt};
80 if (std::abs(det) < epsilon)
81 return {
false, cpp17::nullopt};
83 const float inv_det = 1 / det;
85 const Vector3f tvec = ray_origin - v0;
86 const auto u = tvec.dot(pvec) * inv_det;
88 return {
false, cpp17::nullopt};
90 const Vector3f qvec = tvec.cross(v0v1);
91 const auto v = ray_direction.dot(qvec) * inv_det;
92 if (v < 0 || u + v > 1)
93 return {
false, cpp17::nullopt};
95 const auto t = v0v2.dot(qvec) * inv_det;
std::pair< bool, cpp17::optional< float > > 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)
Computes the intersection of the given ray with the given triangle.
Definition: ray_triangle_intersect.hpp:57
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.