|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Continuous (swept) SDF collision error function over two consecutive frames. More...
#include <sdf_collision_sequence_error_function.h>
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_ |
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.
|
explicit |
| character | The character containing skeleton, mesh, and skin weights |
| sdfColliders | The SDF collision geometry to sweep against |
| participatingVertices | Vertex indices to include (empty means all vertices) |
| vertexWeights | Per-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().
|
inlinenodiscard |
Definition at line 116 of file sdf_collision_sequence_error_function.h.
|
finalvirtual |
Reimplemented from momentum::SequenceErrorFunctionT< T >.
Definition at line 355 of file sdf_collision_sequence_error_function.h.
References momentum::detail_sdf_collision::computeWorldToColliderTransform(), kSDFCollisionWeight, MT_CHECK, MT_CHECK_NOTNULL, MT_PROFILE_FUNCTION, and momentum::SequenceErrorFunctionT< T >::weight_.
|
finalvirtual |
Reimplemented from momentum::SequenceErrorFunctionT< T >.
Definition at line 411 of file sdf_collision_sequence_error_function.h.
References momentum::detail_sdf_collision::accumulateColliderHierarchyGradient(), momentum::detail_sdf_collision::accumulateJointGradient(), momentum::SequenceErrorFunctionT< T >::activeJointParams_, momentum::detail_sdf_collision::computeWorldToColliderTransform(), momentum::detail_sdf_collision::findCommonAncestorForVertex(), momentum::SkinningWeightIteratorT< T >::finished(), momentum::kInvalidIndex, momentum::kParametersPerJoint, kSDFCollisionWeight, MT_CHECK, MT_CHECK_NOTNULL, MT_PROFILE_FUNCTION, momentum::SkinningWeightIteratorT< T >::next(), momentum::SequenceErrorFunctionT< T >::parameterTransform_, and momentum::SequenceErrorFunctionT< T >::weight_.
|
finalvirtual |
Reimplemented from momentum::SequenceErrorFunctionT< T >.
Definition at line 523 of file sdf_collision_sequence_error_function.h.
References momentum::detail_sdf_collision::accumulateColliderHierarchyJacobian(), momentum::detail_sdf_collision::accumulateJointJacobian(), momentum::SequenceErrorFunctionT< T >::activeJointParams_, momentum::detail_sdf_collision::computeWorldToColliderTransform(), momentum::detail_sdf_collision::findCommonAncestorForVertex(), momentum::SkinningWeightIteratorT< T >::finished(), momentum::kInvalidIndex, momentum::kParametersPerJoint, kSDFCollisionWeight, MT_CHECK, MT_CHECK_NOTNULL, MT_PROFILE_FUNCTION, momentum::SkinningWeightIteratorT< T >::next(), momentum::SequenceErrorFunctionT< T >::parameterTransform_, and momentum::SequenceErrorFunctionT< T >::weight_.
|
nodiscardfinalvirtual |
Reimplemented from momentum::SequenceErrorFunctionT< T >.
Definition at line 644 of file sdf_collision_sequence_error_function.h.
References kMaxIntervals.
|
inlinenodiscardfinalvirtual |
Reimplemented from momentum::SequenceErrorFunctionT< T >.
Definition at line 91 of file sdf_collision_sequence_error_function.h.
|
inlinenodiscardfinalvirtual |
Implements momentum::SequenceErrorFunctionT< T >.
Definition at line 87 of file sdf_collision_sequence_error_function.h.
|
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().
|
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().