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

Error function that penalizes deviation from a target distance between two points attached to different joints. More...

#include <joint_to_joint_distance_error_function.h>

Inheritance diagram for momentum::JointToJointDistanceErrorFunctionT< T >:

Public Member Functions

 JointToJointDistanceErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt)
 JointToJointDistanceErrorFunctionT (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 joint1, const Vector3< T > &offset1, size_t joint2, const Vector3< T > &offset2, T targetDistance, T weight=T(1))
 Add a constraint between two joints with local offsets.
void clearConstraints ()
 Clear all constraints.
const std::vector< JointToJointDistanceConstraintT< 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

Static Public Attributes

static constexpr T kDistanceWeight = 1e-2
 Default weight for distance constraints.

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::JointToJointDistanceErrorFunctionT< T >

Error function that penalizes deviation from a target distance between two points attached to different joints.

This is useful for enforcing distance constraints between different parts of a character, such as maintaining a fixed distance between hands or ensuring two joints stay a certain distance apart.

The residual is: f = ||p1 - p2|| - targetDistance

where p1 and p2 are the world-space positions of the two joint points.

Template Parameters
TScalar type (float or double)

Definition at line 67 of file joint_to_joint_distance_error_function.h.

Constructor & Destructor Documentation

◆ JointToJointDistanceErrorFunctionT() [1/2]

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

◆ JointToJointDistanceErrorFunctionT() [2/2]

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

Member Function Documentation

◆ addConstraint()

template<typename T>
void momentum::JointToJointDistanceErrorFunctionT< T >::addConstraint ( size_t joint1,
const Vector3< T > & offset1,
size_t joint2,
const Vector3< T > & offset2,
T targetDistance,
T weight = T(1) )

Add a constraint between two joints with local offsets.

Definition at line 32 of file joint_to_joint_distance_error_function.cpp.

References MT_CHECK, and momentum::SkeletonErrorFunctionT< T >::skeleton_.

◆ clearConstraints()

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

Clear all constraints.

Definition at line 49 of file joint_to_joint_distance_error_function.cpp.

◆ getConstraints()

template<typename T>
const std::vector< JointToJointDistanceConstraintT< T > > & momentum::JointToJointDistanceErrorFunctionT< T >::getConstraints ( ) const
inlinenodiscard

Get all constraints.

Definition at line 107 of file joint_to_joint_distance_error_function.h.

◆ getError()

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

◆ getGradient()

◆ getJacobian()

◆ getJacobianSize()

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

◆ getNumConstraints()

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

Returns the number of constraints.

Definition at line 112 of file joint_to_joint_distance_error_function.h.

Member Data Documentation

◆ kDistanceWeight

template<typename T>
T momentum::JointToJointDistanceErrorFunctionT< T >::kDistanceWeight = 1e-2
staticconstexpr

Default weight for distance constraints.

Definition at line 117 of file joint_to_joint_distance_error_function.h.

Referenced by getError(), getGradient(), and getJacobian().


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