Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
camera_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
18namespace momentum {
19
25template <typename T>
27 size_t parent{};
28 Eigen::Vector3<T> offset = Eigen::Vector3<T>::Zero();
29 T weight = 1;
30 Eigen::Vector2<T> target = Eigen::Vector2<T>::Zero();
31};
32
45template <typename T>
47 public:
49 const Skeleton& skel,
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 Skeleton& skel,
59 const ParameterTransform& pt,
60 const CameraT<T>& camera,
61 size_t cameraParent = kInvalidIndex);
62
63 [[nodiscard]] double getError(
64 const ModelParametersT<T>& params,
65 const SkeletonStateT<T>& state,
66 const MeshStateT<T>& meshState) final;
68 const ModelParametersT<T>& params,
69 const SkeletonStateT<T>& state,
70 const MeshStateT<T>& meshState,
71 Eigen::Ref<Eigen::VectorX<T>> gradient) final;
73 const ModelParametersT<T>& params,
74 const SkeletonStateT<T>& state,
75 const MeshStateT<T>& meshState,
76 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
77 Eigen::Ref<Eigen::VectorX<T>> residual,
78 int& usedRows) final;
79 [[nodiscard]] size_t getJacobianSize() const final;
80
81 void addConstraint(const ProjectionConstraintT<T>& constraint);
82
84 constraints_.clear();
85 }
86
87 void setConstraints(std::vector<ProjectionConstraintT<T>> constraints) {
88 constraints_ = std::move(constraints);
89 }
90
91 [[nodiscard]] const std::vector<ProjectionConstraintT<T>>& getConstraints() const {
92 return constraints_;
93 }
94
95 [[nodiscard]] size_t getNumConstraints() const {
96 return constraints_.size();
97 }
98
99 [[nodiscard]] bool empty() const {
100 return constraints_.empty();
101 }
102
103 protected:
104 std::vector<ProjectionConstraintT<T>> constraints_;
105 std::shared_ptr<const IntrinsicsModelT<T>> intrinsicsModel_;
106 std::optional<CameraIntrinsicsMapping<T>> intrinsicsMapping_;
108 Eigen::Transform<T, 3, Eigen::Affine> cameraOffset_;
110};
111
112} // namespace momentum
std::vector< ProjectionConstraintT< float > > constraints_
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, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) final
void addConstraint(const ProjectionConstraintT< float > &constraint)
const std::vector< ProjectionConstraintT< T > > & getConstraints() const
void setConstraints(std::vector< ProjectionConstraintT< T > > constraints)
CameraProjectionErrorFunctionT(const Skeleton &skel, 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())
std::shared_ptr< const IntrinsicsModelT< float > > intrinsicsModel_
std::optional< CameraIntrinsicsMapping< float > > intrinsicsMapping_
Eigen::Transform< float, 3, Eigen::Affine > cameraOffset_
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) final
CameraProjectionErrorFunctionT(const Skeleton &skel, 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)
SkeletonT< float > Skeleton
Definition fwd.h:263
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Definition types.h:182
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
Per-constraint data for CameraProjectionErrorFunctionT.
Represents the complete state of a skeleton.