Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
vertex_projection_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
11
12namespace momentum {
13
17template <typename T>
20 Eigen::Vector2<T> target = Eigen::Vector2<T>::Zero();
21
23 Eigen::Matrix<T, 3, 4> projectionMatrix = Eigen::Matrix<T, 3, 4>::Zero();
24
27 size_t vIndex,
28 const Eigen::Vector2<T>& targetPos,
29 const Eigen::Matrix<T, 3, 4>& proj,
30 float w,
31 const std::string& nm = "")
32 : VertexConstraintData(vIndex, w, nm), target(targetPos), projectionMatrix(proj) {}
33};
34
42template <typename T>
43class VertexProjectionErrorFunctionT : public VertexErrorFunctionT<T, VertexProjectionDataT<T>, 2> {
44 public:
46 using typename Base::DfdvType;
47 using typename Base::FuncType;
48
50 const Character& character,
51 const ParameterTransform& parameterTransform,
52 const T& lossAlpha = GeneralizedLossT<T>::kL2,
53 const T& lossC = T(1));
54
55 ~VertexProjectionErrorFunctionT() override = default;
56
58 size_t constrIndex,
59 const SkeletonStateT<T>& state,
60 const MeshStateT<T>& meshState,
61 std::span<const Eigen::Vector3<T>> worldVecs,
62 FuncType& f,
63 std::span<DfdvType> dfdv) const final;
64};
65
66} // namespace momentum
static constexpr T kL2
Special-case alpha values that are either at a singularity in the general formula or simplify to a cl...
VertexErrorFunctionT(const Character &character, const ParameterTransform &parameterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
Eigen::Matrix< T, FuncDim, 1 > FuncType
Eigen::Matrix< T, FuncDim, 3 > DfdvType
void evalFunction(size_t constrIndex, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, std::span< const Eigen::Vector3< T > > worldVecs, FuncType &f, std::span< DfdvType > dfdv) const final
Computes the residual and derivatives.
VertexProjectionErrorFunctionT(const Character &character, const ParameterTransform &parameterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
~VertexProjectionErrorFunctionT() override=default
VertexErrorFunctionT< float, VertexProjectionDataT< float >, 2 > Base
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
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
Represents the complete state of a skeleton.
Eigen::Vector2< T > target
Target position in 2D screen space.
VertexProjectionDataT(size_t vIndex, const Eigen::Vector2< T > &targetPos, const Eigen::Matrix< T, 3, 4 > &proj, float w, const std::string &nm="")
Eigen::Matrix< T, 3, 4 > projectionMatrix
Camera projection matrix (3x4).