Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
orientation_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>
18 Eigen::Quaternion<T> offset;
20 Eigen::Quaternion<T> target;
21
28 const Eigen::Quaternion<T>& inOffset,
29 const Eigen::Quaternion<T>& inTarget,
30 size_t pIndex,
31 float w,
32 const std::string& n = "")
33 : ConstraintData(pIndex, w, n),
34 offset(inOffset.normalized()),
35 target(inTarget.normalized()) {}
36};
37
41template <typename T>
42class OrientationErrorFunctionT : public JointErrorFunctionT<T, OrientationDataT<T>, 9, 3, 0> {
43 public:
45 const Skeleton& skel,
46 const ParameterTransform& pt,
47 const T& lossAlpha = GeneralizedLossT<T>::kL2,
48 const T& lossC = T(1))
49 : JointErrorFunctionT<T, OrientationDataT<T>, 9, 3, 0>(skel, pt, lossAlpha, lossC) {}
50
52 const Character& character,
53 const T& lossAlpha = GeneralizedLossT<T>::kL2,
54 const T& lossC = T(1))
56 character.skeleton,
57 character.parameterTransform,
58 lossAlpha,
59 lossC) {}
60
63 static constexpr T kLegacyWeight = 1e-1;
64
65 protected:
67 size_t constrIndex,
68 const JointStateT<T>& state,
69 Vector<T, 9>& f,
70 std::array<Vector3<T>, 3>& v,
71 std::array<Eigen::Matrix<T, 9, 3>, 3>& dfdv) const final;
72};
73
80template <typename T>
82 : public JointErrorFunctionT<T, OrientationDataT<T>, 9, 3, 0> {
83 public:
85 const Skeleton& skel,
86 const ParameterTransform& pt,
87 const T& lossAlpha = GeneralizedLossT<T>::kL2,
88 const T& lossC = T(1))
89 : JointErrorFunctionT<T, OrientationDataT<T>, 9, 3, 0>(skel, pt, lossAlpha, lossC) {}
90
92 const Character& character,
93 const T& lossAlpha = GeneralizedLossT<T>::kL2,
94 const T& lossC = T(1))
96 character.skeleton,
97 character.parameterTransform,
98 lossAlpha,
99 lossC) {}
100
101 protected:
103 size_t constrIndex,
104 const JointStateT<T>& state,
105 Vector<T, 9>& f,
106 std::array<Vector3<T>, 3>& v,
107 std::array<Eigen::Matrix<T, 9, 3>, 3>& dfdv) const final;
108};
109
110} // 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...
JointErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
OrientationErrorFunctionT(const Character &character, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
OrientationErrorFunctionT(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, 9 > &f, std::array< Vector3< T >, 3 > &v, std::array< Eigen::Matrix< T, 9, 3 >, 3 > &dfdv) const final
OrientationRotDiffErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
OrientationRotDiffErrorFunctionT(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, 9 > &f, std::array< Vector3< T >, 3 > &v, std::array< Eigen::Matrix< T, 9, 3 >, 3 > &dfdv) const final
SkeletonT< float > Skeleton
Definition fwd.h:263
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="")
Represents the state of a joint with local and global transformations.
Definition joint_state.h:50
Constraint data on 3x3 rotation represented in quaternions.
OrientationDataT(const Eigen::Quaternion< T > &inOffset, const Eigen::Quaternion< T > &inTarget, size_t pIndex, float w, const std::string &n="")
param[in] inOffset: input rotation offset in the parent space param[in] inTarget: input target rotati...