Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::VelocityMagnitudeSequenceErrorFunctionT< T > Class Template Reference

Error function that penalizes the deviation of per-joint velocity magnitude from a target speed. More...

#include <velocity_magnitude_sequence_error_function.h>

Inheritance diagram for momentum::VelocityMagnitudeSequenceErrorFunctionT< T >:

Public Member Functions

 VelocityMagnitudeSequenceErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt)
 VelocityMagnitudeSequenceErrorFunctionT (const Character &character)
size_t numFrames () const final
double getError (std::span< const ModelParametersT< T > > modelParameters, std::span< const SkeletonStateT< T > > skelStates, std::span< const MeshStateT< T > > meshStates) const final
double getGradient (std::span< const ModelParametersT< T > > modelParameters, std::span< const SkeletonStateT< T > > skelStates, std::span< const MeshStateT< T > > meshStates, Eigen::Ref< Eigen::VectorX< T > > gradient) const final
double getJacobian (std::span< const ModelParametersT< T > > modelParameters, std::span< const SkeletonStateT< T > > skelStates, std::span< const MeshStateT< T > > meshStates, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) const final
size_t getJacobianSize () const final
void setTargetWeights (const Eigen::VectorX< T > &weights)
 Set the per-joint weights for the velocity magnitude error.
void setTargetSpeed (T speed)
 Set a single target speed applied to all joints.
void setTargetSpeeds (const Eigen::VectorX< T > &speeds)
 Set per-joint target speeds.
void reset ()
 Reset weights to ones and target speeds to zero.
const Eigen::VectorX< T > & getTargetWeights () const
const Eigen::VectorX< T > & getTargetSpeeds () const
Public Member Functions inherited from momentum::SequenceErrorFunctionT< T >
 SequenceErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt)
virtual ~SequenceErrorFunctionT ()=default
void setWeight (T w)
float getWeight () const
void setActiveJoints (const VectorX< bool > &aj)
void setEnabledParameters (const ParameterSet &ps)
virtual bool needsMesh () const
const Skeleton & getSkeleton () const
const ParameterTransform & getParameterTransform () const

Additional Inherited Members

Protected Attributes inherited from momentum::SequenceErrorFunctionT< T >
const Skeleton & skeleton_
const ParameterTransform & parameterTransform_
T weight_ = 1.0f
VectorX< bool > activeJointParams_
ParameterSet enabledParameters_

Detailed Description

template<typename T>
class momentum::VelocityMagnitudeSequenceErrorFunctionT< T >

Error function that penalizes the deviation of per-joint velocity magnitude from a target speed.

Given two consecutive frames, this error function computes the velocity for each joint as: velocity = pos[t+1] - pos[t]

The velocity magnitude is computed using a smooth approximation to avoid discontinuities: ||v||_smooth = sqrt(||v||^2 + eps^2)

This provides a differentiable approximation to the velocity magnitude with well-defined gradients even when velocity is near zero. The gradient is: d(||v||_smooth)/d(v) = v / ||v||_smooth

The residual for each joint is the difference between the smooth velocity magnitude and a target speed: residual = ||v||_smooth - targetSpeed

This is useful for constraining character motion to maintain a specific speed profile, such as ensuring that joints move at a consistent pace during walking or running animations.

Note: This error function only constrains position velocity magnitude, not rotation velocity.

Definition at line 44 of file velocity_magnitude_sequence_error_function.h.

Constructor & Destructor Documentation

◆ VelocityMagnitudeSequenceErrorFunctionT() [1/2]

◆ VelocityMagnitudeSequenceErrorFunctionT() [2/2]

template<typename T>
momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::VelocityMagnitudeSequenceErrorFunctionT ( const Character & character)
explicit

Member Function Documentation

◆ getError()

template<typename T>
double momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::getError ( std::span< const ModelParametersT< T > > modelParameters,
std::span< const SkeletonStateT< T > > skelStates,
std::span< const MeshStateT< T > > meshStates ) const
nodiscardfinalvirtual

◆ getGradient()

◆ getJacobian()

template<typename T>
double momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::getJacobian ( std::span< const ModelParametersT< T > > modelParameters,
std::span< const SkeletonStateT< T > > skelStates,
std::span< const MeshStateT< T > > meshStates,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
Eigen::Ref< Eigen::VectorX< T > > residual,
int & usedRows ) const
finalvirtual

◆ getJacobianSize()

template<typename T>
size_t momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::getJacobianSize ( ) const
nodiscardfinalvirtual

◆ getTargetSpeeds()

template<typename T>
const Eigen::VectorX< T > & momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::getTargetSpeeds ( ) const
inlinenodiscard

Definition at line 93 of file velocity_magnitude_sequence_error_function.h.

◆ getTargetWeights()

template<typename T>
const Eigen::VectorX< T > & momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::getTargetWeights ( ) const
inlinenodiscard

Definition at line 89 of file velocity_magnitude_sequence_error_function.h.

◆ numFrames()

template<typename T>
size_t momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::numFrames ( ) const
inlinenodiscardfinalvirtual

◆ reset()

template<typename T>
void momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::reset ( )

Reset weights to ones and target speeds to zero.

Definition at line 34 of file velocity_magnitude_sequence_error_function.cpp.

References momentum::SequenceErrorFunctionT< T >::skeleton_.

◆ setTargetSpeed()

template<typename T>
void momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::setTargetSpeed ( T speed)

Set a single target speed applied to all joints.

Parameters
speedThe target speed (velocity magnitude) for all joints.

Definition at line 47 of file velocity_magnitude_sequence_error_function.cpp.

References momentum::SequenceErrorFunctionT< T >::skeleton_.

◆ setTargetSpeeds()

template<typename T>
void momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::setTargetSpeeds ( const Eigen::VectorX< T > & speeds)

Set per-joint target speeds.

Parameters
speedsVector of target speeds, one per joint.

Definition at line 52 of file velocity_magnitude_sequence_error_function.cpp.

References MT_CHECK.

◆ setTargetWeights()

template<typename T>
void momentum::VelocityMagnitudeSequenceErrorFunctionT< T >::setTargetWeights ( const Eigen::VectorX< T > & weights)

Set the per-joint weights for the velocity magnitude error.

Parameters
weightsPer-joint weights vector. Size must match the number of joints.

Definition at line 40 of file velocity_magnitude_sequence_error_function.cpp.

References MT_CHECK.


The documentation for this class was generated from the following files: