Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
skeleton_utility.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
10
11namespace momentum {
12
14 const ModelParameters& previous,
15 const ModelParameters& current,
16 const float factor,
17 const float maxDelta) {
19 if (current.size() != previous.size()) {
20 return current;
21 }
22
23 ModelParameters result =
24 current.v + (current.v - previous.v).cwiseMin(maxDelta).cwiseMax(-maxDelta) * factor;
25
26 return result;
27}
28
30 const ModelParameters& previous,
31 const ModelParameters& current,
32 const ParameterSet& activeParams,
33 const float factor,
34 const float maxDelta) {
36 if (current.size() != previous.size()) {
37 return current;
38 }
39
40 // Clamp the per-parameter delta to maxDelta so repeated extrapolation cannot
41 // accumulate unbounded growth across frames.
42 const auto sz = current.size();
43 ModelParameters result = current;
44 for (Eigen::Index i = 0; i < sz; ++i) {
45 if (activeParams.test(i)) {
46 result(i) = current(i) + factor * std::clamp(current(i) - previous(i), -maxDelta, maxDelta);
47 }
48 }
49
50 return result;
51}
52
53} // namespace momentum
ModelParametersT< float > ModelParameters
Definition types.h:105
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Definition types.h:430
ModelParameters extrapolateModelParameters(const ModelParameters &previous, const ModelParameters &current, const float factor, const float maxDelta)
Extrapolates model parameters by first clamping the difference between current and previous parameter...
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_FUNCTION()
Definition profile.h:110
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE auto size() const
Definition types.h:87