|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Error function for vertex Normal and SymmetricNormal constraints. More...
#include <vertex_normal_error_function.h>
Public Types | |
| using | Base = VertexErrorFunctionT<T, VertexNormalDataT<T>, 1> |
| Public Types inherited from momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 > | |
| using | FuncType |
| using | DfdvType |
Public Member Functions | |
| VertexNormalErrorFunctionT (const Character &character, const ParameterTransform ¶meterTransform, T sourceNormalWeight=T(1), T targetNormalWeight=T(0), const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1), bool computeAccurateNormalDerivatives=false) | |
| Constructor. | |
| ~VertexNormalErrorFunctionT () 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 |
| Override to handle normal rotation correction terms via SkeletonDerivativeT. | |
| 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 |
| Override to handle normal rotation correction terms via SkeletonDerivativeT. | |
| void | setComputeAccurateNormalDerivatives (bool enable) |
| Enable or disable the expensive d(normal)/d(blendShapeWeight) computation. | |
| bool | computeAccurateNormalDerivatives () const |
| Returns whether accurate normal blend shape derivatives are enabled. | |
| Public Member Functions inherited from momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 > | |
| 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 VertexNormalDataT< T > &constraint) |
| Adds a constraint. | |
| void | addConstraints (std::span< const VertexNormalDataT< T > > constraints) |
| Appends a list of constraints. | |
| void | setConstraints (std::span< const VertexNormalDataT< T > > constraints) |
| Sets all constraints, replacing existing ones. | |
| void | clearConstraints () |
| Clears all constraints. | |
| const std::vector< VertexNormalDataT< 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, VertexNormalDataT< 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, VertexNormalDataT< T >, 1 > | |
| const Character & | character_ |
| std::vector< VertexNormalDataT< 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 for vertex Normal and SymmetricNormal constraints.
Computes point-to-plane distance using a mix of source (mesh) and target normals: f = (sW * sourceNormal + tW * targetNormal) ยท (vertexPos - targetPosition)
The sourceNormalWeight and targetNormalWeight control the mix:
The source normal rotates with the mesh, which requires special derivative handling. This is handled automatically by the normal correction methods in SkeletonDerivativeT.
| T | Scalar type (float or double) |
Definition at line 50 of file vertex_normal_error_function.h.
| using momentum::VertexNormalErrorFunctionT< T >::Base = VertexErrorFunctionT<T, VertexNormalDataT<T>, 1> |
Definition at line 52 of file vertex_normal_error_function.h.
|
explicit |
Constructor.
| character | The character (needed for mesh access) |
| parameterTransform | Maps joint parameters to model parameters |
| sourceNormalWeight | Weight for source (mesh) normal (1.0 for Normal, 0.5 for SymmetricNormal) |
| targetNormalWeight | Weight for target normal (0.0 for Normal, 0.5 for SymmetricNormal) |
| lossAlpha | Alpha parameter for the generalized loss function (default: L2) |
| lossC | C parameter for the generalized loss function (default: 1) |
| computeAccurateNormalDerivatives | If true, compute expensive d(normal)/d(blendShapeWeight) terms in the gradient and Jacobian. Default false for better performance. |
Definition at line 23 of file vertex_normal_error_function.cpp.
References computeAccurateNormalDerivatives(), momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::kLegacyWeight, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::legacyWeight_, and momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::VertexErrorFunctionT().
|
overridedefault |
|
inlinenodiscard |
Returns whether accurate normal blend shape derivatives are enabled.
Definition at line 109 of file vertex_normal_error_function.h.
Referenced by VertexNormalErrorFunctionT().
|
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, VertexNormalDataT< T >, 1 >.
Definition at line 43 of file vertex_normal_error_function.cpp.
References momentum::cast(), momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::constraints_, MT_CHECK, MT_CHECK_NOTNULL, momentum::normal(), and momentum::MeshStateT< T >::posedMesh_.
|
overridevirtual |
Override to handle normal rotation correction terms via SkeletonDerivativeT.
Reimplemented from momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >.
Definition at line 107 of file vertex_normal_error_function.cpp.
References momentum::SkeletonDerivativeT< T >::accumulateVertexGradientWithNormalCorrectionDirect(), momentum::SkeletonDerivativeT< T >::accumulateVertexNormalBlendShapeGradient(), momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::cast(), momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::character_, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::constraints_, momentum::SkeletonErrorFunctionT< T >::enabledParameters_, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::legacyWeight_, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::loss_, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::maxThreads_, MT_CHECK_NOTNULL, momentum::normal(), momentum::SkeletonErrorFunctionT< T >::parameterTransform_, momentum::MeshStateT< T >::posedMesh_, momentum::SkeletonErrorFunctionT< T >::skeleton_, and momentum::SkeletonErrorFunctionT< T >::weight_.
|
overridevirtual |
Override to handle normal rotation correction terms via SkeletonDerivativeT.
Reimplemented from momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >.
Definition at line 251 of file vertex_normal_error_function.cpp.
References momentum::SkeletonDerivativeT< T >::accumulateVertexJacobianWithNormalCorrectionDirect(), momentum::SkeletonDerivativeT< T >::accumulateVertexNormalBlendShapeJacobian(), momentum::SkeletonErrorFunctionT< T >::activeJointParams_, momentum::cast(), momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::character_, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::constraints_, momentum::SkeletonErrorFunctionT< T >::enabledParameters_, getJacobian(), momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::legacyWeight_, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::loss_, momentum::VertexErrorFunctionT< T, VertexNormalDataT< T >, 1 >::maxThreads_, MT_CHECK_NOTNULL, momentum::normal(), momentum::SkeletonErrorFunctionT< T >::parameterTransform_, momentum::MeshStateT< T >::posedMesh_, momentum::SkeletonErrorFunctionT< T >::skeleton_, and momentum::SkeletonErrorFunctionT< T >::weight_.
Referenced by getJacobian().
|
inline |
Enable or disable the expensive d(normal)/d(blendShapeWeight) computation.
Definition at line 104 of file vertex_normal_error_function.h.