88 for (
int k = 0; k < 100000; ++k) {
92 Vector3D rotAxisAngle = Vector3D::Random();
93 rotAxisAngle += Vector3D::Random();
94 Eigen::AngleAxisd rotation(rotAxisAngle.norm(), rotAxisAngle.normalized());
95 Matrix3D Re = rotation.toRotationMatrix();
98 Matrix<double, 3, 9, Eigen::ColMajor> dq_dR;
100 Re(0,0),Re(1,0),Re(2,0),
101 Re(0,1),Re(1,1),Re(2,1),
102 Re(0,2),Re(1,2),Re(2,2));
105 Matrix<double, 3, 9, Eigen::RowMajor> dq_dR_AD;
106 typedef ceres::internal::AutoDiff<RotationMatrix2QuaternionManifold, double, 9> AutoDiff_Dq_DR;
107 double *parameters[] = { Re.data() };
108 double *jacobians[] = { dq_dR_AD.data() };
111 AutoDiff_Dq_DR::Differentiate(rot2quat, parameters, 3, value, jacobians);
114 const double allowedDifference = 1e-6;
115 for (
int i = 0; i < dq_dR.rows(); ++i) {
116 for (
int j = 0; j < dq_dR.cols(); ++j) {
117 double d = fabs(dq_dR_AD(i,j) - dq_dR(i,j));
118 if (d > allowedDifference) {
119 cerr <<
"\ndetected difference in the Jacobians" << endl;
120 cerr << PVAR(Re) << endl << endl;
121 cerr << PVAR(dq_dR_AD) << endl << endl;
122 cerr << PVAR(dq_dR) << endl << endl;
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
void compute_dq_dR(Eigen::Matrix< double, 3, 9, Eigen::ColMajor > &dq_dR, const double &r11, const double &r21, const double &r31, const double &r12, const double &r22, const double &r32, const double &r13, const double &r23, const double &r33)
Eigen::Matrix< double, 3, 3, Eigen::ColMajor > Matrix3D
Functor used to compute the Jacobian via AD.