Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
plane_error_function.cpp
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
9
11
12namespace momentum {
13
14template <typename T>
15std::vector<PlaneDataT<T>> createFloorConstraints(
16 const std::string& prefix,
17 const LocatorList& locators,
18 const Vector3<T>& floorNormal,
19 const T& floorOffset,
20 const float weight) {
21 std::vector<PlaneDataT<T>> result;
22 for (const auto& loc : locators) {
23 if (loc.name.find(prefix) == 0) {
24 result.emplace_back(
26 loc.offset.cast<T>(),
27 floorNormal,
28 floorOffset,
29 loc.parent,
30 loc.weight * weight,
31 loc.name));
32 }
33 }
34 return result;
35}
36
37template std::vector<PlaneDataT<float>> createFloorConstraints<float>(
38 const std::string& prefix,
39 const LocatorList& locators,
40 const Vector3f& floorNormal,
41 const float& floorOffset,
42 const float weight);
43template std::vector<PlaneDataT<double>> createFloorConstraints<double>(
44 const std::string& prefix,
45 const LocatorList& locators,
46 const Vector3d& floorNormal,
47 const double& floorOffset,
48 const float weight);
49
50template <typename T>
52 const size_t constrIndex,
53 const JointStateT<T>& state,
54 Vector<T, 1>& f,
55 std::array<Vector3<T>, 1>& v,
56 std::array<Eigen::Matrix<T, 1, 3>, 1>& dfdv) const {
58
59 const PlaneDataT<T>& constr = this->constraints_[constrIndex];
60 v[0] = state.transform * constr.offset;
61 T val = v[0].dot(constr.normal) - constr.d;
62 if (halfPlane_ && val > T(0)) {
63 val = T(0);
64 }
65 f[0] = val;
66
67 dfdv[0].setZero();
68 if (!halfPlane_ || val < T(0)) {
69 dfdv[0] = constr.normal.transpose();
70 }
71}
72
73template class PlaneErrorFunctionT<float>;
74template class PlaneErrorFunctionT<double>;
75
76} // namespace momentum
The PlaneErrorFunction computes the point-on-plane error or point-in-half-plane error.
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
Vector3< double > Vector3d
Definition types.h:261
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
Vector3< float > Vector3f
Definition types.h:251
template std::vector< PlaneDataT< float > > createFloorConstraints< float >(const std::string &prefix, const LocatorList &locators, const Vector3f &floorNormal, const float &floorOffset, const float weight)
std::vector< Locator > LocatorList
A collection of locators attached to a skeleton.
Definition locator.h:79
template std::vector< PlaneDataT< double > > createFloorConstraints< double >(const std::string &prefix, const LocatorList &locators, const Vector3d &floorNormal, const double &floorOffset, const float weight)
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_FUNCTION()
Definition profile.h:110
Represents the state of a joint with local and global transformations.
Definition joint_state.h:50
TransformT< T > transform
Global transformation in world space.
Definition joint_state.h:59
Point-on-plane or Point-in-half-plane constraint data.