Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
aim_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>
23
24 explicit AimDataT(
25 const Vector3<T>& inLocalPt,
26 const Vector3<T>& inLocalDir,
27 const Vector3<T>& inTarget,
28 size_t pIndex,
29 float w,
30 const std::string& n = {})
31 : ConstraintData(pIndex, w, n),
32 localPoint(inLocalPt),
33 localDir(inLocalDir.normalized()),
34 globalTarget(inTarget) {}
35};
36
43template <typename T>
44class AimDistErrorFunctionT : public JointErrorFunctionT<T, AimDataT<T>, 3, 2, 1> {
45 public:
47 const Skeleton& skel,
48 const ParameterTransform& pt,
49 const T& lossAlpha = GeneralizedLossT<T>::kL2,
50 const T& lossC = T(1))
51 : JointErrorFunctionT<T, AimDataT<T>, 3, 2, 1>(skel, pt, lossAlpha, lossC) {}
52
54 const Character& character,
55 const T& lossAlpha = GeneralizedLossT<T>::kL2,
56 const T& lossC = T(1))
58 character.skeleton,
59 character.parameterTransform,
60 lossAlpha,
61 lossC) {}
62
65 static constexpr T kLegacyWeight = 1e-1;
66
67 protected:
69 size_t constrIndex,
70 const JointStateT<T>& state,
71 Vector3<T>& f,
72 std::array<Vector3<T>, 2>& v,
73 std::array<Eigen::Matrix3<T>, 2>& dfdv) const final;
74};
75
77
82template <typename T>
83class AimDirErrorFunctionT : public JointErrorFunctionT<T, AimDataT<T>, 3, 2, 1> {
84 public:
86 const Skeleton& skel,
87 const ParameterTransform& pt,
88 const T& lossAlpha = GeneralizedLossT<T>::kL2,
89 const T& lossC = T(1))
90 : JointErrorFunctionT<T, AimDataT<T>, 3, 2, 1>(skel, pt, lossAlpha, lossC) {}
91
93 const Character& character,
94 const T& lossAlpha = GeneralizedLossT<T>::kL2,
95 const T& lossC = T(1))
97 character.skeleton,
98 character.parameterTransform,
99 lossAlpha,
100 lossC) {}
101
104 static constexpr T kLegacyWeight = 1e-1;
105
106 protected:
108 size_t constrIndex,
109 const JointStateT<T>& state,
110 Vector3<T>& f,
111 std::array<Vector3<T>, 2>& v,
112 std::array<Eigen::Matrix3<T>, 2>& dfdv) const final;
113};
114} // namespace momentum
void evalFunction(size_t constrIndex, const JointStateT< T > &state, Vector3< T > &f, std::array< Vector3< T >, 2 > &v, std::array< Eigen::Matrix3< T >, 2 > &dfdv) const final
AimDirErrorFunctionT(const Character &character, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
AimDirErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
AimDistErrorFunctionT(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, Vector3< T > &f, std::array< Vector3< T >, 2 > &v, std::array< Eigen::Matrix3< T >, 2 > &dfdv) const final
AimDistErrorFunctionT(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
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
Vector< T, 3 > Vector3
Definition types.h:236
Aim constraint data: a local ray (point, dir) passes a global point target.
AimDataT(const Vector3< T > &inLocalPt, const Vector3< T > &inLocalDir, const Vector3< T > &inTarget, size_t pIndex, float w, const std::string &n={})
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Base structure of constraint data for joint-based error functions.
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