|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Mid-level adapter for single-vertex constraints. More...
#include <vertex_error_function.h>
Public Types | |
| using | FuncType = Eigen::Matrix<T, FuncDim, 1> |
| using | DfdvType = Eigen::Matrix<T, FuncDim, 3> |
Public Member Functions | |
| VertexErrorFunctionT (const Character &character, const ParameterTransform ¶meterTransform, 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 Data &constraint) |
| Adds a constraint. | |
| void | addConstraints (std::span< const Data > constraints) |
| Appends a list of constraints. | |
| void | setConstraints (std::span< const Data > constraints) |
| Sets all constraints, replacing existing ones. | |
| void | clearConstraints () |
| Clears all constraints. | |
| const std::vector< Data > & | 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 > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) override |
| Computes the error. | |
| double | getGradient (const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) override |
| Computes the gradient. | |
| double | getJacobian (const ModelParametersT< T > ¶ms, 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. | |
| virtual 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 =0 |
| Computes the residual and derivatives. | |
| 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 > ¶meters, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, const size_t actualParameters, Eigen::MatrixX< T > &hess, Eigen::VectorX< T > &grad) |
Static Public Attributes | |
| static constexpr size_t | kFuncDim = FuncDim |
| static constexpr T | kLegacyWeight = T(1e-4) |
| Default constant weight for backwards compatibility with the legacy VertexErrorFunctionT. | |
Protected Attributes | |
| const Character & | character_ |
| std::vector< Data > | constraints_ |
| GeneralizedLossT< T > | loss_ |
| size_t | maxThreads_ = 0 |
| T | legacyWeight_ = T(1) |
| 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} |
Mid-level adapter for single-vertex constraints.
VertexErrorFunctionT handles constraints involving a single mesh vertex. It inherits from SkeletonErrorFunctionT directly and uses SkeletonDerivativeT for derivative computation through skinning weights.
Derived classes implement evalFunction() with vertex-specific logic. The base class handles:
| T | Scalar type (float or double) |
| Data | Derived constraint data type (must extend VertexConstraintData) |
| FuncDim | Dimension of the residual (1, 2, 3, or 9) |
Definition at line 60 of file vertex_error_function.h.
| using momentum::VertexErrorFunctionT< T, Data, FuncDim >::DfdvType = Eigen::Matrix<T, FuncDim, 3> |
Definition at line 63 of file vertex_error_function.h.
| using momentum::VertexErrorFunctionT< T, Data, FuncDim >::FuncType = Eigen::Matrix<T, FuncDim, 1> |
Definition at line 62 of file vertex_error_function.h.
|
explicit |
Constructor.
| character | The character (needed for mesh access) |
| parameterTransform | Maps joint parameters to model parameters |
| lossAlpha | Alpha parameter for the generalized loss function (default: L2) |
| lossC | C parameter for the generalized loss function (default: 1) |
Definition at line 22 of file vertex_error_function.cpp.
References character_, loss_, and momentum::SkeletonErrorFunctionT< T >::SkeletonErrorFunctionT().
|
overridedefault |
| void momentum::VertexErrorFunctionT< T, Data, FuncDim >::addConstraint | ( | const Data & | constraint | ) |
Adds a constraint.
Definition at line 42 of file vertex_error_function.cpp.
References constraints_, momentum::kInvalidIndex, and MT_CHECK.
Referenced by momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::addConstraints().
|
inline |
Appends a list of constraints.
Definition at line 96 of file vertex_error_function.h.
| void momentum::VertexErrorFunctionT< T, Data, FuncDim >::clearConstraints | ( | ) |
Clears all constraints.
Definition at line 53 of file vertex_error_function.cpp.
References constraints_.
|
pure virtual |
Computes the residual and derivatives.
Derived classes implement this with their specific constraint logic. worldVecs[0] is the pre-computed vertex world position.
| constrIndex | Index of the constraint |
| state | Current skeleton state |
| meshState | Current mesh state |
| worldVecs | Pre-computed world position (size 1 for vertex constraints) |
| f | Output: residual (FuncDim x 1) |
| dfdv | Output: derivative df/dv (must be filled if non-empty) |
Implemented in momentum::VertexNormalErrorFunctionT< T >, momentum::VertexPlaneErrorFunctionT< T >, momentum::VertexPositionErrorFunctionT< T >, and momentum::VertexProjectionErrorFunctionT< T >.
Referenced by getError(), getGradient(), and getJacobian().
|
nodiscardfinalvirtual |
Returns the character (needed for mesh-based computations).
Reimplemented from momentum::SkeletonErrorFunctionT< T >.
Definition at line 32 of file vertex_error_function.cpp.
References character_.
|
nodiscard |
Returns the current constraints.
Definition at line 58 of file vertex_error_function.cpp.
References constraints_.
|
nodiscardoverridevirtual |
Computes the error.
Reimplemented from momentum::SkeletonErrorFunctionT< T >.
Definition at line 63 of file vertex_error_function.cpp.
References momentum::cast(), constraints_, evalFunction(), legacyWeight_, loss_, MT_CHECK_NOTNULL, momentum::MeshStateT< T >::posedMesh_, and momentum::SkeletonErrorFunctionT< T >::weight_.
|
overridevirtual |
Computes the gradient.
Reimplemented from momentum::SkeletonErrorFunctionT< T >.
Reimplemented in momentum::VertexNormalErrorFunctionT< T >, and momentum::VertexPositionErrorFunctionT< T >.
Definition at line 96 of file vertex_error_function.cpp.
References momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::cast(), character_, constraints_, momentum::SkeletonErrorFunctionT< T >::enabledParameters_, evalFunction(), legacyWeight_, loss_, maxThreads_, MT_CHECK_NOTNULL, momentum::SkeletonErrorFunctionT< T >::parameterTransform_, momentum::MeshStateT< T >::posedMesh_, momentum::SkeletonErrorFunctionT< T >::skeleton_, and momentum::SkeletonErrorFunctionT< T >::weight_.
|
overridevirtual |
Computes the Jacobian.
Reimplemented from momentum::SkeletonErrorFunctionT< T >.
Reimplemented in momentum::VertexNormalErrorFunctionT< T >, and momentum::VertexPositionErrorFunctionT< T >.
Definition at line 190 of file vertex_error_function.cpp.
References momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::cast(), character_, constraints_, momentum::SkeletonErrorFunctionT< T >::enabledParameters_, evalFunction(), getJacobian(), legacyWeight_, loss_, maxThreads_, MT_CHECK_NOTNULL, momentum::SkeletonErrorFunctionT< T >::parameterTransform_, momentum::MeshStateT< T >::posedMesh_, momentum::SkeletonErrorFunctionT< T >::skeleton_, and momentum::SkeletonErrorFunctionT< T >::weight_.
Referenced by getJacobian().
|
inlinenodiscardfinalvirtual |
Returns the Jacobian size.
Reimplemented from momentum::SkeletonErrorFunctionT< T >.
Definition at line 117 of file vertex_error_function.h.
|
inlinenodiscard |
Returns the number of constraints.
Definition at line 112 of file vertex_error_function.h.
|
nodiscardfinalvirtual |
Returns true (vertex constraints always need mesh).
Reimplemented from momentum::SkeletonErrorFunctionT< T >.
Definition at line 37 of file vertex_error_function.cpp.
| void momentum::VertexErrorFunctionT< T, Data, FuncDim >::setConstraints | ( | std::span< const Data > | constraints | ) |
Sets all constraints, replacing existing ones.
Definition at line 48 of file vertex_error_function.cpp.
References constraints_.
|
inline |
Sets the maximum number of threads for parallel execution.
Definition at line 122 of file vertex_error_function.h.
|
protected |
Definition at line 168 of file vertex_error_function.h.
Referenced by getCharacter(), getGradient(), getJacobian(), and VertexErrorFunctionT().
|
protected |
Definition at line 169 of file vertex_error_function.h.
Referenced by addConstraint(), clearConstraints(), getConstraints(), getError(), getGradient(), getJacobian(), and setConstraints().
|
staticconstexpr |
Definition at line 65 of file vertex_error_function.h.
|
staticconstexpr |
Default constant weight for backwards compatibility with the legacy VertexErrorFunctionT.
Position/Normal/Plane leaf classes set this to 1e-4 (matching PositionErrorFunctionT::kLegacyWeight). Defaults to 1 (no scaling) for other leaf classes.
Definition at line 70 of file vertex_error_function.h.
|
protected |
Legacy weight multiplied into error/gradient/Jacobian for backwards compatibility.
Leaf classes that replace the old VertexErrorFunctionT set this to kLegacyWeight (1e-4).
Definition at line 175 of file vertex_error_function.h.
Referenced by getError(), getGradient(), and getJacobian().
|
protected |
Definition at line 170 of file vertex_error_function.h.
Referenced by getError(), getGradient(), getJacobian(), and VertexErrorFunctionT().
|
protected |
Definition at line 171 of file vertex_error_function.h.
Referenced by getGradient(), and getJacobian().