Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
vertex_position_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
11
12namespace momentum {
13
17template <typename T>
20 Eigen::Vector3<T> target = Eigen::Vector3<T>::Zero();
21
24 size_t vIndex,
25 const Eigen::Vector3<T>& targetPos,
26 float w,
27 const std::string& n = "")
28 : VertexConstraintData(vIndex, w, n), target(targetPos) {}
29};
30
37template <typename T>
38class VertexPositionErrorFunctionT : public VertexErrorFunctionT<T, VertexPositionDataT<T>, 3> {
39 public:
41 using typename Base::DfdvType;
42 using typename Base::FuncType;
43
45 const Character& character,
46 const ParameterTransform& parameterTransform,
47 const T& lossAlpha = GeneralizedLossT<T>::kL2,
48 const T& lossC = T(1));
49
50 ~VertexPositionErrorFunctionT() override = default;
51
53 size_t constrIndex,
54 const SkeletonStateT<T>& state,
55 const MeshStateT<T>& meshState,
56 std::span<const Eigen::Vector3<T>> worldVecs,
57 FuncType& f,
58 std::span<DfdvType> dfdv) const final;
59
66 const ModelParametersT<T>& params,
67 const SkeletonStateT<T>& state,
68 const MeshStateT<T>& meshState,
69 Eigen::Ref<Eigen::VectorX<T>> gradient) override;
70
73 const ModelParametersT<T>& params,
74 const SkeletonStateT<T>& state,
75 const MeshStateT<T>& meshState,
76 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
77 Eigen::Ref<Eigen::VectorX<T>> residual,
78 int& usedRows) override;
79};
80
81} // namespace momentum
static constexpr T kL2
Special-case alpha values that are either at a singularity in the general formula or simplify to a cl...
VertexErrorFunctionT(const Character &character, const ParameterTransform &parameterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
Eigen::Matrix< T, FuncDim, 1 > FuncType
Eigen::Matrix< T, FuncDim, 3 > DfdvType
void evalFunction(size_t constrIndex, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, std::span< const Eigen::Vector3< T > > worldVecs, FuncType &f, std::span< DfdvType > dfdv) const final
Computes the residual and derivatives.
VertexErrorFunctionT< float, VertexPositionDataT< float >, 3 > Base
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) override
Specialized getGradient that avoids the dfdv*derivative matrix multiply.
~VertexPositionErrorFunctionT() override=default
VertexPositionErrorFunctionT(const Character &character, const ParameterTransform &parameterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
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) override
Specialized getJacobian with the same dfdv=Identity optimization.
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
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.
Eigen::Vector3< T > target
Target position in world space.
VertexPositionDataT(size_t vIndex, const Eigen::Vector3< T > &targetPos, float w, const std::string &n="")