Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
fixed_axis_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
15template <typename T>
21
23 const Vector3<T>& local,
24 const Vector3<T>& global,
25 size_t pIndex,
26 float w,
27 const std::string& n = "")
28 : ConstraintData(pIndex, w, n),
29 localAxis(local.normalized()),
30 globalAxis(global.normalized()) {}
31};
32
33// The fixed angle error minimizes the difference between a local axis and a target direction in the
34// global frame. These error functions differ in how they calculate the difference between two axis.
35
37template <typename T>
38class FixedAxisDiffErrorFunctionT : public JointErrorFunctionT<T, FixedAxisDataT<T>, 3, 1, 0> {
39 public:
41 const Skeleton& skel,
42 const ParameterTransform& pt,
43 const T& lossAlpha = GeneralizedLossT<T>::kL2,
44 const T& lossC = T(1))
45 : JointErrorFunctionT<T, FixedAxisDataT<T>, 3, 1, 0>(skel, pt, lossAlpha, lossC) {}
46
48 const Character& character,
49 const T& lossAlpha = GeneralizedLossT<T>::kL2,
50 const T& lossC = T(1))
52 character.skeleton,
53 character.parameterTransform,
54 lossAlpha,
55 lossC) {}
56
59 static constexpr T kLegacyWeight = 1e-1;
60
61 protected:
63 size_t constrIndex,
64 const JointStateT<T>& state,
65 Vector3<T>& f,
66 std::array<Vector3<T>, 1>& v,
67 std::array<Matrix3<T>, 1>& dfdv) const final;
68};
69
71template <typename T>
72class FixedAxisCosErrorFunctionT : public JointErrorFunctionT<T, FixedAxisDataT<T>, 1, 1, 0> {
73 public:
75 const Skeleton& skel,
76 const ParameterTransform& pt,
77 const T& lossAlpha = GeneralizedLossT<T>::kL2,
78 const T& lossC = T(1))
79 : JointErrorFunctionT<T, FixedAxisDataT<T>, 1, 1, 0>(skel, pt, lossAlpha, lossC) {}
80
82 const Character& character,
83 const T& lossAlpha = GeneralizedLossT<T>::kL2,
84 const T& lossC = T(1))
86 character.skeleton,
87 character.parameterTransform,
88 lossAlpha,
89 lossC) {}
90
93 static constexpr T kLegacyWeight = 1e-1;
94
95 protected:
97 size_t constrIndex,
98 const JointStateT<T>& state,
99 Vector<T, 1>& f,
100 std::array<Vector3<T>, 1>& v,
101 std::array<Eigen::Matrix<T, 1, 3>, 1>& dfdv) const final;
102};
103
105
107template <typename T>
108class FixedAxisAngleErrorFunctionT : public JointErrorFunctionT<T, FixedAxisDataT<T>, 1, 1, 0> {
109 public:
111 const Skeleton& skel,
112 const ParameterTransform& pt,
113 const T& lossAlpha = GeneralizedLossT<T>::kL2,
114 const T& lossC = T(1))
115 : JointErrorFunctionT<T, FixedAxisDataT<T>, 1, 1, 0>(skel, pt, lossAlpha, lossC) {}
116
118 const Character& character,
119 const T& lossAlpha = GeneralizedLossT<T>::kL2,
120 const T& lossC = T(1))
122 character.skeleton,
123 character.parameterTransform,
124 lossAlpha,
125 lossC) {}
126
129 static constexpr T kLegacyWeight = 1e-1;
130
131 protected:
133 size_t constrIndex,
134 const JointStateT<T>& state,
135 Vector<T, 1>& f,
136 std::array<Vector3<T>, 1>& v,
137 std::array<Eigen::Matrix<T, 1, 3>, 1>& dfdv) const final;
138};
139
140} // namespace momentum
FixedAxisAngleErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
FixedAxisAngleErrorFunctionT(const Character &character, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
void evalFunction(size_t constrIndex, const JointStateT< T > &state, Vector< T, 1 > &f, std::array< Vector3< T >, 1 > &v, std::array< Eigen::Matrix< T, 1, 3 >, 1 > &dfdv) const final
FixedAxisCosErrorFunctionT(const Character &character, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
FixedAxisCosErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
void evalFunction(size_t constrIndex, const JointStateT< T > &state, Vector< T, 1 > &f, std::array< Vector3< T >, 1 > &v, std::array< Eigen::Matrix< T, 1, 3 >, 1 > &dfdv) const final
void evalFunction(size_t constrIndex, const JointStateT< T > &state, Vector3< T > &f, std::array< Vector3< T >, 1 > &v, std::array< Matrix3< T >, 1 > &dfdv) const final
FixedAxisDiffErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
FixedAxisDiffErrorFunctionT(const Character &character, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
static constexpr T kL2
Special-case alpha values that are either at a singularity in the general formula or simplify to a cl...
JointErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
SkeletonT< float > Skeleton
Definition fwd.h:263
Eigen::Matrix< T, 3, 3 > Matrix3
Definition types.h:96
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
Eigen::Matrix< T, Dim, 1, Options > Vector
Column vector alias (an Nx1 Eigen matrix).
Definition types.h:203
Vector< T, 3 > Vector3
Definition types.h:236
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
ConstraintData(size_t pIndex, float w, const std::string &n="")
FixedAxisDataT(const Vector3< T > &local, const Vector3< T > &global, size_t pIndex, float w, const std::string &n="")
Represents the state of a joint with local and global transformations.
Definition joint_state.h:50