Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
blend_shape.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
11
12namespace momentum {
13
19struct BlendShape : public BlendShapeBase {
20 public:
21 BlendShape() : factorizationValid_(false) {}
22
29 size_t numShapes,
30 momentum::span<const std::string> shapeNames = {});
31
33 baseShape_.assign(baseShape.begin(), baseShape.end());
34 }
35
36 [[nodiscard]] const std::vector<Vector3f>& getBaseShape() const {
37 return baseShape_;
38 }
39
41 [[nodiscard]] bool getFactorizationValid() const {
42 return factorizationValid_;
43 }
44
52 template <typename T>
53 [[nodiscard]] std::vector<Eigen::Vector3<T>> computeShape(
54 const BlendWeightsT<T>& coefficients) const;
55
62 template <typename T>
63 void computeShape(const BlendWeightsT<T>& coefficients, std::vector<Eigen::Vector3<T>>& output)
64 const;
65
81 [[nodiscard]] VectorXf estimateCoefficients(
83 float regularization = 1.0f,
84 const VectorXf& weights = VectorXf()) const;
85
93 void setShapeVector(
94 size_t index,
96 std::string_view name = "");
97
101 [[nodiscard]] bool isApprox(const BlendShape& blendShape) const;
102
103 private:
104 std::vector<Vector3f> baseShape_;
105 mutable Eigen::JacobiSVD<MatrixXf> factorization_;
106 mutable bool factorizationValid_;
107};
108
109} // namespace momentum
gsl::span< T > span
Span type alias using gsl::span (C++17 fallback).
Definition span_compat.h:54
VectorX< float > VectorXf
Definition types.h:209
Skinning class that combines blend shape vectors with a base shape.
Definition blend_shape.h:19
std::vector< Eigen::Vector3< T > > computeShape(const BlendWeightsT< T > &coefficients) const
Applies blend weights to create a deformed shape.
void setBaseShape(momentum::span< const Vector3f > baseShape)
Definition blend_shape.h:32
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.
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.
bool isApprox(const BlendShape &blendShape) const
Compares all components of two blend shapes.
bool getFactorizationValid() const
Whether SVD factorization is up-to-date.
Definition blend_shape.h:41
const std::vector< Vector3f > & getBaseShape() const
Definition blend_shape.h:36