Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
joint_to_joint_position_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
14namespace momentum {
15
21template <typename T>
25
28
31
35
38
40 T weight = T(1);
41
43 std::string name = {};
44
45 template <typename T2>
47 return {
48 this->sourceJoint,
49 this->sourceOffset.template cast<T2>(),
50 this->referenceJoint,
51 this->referenceOffset.template cast<T2>(),
52 this->target.template cast<T2>(),
53 static_cast<T2>(this->weight),
54 this->name};
55 }
56};
57
73template <typename T>
75 public:
77
79
80 [[nodiscard]] double getError(
81 const ModelParametersT<T>& params,
82 const SkeletonStateT<T>& state,
83 const MeshStateT<T>& meshState) final;
84
86 const ModelParametersT<T>& params,
87 const SkeletonStateT<T>& state,
88 const MeshStateT<T>& meshState,
89 Ref<VectorX<T>> gradient) override;
90
92 const ModelParametersT<T>& params,
93 const SkeletonStateT<T>& state,
94 const MeshStateT<T>& meshState,
95 Ref<MatrixX<T>> jacobian,
96 Ref<VectorX<T>> residual,
97 int& usedRows) override;
98
99 [[nodiscard]] size_t getJacobianSize() const final;
100
111 size_t sourceJoint,
112 const Vector3<T>& sourceOffset,
113 size_t referenceJoint,
114 const Vector3<T>& referenceOffset,
115 const Vector3<T>& target,
116 T weight = T(1),
117 const std::string& name = {});
118
121
124
126 [[nodiscard]] const std::vector<JointToJointPositionDataT<T>>& getConstraints() const {
127 return constraints_;
128 }
129
131 [[nodiscard]] size_t getNumConstraints() const {
132 return constraints_.size();
133 }
134
135 private:
136 std::vector<JointToJointPositionDataT<T>> constraints_;
137};
138
139} // namespace momentum
JointToJointPositionErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
void addConstraint(const JointToJointPositionDataT< T > &constraint)
Add a constraint using the JointToJointPositionDataT struct.
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< VectorX< T > > gradient) override
void addConstraint(size_t sourceJoint, const Vector3< float > &sourceOffset, size_t referenceJoint, const Vector3< float > &referenceOffset, const Vector3< float > &target, float weight=float(1), const std::string &name={})
double getError(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
const std::vector< JointToJointPositionDataT< T > > & getConstraints() const
Get all constraints.
size_t getNumConstraints() const
Returns the number of constraints.
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
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
SkeletonT< float > Skeleton
Definition fwd.h:263
Eigen::Ref< T > Ref
Definition types.h:43
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
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Definition types.h:182
Vector< T, 3 > Vector3
Definition types.h:236
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Constraint data for joint-to-joint position error between two joints.
size_t referenceJoint
Index of the reference joint (the joint whose coordinate frame we use).
Vector3< T > referenceOffset
Offset from referenceJoint in the local coordinate system of referenceJoint.
size_t sourceJoint
Index of the source joint (the joint whose position we want to constrain).
std::string name
Name of the constraint (for debugging).
Vector3< T > target
Target position in the reference joint's coordinate frame.
Vector3< T > sourceOffset
Offset from sourceJoint in the local coordinate system of sourceJoint.
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.