Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
plane_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
17template <typename T>
21 T d;
22
23 explicit PlaneDataT(
24 const Vector3<T>& inOffset,
25 const Vector3<T>& inNormal,
26 const T inD,
27 size_t pIndex,
28 float w,
29 const std::string& n = "")
30 : ConstraintData(pIndex, w, n), offset(inOffset), normal(inNormal.normalized()), d(inD) {}
31};
32
34template <typename T>
35std::vector<PlaneDataT<T>> createFloorConstraints(
36 const std::string& prefix,
37 const LocatorList& locators,
38 const Vector3<T>& floorNormal,
39 const T& floorOffset,
40 float weight);
41
46template <typename T>
47class PlaneErrorFunctionT : public JointErrorFunctionT<T, PlaneDataT<T>, 1> {
48 public:
58 const Skeleton& skel,
59 const ParameterTransform& pt,
60 const bool above = false,
61 const T& lossAlpha = GeneralizedLossT<T>::kL2,
62 const T& lossC = T(1))
63 : JointErrorFunctionT<T, PlaneDataT<T>, 1>(skel, pt, lossAlpha, lossC), halfPlane_(above) {}
64
73 const Character& character,
74 const bool above = false,
75 const T& lossAlpha = GeneralizedLossT<T>::kL2,
76 const T& lossC = T(1))
78 character.skeleton,
79 character.parameterTransform,
80 above,
81 lossAlpha,
82 lossC) {}
83
86 static constexpr T kLegacyWeight = 1e-4;
87
88 protected:
90 size_t constrIndex,
91 const JointStateT<T>& state,
92 Vector<T, 1>& f,
93 std::array<Vector3<T>, 1>& v,
94 std::array<Eigen::Matrix<T, 1, 3>, 1>& dfdv) const final;
95
96 private:
98 bool halfPlane_ = false;
99};
100
101} // 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))
PlaneErrorFunctionT(const Character &character, const bool above=false, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
A convenience api where character contains info of the skeleton and parameter transform.
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
PlaneErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, const bool above=false, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
Constructor.
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
std::vector< PlaneDataT< T > > createFloorConstraints(const std::string &prefix, const LocatorList &locators, const Vector3< T > &floorNormal, const T &floorOffset, const float weight)
Create non-penetration half-plane constraints from locators with the input prefix.
Vector< T, 3 > Vector3
Definition types.h:236
std::vector< Locator > LocatorList
A collection of locators attached to a skeleton.
Definition locator.h:79
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
Point-on-plane or Point-in-half-plane constraint data.
PlaneDataT(const Vector3< T > &inOffset, const Vector3< T > &inNormal, const T inD, size_t pIndex, float w, const std::string &n="")