Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
vertex_vertex_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/fwd.h>
13
14#include <Eigen/Dense>
15#include <memory>
16#include <vector>
17
18namespace momentum {
19
21template <typename T>
23 int vertexIndex1 = -1;
24 int vertexIndex2 = -1;
25 T weight = 1;
27
28 template <typename T2>
30 return {
31 this->vertexIndex1,
32 this->vertexIndex2,
33 static_cast<T2>(this->weight),
34 static_cast<T2>(this->targetDistance)};
35 }
36};
37
39template <typename T>
41 public:
44
48 delete;
50 delete;
51
52 [[nodiscard]] double getError(
53 const ModelParametersT<T>& modelParameters,
54 const SkeletonStateT<T>& state,
55 const MeshStateT<T>& meshState) final;
56
58 const ModelParametersT<T>& modelParameters,
59 const SkeletonStateT<T>& state,
60 const MeshStateT<T>& meshState,
61 Eigen::Ref<Eigen::VectorX<T>> gradient) final;
62
64 const ModelParametersT<T>& modelParameters,
65 const SkeletonStateT<T>& state,
66 const MeshStateT<T>& meshState,
67 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
68 Eigen::Ref<Eigen::VectorX<T>> residual,
69 int& usedRows) final;
70
71 [[nodiscard]] size_t getJacobianSize() const final;
72
74 void addConstraint(int vertexIndex1, int vertexIndex2, T weight, T targetDistance);
75
78
80 [[nodiscard]] const std::vector<VertexVertexDistanceConstraintT<T>>& getConstraints() const {
81 return constraints_;
82 }
83
85 [[nodiscard]] size_t getNumConstraints() const {
86 return constraints_.size();
87 }
88
90 [[nodiscard]] const Character* getCharacter() const override {
91 return &character_;
92 }
93
95 [[nodiscard]] bool needsMesh() const override {
96 return true;
97 }
98
99 private:
101 double calculateJacobian(
102 const ModelParametersT<T>& modelParameters,
103 const SkeletonStateT<T>& state,
104 const MeshStateT<T>& meshState,
105 const VertexVertexDistanceConstraintT<T>& constraint,
106 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
107 T& residual) const;
108
110 double calculateGradient(
111 const ModelParametersT<T>& modelParameters,
112 const SkeletonStateT<T>& state,
113 const MeshStateT<T>& meshState,
114 const VertexVertexDistanceConstraintT<T>& constraint,
115 Eigen::Ref<Eigen::VectorX<T>> gradient) const;
116
117 const Character& character_;
118
119 std::vector<VertexVertexDistanceConstraintT<T>> constraints_;
120};
121
122} // namespace momentum
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
double getJacobian(const ModelParametersT< T > &modelParameters, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) final
const std::vector< VertexVertexDistanceConstraintT< float > > & getConstraints() const
VertexVertexDistanceErrorFunctionT(const VertexVertexDistanceErrorFunctionT &other)=delete
void addConstraint(int vertexIndex1, int vertexIndex2, float weight, float targetDistance)
VertexVertexDistanceErrorFunctionT(VertexVertexDistanceErrorFunctionT &&other) noexcept=delete
bool needsMesh() const override
Override to indicate this function requires mesh state.
double getError(const ModelParametersT< T > &modelParameters, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
VertexVertexDistanceErrorFunctionT & operator=(VertexVertexDistanceErrorFunctionT &&other)=delete
const Character * getCharacter() const override
Get the character.
size_t getNumConstraints() const
Get the number of constraints.
VertexVertexDistanceErrorFunctionT & operator=(const VertexVertexDistanceErrorFunctionT &other)=delete
double getGradient(const ModelParametersT< T > &modelParameters, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) final
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
Represents the complete state of a skeleton.
Constraint for vertex-to-vertex distance errors.
VertexVertexDistanceConstraintT< T2 > cast() const
T targetDistance
Desired distance between the two vertices.