Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
camera_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
10#include <momentum/camera/camera.h>
14
15#include <memory>
16#include <optional>
17#include <vector>
18
19namespace momentum {
20
26template <typename T>
29 Eigen::Vector2<T> target = Eigen::Vector2<T>::Zero();
30 T weight = T(1);
31};
32
45template <typename T>
47 public:
49 const Character& character,
50 const ParameterTransform& pt,
51 std::shared_ptr<const IntrinsicsModelT<T>> intrinsicsModel,
52 size_t cameraParent,
53 const Eigen::Transform<T, 3, Eigen::Affine>& cameraOffset =
54 Eigen::Transform<T, 3, Eigen::Affine>::Identity());
55
58 const Character& character,
59 const ParameterTransform& pt,
60 const CameraT<T>& camera,
61 size_t cameraParent = kInvalidIndex);
62
63 [[nodiscard]] const Character* getCharacter() const final;
64 [[nodiscard]] bool needsMesh() const final;
65
66 [[nodiscard]] double getError(
67 const ModelParametersT<T>& params,
68 const SkeletonStateT<T>& state,
69 const MeshStateT<T>& meshState) final;
71 const ModelParametersT<T>& params,
72 const SkeletonStateT<T>& state,
73 const MeshStateT<T>& meshState,
74 Eigen::Ref<Eigen::VectorX<T>> gradient) final;
76 const ModelParametersT<T>& params,
77 const SkeletonStateT<T>& state,
78 const MeshStateT<T>& meshState,
79 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
80 Eigen::Ref<Eigen::VectorX<T>> residual,
81 int& usedRows) final;
82 [[nodiscard]] size_t getJacobianSize() const final;
83
84 void addConstraint(const CameraVertexProjectionDataT<T>& constraint);
85
87 constraints_.clear();
88 }
89
90 void setConstraints(std::vector<CameraVertexProjectionDataT<T>> constraints) {
91 constraints_ = std::move(constraints);
92 }
93
94 [[nodiscard]] const std::vector<CameraVertexProjectionDataT<T>>& getConstraints() const {
95 return constraints_;
96 }
97
98 [[nodiscard]] size_t getNumConstraints() const {
99 return constraints_.size();
100 }
101
102 [[nodiscard]] bool empty() const {
103 return constraints_.empty();
104 }
105
106 void setMaxThreads(size_t maxThreads) {
107 maxThreads_ = maxThreads;
108 }
109
110 protected:
112 std::vector<CameraVertexProjectionDataT<T>> constraints_;
113 std::shared_ptr<const IntrinsicsModelT<T>> intrinsicsModel_;
114 std::optional<CameraIntrinsicsMapping<T>> intrinsicsMapping_;
116 Eigen::Transform<T, 3, Eigen::Affine> cameraOffset_;
118 size_t maxThreads_ = 0;
119};
120
121} // namespace momentum
double getGradient(const ModelParametersT< float > &params, const SkeletonStateT< float > &state, const MeshStateT< float > &meshState, Eigen::Ref< Eigen::VectorX< float > > gradient) final
double getError(const ModelParametersT< float > &params, const SkeletonStateT< float > &state, const MeshStateT< float > &meshState) final
double getJacobian(const ModelParametersT< float > &params, const SkeletonStateT< float > &state, const MeshStateT< float > &meshState, Eigen::Ref< Eigen::MatrixX< float > > jacobian, Eigen::Ref< Eigen::VectorX< float > > residual, int &usedRows) final
CameraVertexProjectionErrorFunctionT(const Character &character, const ParameterTransform &pt, std::shared_ptr< const IntrinsicsModelT< T > > intrinsicsModel, size_t cameraParent, const Eigen::Transform< T, 3, Eigen::Affine > &cameraOffset=Eigen::Transform< T, 3, Eigen::Affine >::Identity())
const Character * getCharacter() const final
For mesh-based error functions, get access to the underlying character.
const std::vector< CameraVertexProjectionDataT< T > > & getConstraints() const
void setConstraints(std::vector< CameraVertexProjectionDataT< T > > constraints)
void addConstraint(const CameraVertexProjectionDataT< float > &constraint)
CameraVertexProjectionErrorFunctionT(const Character &character, const ParameterTransform &pt, const CameraT< T > &camera, size_t cameraParent=kInvalidIndex)
Convenience constructor that extracts intrinsics and extrinsics from a Camera.
Shared utility for derivative computation in error functions.
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
Definition types.h:28
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
Per-constraint data for CameraVertexProjectionErrorFunctionT.
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.