Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
joint_to_joint_orientation_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/types.h>
13
14#include <Eigen/Core>
15#include <Eigen/Geometry>
16
17namespace momentum {
18
24template <typename T>
28
31
33 Eigen::Quaternion<T> target = Eigen::Quaternion<T>::Identity();
34
36 T weight = T(1);
37
39 std::string name = {};
40
41 template <typename T2>
43 return {
44 this->sourceJoint,
45 this->referenceJoint,
46 this->target.template cast<T2>(),
47 static_cast<T2>(this->weight),
48 this->name};
49 }
50};
51
65template <typename T>
67 public:
69 const Skeleton& skel,
70 const ParameterTransform& pt);
71
73
74 [[nodiscard]] double getError(
75 const ModelParametersT<T>& params,
76 const SkeletonStateT<T>& state,
77 const MeshStateT<T>& meshState) final;
78
80 const ModelParametersT<T>& params,
81 const SkeletonStateT<T>& state,
82 const MeshStateT<T>& meshState,
83 Ref<VectorX<T>> gradient) override;
84
86 const ModelParametersT<T>& params,
87 const SkeletonStateT<T>& state,
88 const MeshStateT<T>& meshState,
89 Ref<MatrixX<T>> jacobian,
90 Ref<VectorX<T>> residual,
91 int& usedRows) override;
92
93 [[nodiscard]] size_t getJacobianSize() const final;
94
103 size_t sourceJoint,
104 size_t referenceJoint,
105 const Eigen::Quaternion<T>& target,
106 T weight = T(1),
107 const std::string& name = {});
108
111
114
116 [[nodiscard]] const std::vector<JointToJointOrientationDataT<T>>& getConstraints() const {
117 return constraints_;
118 }
119
121 [[nodiscard]] size_t numConstraints() const {
122 return constraints_.size();
123 }
124
125 private:
126 std::vector<JointToJointOrientationDataT<T>> constraints_;
127};
128
129} // namespace momentum
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< VectorX< T > > gradient) override
double getJacobian(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< MatrixX< T > > jacobian, Ref< VectorX< T > > residual, int &usedRows) override
void addConstraint(const JointToJointOrientationDataT< T > &constraint)
Add a constraint using the JointToJointOrientationDataT struct.
const std::vector< JointToJointOrientationDataT< T > > & getConstraints() const
Get all constraints.
void addConstraint(size_t sourceJoint, size_t referenceJoint, const Eigen::Quaternion< float > &target, float weight=float(1), const std::string &name={})
JointToJointOrientationErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
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
Eigen::Ref< T > Ref
Definition types.h:43
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
Eigen::Quaternion< T > Quaternion
Unit quaternion representing a 3D rotation.
Definition types.h:385
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
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Definition types.h:182
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Constraint data for joint-to-joint orientation error between two joints.
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
Represents the complete state of a skeleton.