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

Penalizes collision between character collision primitives and a fixed plane. More...

#include <plane_collision_error_function.h>

Inheritance diagram for momentum::PlaneCollisionErrorFunctionT< T >:

Public Member Functions

 PlaneCollisionErrorFunctionT (const Skeleton &skel, const ParameterTransform &pt, const CollisionGeometry &cg, const Vector3< T > &planeNormal, T planeOffset)
 PlaneCollisionErrorFunctionT (const Character &character, const Vector3< T > &planeNormal, T planeOffset)
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 setPlane (const Vector3< T > &planeNormal, T planeOffset)
 Set the collision plane after normalizing planeNormal and the matching offset.
const Vector3< T > & getPlaneNormal () const
 Return the normalized plane normal used by collision and contact queries.
T getPlaneOffset () const
 Return the plane offset after normalization by setPlane().
PlaneCollisionQueryT< T > & getCollisionQuery ()
 Return the reusable query helper used by this error function.
const PlaneCollisionQueryT< T > & getCollisionQuery () const
 Return the reusable query helper used by this error function.
std::vector< size_t > getCollidingPrimitives () const
std::vector< PlaneCollisionDebugEntryT< T > > getCollisionDebugInfo () const
 Query detailed collision state for all currently-colliding primitives.
std::vector< Vector3< T > > getContactPoints (std::span< const JointStateT< T > > states, T contactMargin)
 Return world-space primitive surface points at or near the plane for an explicit state.
std::vector< Vector3< T > > getContactPointsByParent (std::span< const JointStateT< T > > states, T contactMargin)
 Return one world-space primitive surface point per parent joint at or near the plane.
std::vector< PlaneCollisionContactPointT< T > > getContactPointsByParentWithDetails (std::span< const JointStateT< T > > states, T contactMargin)
 Return one detailed world-space primitive surface point per parent joint at or near the plane.
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 accumulateGradientAlongChain (const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T weight, size_t startJoint, Ref< VectorX< T > > gradient, T scaleCorrection=T(0)) const
 Accumulate gradient contributions along a joint chain up to the root.
void accumulateJacobianAlongChain (const SkeletonStateT< T > &state, const Vector3< T > &position, const Vector3< T > &direction, T factor, size_t startJoint, Ref< MatrixX< T > > jacobian, int row, T scaleCorrection=T(0)) const
 Accumulate Jacobian contributions along a joint chain up to the root.

Protected Attributes

PlaneCollisionQueryT< T > collisionQuery_
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-3f

Detailed Description

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

Penalizes collision between character collision primitives and a fixed plane.

The plane is represented by planeNormal.dot(x) - planeOffset = 0; the non-penetrating side is planeNormal.dot(x) >= planeOffset. Capsules, ellipsoids, and boxes use the same collision geometry state and support-radius convention as CollisionErrorFunctionT.

Definition at line 25 of file plane_collision_error_function.h.

Constructor & Destructor Documentation

◆ PlaneCollisionErrorFunctionT() [1/2]

template<typename T>
momentum::PlaneCollisionErrorFunctionT< T >::PlaneCollisionErrorFunctionT ( const Skeleton & skel,
const ParameterTransform & pt,
const CollisionGeometry & cg,
const Vector3< T > & planeNormal,
T planeOffset )
explicit

◆ PlaneCollisionErrorFunctionT() [2/2]

template<typename T>
momentum::PlaneCollisionErrorFunctionT< T >::PlaneCollisionErrorFunctionT ( const Character & character,
const Vector3< T > & planeNormal,
T planeOffset )
explicit

Definition at line 38 of file plane_collision_error_function.cpp.

References PlaneCollisionErrorFunctionT().

Member Function Documentation

◆ accumulateGradientAlongChain()

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

Accumulate gradient contributions along a joint chain up to the root.

scaleCorrection accounts for the primitive support radius changing with uniform scale.

Definition at line 56 of file plane_collision_error_function.cpp.

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

Referenced by getGradient().

◆ accumulateJacobianAlongChain()

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

Accumulate Jacobian contributions along a joint chain up to the root.

scaleCorrection accounts for the primitive support radius changing with uniform scale.

Definition at line 81 of file plane_collision_error_function.cpp.

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

Referenced by getJacobian().

◆ getCollidingPrimitives()

