Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
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
13namespace momentum {
14
15// The distance constraint is defined as ||(p_joint - origin)^2 - target||^2
16template <typename T>
18 Eigen::Vector3<T> origin = Eigen::Vector3<T>::Zero(); // origin in world space
19 T target{}; // distance target in world space
20 size_t parent{}; // parent joint of the constraint
21 Eigen::Vector3<T> offset; // relative offset to the parent
22 T weight{}; // constraint weight
23 // comment for now
25};
26
27template <typename T>
29 public:
31
32 [[nodiscard]] double getError(
34 const momentum::SkeletonStateT<T>& state,
35 const momentum::MeshStateT<T>& meshState) final;
38 const momentum::SkeletonStateT<T>& state,
39 const momentum::MeshStateT<T>& meshState,
40 Eigen::Ref<Eigen::VectorX<T>> gradient) final;
43 const momentum::SkeletonStateT<T>& state,
44 const momentum::MeshStateT<T>& meshState,
45 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
46 Eigen::Ref<Eigen::VectorX<T>> residual,
47 int& usedRows) final;
48 [[nodiscard]] size_t getJacobianSize() const final;
49
50 void addConstraint(const DistanceConstraintDataT<T>& constr) {
51 constraints_.push_back(constr);
52 }
54 constraints_.clear();
55 }
56 void setConstraints(std::vector<DistanceConstraintDataT<T>> constr) {
57 constraints_ = std::move(constr);
58 }
59 [[nodiscard]] bool empty() const {
60 return constraints_.empty();
61 }
62 [[nodiscard]] size_t getNumConstraints() const {
63 return constraints_.size();
64 }
65
66 [[nodiscard]] const std::vector<DistanceConstraintDataT<T>>& getConstraints() const {
67 return constraints_;
68 }
69
70 protected:
71 // TODO: what should we use here?
72 const T kDistanceWeight = 1.0f;
73
74 std::vector<DistanceConstraintDataT<T>> constraints_;
75};
76
77} // namespace momentum
double getJacobian(const momentum::ModelParametersT< T > &params, const momentum::SkeletonStateT< T > &state, const momentum::MeshStateT< T > &meshState, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) final
double getError(const momentum::ModelParametersT< T > &params, const momentum::SkeletonStateT< T > &state, const momentum::MeshStateT< T > &meshState) final
std::vector< DistanceConstraintDataT< float > > constraints_
void setConstraints(std::vector< DistanceConstraintDataT< T > > constr)
const std::vector< DistanceConstraintDataT< T > > & getConstraints() const
DistanceErrorFunctionT(const momentum::Skeleton &skel, const momentum::ParameterTransform &pt)
double getGradient(const momentum::ModelParametersT< T > &params, const momentum::SkeletonStateT< T > &state, const momentum::MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) final
void addConstraint(const DistanceConstraintDataT< float > &constr)
SkeletonT< float > Skeleton
Definition fwd.h:263
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
static DistanceConstraintDataT< T > createFromLocator(const momentum::Locator &locator)
Represents a point attached to a joint in a skeleton.
Definition locator.h:19
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.