Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::BlendShape Struct Reference

Skinning class that combines blend shape vectors with a base shape. More...

#include <blend_shape.h>

Inheritance diagram for momentum::BlendShape:

Public Member Functions

 BlendShape ()
 BlendShape (momentum::span< const Vector3f > baseShape, size_t numShapes, momentum::span< const std::string > shapeNames={})
void setBaseShape (momentum::span< const Vector3f > baseShape)
const std::vector< Vector3f > & getBaseShape () const
bool getFactorizationValid () const
 Whether SVD factorization is up-to-date.
template<typename T>
std::vector< Eigen::Vector3< T > > computeShape (const BlendWeightsT< T > &coefficients) const
 Applies blend weights to create a deformed shape.
template<typename T>
void computeShape (const BlendWeightsT< T > &coefficients, std::vector< Eigen::Vector3< T > > &output) const
 Output parameter version of computeShape, for callers that want to reuse a preallocated buffer.
VectorXf estimateCoefficients (momentum::span< const Vector3f > vertices, float regularization=1.0f, const VectorXf &weights=VectorXf()) const
 Solves for blend weights that best approximate a target shape.
void setShapeVector (size_t index, momentum::span< const Vector3f > shapeVector, std::string_view name="")
 Overrides base method to also invalidate the cached SVD factorization used by estimateCoefficients.
bool isApprox (const BlendShape &blendShape) const
 Compares all components of two blend shapes.
Public Member Functions inherited from momentum::BlendShapeBase
 BlendShapeBase ()=default
 BlendShapeBase (const BlendShapeBase &)=default
BlendShapeBase & operator= (const BlendShapeBase &)=default
 BlendShapeBase (BlendShapeBase &&)=default
BlendShapeBase & operator= (BlendShapeBase &&)=default
 BlendShapeBase (size_t modelSize, size_t numShapes, momentum::span< const std::string > shapeNames={})
virtual ~BlendShapeBase ()=default
void setShapeVectors (const MatrixXf &shapeVectors, momentum::span< const std::string > shapeNames={})
const MatrixXf & getShapeVectors () const
template<typename T>
VectorX< T > computeDeltas (const BlendWeightsT< T > &blendWeights) const
 Calculates weighted combination of shape vectors.
template<typename T>
void applyDeltas (const BlendWeightsT< T > &blendWeights, std::vector< Eigen::Vector3< T > > &result) const
 Adds weighted shape vectors to existing vertices.
void setShapeVector (size_t index, momentum::span< const Vector3f > shapeVector, std::string_view name="")
Eigen::Index shapeSize () const
size_t modelSize () const
const std::vector< std::string > & getShapeNames () const
std::string_view getShapeName (size_t index) const
void setShapeName (size_t index, std::string_view name)

Additional Inherited Members

Protected Attributes inherited from momentum::BlendShapeBase
MatrixXf shapeVectors_
std::vector< std::string > shapeNames_

Detailed Description

Skinning class that combines blend shape vectors with a base shape.

Extends BlendShapeBase by adding a base shape (e.g., PCA mean) and functionality for computing deformed shapes and estimating blend coefficients. Primarily used to model identity-dependent shape deformations.

Definition at line 19 of file blend_shape.h.

Constructor & Destructor Documentation

◆ BlendShape() [1/2]

momentum::BlendShape::BlendShape ( )
inline

Definition at line 21 of file blend_shape.h.

Referenced by isApprox().

◆ BlendShape() [2/2]

momentum::BlendShape::BlendShape ( momentum::span< const Vector3f > baseShape,
size_t numShapes,
momentum::span< const std::string > shapeNames = {} )
Parameters
baseShapeBase shape vertices
numShapesNumber of blend shapes
shapeNamesNames of the blend shapes (will be automatically generated if empty or not the right size)

Definition at line 96 of file blend_shape.cpp.

References momentum::BlendShapeBase::BlendShapeBase().

Member Function Documentation

