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

#include <collision_error_function.h>

Inheritance diagram for momentum::CollisionErrorFunctionT< T >:

Classes

struct  CollisionPairInfo
 Pre-computed valid collision pair with common ancestor. More...

Public Member Functions

 CollisionErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt, const CollisionGeometry &cg, bool filterRestPoseOverlaps=true)
 CollisionErrorFunctionT (const Character &character, bool filterRestPoseOverlaps=true)
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 > &, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< MatrixX< T > > jacobian, Ref< VectorX< T > > residual, int &usedRows) override
size_t getJacobianSize () const final
std::vector< Vector2i > getCollisionPairs () const
std::vector< CollisionDebugEntryT< T > > getCollisionDebugInfo () const
 Query detailed collision state for all currently-colliding pairs.
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

Protected Member Functions

void updateCollisionPairs (bool filterRestPoseOverlaps=true)
void computeBroadPhase (const SkeletonStateT< T > &state)
 Update collisionState_ and aabbs_ given the new skeleton state.
bool checkCollision (const CollisionGeometryStateT< T > &colState, size_t indexA, size_t indexB, CollisionOverlapResultT< T > &result) const
 AABB broadphase pre-check followed by narrow-phase collision overlap test.
void accumulateGradientAlongChain (const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T weight, size_t startJoint, size_t stopJoint, Ref< VectorX< T > > gradient, T scaleCorrection=T(0)) const
 Accumulate gradient contributions along a joint chain from startJoint up to (but not including) stopJoint.
void accumulateJacobianAlongChain (const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T factor, size_t startJoint, size_t stopJoint, Ref< MatrixX< T > > jacobian, int row, T scaleCorrection=T(0)) const
 Accumulate Jacobian contributions along a joint chain from startJoint up to (but not including) stopJoint.

Protected Attributes

const CollisionGeometry collisionGeometry_
std::vector< CollisionPairInfo > validPairs_
 Pre-filtered list of valid collision pairs (excludes rest-pose overlaps and adjacent joints).
std::vector< axel::BoundingBox< T > > aabbs_
 Per-capsule AABBs, updated each frame for broadphase culling.
CollisionGeometryStateT< T > collisionState_
Protected Attributes inherited from momentum::SkeletonErrorFunctionT< T >
const Skeleton & skeleton_
const ParameterTransform & parameterTransform_
T weight_
VectorX< bool > activeJointParams_
ParameterSet enabledParameters_
bool useHessian_ {false}

Static Protected Attributes

static constexpr T kCollisionWeight = 5e-3

Detailed Description

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

Definition at line 36 of file collision_error_function.h.

Constructor & Destructor Documentation

◆ CollisionErrorFunctionT() [1/2]

template<typename T>
momentum::CollisionErrorFunctionT< T >::CollisionErrorFunctionT ( const Skeleton & skel,
const ParameterTransform & pt,
const CollisionGeometry & cg,
bool filterRestPoseOverlaps = true )
explicit
Parameters
filterRestPoseOverlapsWhen true (default), capsule pairs that overlap in the rest pose are excluded from collision checking. Set to false for characters where limbs are close to the body in bind pose (e.g., beefy characters) and you still want collision avoidance between those pairs.

Definition at line 23 of file collision_error_function.cpp.

References collisionGeometry_, momentum::SkeletonErrorFunctionT< T >::SkeletonErrorFunctionT(), and updateCollisionPairs().

Referenced by CollisionErrorFunctionT().

◆ CollisionErrorFunctionT() [2/2]

template<typename T>
momentum::CollisionErrorFunctionT< T >::CollisionErrorFunctionT ( const Character & character,
bool filterRestPoseOverlaps = true )
explicit

Definition at line 33 of file collision_error_function.cpp.

References CollisionErrorFunctionT().

Member Function Documentation

◆ accumulateGradientAlongChain()

template<typename T>
void momentum::CollisionErrorFunctionT< T >::accumulateGradientAlongChain ( const SkeletonStateT< T > & state,
const Vector3< T > & position,
const Vector3< T > & direction,
T weight,
size_t startJoint,
size_t stopJoint,
Ref< VectorX< T > > gradient,
T scaleCorrection = T(0) ) const
protected

Accumulate gradient contributions along a joint chain from startJoint up to (but not including) stopJoint.

The sign of weight controls the push direction. scaleCorrection is an additive term for the scale derivative (for capsule radius correction).

Definition at line 104 of file collision_error_function.cpp.

