Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
joint.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/types.h>
13
14namespace momentum {
15
17template <typename T>
18struct JointT {
19 using Scalar = T;
20
21 std::string name{"uninitialized"};
22
25
26 // TODO: does it make sense to save its own index too?
27
33
37
39 [[nodiscard]] bool isApprox(
40 const JointT<T>& joint,
41 const T& rotTol = Eps<T>(1e-4, 1e-10),
42 const T& tranTol = Eigen::NumTraits<Scalar>::dummy_precision()) const {
43 if (name != joint.name) {
44 return false;
45 }
46
47 if (parent != joint.parent) {
48 return false;
49 }
50
51 if (!preRotation.toRotationMatrix().isApprox(joint.preRotation.toRotationMatrix(), rotTol)) {
52 return false;
53 }
54
55 if (!translationOffset.isApprox(joint.translationOffset, tranTol)) {
56 return false;
57 }
58
59 return true;
60 }
61
63 template <typename U>
64 [[nodiscard]] auto cast() const {
65 if constexpr (std::is_same_v<T, U>) {
66 return *this;
67 } else {
68 JointT<U> newJoint;
69 newJoint.name = name;
70 newJoint.parent = parent;
71 newJoint.preRotation = preRotation.template cast<U>();
72 newJoint.translationOffset = translationOffset.template cast<U>();
73 return newJoint;
74 }
75 }
76};
77
79template <typename T>
80using JointListT = std::vector<JointT<T>>;
83
93 std::string jointName;
94
98
100 float mass = 0.0f;
101
103 Vector3f centerOfMassOffset = Vector3f::Zero();
104
107 Matrix3f inertia = Matrix3f::Zero();
108
110 Quaternionf inertiaRotation = Quaternionf::Identity();
111};
112
114using PhysicalProperties = std::vector<JointPhysicalProperties>;
115
116} // namespace momentum
constexpr T Eps(T FloatEps=T(1e-7), T DoubleEps=T(1e-16))
Returns a type-appropriate tolerance/epsilon value.
Definition constants.h:30
Matrix3< float > Matrix3f
Definition types.h:107
Quaternion< float > Quaternionf
Definition types.h:386
JointListT< float > JointList
Definition joint.h:81
JointListT< double > JointListd
Definition joint.h:82
Eigen::Quaternion< T > Quaternion
Unit quaternion representing a 3D rotation.
Definition types.h:385
std::vector< JointPhysicalProperties > PhysicalProperties
Optional physical mass properties for a character.
Definition joint.h:114
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Definition types.h:182
Vector< T, 3 > Vector3
Definition types.h:236
Vector3< float > Vector3f
Definition types.h:251
std::vector< JointT< T > > JointListT
A list of joints (e.g., of a skeleton).
Definition joint.h:80
Physical mass properties attached to one skeleton joint.
Definition joint.h:88
Vector3f centerOfMassOffset
Local center-of-mass offset from the joint frame, in centimeters.
Definition joint.h:103
size_t jointIndex
Cached joint index.
Definition joint.h:97
Matrix3f inertia
Inertia tensor about the body's center of mass, expressed in the local inertia frame,...
Definition joint.h:107
Quaternionf inertiaRotation
Rotation from the inertia frame to the joint frame.
Definition joint.h:110
std::string jointName
Skeleton joint that owns this physical body.
Definition joint.h:93
float mass
Body mass in kilograms.
Definition joint.h:100
A simplified version of a Maya joint with pre-rotation only (no post-rotation).
Definition joint.h:18
bool isApprox(const JointT< T > &joint, const T &rotTol=Eps< T >(1e-4, 1e-10), const T &tranTol=Eigen::NumTraits< Scalar >::dummy_precision()) const
Checks if the current joint is approximately equal to the provided joint.
Definition joint.h:39
auto cast() const
Casts the current joint to another scalar type.
Definition joint.h:64
Quaternion< float > preRotation
Definition joint.h:32
Vector3< float > translationOffset
Definition joint.h:36