19 const T& grad_jointParams,
20 const Eigen::Index iJointParam,
22 Eigen::Ref<Eigen::VectorX<T>> gradient) {
24 for (
auto index = parameterTransform.
transform.outerIndexPtr()[iJointParam];
25 index < parameterTransform.
transform.outerIndexPtr()[iJointParam + 1];
27 gradient[parameterTransform.
transform.innerIndexPtr()[index]] +=
28 grad_jointParams * parameterTransform.
transform.valuePtr()[index];
34 const Eigen::Ref<
const Eigen::VectorX<T>>& jacobian_jointParams,
35 const Eigen::Index iJointParam,
37 Eigen::Ref<Eigen::MatrixX<T>> jacobian) {
39 for (
auto index = parameterTransform.
transform.outerIndexPtr()[iJointParam];
40 index < parameterTransform.
transform.outerIndexPtr()[iJointParam + 1];
42 jacobian.col(parameterTransform.
transform.innerIndexPtr()[index]) +=
43 jacobian_jointParams * parameterTransform.
transform.valuePtr()[index];
49 const T& jacobian_jointParams,
50 const Eigen::Index iJointParam,
52 Eigen::Ref<Eigen::MatrixX<T>> jacobian) {
54 for (
auto index = parameterTransform.
transform.outerIndexPtr()[iJointParam];
55 index < parameterTransform.
transform.outerIndexPtr()[iJointParam + 1];
57 jacobian(0, parameterTransform.
transform.innerIndexPtr()[index]) +=
58 jacobian_jointParams * parameterTransform.
transform.valuePtr()[index];
63template <
typename T,
typename Derived>
65 const T& jacobian_jointParams,
66 const Eigen::Index iJointParam,
68 Eigen::MatrixBase<Derived>& jacobian) {
69 for (
auto index = parameterTransform.
transform.outerIndexPtr()[iJointParam];
70 index < parameterTransform.
transform.outerIndexPtr()[iJointParam + 1];
72 jacobian(0, parameterTransform.
transform.innerIndexPtr()[index]) +=
73 jacobian_jointParams * parameterTransform.
transform.valuePtr()[index];
79 const T& jacobian_jointParams,
80 const Eigen::Index iJointParam,
81 const Eigen::Index iRow,
83 Eigen::Ref<Eigen::MatrixX<T>> jacobian) {
85 for (
auto index = parameterTransform.
transform.outerIndexPtr()[iJointParam];
86 index < parameterTransform.
transform.outerIndexPtr()[iJointParam + 1];
88 jacobian(iRow, parameterTransform.
transform.innerIndexPtr()[index]) +=
89 jacobian_jointParams * parameterTransform.
transform.valuePtr()[index];
101template <
typename T,
typename SinkFn>
112 const SinkFn& sink) {
113 size_t jointIndex = startJoint;
114 while (jointIndex !=
kInvalidIndex && jointIndex != stopJoint) {
115 const auto& jointState = state.
jointState[jointIndex];
117 const Vector3<T> posd = position - jointState.translation();
119 for (
size_t d = 0; d < 3; ++d) {
120 if (activeJointParams[paramIndex + d]) {
121 sink(direction.dot(jointState.getTranslationDerivative(d)) * weight, paramIndex + d);
123 if (activeJointParams[paramIndex + 3 + d]) {
124 sink(direction.dot(jointState.getRotationDerivative(d, posd)) * weight, paramIndex + 3 + d);
127 if (activeJointParams[paramIndex + 6]) {
129 (direction.dot(jointState.getScaleDerivative(posd)) + scaleCorrection) * weight,
133 jointIndex = skeleton.
joints[jointIndex].parent;
SkeletonT< float > Skeleton
void jacobian_jointParams_to_modelParams(const Eigen::Ref< const Eigen::VectorX< T > > &jacobian_jointParams, const Eigen::Index iJointParam, const ParameterTransform ¶meterTransform, Eigen::Ref< Eigen::MatrixX< T > > jacobian)
void accumulateChainDerivatives(const SkeletonStateT< T > &state, const Skeleton &skeleton, const VectorX< bool > &activeJointParams, const Vector3< T > &position, const Vector3< T > &direction, T weight, size_t startJoint, size_t stopJoint, T scaleCorrection, const SinkFn &sink)
Accumulate the derivatives of direction .
ParameterTransformT< float > ParameterTransform
void gradient_jointParams_to_modelParams(const T &grad_jointParams, const Eigen::Index iJointParam, const ParameterTransform ¶meterTransform, Eigen::Ref< Eigen::VectorX< T > > gradient)
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
constexpr size_t kParametersPerJoint
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Represents the complete state of a skeleton.
JointStateListT< T > jointState
Computed joint states for all joints in the skeleton.
JointList joints
The list of joints in this skeleton, ordered such that every joint's parent appears earlier in the li...