References momentum::accumulateChainDerivatives(), momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::gradient_jointParams_to_modelParams(), momentum::SkeletonErrorFunctionT< T >::parameterTransform_, and momentum::SkeletonErrorFunctionT< T >::skeleton_.

Referenced by getGradient().

◆ accumulateJacobianAlongChain()

template<typename T>
void momentum::CollisionErrorFunctionT< T >::accumulateJacobianAlongChain ( const SkeletonStateT< T > & state,
const Vector3< T > & position,
const Vector3< T > & direction,
T factor,
size_t startJoint,
size_t stopJoint,
Ref< MatrixX< T > > jacobian,
int row,
T scaleCorrection = T(0) ) const
protected

Accumulate Jacobian contributions along a joint chain from startJoint up to (but not including) stopJoint.

The sign of factor controls the push direction. scaleCorrection is an additive term for the scale derivative (for capsule radius correction).

Definition at line 130 of file collision_error_function.cpp.

References momentum::accumulateChainDerivatives(), momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::jacobian_jointParams_to_modelParams(), momentum::SkeletonErrorFunctionT< T >::parameterTransform_, and momentum::SkeletonErrorFunctionT< T >::skeleton_.

Referenced by getJacobian().

◆ checkCollision()

template<typename T>
bool momentum::CollisionErrorFunctionT< T >::checkCollision ( const CollisionGeometryStateT< T > & colState,
size_t indexA,
size_t indexB,
CollisionOverlapResultT< T > & result ) const
nodiscardprotected

AABB broadphase pre-check followed by narrow-phase collision overlap test.

Returns true when the pair collides, filling result with contact details.

Definition at line 92 of file collision_error_function.cpp.

References aabbs_, collisionGeometry_, and momentum::overlaps().

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

◆ computeBroadPhase()

template<typename T>
void momentum::CollisionErrorFunctionT< T >::computeBroadPhase ( const SkeletonStateT< T > & state)
protected

Update collisionState_ and aabbs_ given the new skeleton state.

Definition at line 80 of file collision_error_function.cpp.

References aabbs_, collisionGeometry_, collisionState_, MT_PROFILE_EVENT, and momentum::updateAabb().

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

◆ getCollisionDebugInfo()

template<typename T>
std::vector< CollisionDebugEntryT< T > > momentum::CollisionErrorFunctionT< T >::getCollisionDebugInfo ( ) const
nodiscard

Query detailed collision state for all currently-colliding pairs.

Returns overlap, distance, capsule indices, and parent joint indices for each colliding pair. Uses the collision state from the most recent solver iteration (computed during getJacobian/getError/getGradient).

Definition at line 364 of file collision_error_function.cpp.

References checkCollision(), collisionGeometry_, collisionState_, momentum::CollisionOverlapResultT< T >::distance, momentum::CollisionOverlapResultT< T >::overlap, and validPairs_.

◆ getCollisionPairs()

template<typename T>
std::vector< Vector2i > momentum::CollisionErrorFunctionT< T >::getCollisionPairs ( ) const
nodiscard

Definition at line 157 of file collision_error_function.cpp.

References checkCollision(), collisionState_, and validPairs_.

◆ getError()

◆ getGradient()

◆ getJacobian()

◆ getJacobianSize()

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

Reimplemented from momentum::SkeletonErrorFunctionT< T >.

Definition at line 382 of file collision_error_function.cpp.

References validPairs_.

Referenced by getJacobian().

◆ updateCollisionPairs()

Member Data Documentation

◆ aabbs_

template<typename T>
std::vector<axel::BoundingBox<T> > momentum::CollisionErrorFunctionT< T >::aabbs_
protected

Per-capsule AABBs, updated each frame for broadphase culling.

Definition at line 134 of file collision_error_function.h.

Referenced by checkCollision(), computeBroadPhase(), and updateCollisionPairs().

◆ collisionGeometry_

◆ collisionState_

◆ kCollisionWeight

template<typename T>
T momentum::CollisionErrorFunctionT< T >::kCollisionWeight = 5e-3
staticconstexprprotected

Definition at line 139 of file collision_error_function.h.

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

◆ validPairs_

template<typename T>
std::vector<CollisionPairInfo> momentum::CollisionErrorFunctionT< T >::validPairs_
protected

Pre-filtered list of valid collision pairs (excludes rest-pose overlaps and adjacent joints).

Definition at line 131 of file collision_error_function.h.

Referenced by getCollisionDebugInfo(), getCollisionPairs(), getError(), getGradient(), getJacobian(), getJacobianSize(), and updateCollisionPairs().


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