2#include <muda/ext/eigen/svd/svd_impl.h>
8 MUDA_INLINE MUDA_DEVICE
void device_svd(
const Eigen::Matrix<float, 3, 3>& F,
9 Eigen::Matrix<float, 3, 3>& U,
10 Eigen::Vector3<float>& Sigma,
11 Eigen::Matrix<float, 3, 3>& V)
13 muda::details::eigen::svd3x3(F(0, 0),
48#include <muda/ext/eigen/eigen_dense_cxx20.h>
51MUDA_INLINE MUDA_GENERIC
void svd(
const Eigen::Matrix<float, 3, 3>& F,
52 Eigen::Matrix<float, 3, 3>& U,
53 Eigen::Vector3<float>& Sigma,
54 Eigen::Matrix<float, 3, 3>& V)
56 using mat3 = Eigen::Matrix<float, 3, 3>;
57 using vec3 = Eigen::Vector3<float>;
59 details::device_svd(F, U, Sigma, V);
61 const Eigen::JacobiSVD<mat3, Eigen::NoQRPreconditioner> svd(
62 F, Eigen::ComputeFullU | Eigen::ComputeFullV);
65 Sigma = svd.singularValues();
67 mat3 L = mat3::Identity();
68 L(2, 2) = (U * V.transpose()).determinant();
70 const float detU = U.determinant();
71 const float detV = V.determinant();
73 if(detU < 0.0 && detV > 0)
75 if(detU > 0.0 && detV < 0.0)
77 Sigma[2] = Sigma[2] * L(2, 2);
80MUDA_INLINE MUDA_GENERIC
void pd(
const Eigen::Matrix<float, 3, 3>& F,
81 Eigen::Matrix<float, 3, 3>& R,
82 Eigen::Matrix<float, 3, 3>& S)
84 Eigen::Matrix<float, 3, 3> U, V;
85 Eigen::Vector3<float> Sigma;
87 R = U * V.transpose();
88 S = V * Sigma.asDiagonal() * V.transpose();
91MUDA_INLINE MUDA_GENERIC
void svd(
const Eigen::Matrix<double, 3, 3>& F,
92 Eigen::Matrix<double, 3, 3>& U,
93 Eigen::Vector3<double>& Sigma,
94 Eigen::Matrix<double, 3, 3>& V)
97 Eigen::Vector3f fSigma;
99 svd(F.cast<
float>(), fU, fSigma, fV);
100 U = fU.cast<
double>();
101 Sigma = fSigma.cast<
double>();
102 V = fV.cast<
double>();
105MUDA_INLINE MUDA_GENERIC
void pd(
const Eigen::Matrix<double, 3, 3>& F,
106 Eigen::Matrix<double, 3, 3>& R,
107 Eigen::Matrix<double, 3, 3>& S)
111 pd(F.cast<
float>(), fR, fS);
112 R = fR.cast<
double>();
113 S = fS.cast<
double>();