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

Error function that penalizes deviation from a target position expressed in a reference joint's coordinate frame. More...

#include <joint_to_joint_position_error_function.h>

Inheritance diagram for momentum::JointToJointPositionErrorFunctionT< T >:

Public Member Functions

 JointToJointPositionErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt)
 JointToJointPositionErrorFunctionT (const Character &character)
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, Ref< VectorX< T > > gradient) override
double getJacobian (const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< MatrixX< T > > jacobian, Ref< VectorX< T > > residual, int &usedRows) override
size_t getJacobianSize () const final
void addConstraint (size_t sourceJoint, const Vector3< T > &sourceOffset, size_t referenceJoint, const Vector3< T > &referenceOffset, const Vector3< T > &target, T weight=T(1), const std::string &name={})
 Add a joint-to-joint position constraint.
void addConstraint (const JointToJointPositionDataT< T > &constraint)
 Add a constraint using the JointToJointPositionDataT struct.
void clearConstraints ()
 Clear all constraints.
const std::vector< JointToJointPositionDataT< T > > & getConstraints () const
 Get all 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 double getGradient (const ModelParametersT< T > &, const SkeletonStateT< T > &, const MeshStateT< T > &, Eigen::Ref< Eigen::VectorX< T > >)
virtual double getJacobian (const ModelParametersT< T > &, const SkeletonStateT< T > &, const MeshStateT< T > &, Eigen::Ref< Eigen::MatrixX< T > >, Eigen::Ref< Eigen::VectorX< T > >, int &usedRows)
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::JointToJointPositionErrorFunctionT< T >

Error function that penalizes deviation from a target position expressed in a reference joint's coordinate frame.

This is useful for constraints where you want to control the relative position between two body parts, such as keeping a hand at a specific position relative to the body, or maintaining a specific relationship between two joints that should move together.

The error is computed as: error = T_ref^{-1} * (T_src * src_offset) - target

where T_ref and T_src are the global transformations of the reference and source joints respectively.

Template Parameters
TScalar type (float or double)

Definition at line 74 of file joint_to_joint_position_error_function.h.

Constructor & Destructor Documentation

◆ JointToJointPositionErrorFunctionT() [1/2]

template<typename T>
momentum::JointToJointPositionErrorFunctionT< T >::JointToJointPositionErrorFunctionT ( const Skeleton & skel,
const ParameterTransform & pt )
explicit

◆ JointToJointPositionErrorFunctionT() [2/2]

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

Member Function Documentation

◆ addConstraint() [1/2]

◆ addConstraint() [2/2]

template<typename T>
void momentum::JointToJointPositionErrorFunctionT< T >::addConstraint ( size_t sourceJoint,
const Vector3< T > & sourceOffset,
size_t referenceJoint,
const Vector3< T > & referenceOffset,
const Vector3< T > & target,
T weight = T(1),
const std::string & name = {} )

Add a joint-to-joint position constraint.

Parameters
[in]sourceJointIndex of the source joint.
[in]sourceOffsetOffset from sourceJoint in local coordinates.
[in]referenceJointIndex of the reference joint.
[in]referenceOffsetOffset from referenceJoint in local coordinates.
[in]targetTarget position in the reference joint's coordinate frame.
[in]weightWeight for this constraint.
[in]nameName of the constraint (for debugging).

Definition at line 31 of file joint_to_joint_position_error_function.cpp.

References MT_CHECK, momentum::JointToJointPositionDataT< T >::name, momentum::JointToJointPositionDataT< T >::referenceJoint, momentum::JointToJointPositionDataT< T >::referenceOffset, momentum::SkeletonErrorFunctionT< T >::skeleton_, momentum::JointToJointPositionDataT< T >::sourceJoint, momentum::JointToJointPositionDataT< T >::sourceOffset, momentum::JointToJointPositionDataT< T >::target, and momentum::JointToJointPositionDataT< T >::weight.

◆ clearConstraints()

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

Clear all constraints.

Definition at line 72 of file joint_to_joint_position_error_function.cpp.

◆ getConstraints()

template<typename T>
const std::vector< JointToJointPositionDataT< T > > & momentum::JointToJointPositionErrorFunctionT< T >::getConstraints ( ) const
inlinenodiscard

Get all constraints.

Definition at line 126 of file joint_to_joint_position_error_function.h.

◆ getError()

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

◆ getGradient()

◆ getJacobian()

◆ getJacobianSize()

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

◆ getNumConstraints()

template<typename T>
size_t momentum::JointToJointPositionErrorFunctionT< T >::getNumConstraints ( ) const
inlinenodiscard

Returns the number of constraints.

Definition at line 131 of file joint_to_joint_position_error_function.h.


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