Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
state_sequence_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
14
15namespace momentum {
16
21template <typename T>
23 public:
25 const Skeleton& skel,
26 const ParameterTransform& pt,
29 const Character& character,
31
32 [[nodiscard]] size_t numFrames() const final {
33 return 2;
34 }
35
36 double getError(
37 std::span<const ModelParametersT<T>> modelParameters,
38 std::span<const SkeletonStateT<T>> skelStates,
39 std::span<const MeshStateT<T>> /* meshStates */) const final;
41 std::span<const ModelParametersT<T>> modelParameters,
42 std::span<const SkeletonStateT<T>> skelStates,
43 std::span<const MeshStateT<T>> /* meshStates */,
44 Eigen::Ref<Eigen::VectorX<T>> gradient) const final;
45
46 // modelParameters: [numFrames() * parameterTransform] parameter vector
47 // skelStates: [numFrames()] array of skeleton states
48 // jacobian: [getJacobianSize()] x [numFrames() * parameterTransform] Jacobian matrix
49 // residual: [getJacobianSize()] residual vector.
51 std::span<const ModelParametersT<T>> modelParameters,
52 std::span<const SkeletonStateT<T>> skelStates,
53 std::span<const MeshStateT<T>> /* meshStates */,
54 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
55 Eigen::Ref<Eigen::VectorX<T>> residual,
56 int& usedRows) const final;
57
58 [[nodiscard]] size_t getJacobianSize() const final;
59
63 void setTargetWeights(const Eigen::VectorX<T>& posWeight, const Eigen::VectorX<T>& rotWeight);
64
67 void setPositionTargetWeights(const Eigen::VectorX<T>& posWeight);
68
71 void setRotationTargetWeights(const Eigen::VectorX<T>& rotWeight);
72 void setWeights(const float posWeight, const float rotationWeight) {
73 posWgt_ = posWeight;
74 rotWgt_ = rotationWeight;
75 }
76
77 void reset();
78
79 [[nodiscard]] const Eigen::VectorX<T>& getPositionWeights() const {
80 return targetPositionWeights_;
81 }
82 [[nodiscard]] const Eigen::VectorX<T>& getRotationWeights() const {
83 return targetRotationWeights_;
84 }
85 [[nodiscard]] const T& getPositionWeight() const {
86 return posWgt_;
87 }
88 [[nodiscard]] const T& getRotationWeight() const {
89 return rotWgt_;
90 }
91
99
100 private:
101 Eigen::VectorX<T> targetPositionWeights_;
102 Eigen::VectorX<T> targetRotationWeights_;
103
104 TransformListT<T> targetState_;
105
106 T posWgt_;
107 T rotWgt_;
108
109 const RotationErrorType rotationErrorType_;
110
111 public:
112 // weights for the error functions
113 static constexpr T kPositionWeight = 1e-3;
114 static constexpr T kOrientationWeight = 1e+0;
115};
116
117} // namespace momentum
SequenceErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
void setWeights(const float posWeight, const float rotationWeight)
void setRotationTargetWeights(const Eigen::VectorX< float > &rotWeight)
double getError(std::span< const ModelParametersT< T > > modelParameters, std::span< const SkeletonStateT< T > > skelStates, std::span< const MeshStateT< T > >) const final
const Eigen::VectorX< T > & getRotationWeights() const
const Eigen::VectorX< T > & getPositionWeights() const
double getGradient(std::span< const ModelParametersT< float > > modelParameters, std::span< const SkeletonStateT< float > > skelStates, std::span< const MeshStateT< float > >, Eigen::Ref< Eigen::VectorX< float > > gradient) const final
void setTargetState(TransformListT< T > target)
Set the target state for the skeleton.
double getJacobian(std::span< const ModelParametersT< float > > modelParameters, std::span< const SkeletonStateT< float > > skelStates, std::span< const MeshStateT< float > >, Eigen::Ref< Eigen::MatrixX< float > > jacobian, Eigen::Ref< Eigen::VectorX< float > > residual, int &usedRows) const final
void setTargetWeights(const Eigen::VectorX< float > &posWeight, const Eigen::VectorX< float > &rotWeight)
StateSequenceErrorFunctionT(const Character &character, RotationErrorType rotationErrorType=RotationErrorType::RotationMatrixDifference)
StateSequenceErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, RotationErrorType rotationErrorType=RotationErrorType::RotationMatrixDifference)
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.
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
Eigen::Ref< T > Ref
Definition types.h:43
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
Eigen::Matrix< T, Dynamic, Dynamic > MatrixX
Dynamic-size, column-major dense matrix.
Definition types.h:80
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
Definition types.h:207
gsl::span< T > span
Span type alias using gsl::span (C++17 fallback).
Definition span_compat.h:54
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.