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

Error function that constrains the center of mass to a target position. More...

#include <center_of_mass_error_function.h>

Inheritance diagram for momentum::CenterOfMassErrorFunctionT< T >:

Public Types

using ConstraintType = CenterOfMassConstraintT<T>

Public Member Functions

 CenterOfMassErrorFunctionT (const Skeleton &skeleton, const ParameterTransform &parameterTransform)
 Constructs the error function.
 ~CenterOfMassErrorFunctionT () override=default
double getError (const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
double getGradient (const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) override
double getJacobian (const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) override
size_t getJacobianSize () const final
void addConstraint (const ConstraintType &constraint)
 Adds a center of mass constraint.
void setConstraints (std::span< const ConstraintType > constraints)
 Sets all constraints, replacing any existing ones.
void clearConstraints ()
 Clears all constraints.
const std::vector< ConstraintType > & getConstraints () const
 Returns the current constraints.
size_t getNumConstraints () const
 Returns the number of constraints.
Public Member Functions inherited from momentum::SkeletonErrorFunctionT< T >
 SkeletonErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt)
virtual ~SkeletonErrorFunctionT ()=default
const Skeleton & getSkeleton () const
const ParameterTransform & getParameterTransform () const
virtual const Character * getCharacter () const
 For mesh-based error functions, get access to the underlying character.
void setWeight (T w)
T getWeight () const
void setActiveJoints (const VectorX< bool > &aj)
void setEnabledParameters (const ParameterSet &ps)
virtual void getHessian (const ModelParametersT< T > &, const SkeletonStateT< T > &, const MeshStateT< T > &, Eigen::Ref< Eigen::MatrixX< T > >)
virtual double getSolverDerivatives (const ModelParametersT< T > &parameters, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, const size_t actualParameters, Eigen::MatrixX< T > &hess, Eigen::VectorX< T > &grad)
virtual bool needsMesh () const

Additional Inherited Members

Protected Attributes inherited from momentum::SkeletonErrorFunctionT< T >
const Skeleton & skeleton_
const ParameterTransform & parameterTransform_
T weight_
VectorX< bool > activeJointParams_
ParameterSet enabledParameters_
bool useHessian_ {false}

Detailed Description

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

Error function that constrains the center of mass to a target position.

The center of mass is computed as: CoM = (sum m_k * p_k) / (sum m_k)

where m_k is the mass at joint k and p_k is the world position of joint k.

The residual is: f = CoM - target or, when projection is enabled: f = project(CoM) - target where project(x) orthogonally projects x to the configured plane.

This uses SkeletonDerivativeT for efficient hierarchy walks, similar to CameraProjectionErrorFunctionT.

Usage

CenterOfMassErrorFunctionT<float> errorFn(skeleton, parameterTransform);
constraint.jointIndices = {0, 1, 2};
constraint.masses = {10.0f, 5.0f, 3.0f};
constraint.target = Eigen::Vector3f(0, 1.0f, 0);
constraint.weight = 1.0f;
errorFn.addConstraint(constraint);
CenterOfMassErrorFunctionT(const Skeleton &skeleton, const ParameterTransform &parameterTransform)
Constructs the error function.
Constraint data for a center of mass target.
Eigen::Vector3< T > target
Target position for the center of mass.
std::vector< T > masses
Mass values for each joint (must match jointIndices size).
std::vector< size_t > jointIndices
Indices of joints contributing to this CoM constraint.
Template Parameters
TScalar type (float or double)

Definition at line 111 of file center_of_mass_error_function.h.

Member Typedef Documentation

◆ ConstraintType

template<typename T>
using momentum::CenterOfMassErrorFunctionT< T >::ConstraintType = CenterOfMassConstraintT<T>

Definition at line 113 of file center_of_mass_error_function.h.

Constructor & Destructor Documentation

◆ CenterOfMassErrorFunctionT()

template<typename T>
momentum::CenterOfMassErrorFunctionT< T >::CenterOfMassErrorFunctionT ( const Skeleton & skeleton,
const ParameterTransform & parameterTransform )

Constructs the error function.

Parameters
skeletonThe skeleton structure
parameterTransformMaps joint parameters to model parameters

Definition at line 94 of file center_of_mass_error_function.cpp.

References momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::SkeletonErrorFunctionT< T >::enabledParameters_, and momentum::SkeletonErrorFunctionT< T >::SkeletonErrorFunctionT().

◆ ~CenterOfMassErrorFunctionT()

template<typename T>
momentum::CenterOfMassErrorFunctionT< T >::~CenterOfMassErrorFunctionT ( )
overridedefault

Member Function Documentation

◆ addConstraint()

◆ clearConstraints()

template<typename T>
void momentum::CenterOfMassErrorFunctionT< T >::clearConstraints ( )

Clears all constraints.

Definition at line 146 of file center_of_mass_error_function.cpp.

◆ getConstraints()

template<typename T>
const std::vector< CenterOfMassConstraintT< T > > & momentum::CenterOfMassErrorFunctionT< T >::getConstraints ( ) const
nodiscard

Returns the current constraints.

Definition at line 151 of file center_of_mass_error_function.cpp.

◆ getError()

template<typename T>
double momentum::CenterOfMassErrorFunctionT< T >::getError ( const ModelParametersT< T > & params,
const SkeletonStateT< T > & state,
const MeshStateT< T > & meshState )
nodiscardfinalvirtual

◆ getGradient()

template<typename T>
double momentum::CenterOfMassErrorFunctionT< T >::getGradient ( const ModelParametersT< T > & params,
const SkeletonStateT< T > & state,
const MeshStateT< T > & meshState,
Eigen::Ref< Eigen::VectorX< T > > gradient )
overridevirtual

◆ getJacobian()

template<typename T>
double momentum::CenterOfMassErrorFunctionT< T >::getJacobian ( const ModelParametersT< T > & params,
const SkeletonStateT< T > & state,
const MeshStateT< T > & meshState,
Eigen::Ref< Eigen::MatrixX< T > > jacobian,
Eigen::Ref< Eigen::VectorX< T > > residual,
int & usedRows )
overridevirtual

◆ getJacobianSize()

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

Reimplemented from momentum::SkeletonErrorFunctionT< T >.

Definition at line 334 of file center_of_mass_error_function.cpp.

◆ getNumConstraints()

template<typename T>
size_t momentum::CenterOfMassErrorFunctionT< T >::getNumConstraints ( ) const
nodiscard

Returns the number of constraints.

Definition at line 157 of file center_of_mass_error_function.cpp.

◆ setConstraints()

template<typename T>
void momentum::CenterOfMassErrorFunctionT< T >::setConstraints ( std::span< const ConstraintType > constraints)

Sets all constraints, replacing any existing ones.

Parameters
constraintsThe new list of constraints

Definition at line 137 of file center_of_mass_error_function.cpp.

References addConstraint().


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