Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
joint_to_joint_distance_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
34
37
39 T weight = T(1);
40
41 template <typename T2>
43 return {
44 this->joint1,
45 this->offset1.template cast<T2>(),
46 this->joint2,
47 this->offset2.template cast<T2>(),
48 static_cast<T2>(this->targetDistance),
49 static_cast<T2>(this->weight)};
50 }
51};
52
66template <typename T>
68 public:
70
72
73 [[nodiscard]] double getError(
74 const ModelParametersT<T>& params,
75 const SkeletonStateT<T>& state,
76 const MeshStateT<T>& meshState) final;
77
79 const ModelParametersT<T>& params,
80 const SkeletonStateT<T>& state,
81 const MeshStateT<T>& meshState,
82 Ref<VectorX<T>> gradient) override;
83
85 const ModelParametersT<T>& params,
86 const SkeletonStateT<T>& state,
87 const MeshStateT<T>& meshState,
88 Ref<MatrixX<T>> jacobian,
89 Ref<VectorX<T>> residual,
90 int& usedRows) override;
91
92 [[nodiscard]] size_t getJacobianSize() const final;
93
96 size_t joint1,
97 const Vector3<T>& offset1,
98 size_t joint2,
99 const Vector3<T>& offset2,
100 T targetDistance,
101 T weight = T(1));
102
105
107 [[nodiscard]] const std::vector<JointToJointDistanceConstraintT<T>>& getConstraints() const {
108 return constraints_;
109 }
110
112 [[nodiscard]] size_t getNumConstraints() const {
113 return constraints_.size();
114 }
115
117 static constexpr T kDistanceWeight = 1e-2;
118
119 private:
120 std::vector<JointToJointDistanceConstraintT<T>> constraints_;
121};
122
123} // namespace momentum
const std::vector< JointToJointDistanceConstraintT< float > > & getConstraints() const
double getError(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
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(size_t joint1, const Vector3< float > &offset1, size_t joint2, const Vector3< float > &offset2, float targetDistance, float weight=float(1))
size_t getNumConstraints() const
Returns the number of constraints.
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< VectorX< T > > gradient) override
JointToJointDistanceErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
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 that enforces a distance relationship between two points attached to different joints.
Vector3< T > offset2
Offset from joint2 in the local coordinate system of joint2.
Vector3< T > offset1
Offset from joint1 in the local coordinate system of joint1.
T targetDistance
Target distance between the two points (in world space).
JointToJointDistanceConstraintT< T2 > cast() const
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.