32 std::span<
const Eigen::Vector3<T>> worldVecs,
34 std::span<DfdvType> dfdv)
const {
36 MT_CHECK(worldVecs.size() == 1,
"Expected exactly one world vector for vertex projection");
38 const auto& constraint = this->
constraints_[constrIndex];
39 const Eigen::Vector3<T>& v = worldVecs[0];
43 Eigen::Vector4<T> vHom;
45 const Eigen::Vector3<T> pHom = constraint.projectionMatrix * vHom;
54 const T invZ = T(1) / pHom(2);
55 const Eigen::Vector2<T> projected(pHom(0) * invZ, pHom(1) * invZ);
58 f = projected - constraint.target;
62 MT_CHECK(dfdv.size() == 1,
"Expected exactly one dfdv for vertex projection");
66 const T invZ2 = invZ * invZ;
69 const Eigen::Matrix<T, 3, 3> P33 = constraint.projectionMatrix.template leftCols<3>();
73 dfdv[0].row(0) = (P33.row(0) * pHom(2) - pHom(0) * P33.row(2)) * invZ2;
74 dfdv[0].row(1) = (P33.row(1) * pHom(2) - pHom(1) * P33.row(2)) * invZ2;
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
VertexErrorFunctionT(const Character &character, const ParameterTransform ¶meterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
std::vector< VertexProjectionDataT< T > > constraints_
Eigen::Matrix< T, FuncDim, 1 > FuncType
Error function that constrains mesh vertices to 2D projected positions.
void evalFunction(size_t constrIndex, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, std::span< const Eigen::Vector3< T > > worldVecs, FuncType &f, std::span< DfdvType > dfdv) const final
Computes the residual and derivatives.
VertexProjectionErrorFunctionT(const Character &character, const ParameterTransform ¶meterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
ParameterTransformT< float > ParameterTransform
A character model with skeletal structure, mesh, and optional components.
Represents the complete state of a model's mesh.
Represents the complete state of a skeleton.
Constraint data for a vertex 2D projection target.