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

Error function that constrains mesh vertices to a plane. More...

#include <vertex_plane_error_function.h>

Inheritance diagram for momentum::VertexPlaneErrorFunctionT< T >:

Public Types

using Base = VertexErrorFunctionT<T, VertexPlaneDataT<T>, 1>
Public Types inherited from momentum::VertexErrorFunctionT< T, VertexPlaneDataT< T >, 1 >
using FuncType
using DfdvType

Public Member Functions

 VertexPlaneErrorFunctionT (const Character &character, const ParameterTransform &parameterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
 ~VertexPlaneErrorFunctionT () override=default
void evalFunction (size_t constrIndex, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, std::span< const Eigen::Vector3< T > > worldVecs, FuncType &f, std::span< DfdvType > dfdv) const final
 Computes the residual and derivatives.
Public Member Functions inherited from momentum::VertexErrorFunctionT< T, VertexPlaneDataT< T >, 1 >
 VertexErrorFunctionT (const Character &character, const ParameterTransform &parameterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
 Constructor.
 ~VertexErrorFunctionT () override=default
const Character * getCharacter () const final
 Returns the character (needed for mesh-based computations).
bool needsMesh () const final
 Returns true (vertex constraints always need mesh).
void addConstraint (const VertexPlaneDataT< T > &constraint)
 Adds a constraint.
void addConstraints (std::span< const VertexPlaneDataT< T > > constraints)
 Appends a list of constraints.
void setConstraints (std::span< const VertexPlaneDataT< T > > constraints)
 Sets all constraints, replacing existing ones.
void clearConstraints ()
 Clears all constraints.
const std::vector< VertexPlaneDataT< T > > & getConstraints () const
 Returns the current constraints.
size_t getNumConstraints () const
 Returns the number of constraints.
size_t getJacobianSize () const final
 Returns the Jacobian size.
void setMaxThreads (size_t maxThreads)
 Sets the maximum number of threads for parallel execution.
double getError (const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) override
 Computes the error.
double getGradient (const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) override
 Computes the gradient.
double getJacobian (const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) override
 Computes the Jacobian.
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
void setWeight (T w)
T getWeight () const
void setActiveJoints (const VectorX< bool > &aj)
void setEnabledParameters (const ParameterSet &ps)
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)

Additional Inherited Members

Static Public Attributes inherited from momentum::VertexErrorFunctionT< T, VertexPlaneDataT< T >, 1 >
static constexpr size_t kFuncDim
static constexpr T kLegacyWeight
 Default constant weight for backwards compatibility with the legacy VertexErrorFunctionT.
Protected Attributes inherited from momentum::VertexErrorFunctionT< T, VertexPlaneDataT< T >, 1 >
const Character & character_
std::vector< VertexPlaneDataT< T > > constraints_
GeneralizedLossT< T > loss_
size_t maxThreads_
T legacyWeight_
 Legacy weight multiplied into error/gradient/Jacobian for backwards compatibility.
Protected Attributes inherited from momentum::SkeletonErrorFunctionT< T >
const Skeleton & skeleton_
const ParameterTransform & parameterTransform_
T weight_
VectorX< bool > activeJointParams_
ParameterSet enabledParameters_
bool useHessian_ {false}

Detailed Description

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

Error function that constrains mesh vertices to a plane.

The residual is the signed distance from the vertex to the plane: f = dot(vertexPosition - point, normal)

If above=true, the constraint is a half-space constraint where f is clamped to zero when the vertex is above the plane.

Template Parameters
TScalar type (float or double)

Definition at line 49 of file vertex_plane_error_function.h.

Member Typedef Documentation

◆ Base

template<typename T>
using momentum::VertexPlaneErrorFunctionT< T >::Base = VertexErrorFunctionT<T, VertexPlaneDataT<T>, 1>

Definition at line 51 of file vertex_plane_error_function.h.

Constructor & Destructor Documentation

◆ VertexPlaneErrorFunctionT()

◆ ~VertexPlaneErrorFunctionT()

template<typename T>
momentum::VertexPlaneErrorFunctionT< T >::~VertexPlaneErrorFunctionT ( )
overridedefault

Member Function Documentation

◆ evalFunction()

template<typename T>
void momentum::VertexPlaneErrorFunctionT< T >::evalFunction ( size_t constrIndex,
const SkeletonStateT< T > & state,
const MeshStateT< T > & meshState,
std::span< const Eigen::Vector3< T > > worldVecs,
FuncType & f,
std::span< DfdvType > dfdv ) const
finalvirtual

Computes the residual and derivatives.

Derived classes implement this with their specific constraint logic. worldVecs[0] is the pre-computed vertex world position.

Parameters
constrIndexIndex of the constraint
stateCurrent skeleton state
meshStateCurrent mesh state
worldVecsPre-computed world position (size 1 for vertex constraints)
fOutput: residual (FuncDim x 1)
dfdvOutput: derivative df/dv (must be filled if non-empty)

Implements momentum::VertexErrorFunctionT< T, VertexPlaneDataT< T >, 1 >.

Definition at line 32 of file vertex_plane_error_function.cpp.

References momentum::cast(), momentum::VertexErrorFunctionT< T, VertexPlaneDataT< T >, 1 >::constraints_, momentum::dot(), MT_CHECK, MT_CHECK_NOTNULL, momentum::normal(), and momentum::MeshStateT< T >::posedMesh_.


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