Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
collision_error_function_stateless.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
14
15#include <axel/BoundingBox.h>
16
17#include <vector>
18
19namespace momentum {
20
29template <typename T>
31 public:
33 const Skeleton& skel,
34 const ParameterTransform& pt,
35 const CollisionGeometry& cg);
36
37 explicit CollisionErrorFunctionStatelessT(const Character& character);
38
39 [[nodiscard]] double getError(
40 const ModelParametersT<T>& params,
41 const SkeletonStateT<T>& state,
42 const MeshStateT<T>& meshState) final;
43
45 const ModelParametersT<T>& params,
46 const SkeletonStateT<T>& state,
47 const MeshStateT<T>& meshState,
48 Ref<VectorX<T>> gradient) override;
49
51 const ModelParametersT<T>& /*unused*/,
52 const SkeletonStateT<T>& state,
53 const MeshStateT<T>& meshState,
54 Ref<MatrixX<T>> jacobian,
55 Ref<VectorX<T>> residual,
56 int& usedRows) override;
57
58 [[nodiscard]] size_t getJacobianSize() const final;
59
60 [[nodiscard]] std::vector<Vector2i> getCollisionPairs() const;
61
62 protected:
64
66 void computeBroadPhase(const SkeletonStateT<T>& state);
67
70 [[nodiscard]] bool checkCollision(
71 const CollisionGeometryStateT<T>& colState,
72 size_t indexA,
73 size_t indexB,
74 CollisionOverlapResultT<T>& result) const;
75
79 const SkeletonStateT<T>& state,
80 const Vector3<T>& position,
81 const Vector3<T>& direction,
82 T weight,
83 size_t startJoint,
84 size_t stopJoint,
85 Ref<VectorX<T>> gradient,
86 T scaleCorrection = T(0)) const;
87
91 const SkeletonStateT<T>& state,
92 const Vector3<T>& position,
93 const Vector3<T>& direction,
94 T factor,
95 size_t startJoint,
96 size_t stopJoint,
97 Ref<MatrixX<T>> jacobian,
98 int row,
99 T scaleCorrection = T(0)) const;
100
103 size_t indexA;
104 size_t indexB;
106 };
107
109
111 std::vector<CollisionPairInfo> validPairs_;
112
114 std::vector<axel::BoundingBox<T>> aabbs_;
115
117
118 // weights for the error functions
119 static constexpr T kCollisionWeight = 5e-3;
120};
121
122} // namespace momentum
void computeBroadPhase(const SkeletonStateT< float > &state)
std::vector< Vector2i > getCollisionPairs() const
double getGradient(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< VectorX< T > > gradient) override
void accumulateGradientAlongChain(const SkeletonStateT< float > &state, const Vector3< float > &position, const Vector3< float > &direction, float weight, size_t startJoint, size_t stopJoint, Ref< VectorX< float > > gradient, float scaleCorrection=float(0)) const
double getError(const ModelParametersT< T > &params, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) final
double getJacobian(const ModelParametersT< T > &, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Ref< MatrixX< T > > jacobian, Ref< VectorX< T > > residual, int &usedRows) override
void accumulateJacobianAlongChain(const SkeletonStateT< float > &state, const Vector3< float > &position, const Vector3< float > &direction, float factor, size_t startJoint, size_t stopJoint, Ref< MatrixX< float > > jacobian, int row, float scaleCorrection=float(0)) const
bool checkCollision(const CollisionGeometryStateT< float > &colState, size_t indexA, size_t indexB, CollisionOverlapResultT< float > &result) const
CollisionErrorFunctionStatelessT(const Skeleton &skel, const ParameterTransform &pt, const CollisionGeometry &cg)
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
CollisionGeometryT< float > CollisionGeometry
SkeletonT< float > Skeleton
Definition fwd.h:263
Eigen::Ref< T > Ref
Definition types.h:43
Vector2< std::int32_t > Vector2i
Definition types.h:292
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
Vector< T, 3 > Vector3
Definition types.h:236
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Represents collision geometry states using a Structure of Arrays (SoA) format.
Narrow-phase collision information for a pair of primitives.
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.