Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
normal_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
16template <typename T>
24
25 explicit NormalDataT(
26 const Vector3<T>& inLocalPt,
27 const Vector3<T>& inLocalNorm,
28 const Vector3<T>& inTargetPt,
29 size_t pIndex,
30 float w,
31 const std::string& n = {})
32 : ConstraintData(pIndex, w, n),
33 localPoint(inLocalPt),
34 localNormal(inLocalNorm.normalized()),
35 globalPoint(inTargetPt) {}
36};
37
41template <typename T>
42class NormalErrorFunctionT : public JointErrorFunctionT<T, NormalDataT<T>, 1, 2, 1> {
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, NormalDataT<T>, 1, 2, 1>(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-4;
64
65 protected:
67 size_t constrIndex,
68 const JointStateT<T>& state,
69 Vector<T, 1>& f,
70 std::array<Vector3<T>, 2>& v,
71 std::array<Eigen::Matrix<T, 1, 3>, 2>& dfdv) const final;
72};
73} // 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))
NormalErrorFunctionT(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 >, 2 > &v, std::array< Eigen::Matrix< T, 1, 3 >, 2 > &dfdv) const final
NormalErrorFunctionT(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
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
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
Normal constraint data: data needed to compute the point-to-plane distance for "data-to-template" in ...
NormalDataT(const Vector3< T > &inLocalPt, const Vector3< T > &inLocalNorm, const Vector3< T > &inTargetPt, size_t pIndex, float w, const std::string &n={})