in visualization/FitAdam/include/pose_to_transforms.h [213:291]
bool operator()(const T* const pose, // SMPLModel::NUM_JOINTS*3
const T* const joints, // (SMPLModel::NUM_JOINTS)*3
T* transforms // (SMPLModel::NUM_JOINTS)*3*4
) const
{
using namespace Eigen;
Map< const Matrix<T, TotalModel::NUM_JOINTS, 3, RowMajor> > J(joints);
Map< Matrix<T, 3 * TotalModel::NUM_JOINTS, 4, RowMajor> > outT(transforms);
Map< Matrix<T, TotalModel::NUM_JOINTS, 3, RowMajor> > outJoint(transforms + 3 * TotalModel::NUM_JOINTS * 4);
Matrix<T, Dynamic, 4, RowMajor> Ms(4 * TotalModel::NUM_JOINTS, 4);
// Matrix<T, 3, 3, ColMajor> R; // Interface with ceres
Matrix<T, 3, 3, RowMajor> R; // Interface with ceres
ceres::AngleAxisToRotationMatrix(pose, R.data());
Ms.setZero();
Ms.block(0, 0, 3, 3) = R;
Ms(0, 3) = J(0, 0);
Ms(1, 3) = J(0, 1);
Ms(2, 3) = J(0, 2);
Ms(3, 3) = T(1.0);
for (int idj = 1; idj < mod_.NUM_JOINTS; idj++)
{
int ipar = mod_.m_parent[idj];
//std::cout << idj << " " << ipar << "\n\n";
// ceres::AngleAxisToRotationMatrix(pose + idj * 3, R.data());
T angles[3];
angles[0] = pose[idj * 3];
angles[1] = pose[idj * 3 + 1];
angles[2] = pose[idj * 3 + 2];
//Freezing joints here //////////////////////////////////////////////////////
if (idj == 10 || idj == 11) //foot ends
{
//R.setIdentity();
angles[0] = T(0.0);
angles[1] = T(0.0);
angles[2] = T(0.0);
}
if (euler_)
{
if (idj == 7 || idj == 8) //foot ankle. Restrict side movement
{
angles[2] = T(0.0);
}
if (idj == 24 || idj == 27 || idj == 28 || idj == 31 || idj == 32 || idj == 35 || idj == 36 || idj == 39 || idj == 40) //all hands
{
angles[0] = T(0.0);
angles[1] = T(0.0);
}
if (idj == 44 || idj == 47 || idj == 48 || idj == 51 || idj == 52 || idj == 55 || idj == 56 || idj == 59 || idj == 60) //all hands
{
angles[0] = T(0.0);
angles[1] = T(0.0);
}
ceres::EulerAnglesToRotationMatrix(angles, 3, R.data());
}
else
{
ceres::AngleAxisToRotationMatrix(angles, R.data());
}
Ms.block(idj * 4, 0, 3, 3) = Ms.block(ipar * 4, 0, 3, 3)*R;
Ms.block(idj * 4, 3, 3, 1) = Ms.block(ipar * 4, 3, 3, 1) +
Ms.block(ipar * 4, 0, 3, 3)*(J.row(idj).transpose() - J.row(ipar).transpose());
Ms(idj * 4 + 3, 3) = T(1.0);
}
for (int idj = 0; idj < mod_.NUM_JOINTS; idj++) {
Ms.block(idj * 4, 3, 3, 1) -= Ms.block(idj * 4, 0, 3, 3)*J.row(idj).transpose();
}
for (int idj = 0; idj < mod_.NUM_JOINTS; idj++) {
outT.block(idj * 3, 0, 3, 4) = Ms.block(idj * 4, 0, 3, 4);
outJoint.row(idj) = (Ms.block(idj * 4, 0, 3, 3) * J.row(idj).transpose() + Ms.block(idj * 4, 3, 3, 1)).transpose();
}
return true;
}