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

Continuous (swept) SDF collision error function over two consecutive frames. More...

#include <sdf_collision_sequence_error_function.h>

Inheritance diagram for momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >:

Public Member Functions

 SDFCollisionSequenceErrorFunctionT (const Character &character, const std::vector< SdfColliderType > &sdfColliders, const std::vector< int > &participatingVertices={}, const std::vector< T > &vertexWeights={})
size_t numFrames () const final
bool needsMesh () const final
double getError (std::span< const ModelParametersT< T > > modelParameters, std::span< const SkeletonStateT< T > > skelStates, std::span< const MeshStateT< T > > meshStates) const final
double getGradient (std::span< const ModelParametersT< T > > modelParameters, std::span< const SkeletonStateT< T > > skelStates, std::span< const MeshStateT< T > > meshStates, Eigen::Ref< Eigen::VectorX< T > > gradient) const final
double getJacobian (std::span< const ModelParametersT< T > > modelParameters, std::span< const SkeletonStateT< T > > skelStates, std::span< const MeshStateT< T > > meshStates, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) const final
size_t getJacobianSize () const final
const Character & getCharacter () const
Public Member Functions inherited from momentum::SequenceErrorFunctionT< T >
 SequenceErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt)
virtual ~SequenceErrorFunctionT ()=default
void setWeight (T w)
float getWeight () const
void setActiveJoints (const VectorX< bool > &aj)
void setEnabledParameters (const ParameterSet &ps)
const Skeleton & getSkeleton () const
const ParameterTransform & getParameterTransform () const

Static Public Attributes

static constexpr T kSDFCollisionWeight = T(5e-3)
 Penetration penalty weight, matching the single-frame SDFCollisionErrorFunctionT.
static constexpr size_t kMaxIntervals = 2
 Upper bound on the number of penetrating sub-intervals penalized per (vertex, collider).

Additional Inherited Members

Protected Attributes inherited from momentum::SequenceErrorFunctionT< T >
const Skeleton & skeleton_
const ParameterTransform & parameterTransform_
T weight_ = 1.0f
VectorX< bool > activeJointParams_
ParameterSet enabledParameters_

Detailed Description

template<typename T, typename SdfColliderType = SDFColliderT<float>>
class momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >

Continuous (swept) SDF collision error function over two consecutive frames.

The single-frame SDFCollisionErrorFunctionT only sees penetration at the sampled poses, so a vertex moving fast enough to pass entirely through a thin collider (e.g. a finger) between frame t and t+1 is never penalized — it "tunnels". This sequence error function closes that gap: for each participating vertex it sweeps the straight segment connecting the vertex's position at the two frames and penalizes the deepest penetration that segment reaches inside a collider.

The sweep is performed in the collider's local SDF frame: each endpoint is mapped through its own frame's world-to-collider transform and the two local positions are interpolated linearly. This captures the relative motion of vertex and collider (both may be joint-driven), keeps the interpolation exactly differentiable (no slerp-derivative approximation), and makes the sphere-trace used to locate crossings exactly conservative because distances are queried in the same local units the march steps in.

The penalty is w * phiMax^2 per penetrating sub-interval, where phiMax is the greatest penetration depth (phi = max(0, -sdf)) reached along the swept segment. It is a max, not an integral, so it depends only on how deep the pass-through gets, never on how long the segment stays inside — there is no "stretch the trajectory to dilute the penalty" degeneracy.

The deepest point s* is located exactly (bisecting d'(s) = 0, since d decreases then increases across a both-crossing interval). Because s* is a true interior extremum, the envelope theorem makes the penalty's gradient independent of how s* drifts with the parameters: it is simply the single-frame contact gradient evaluated at s*, split across the two frames by the interpolation weights (1 - s*) (frame t) and s* (frame t+1). One residual per interval, gradient and Jacobian both finite-difference-clean.

Only sub-intervals bounded by two real surface crossings (entry + -> - and exit - -> +) are penalized, targeting the pure pass-through case and leaving at-frame penetration to the per-frame error function.

Derivatives reuse the single-frame chain-rule helpers (detail_sdf_collision). The local SDF gradient is mapped to world space including the world-to-collider scale factor, which the derivatives require whenever the collider's joint carries a non-unit scale.

A conservative broadphase skips any (vertex, collider) pair whose swept segment cannot reach the collider's SDF bounds, so distant pairs cost only an axis-aligned-bounding-box test.

The SdfColliderType is duck-typed; see SDFCollisionErrorFunctionT for the required interface (this function additionally uses bounds()).

Definition at line 75 of file sdf_collision_sequence_error_function.h.

Constructor & Destructor Documentation

◆ SDFCollisionSequenceErrorFunctionT()

template<typename T, typename SdfColliderType>
momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::SDFCollisionSequenceErrorFunctionT ( const Character & character,
const std::vector< SdfColliderType > & sdfColliders,
const std::vector< int > & participatingVertices = {},
const std::vector< T > & vertexWeights = {} )
explicit
Parameters
characterThe character containing skeleton, mesh, and skin weights
sdfCollidersThe SDF collision geometry to sweep against
participatingVerticesVertex indices to include (empty means all vertices)
vertexWeightsPer-vertex collision weights (empty means uniform weight of 1.0)

Definition at line 206 of file sdf_collision_sequence_error_function.h.

References MT_CHECK, MT_CHECK_NOTNULL, and momentum::SequenceErrorFunctionT< T >::SequenceErrorFunctionT().

Member Function Documentation

◆ getCharacter()

template<typename T, typename SdfColliderType = SDFColliderT<float>>
const Character & momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::getCharacter ( ) const
inlinenodiscard

Definition at line 116 of file sdf_collision_sequence_error_function.h.

◆ getError()

template<typename T, typename SdfColliderType>
double momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::getError ( std::span< const ModelParametersT< T > > modelParameters,
std::span< const SkeletonStateT< T > > skelStates,
std::span< const MeshStateT< T > > meshStates ) const
finalvirtual

◆ getGradient()

◆ getJacobian()

◆ getJacobianSize()

template<typename T, typename SdfColliderType>
size_t momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::getJacobianSize ( ) const
nodiscardfinalvirtual

Reimplemented from momentum::SequenceErrorFunctionT< T >.

Definition at line 644 of file sdf_collision_sequence_error_function.h.

References kMaxIntervals.

◆ needsMesh()

template<typename T, typename SdfColliderType = SDFColliderT<float>>
bool momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::needsMesh ( ) const
inlinenodiscardfinalvirtual

Reimplemented from momentum::SequenceErrorFunctionT< T >.

Definition at line 91 of file sdf_collision_sequence_error_function.h.

◆ numFrames()

template<typename T, typename SdfColliderType = SDFColliderT<float>>
size_t momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::numFrames ( ) const
inlinenodiscardfinalvirtual

Member Data Documentation

◆ kMaxIntervals

template<typename T, typename SdfColliderType = SDFColliderT<float>>
size_t momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::kMaxIntervals = 2
staticconstexpr

Upper bound on the number of penetrating sub-intervals penalized per (vertex, collider).

Definition at line 124 of file sdf_collision_sequence_error_function.h.

Referenced by getJacobianSize().

◆ kSDFCollisionWeight

template<typename T, typename SdfColliderType = SDFColliderT<float>>
T momentum::SDFCollisionSequenceErrorFunctionT< T, SdfColliderType >::kSDFCollisionWeight = T(5e-3)
staticconstexpr

Penetration penalty weight, matching the single-frame SDFCollisionErrorFunctionT.

Definition at line 121 of file sdf_collision_sequence_error_function.h.

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


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