|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Represents the state of a joint with local and global transformations. More...
#include <joint_state.h>
Public Member Functions | |
| void | set (const JointT< T > &joint, const JointVectorT< T > ¶meters, const JointStateT< T > *parentState=nullptr, bool computeDeriv=true) noexcept |
| Updates joint state based on joint definition and parameters. | |
| Vector3< T > | getRotationDerivative (size_t index, const Vector3< T > &ref) const |
| Calculates the derivative of a point with respect to rotation around a specific axis. | |
| Vector3< T > | getTranslationDerivative (size_t index) const |
| Calculates the derivative with respect to translation along a specific axis. | |
| Vector3< T > | getScaleDerivative (const Vector3< T > &ref) const noexcept |
| Calculates the derivative of a point with respect to uniform scaling. | |
| template<typename T2> | |
| void | set (const JointStateT< T2 > &rhs) |
| Copies state from another JointState with potentially different scalar type. | |
| const Quaternion< T > & | localRotation () const |
| Access the joint's local rotation quaternion. | |
| Quaternion< T > & | localRotation () |
| Access the joint's local rotation quaternion (mutable). | |
| const Vector3< T > & | localTranslation () const |
| Access the joint's local translation vector. | |
| Vector3< T > & | localTranslation () |
| Access the joint's local translation vector (mutable). | |
| const T & | localScale () const |
| Access the joint's local scale factor. | |
| T & | localScale () |
| Access the joint's local scale factor (mutable). | |
| const Quaternion< T > & | rotation () const |
| Access the joint's global rotation quaternion. | |
| Quaternion< T > & | rotation () |
| Access the joint's global rotation quaternion (mutable). | |
| const Vector3< T > & | translation () const |
| Access the joint's global position vector. | |
| Vector3< T > & | translation () |
| Access the joint's global position vector (mutable). | |
| const T & | x () const |
| Access the X component of the global position. | |
| T & | x () |
| Access the X component of the global position (mutable). | |
| const T & | y () const |
| Access the Y component of the global position. | |
| T & | y () |
| Access the Y component of the global position (mutable). | |
| const T & | z () const |
| Access the Z component of the global position. | |
| T & | z () |
| Access the Z component of the global position (mutable). | |
| const T & | quatW () const |
| Access the W component of the global rotation quaternion. | |
| T & | quatW () |
| Access the W component of the global rotation quaternion (mutable). | |
| const T & | quatX () const |
| Access the X component of the global rotation quaternion. | |
| T & | quatX () |
| Access the X component of the global rotation quaternion (mutable). | |
| const T & | quatY () const |
| Access the Y component of the global rotation quaternion. | |
| T & | quatY () |
| Access the Y component of the global rotation quaternion (mutable). | |
| const T & | quatZ () const |
| Access the Z component of the global rotation quaternion. | |
| T & | quatZ () |
| Access the Z component of the global rotation quaternion (mutable). | |
| const T & | scale () const |
| Access the joint's global scale factor. | |
| T & | scale () |
| Access the joint's global scale factor (mutable). | |
Public Attributes | |
| TransformT< T > | localTransform |
| Local transformation relative to parent joint. | |
| TransformT< T > | transform |
| Global transformation in world space. | |
| Matrix3< T > | translationAxis |
| Translation axes in global space. | |
| Matrix3< T > | rotationAxis |
| Rotation axes in global space. | |
| bool | derivDirty = true |
| Indicates if derivative data needs recomputation. | |
Represents the state of a joint with local and global transformations.
Joint transform hierarchy is defined as: WorldTransform = ParentWorldTransform * Tz * Ty * Tx * Rpre * R * S
Where:
Each joint has 7 parameters: 3 translation, 3 rotation, and 1 scale.
The ordering has direct implications for derivative computation:
Swapping the order (e.g., applying rotation before translation) would change which frame the translation operates in, producing incorrect Jacobians in all error functions.
Definition at line 50 of file joint_state.h.
|
nodiscard |
Calculates the derivative of a point with respect to rotation around a specific axis.
| index | The rotation axis index (0=X, 1=Y, 2=Z) |
| ref | The reference point in global space |
Definition at line 68 of file joint_state.cpp.
References derivDirty, MT_CHECK, and rotationAxis.
Referenced by momentum::detail_sdf_collision::accumulateJointGradient(), and momentum::detail_sdf_collision::accumulateJointJacobian().
|
nodiscardnoexcept |
Calculates the derivative of a point with respect to uniform scaling.
| ref | The reference point in global space |
Definition at line 80 of file joint_state.cpp.
References momentum::ln2().
Referenced by momentum::detail_sdf_collision::accumulateJointGradient(), and momentum::detail_sdf_collision::accumulateJointJacobian().
|
nodiscard |
Calculates the derivative with respect to translation along a specific axis.
| index | The translation axis index (0=X, 1=Y, 2=Z) |
Definition at line 74 of file joint_state.cpp.
References derivDirty, MT_CHECK, and translationAxis.
Referenced by momentum::detail_sdf_collision::accumulateJointGradient(), and momentum::detail_sdf_collision::accumulateJointJacobian().
|
inline |
Access the joint's local rotation quaternion (mutable).
Definition at line 130 of file joint_state.h.
|
inlinenodiscard |
Access the joint's local rotation quaternion.
Definition at line 125 of file joint_state.h.
|
inline |
Access the joint's local scale factor (mutable).
Definition at line 162 of file joint_state.h.
|
inlinenodiscard |
Access the joint's local scale factor.
This scale propagates to all descendant joints
The scale parameter is stored as a log2 value and applied as exp2(parameter[6]). This means:
This encoding keeps scale always positive and makes the parameter space more linear for optimization (uniform steps in log-space = uniform ratios).
Definition at line 157 of file joint_state.h.
|
inline |
Access the joint's local translation vector (mutable).
Definition at line 140 of file joint_state.h.
|
inlinenodiscard |
Access the joint's local translation vector.
Definition at line 135 of file joint_state.h.
|
inline |
Access the W component of the global rotation quaternion (mutable).
Definition at line 222 of file joint_state.h.
|
inlinenodiscard |
Access the W component of the global rotation quaternion.
Definition at line 217 of file joint_state.h.
|
inline |
Access the X component of the global rotation quaternion (mutable).
Definition at line 232 of file joint_state.h.
|
inlinenodiscard |
Access the X component of the global rotation quaternion.
Definition at line 227 of file joint_state.h.
|
inline |
Access the Y component of the global rotation quaternion (mutable).
Definition at line 242 of file joint_state.h.
|
inlinenodiscard |
Access the Y component of the global rotation quaternion.
Definition at line 237 of file joint_state.h.
|
inline |
Access the Z component of the global rotation quaternion (mutable).
Definition at line 252 of file joint_state.h.
|
inlinenodiscard |
Access the Z component of the global rotation quaternion.
Definition at line 247 of file joint_state.h.
|
inline |
Access the joint's global rotation quaternion (mutable).
Definition at line 172 of file joint_state.h.
|
inlinenodiscard |
Access the joint's global rotation quaternion.
Definition at line 167 of file joint_state.h.
Referenced by momentum::AimDirErrorFunctionT< T >::evalFunction(), momentum::AimDistErrorFunctionT< T >::evalFunction(), momentum::FixedAxisAngleErrorFunctionT< T >::evalFunction(), momentum::FixedAxisCosErrorFunctionT< T >::evalFunction(), momentum::FixedAxisDiffErrorFunctionT< T >::evalFunction(), momentum::NormalErrorFunctionT< T >::evalFunction(), momentum::OrientationErrorFunctionT< T >::evalFunction(), and momentum::OrientationRotDiffErrorFunctionT< T >::evalFunction().
|
inline |
Access the joint's global scale factor (mutable).
Definition at line 264 of file joint_state.h.
|
inlinenodiscard |
Access the joint's global scale factor.
This is the cumulative scale from all parent joints
Definition at line 259 of file joint_state.h.
| void momentum::JointStateT< T >::set | ( | const JointStateT< T2 > & | rhs | ) |
Copies state from another JointState with potentially different scalar type.
| T2 | Source scalar type |
| rhs | Source joint state to copy from |
Definition at line 86 of file joint_state.cpp.
References momentum::cast(), derivDirty, localTransform, rotationAxis, transform, and translationAxis.
|
noexcept |
Updates joint state based on joint definition and parameters.
Recursively computes all transformations from parent to child, including local and global transforms, and optionally derivative information.
| joint | The joint definition containing offset and pre-rotation |
| parameters | The 7 joint parameters [tx, ty, tz, rx, ry, rz, scale] |
| parentState | Optional parent joint state for hierarchical transformations |
| computeDeriv | If true, computes translationAxis and rotationAxis matrices needed for Jacobian computation in error functions. Set to false ONLY when the state is used for visualization, FK output inspection, or IO — never when the state will be passed to a solver or error function. Skipping derivatives saves ~30% of per-joint FK cost. When false, derivDirty is set to true and derivative accessors (getRotationDerivative, getTranslationDerivative, getScaleDerivative) return invalid results. |
Definition at line 22 of file joint_state.cpp.
References derivDirty, localTransform, momentum::TransformT< T >::rotation, momentum::RotationAxis, rotationAxis, transform, and translationAxis.
|
inline |
Access the joint's global position vector (mutable).
Definition at line 182 of file joint_state.h.
|
inlinenodiscard |
Access the joint's global position vector.
Definition at line 177 of file joint_state.h.
|
inline |
Access the X component of the global position (mutable).
Definition at line 192 of file joint_state.h.
|
inlinenodiscard |
Access the X component of the global position.
Definition at line 187 of file joint_state.h.
|
inline |
Access the Y component of the global position (mutable).
Definition at line 202 of file joint_state.h.
|
inlinenodiscard |
Access the Y component of the global position.
Definition at line 197 of file joint_state.h.
|
inline |
Access the Z component of the global position (mutable).
Definition at line 212 of file joint_state.h.
|
inlinenodiscard |
Access the Z component of the global position.
Definition at line 207 of file joint_state.h.
| bool momentum::JointStateT< T >::derivDirty = true |
Indicates if derivative data needs recomputation.
When true, derivative methods should not be called as they may return invalid results
Definition at line 74 of file joint_state.h.
Referenced by getRotationDerivative(), getTranslationDerivative(), set(), and set().
| TransformT<T> momentum::JointStateT< T >::localTransform |
Local transformation relative to parent joint.
Defined by the joint parameters (translation, rotation, scale)
Definition at line 54 of file joint_state.h.
| Matrix3<T> momentum::JointStateT< T >::rotationAxis |
Rotation axes in global space.
Each column represents one rotation axis (X, Y, Z) in global coordinates
Definition at line 69 of file joint_state.h.
Referenced by momentum::getRotationDerivative(), getRotationDerivative(), set(), and set().
| TransformT<T> momentum::JointStateT< T >::transform |
Global transformation in world space.
Combines parent transformations with local transformation
Definition at line 59 of file joint_state.h.
Referenced by momentum::AimDirErrorFunctionT< T >::evalFunction(), momentum::AimDistErrorFunctionT< T >::evalFunction(), momentum::NormalErrorFunctionT< T >::evalFunction(), momentum::PlaneErrorFunctionT< T >::evalFunction(), momentum::PositionErrorFunctionT< T >::evalFunction(), set(), and set().
| Matrix3<T> momentum::JointStateT< T >::translationAxis |
Translation axes in global space.
Each column represents one translation axis (X, Y, Z) in global coordinates
Definition at line 64 of file joint_state.h.
Referenced by getTranslationDerivative(), set(), and set().