IGL_INLINE void igl::frame_to_cross_field( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, const Eigen::MatrixXd& FF1, const Eigen::MatrixXd& FF2, Eigen::MatrixXd& X) { using namespace Eigen; // Generate local basis MatrixXd B1, B2, B3; igl::local_basis(V,F,B1,B2,B3); // Project the frame fields in the local basis MatrixXd d1, d2; d1.resize(F.rows(),2); d2.resize(F.rows(),2); d1 << igl::dot_row(B1,FF1), igl::dot_row(B2,FF1); d2 << igl::dot_row(B1,FF2), igl::dot_row(B2,FF2); X.resize(F.rows(), 3); for (int i=0;i<F.rows();i++) { Vector2d v1 = d1.row(i); Vector2d v2 = d2.row(i); // define inverse map that maps the canonical axis to the given frame directions Matrix2d A; A << v1[0], v2[0], v1[1], v2[1]; // find the closest rotation Eigen::JacobiSVD<Matrix<double,2,2> > svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV ); Matrix2d C = svd.matrixU() * svd.matrixV().transpose(); Vector2d v = C.col(0); X.row(i) = v(0) * B1.row(i) + v(1) * B2.row(i); } }
void getWarpMatrixAffine( const vk::AbstractCamera& cam_ref, const vk::AbstractCamera& cam_cur, const Vector2d& px_ref, const Vector3d& f_ref, const double depth_ref, const SE3& T_cur_ref, const int level_ref, Matrix2d& A_cur_ref) { // Compute affine warp matrix A_ref_cur const int halfpatch_size = 5; const Vector3d xyz_ref(f_ref*depth_ref); Vector3d xyz_du_ref(cam_ref.cam2world(px_ref + Vector2d(halfpatch_size,0)*(1<<level_ref))); Vector3d xyz_dv_ref(cam_ref.cam2world(px_ref + Vector2d(0,halfpatch_size)*(1<<level_ref))); xyz_du_ref *= xyz_ref[2]/xyz_du_ref[2]; xyz_dv_ref *= xyz_ref[2]/xyz_dv_ref[2]; const Vector2d px_cur(cam_cur.world2cam(T_cur_ref*(xyz_ref))); const Vector2d px_du(cam_cur.world2cam(T_cur_ref*(xyz_du_ref))); const Vector2d px_dv(cam_cur.world2cam(T_cur_ref*(xyz_dv_ref))); A_cur_ref.col(0) = (px_du - px_cur)/halfpatch_size; A_cur_ref.col(1) = (px_dv - px_cur)/halfpatch_size; }