Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
state_error_function.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
13
14namespace momentum {
15
33
34template <typename T>
36 public:
38 const Skeleton& skel,
39 const ParameterTransform& pt,
42 const Character& character,
44
45 [[nodiscard]] double getError(
46 const ModelParametersT<T>& params,
47 const SkeletonStateT<T>& state,
48 const MeshStateT<T>& meshState) final;
49
51 const ModelParametersT<T>& params,
52 const SkeletonStateT<T>& state,
53 const MeshStateT<T>& meshState,
54 Eigen::Ref<Eigen::VectorX<T>> gradient) final;
55
57 const ModelParametersT<T>& params,
58 const SkeletonStateT<T>& state,
59 const MeshStateT<T>& meshState,
60 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
61 Eigen::Ref<Eigen::VectorX<T>> residual,
62 int& usedRows) final;
63
64 [[nodiscard]] size_t getJacobianSize() const final;
65
66 void reset();
67 void setTargetState(const SkeletonStateT<T>* target);
68 void setTargetState(const SkeletonStateT<T>& target);
70 void setTargetWeight(const Eigen::VectorX<T>& weights);
71 void setTargetWeights(const Eigen::VectorX<T>& posWeight, const Eigen::VectorX<T>& rotWeight);
72
75 void setPositionTargetWeights(const Eigen::VectorX<T>& posWeight);
76
79 void setRotationTargetWeights(const Eigen::VectorX<T>& rotWeight);
80
81 void setWeights(const float posWeight, const float rotationWeight) {
82 posWgt_ = posWeight;
83 rotWgt_ = rotationWeight;
84 }
85
86 [[nodiscard]] const TransformListT<T>& getTargetState() const {
87 return this->targetState_;
88 }
89
90 [[nodiscard]] const Eigen::VectorX<T>& getPositionWeights() const {
91 return targetPositionWeights_;
92 }
93 [[nodiscard]] const Eigen::VectorX<T>& getRotationWeights() const {
94 return targetRotationWeights_;
95 }
96 [[nodiscard]] const T& getPositionWeight() const {
97 return posWgt_;
98 }
99 [[nodiscard]] const T& getRotationWeight() const {
100 return rotWgt_;
101 }
102
103 private:
104 TransformListT<T> targetState_;
105 Eigen::VectorX<T> targetPositionWeights_;
106 Eigen::VectorX<T> targetRotationWeights_;
107
108 T posWgt_{1};
109 T rotWgt_{1};
110
111 const RotationErrorType rotationErrorType_;
112
113 public:
114 // weights for the error functions
115 static constexpr T kPositionWeight = 1e-3;
116 static constexpr T kOrientationWeight = 1e+0;
117};
118
119} // namespace momentum
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
void setTargetWeights(const Eigen::VectorX< float > &posWeight, const Eigen::VectorX< float > &rotWeight)
double getJacobian(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) final
const TransformListT< T > & getTargetState() const
void setTargetState(const SkeletonStateT< float > *target)
void setWeights(const float posWeight, const float rotationWeight)
StateErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, RotationErrorType rotationErrorType=RotationErrorType::RotationMatrixDifference)
const Eigen::VectorX< T > & getRotationWeights() const
void setTargetWeight(const Eigen::VectorX< float > &weights)
double getError(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) final
void setRotationTargetWeights(const Eigen::VectorX< float > &rotWeight)
StateErrorFunctionT(const Character &character, RotationErrorType rotationErrorType=RotationErrorType::RotationMatrixDifference)
const Eigen::VectorX< T > & getPositionWeights() const
void setPositionTargetWeights(const Eigen::VectorX< float > &posWeight)
Definition types.h:28
RotationErrorType
Defines different methods for computing rotation error between two quaternions.
@ RotationMatrixDifference
Frobenius norm of rotation matrix difference: ||R1 - R2||_F^2.
@ QuaternionLogMap
Logarithmic map of relative rotation: ||log(R1^{-1} * R2)||^2.
SkeletonT< float > Skeleton
Definition fwd.h:263
std::vector< TransformT< T > > TransformListT
Per-joint transform list describing the state of all joints in a skeleton (one entry per joint,...
Definition transform.h:228
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
Definition types.h:207
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Represents the complete state of a model's mesh.
Definition mesh_state.h:24
A vector of size numModelParams holding the values of all model parameters for a character.
Definition types.h:99
Represents the complete state of a skeleton.