|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Error function that constrains mesh vertices to target positions. More...
#include <vertex_position_error_function.h>
Public Types | |
| using | Base = VertexErrorFunctionT<T, VertexPositionDataT<T>, 3> |
| Public Types inherited from momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 > | |
| using | FuncType |
| using | DfdvType |
Public Member Functions | |
| VertexPositionErrorFunctionT (const Character &character, const ParameterTransform ¶meterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1)) | |
| ~VertexPositionErrorFunctionT () 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. | |
| double | getGradient (const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) override |
| Specialized getGradient that avoids the dfdv*derivative matrix multiply. | |
| 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 |
| Specialized getJacobian with the same dfdv=Identity optimization. | |
| Public Member Functions inherited from momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 > | |
| 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 VertexPositionDataT< T > &constraint) |
| Adds a constraint. | |
| void | addConstraints (std::span< const VertexPositionDataT< T > > constraints) |
| Appends a list of constraints. | |
| void | setConstraints (std::span< const VertexPositionDataT< T > > constraints) |
| Sets all constraints, replacing existing ones. | |
| void | clearConstraints () |
| Clears all constraints. | |
| const std::vector< VertexPositionDataT< 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 > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) override |
| Computes the error. | |
| 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) |
Additional Inherited Members | |
| Static Public Attributes inherited from momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 > | |
| 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, VertexPositionDataT< T >, 3 > | |
| const Character & | character_ |
| std::vector< VertexPositionDataT< 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} |
Error function that constrains mesh vertices to target positions.
The residual is the 3D vector from the vertex position to the target: f = vertexPosition - target
| T | Scalar type (float or double) |
Definition at line 38 of file vertex_position_error_function.h.
| using momentum::VertexPositionErrorFunctionT< T >::Base = VertexErrorFunctionT<T, VertexPositionDataT<T>, 3> |
Definition at line 40 of file vertex_position_error_function.h.
|
explicit |
Definition at line 21 of file vertex_position_error_function.cpp.
References momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::kLegacyWeight, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::legacyWeight_, and momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::VertexErrorFunctionT().
|
overridedefault |
|
finalvirtual |
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) |
Implements momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >.
Definition at line 35 of file vertex_position_error_function.cpp.
References momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::constraints_, and MT_CHECK.
|
overridevirtual |
Specialized getGradient that avoids the dfdv*derivative matrix multiply.
Since dfdv=Identity for position constraints, we use accumulateVertexGradientIdentityDfdv which computes weightedResidual.dot(derivative) directly instead of weightedResidual.dot(I * derivative).
Reimplemented from momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >.
Definition at line 58 of file vertex_position_error_function.cpp.
References momentum::SkeletonDerivativeT< T >::accumulateVertexGradientIdentityDfdv(), momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::cast(), momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::character_, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::constraints_, momentum::SkeletonErrorFunctionT< T >::enabledParameters_, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::legacyWeight_, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::loss_, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::maxThreads_, MT_CHECK_NOTNULL, momentum::SkeletonErrorFunctionT< T >::parameterTransform_, momentum::MeshStateT< T >::posedMesh_, momentum::SkeletonErrorFunctionT< T >::skeleton_, and momentum::SkeletonErrorFunctionT< T >::weight_.
|
overridevirtual |
Specialized getJacobian with the same dfdv=Identity optimization.
Reimplemented from momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >.
Definition at line 144 of file vertex_position_error_function.cpp.
References momentum::SkeletonDerivativeT< T >::accumulateVertexJacobianIdentityDfdv(), momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::cast(), momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::character_, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::constraints_, momentum::SkeletonErrorFunctionT< T >::enabledParameters_, getJacobian(), momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::legacyWeight_, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::loss_, momentum::VertexErrorFunctionT< T, VertexPositionDataT< T >, 3 >::maxThreads_, MT_CHECK_NOTNULL, momentum::SkeletonErrorFunctionT< T >::parameterTransform_, momentum::MeshStateT< T >::posedMesh_, momentum::SkeletonErrorFunctionT< T >::skeleton_, and momentum::SkeletonErrorFunctionT< T >::weight_.
Referenced by getJacobian().