Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
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
15template <typename T>
21
22 explicit PositionDataT(
23 const Vector3<T>& inOffset,
24 const Vector3<T>& inTarget,
25 size_t pIndex,
26 float w,
27 const std::string& n = "")
28 : ConstraintData(pIndex, w, n), offset(inOffset), target(inTarget) {}
29};
30
34template <typename T>
35class PositionErrorFunctionT : public JointErrorFunctionT<T, PositionDataT<T>> {
36 public:
44 const Skeleton& skel,
45 const ParameterTransform& pt,
46 const T& lossAlpha = GeneralizedLossT<T>::kL2,
47 const T& lossC = T(1))
48 : JointErrorFunctionT<T, PositionDataT<T>>(skel, pt, lossAlpha, lossC) {}
49
56 const Character& character,
57 const T& lossAlpha = GeneralizedLossT<T>::kL2,
58 const T& lossC = T(1))
59 : PositionErrorFunctionT(character.skeleton, character.parameterTransform, lossAlpha, lossC) {
60 }
61
64 static constexpr T kLegacyWeight = 1e-4;
65
66 protected:
68 size_t constrIndex,
69 const JointStateT<T>& state,
70 Vector3<T>& f,
71 std::array<Vector3<T>, 1>& v,
72 std::array<Matrix3<T>, 1>& dfdv) const final;
73};
74
75} // 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))
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
PositionErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
Constructor.
PositionErrorFunctionT(const Character &character, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
A convenience api where character contains info of the skeleton and parameter transform.
SkeletonT< float > Skeleton
Definition fwd.h:263
Eigen::Matrix< T, 3, 3 > Matrix3
Definition types.h:96
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
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
3D position constraint data
PositionDataT(const Vector3< T > &inOffset, const Vector3< T > &inTarget, size_t pIndex, float w, const std::string &n="")