#ifndef MEDUSA_BITS_DOMAINS_COMPUTE_NORMAL_HPP_ #define MEDUSA_BITS_DOMAINS_COMPUTE_NORMAL_HPP_ /** * @file * Implementation of normal computation. */ #include "compute_normal_fwd.hpp" #include #include #include #include namespace mm { namespace surface_fill_internal { /// @cond template Vec compute_normal(Eigen::Matrix J) { static_assert(dim_from < dim_to, "At least one free dimension must be present."); Eigen::JacobiSVD svd(J, Eigen::ComputeFullU); assert_msg(svd.rank() == dim_from, "Jacobi matrix does not have full rank."); Vec normal = svd.matrixU().col(dim_from); // Find correct orientation Eigen::Matrix M; M.template topLeftCorner() = J.template topLeftCorner(); M.template rightCols<1>() = normal.template tail(); normal *= (M.determinant() > 0) ? -1.0 : 1.0; return normal; } /// @endcond } // namespace surface_fill_internal } // namespace mm #endif // MEDUSA_BITS_DOMAINS_COMPUTE_NORMAL_HPP_