template<typename T>
std::vector< size_t > momentum::PlaneCollisionErrorFunctionT< T >::getCollidingPrimitives ( ) const
nodiscard

Definition at line 107 of file plane_collision_error_function.cpp.

References collisionQuery_.

◆ getCollisionDebugInfo()

template<typename T>
std::vector< PlaneCollisionDebugEntryT< T > > momentum::PlaneCollisionErrorFunctionT< T >::getCollisionDebugInfo ( ) const
nodiscard

Query detailed collision state for all currently-colliding primitives.

Uses the collision state from the most recent solver iteration (computed during getJacobian/getError/getGradient), or the rest pose state immediately after construction.

Definition at line 112 of file plane_collision_error_function.cpp.

References collisionQuery_.

◆ getCollisionQuery() [1/2]

template<typename T>
PlaneCollisionQueryT< T > & momentum::PlaneCollisionErrorFunctionT< T >::getCollisionQuery ( )
inlinenodiscard

Return the reusable query helper used by this error function.

Definition at line 76 of file plane_collision_error_function.h.

◆ getCollisionQuery() [2/2]

template<typename T>
const PlaneCollisionQueryT< T > & momentum::PlaneCollisionErrorFunctionT< T >::getCollisionQuery ( ) const
inlinenodiscard

Return the reusable query helper used by this error function.

Definition at line 81 of file plane_collision_error_function.h.

◆ getContactPoints()

template<typename T>
std::vector< Vector3< T > > momentum::PlaneCollisionErrorFunctionT< T >::getContactPoints ( std::span< const JointStateT< T > > states,
T contactMargin )
nodiscard

Return world-space primitive surface points at or near the plane for an explicit state.

A primitive contributes when its signed surface distance to the plane is <= contactMargin. The returned point is on the primitive surface, deepest toward the plane.

Definition at line 118 of file plane_collision_error_function.cpp.

References collisionQuery_.

◆ getContactPointsByParent()

template<typename T>
std::vector< Vector3< T > > momentum::PlaneCollisionErrorFunctionT< T >::getContactPointsByParent ( std::span< const JointStateT< T > > states,
T contactMargin )
nodiscard

Return one world-space primitive surface point per parent joint at or near the plane.

A primitive contributes when its signed surface distance to the plane is <= contactMargin. When multiple primitives under the same parent joint contribute, the returned point is the deepest one toward the plane.

Definition at line 125 of file plane_collision_error_function.cpp.

References collisionQuery_.

◆ getContactPointsByParentWithDetails()

template<typename T>
std::vector< PlaneCollisionContactPointT< T > > momentum::PlaneCollisionErrorFunctionT< T >::getContactPointsByParentWithDetails ( std::span< const JointStateT< T > > states,
T contactMargin )
nodiscard

Return one detailed world-space primitive surface point per parent joint at or near the plane.

A primitive contributes when its signed surface distance to the plane is <= contactMargin. When multiple primitives under the same parent joint contribute, the returned point is the deepest one toward the plane.

Definition at line 133 of file plane_collision_error_function.cpp.

References collisionQuery_.

◆ getError()

◆ getGradient()

◆ getJacobian()

◆ getJacobianSize()

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

Reimplemented from momentum::SkeletonErrorFunctionT< T >.

Definition at line 263 of file plane_collision_error_function.cpp.

References collisionQuery_.

Referenced by getJacobian().

◆ getPlaneNormal()

template<typename T>
const Vector3< T > & momentum::PlaneCollisionErrorFunctionT< T >::getPlaneNormal ( ) const
inlinenodiscard

Return the normalized plane normal used by collision and contact queries.

Definition at line 66 of file plane_collision_error_function.h.

◆ getPlaneOffset()

template<typename T>
T momentum::PlaneCollisionErrorFunctionT< T >::getPlaneOffset ( ) const
inlinenodiscard

Return the plane offset after normalization by setPlane().

Definition at line 71 of file plane_collision_error_function.h.

◆ setPlane()

template<typename T>
void momentum::PlaneCollisionErrorFunctionT< T >::setPlane ( const Vector3< T > & planeNormal,
T planeOffset )
inline

Set the collision plane after normalizing planeNormal and the matching offset.

Definition at line 61 of file plane_collision_error_function.h.

Member Data Documentation

◆ collisionQuery_

◆ kCollisionWeight

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

Definition at line 147 of file plane_collision_error_function.h.

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


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