Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
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
17template <typename T>
19 public:
21 : skeleton_(skel), parameterTransform_(pt), activeJointParams_(pt.activeJointParams) {
22 enabledParameters_.flip(); // all parameters enabled by default
23 }
24 virtual ~SequenceErrorFunctionT() = default;
25
26 // Number of contiguous frames that this error function affects.
27 [[nodiscard]] virtual size_t numFrames() const = 0;
28
29 void setWeight(T w) {
30 weight_ = w;
31 }
32 [[nodiscard]] float getWeight() const {
33 return weight_;
34 }
35
38 }
39
42 }
43
44 [[nodiscard]] virtual bool needsMesh() const {
45 return false;
46 }
47
48 [[nodiscard]] virtual double getError(
49 std::span<const ModelParametersT<T>> /* modelParameters */,
50 std::span<const SkeletonStateT<T>> /* skelStates */,
51 std::span<const MeshStateT<T>> /* meshStates */) const {
52 return 0.0f;
53 }
54
55 // Get the gradient of the error.
56 // modelParameters: numFrames() array of parameter vectors
57 // skelStates: [numFrames()] array of skeleton states
58 // meshStates: [numFrames()] array of mesh states
59 // gradient: [numFrames() * parameterTransform] gradient vector
60 virtual double getGradient(
61 std::span<const ModelParametersT<T>> /* modelParameters */,
62 std::span<const SkeletonStateT<T>> /* skelStates */,
63 std::span<const MeshStateT<T>> /* meshStates */,
64 Eigen::Ref<Eigen::VectorX<T>> /* gradient */) const {
65 return 0.0f;
66 }
67
68 // modelParameters: [numFrames() * parameterTransform] parameter vector
69 // skelStates: [numFrames()] array of skeleton states
70 // meshStates: [numFrames()] array of mesh states
71 // jacobian: [getJacobianSize()] x [numFrames() * parameterTransform] Jacobian matrix
72 // residual: [getJacobianSize()] residual vector.
73 virtual double getJacobian(
74 std::span<const ModelParametersT<T>> /* modelParameters */,
75 std::span<const SkeletonStateT<T>> /* skelStates */,
76 std::span<const MeshStateT<T>> /* meshStates */,
77 Eigen::Ref<Eigen::MatrixX<T>> /* jacobian */,
78 Eigen::Ref<Eigen::VectorX<T>> /* residual */,
79 int& usedRows) const {
80 usedRows = 0;
81 return 0.0f;
82 }
83
84 [[nodiscard]] virtual size_t getJacobianSize() const {
85 return 0;
86 }
87
88 [[nodiscard]] const Skeleton& getSkeleton() const {
89 return this->skeleton_;
90 }
91
92 [[nodiscard]] const ParameterTransform& getParameterTransform() const {
93 return this->parameterTransform_;
94 }
95
96 protected:
99 T weight_ = 1.0f;
101 ParameterSet enabledParameters_; // set to zero by default constr
102};
103
104} // namespace momentum
virtual double getJacobian(std::span< const ModelParametersT< T > >, std::span< const SkeletonStateT< T > >, std::span< const MeshStateT< T > >, Eigen::Ref< Eigen::MatrixX< T > >, Eigen::Ref< Eigen::VectorX< T > >, int &usedRows) const
const ParameterTransform & getParameterTransform() const
void setActiveJoints(const VectorX< bool > &aj)
virtual size_t numFrames() const =0
void setEnabledParameters(const ParameterSet &ps)
virtual ~SequenceErrorFunctionT()=default
virtual double getGradient(std::span< const ModelParametersT< T > >, std::span< const SkeletonStateT< T > >, std::span< const MeshStateT< T > >, Eigen::Ref< Eigen::VectorX< T > >) const
virtual double getError(std::span< const ModelParametersT< T > >, std::span< const SkeletonStateT< T > >, std::span< const MeshStateT< T > >) const
SequenceErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
SkeletonT< float > Skeleton
Definition fwd.h:263
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
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Definition types.h:430
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.