Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
union_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
12
13#include <unordered_map>
14
15namespace momentum {
16
17template <typename T>
20 public:
22 const Skeleton& skel,
23 const ParameterTransform& pt,
24 const std::vector<std::shared_ptr<SkeletonErrorFunctionT<T>>>& errorFunctions);
25
26 [[nodiscard]] double getError(
27 const ModelParametersT<T>& params,
28 const SkeletonStateT<T>& state,
29 const MeshStateT<T>& meshState) final;
31 const ModelParametersT<T>& params,
32 const SkeletonStateT<T>& state,
33 const MeshStateT<T>& meshState,
34 Eigen::Ref<Eigen::VectorX<T>> gradient) final;
36 const ModelParametersT<T>& params,
37 const SkeletonStateT<T>& state,
38 const MeshStateT<T>& meshState,
39 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
40 Eigen::Ref<Eigen::VectorX<T>> residual,
41 int& usedRows) final;
42 [[nodiscard]] size_t getJacobianSize() const final;
43
44 std::vector<std::string> inputs() const override;
45 void getInputImp(const std::string& name, Eigen::Ref<Eigen::VectorX<T>> result) const override;
46 void setInputImp(const std::string& name, Eigen::Ref<const Eigen::VectorX<T>> value) override;
47 Eigen::Index getInputSize(const std::string& name) const override;
48 const char* name() const override {
49 return name_.c_str();
50 }
51
52 Eigen::VectorX<T> d_gradient_d_input_dot(
53 const std::string& inputName,
54 const ModelParametersT<T>& modelParams,
55 const SkeletonStateT<T>& state,
56 Eigen::Ref<const Eigen::VectorX<T>> inputVec) override;
57
58 private:
59 std::vector<std::shared_ptr<SkeletonErrorFunctionT<T>>> errorFunctions_;
60 std::vector<std::shared_ptr<FullyDifferentiableSkeletonErrorFunctionT<T>>> diffErrorFunctions_;
61 std::string name_;
62
63 // For each input, which error functions support that input
64 std::unordered_map<std::string, std::vector<size_t>> inputs_;
65};
66
67} // namespace momentum
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
void setInputImp(const std::string &name, Eigen::Ref< const Eigen::VectorX< float > > value) override
void getInputImp(const std::string &name, Eigen::Ref< Eigen::VectorX< float > > result) const override
UnionErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const std::vector< std::shared_ptr< SkeletonErrorFunctionT< T > > > &errorFunctions)
Eigen::VectorX< T > d_gradient_d_input_dot(const std::string &inputName, const ModelParametersT< T > &modelParams, const SkeletonStateT< T > &state, Eigen::Ref< const Eigen::VectorX< T > > inputVec) override
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) final
Eigen::Index getInputSize(const std::string &name) const override
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
double getError(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
std::vector< std::string > inputs() const override
Definition types.h:28
SkeletonT< float > Skeleton
Definition fwd.h:263
Eigen::Ref< T > Ref
Definition types.h:43
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
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.