◆ computeShape() [1/2]

template<typename T>
std::vector< Eigen::Vector3< T > > momentum::BlendShape::computeShape ( const BlendWeightsT< T > & coefficients) const
nodiscard

Applies blend weights to create a deformed shape.

Adds weighted shape vectors to the base shape

Template Parameters
TScalar type (float or double)
Parameters
coefficientsWeights for each shape vector
Returns
Resulting deformed shape

Definition at line 17 of file blend_shape.cpp.

References computeShape().

Referenced by computeShape().

◆ computeShape() [2/2]

template<typename T>
void momentum::BlendShape::computeShape ( const BlendWeightsT< T > & coefficients,
std::vector< Eigen::Vector3< T > > & output ) const

Output parameter version of computeShape, for callers that want to reuse a preallocated buffer.

Template Parameters
TScalar type (float or double)
Parameters
coefficientsWeights for each shape vector
output[out] Resulting deformed shape; resized to the base shape's vertex count.

Definition at line 25 of file blend_shape.cpp.

References momentum::cast(), momentum::BlendShapeBase::computeDeltas(), MT_CHECK, and momentum::BlendShapeBase::shapeVectors_.

◆ estimateCoefficients()

VectorXf momentum::BlendShape::estimateCoefficients ( momentum::span< const Vector3f > vertices,
float regularization = 1.0f,
const VectorXf & weights = VectorXf() ) const
nodiscard

Solves for blend weights that best approximate a target shape.

Uses a thin SVD of the shape vectors when no per-vertex weights are supplied (the factorization is cached and reused across calls). When weights are supplied, builds a weighted normal-equation system with Tikhonov regularization on each call.

Precondition
vertices.size() == getBaseShape().size().
Parameters
verticesTarget shape to approximate, in the same vertex order as the base shape.
regularizationTikhonov regularization weight; higher values bias coefficients toward zero. Only used when per-vertex weights are supplied.
weightsOptional per-vertex importance weights. Ignored unless its size equals vertices.size(); when ignored, the cached unweighted SVD path is used.
Returns
Estimated blend shape coefficients (length = number of shape vectors).

Definition at line 41 of file blend_shape.cpp.

References MT_CHECK, and momentum::BlendShapeBase::shapeVectors_.

◆ getBaseShape()

const std::vector< Vector3f > & momentum::BlendShape::getBaseShape ( ) const
inlinenodiscard

Definition at line 36 of file blend_shape.h.

Referenced by isApprox(), and momentum::saveBlendShape().

◆ getFactorizationValid()

bool momentum::BlendShape::getFactorizationValid ( ) const
inlinenodiscard

Whether SVD factorization is up-to-date.

Definition at line 41 of file blend_shape.h.

Referenced by isApprox().

◆ isApprox()

bool momentum::BlendShape::isApprox ( const BlendShape & blendShape) const
nodiscard

Compares all components of two blend shapes.

Parameters
blendShapeOther blend shape to compare with

Definition at line 115 of file blend_shape.cpp.

References BlendShape(), getBaseShape(), getFactorizationValid(), momentum::BlendShapeBase::getShapeVectors(), isApprox(), and momentum::BlendShapeBase::shapeVectors_.

Referenced by isApprox().

◆ setBaseShape()

void momentum::BlendShape::setBaseShape ( momentum::span< const Vector3f > baseShape)
inline

Definition at line 32 of file blend_shape.h.

◆ setShapeVector()

void momentum::BlendShape::setShapeVector ( size_t index,
momentum::span< const Vector3f > shapeVector,
std::string_view name = "" )

Overrides base method to also invalidate the cached SVD factorization used by estimateCoefficients.

Parameters
indexIndex of the shape vector to set
shapeVectorVector of vertex offsets
nameOptional name for the shape vector; if empty, the name is auto-generated as "shape_<index>".

Definition at line 104 of file blend_shape.cpp.

References momentum::BlendShapeBase::setShapeVector().


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