Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
parameter_limits.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
14
15#include <array>
16#include <cstring>
17
18namespace momentum {
19
28
29 // Keep this as the last entry to track the number of enum values
31};
32
33[[nodiscard]] std::string_view toString(LimitType type);
34
39
45
49 size_t targetIndex;
50 float scale;
51 float offset;
52
56 float rangeMin;
57 float rangeMax;
58};
59
74
78 alignas(32) Affine3f
80 alignas(32) Affine3f ellipsoidInv;
81 alignas(32) Vector3f offset;
83 size_t parent;
84};
85
88 size_t param1;
89 size_t param2;
91 float offset;
92};
93
94union LimitData {
101 std::array<unsigned char, 512> rawData;
102
104 LimitData();
105
107 LimitData(const LimitData& rhs);
108
109 LimitData& operator=(const LimitData& rhs);
110
111 ~LimitData() = default;
112
113 LimitData(LimitData&& rhs) noexcept {
114 std::memcpy(rawData.data(), rhs.rawData.data(), rawData.size());
115 }
116
117 LimitData& operator=(LimitData&& rhs) noexcept {
118 std::memcpy(rawData.data(), rhs.rawData.data(), rawData.size());
119 return *this;
120 }
121
123 bool operator==(const LimitData& limitData) const;
124};
125
129 float weight = 1.0f;
130
131 inline bool operator==(const ParameterLimit& parameterLimit) const {
132 return (
133 (data == parameterLimit.data) && (type == parameterLimit.type) &&
134 isApprox(weight, parameterLimit.weight));
135 }
136};
137
138using ParameterLimits = std::vector<ParameterLimit>;
139
142 const ParameterLimits& limits,
143 const JointParameters& jointParams);
144
147 const std::string& name,
148 const ParameterTransform& pt,
149 float weight = 1.0f);
150
152bool isInRange(const LimitLinear& limit, float value);
153
155bool isInRange(const LimitLinearJoint& limit, float value);
156
158} // namespace momentum
#define MOMENTUM_DEFINE_POINTERS(x)
Define the standard set of smart-pointer type aliases for type x.
Definition memory.h:24
Vector2< float > Vector2f
Definition types.h:250
Affine3< float > Affine3f
Definition types.h:405
std::vector< ParameterLimit > ParameterLimits
JointParameters applyPassiveJointParameterLimits(const ParameterLimits &limits, const JointParameters &jointParams)
Only processes MinMaxJointPassive limits, clamping parameters to their ranges.
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
bool isApprox(T l, T r, T eps=Eps< T >(1e-4, 1e-6)) noexcept
Determines if two values are approximately equal within a given tolerance.
Definition utility.h:53
JointParametersT< float > JointParameters
Definition types.h:135
bool isInRange(const LimitLinear &limit, float value)
If rangeMin and rangeMax are both 0, the limit applies to all values.
Vector3< float > Vector3f
Definition types.h:251
ParameterLimits getPoseConstraintParameterLimits(const std::string &name, const ParameterTransform &pt, const float weight)
Creates MinMax limits from a pose constraint.
std::string_view toString(const LimitType type)
Constrains a point (offset in parent joint's frame) to lie on the surface of an ellipsoid defined in ...
size_t parent
Joint whose frame the constrained point is defined in.
Affine3f ellipsoidInv
Cached inverse of ellipsoid.
Vector3f offset
Constrained point's offset in parent joint's local frame.
Affine3f ellipsoid
Maps the unit sphere to the constraint ellipsoid (in ellipsoidParent's frame).
size_t ellipsoidParent
Joint whose frame the ellipsoid is defined in.
Constraint: (p1, p2) ยท (normal) - offset >= 0.
float rangeMax
Non-inclusive.
float rangeMin
Range where limit applies (in target parameter values).
Linear relationship between parameters: p_0 = s * p_1 - o.
float rangeMin
Range where limit applies (in target parameter values).
float rangeMax
Non-inclusive.
size_t jointParameter
One of [tx, ty, tz, rx, ry, rz, sc].
Vector2f limits
[min, max]
bool operator==(const ParameterLimit &parameterLimit) const
bool operator==(const LimitData &limitData) const
Compares raw memory.
LimitData & operator=(LimitData &&rhs) noexcept
LimitData(LimitData &&rhs) noexcept
LimitHalfPlane halfPlane
LimitMinMaxJoint minMaxJoint
LimitData & operator=(const LimitData &rhs)
LimitEllipsoid ellipsoid
LimitData()
Initializes all data to zero.
LimitLinearJoint linearJoint
std::array< unsigned char, 512 > rawData
For memory operations.