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

NOTE: This is a resurrected version of the CollisionErrorFunction (previously updated by D50818775). More...

#include <collision_error_function_stateless.h>

Inheritance diagram for momentum::CollisionErrorFunctionStatelessT< T >:

Classes

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

Public Member Functions

 CollisionErrorFunctionStatelessT (const Skeleton &skel, const ParameterTransform &pt, const CollisionGeometry &cg)
 CollisionErrorFunctionStatelessT (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 > &, 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
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 ()
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.
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.

Protected Attributes

const CollisionGeometry collisionGeometry
std::vector< CollisionPairInfo > validPairs_
 Pre-filtered list of valid collision pairs.
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::CollisionErrorFunctionStatelessT< T >

NOTE: This is a resurrected version of the CollisionErrorFunction (previously updated by D50818775).

Its stateless nature makes it ideal for testing in multi-threaded settings.

Represents an error function that penalizes self-intersections between collision geometries of the character.

The function pre-filters collision geometries to ignore those attached to the same joint, those intersecting in the rest pose, or those very close in the rest pose.

Definition at line 30 of file collision_error_function_stateless.h.

Constructor & Destructor Documentation

◆ CollisionErrorFunctionStatelessT() [1/2]

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

◆ CollisionErrorFunctionStatelessT() [2/2]

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

Member Function Documentation

◆ accumulateGradientAlongChain()

template<typename T>
void momentum::CollisionErrorFunctionStatelessT< 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.

scaleCorrection is an additive term for the scale derivative (for capsule radius correction).

Definition at line 98 of file collision_error_function_stateless.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::CollisionErrorFunctionStatelessT< 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.

scaleCorrection is an additive term for the scale derivative (for capsule radius correction).

Definition at line 124 of file collision_error_function_stateless.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::CollisionErrorFunctionStatelessT< 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 86 of file collision_error_function_stateless.cpp.

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

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

◆ computeBroadPhase()

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

Update collisionState and aabbs_ given the new skeleton state.

Definition at line 74 of file collision_error_function_stateless.cpp.

References aabbs_, collisionGeometry, collisionState, MT_PROFILE_EVENT, and momentum::updateAabb().

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

◆ getCollisionPairs()

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

◆ getError()

◆ getGradient()

◆ getJacobian()

◆ getJacobianSize()

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

Reimplemented from momentum::SkeletonErrorFunctionT< T >.

Definition at line 346 of file collision_error_function_stateless.cpp.

References validPairs_.

Referenced by getJacobian().

◆ updateCollisionPairs()

Member Data Documentation

◆ aabbs_

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

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

Definition at line 114 of file collision_error_function_stateless.h.

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

◆ collisionGeometry

◆ collisionState

◆ kCollisionWeight

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

Definition at line 119 of file collision_error_function_stateless.h.

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

◆ validPairs_

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

Pre-filtered list of valid collision pairs.

Definition at line 111 of file collision_error_function_stateless.h.

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


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