Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
pose_prior_error_function.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
12#include <momentum/math/mppca.h>
13
14#include <span>
15
16namespace momentum {
17
18template <typename T>
20 public:
22 const Skeleton& skel,
23 const ParameterTransform& pt,
24 std::shared_ptr<const MppcaT<T>> pp);
25 PosePriorErrorFunctionT(const Character& character, std::shared_ptr<const MppcaT<T>> pp);
26
27 void setPosePrior(std::shared_ptr<const MppcaT<T>> pp);
28
29 [[nodiscard]] double getError(
30 const ModelParametersT<T>& params,
31 const SkeletonStateT<T>& state,
32 const MeshStateT<T>& meshState) final;
33
35 const ModelParametersT<T>& params,
36 const SkeletonStateT<T>& state,
37 const MeshStateT<T>& meshState,
38 Eigen::Ref<Eigen::VectorX<T>> gradient) final;
39
40 [[nodiscard]] double logProbability(const ModelParametersT<T>& params) const;
41
43 const ModelParametersT<T>& params,
44 const SkeletonStateT<T>& state,
45 const MeshStateT<T>& meshState,
46 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
47 Eigen::Ref<Eigen::VectorX<T>> residual,
48 int& usedRows) final;
49
50 [[nodiscard]] size_t getJacobianSize() const final;
51
52 [[nodiscard]] Eigen::VectorX<T> getMeanShape(const ModelParametersT<T>& params) const;
53
54 protected:
57 const ModelParametersT<T>& params,
58 size_t& bestIdx,
59 Eigen::VectorX<T>& bestDiff,
60 T& bestR,
61 T& minDist) const;
62
63 std::vector<size_t> ppMap_;
64 std::vector<size_t> invMap_;
65
66 // The pose prior: note that once passed in you must not modify it
67 // outside this class. The easiest way to guarantee this is to use
68 // the standard loadMppca() functions which already returns a const-
69 // valued shared_ptr.
70 std::shared_ptr<const MppcaT<T>> posePrior_;
71
72 // weights for the error functions
73 static constexpr T kPosePriorWeight = 1e-3;
74
75 private:
76 // Is used for optimization purpose in getJacobian to allocate memory once
77 Eigen::MatrixX<T> gradientL_;
78};
79
80} // namespace momentum
double getJacobian(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) final
Eigen::VectorX< float > getMeanShape(const ModelParametersT< float > &params) const
PosePriorErrorFunctionT(const Character &character, std::shared_ptr< const MppcaT< T > > pp)
void setPosePrior(std::shared_ptr< const MppcaT< T > > pp)
double logProbability(const ModelParametersT< T > &params) const
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) final
std::shared_ptr< const MppcaT< float > > posePrior_
void getBestFitMode(const ModelParametersT< float > &params, size_t &bestIdx, Eigen::VectorX< float > &bestDiff, float &bestR, float &minDist) const
PosePriorErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt, std::shared_ptr< const MppcaT< T > > pp)
double getError(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
Definition types.h:28
SkeletonT< float > Skeleton
Definition fwd.h:263
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
Eigen::Matrix< T, Dynamic, Dynamic > MatrixX
Dynamic-size, column-major dense matrix.
Definition types.h:80
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
Definition types.h:207
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Represents the complete state of a model's mesh.
Definition mesh_state.h:24
A vector of size numModelParams holding the values of all model parameters for a character.
Definition types.h:99
Mixture of Probabilistic Principal Component Analyzers (MPPCA).
Definition mppca.h:29
Represents the complete state of a skeleton.