Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
joint_state.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
13#include <momentum/math/types.h>
14
15namespace momentum {
16
49template <typename T>
55
60
65
70
74 bool derivDirty = true;
75
92 void set(
93 const JointT<T>& joint,
94 const JointVectorT<T>& parameters,
95 const JointStateT<T>* parentState = nullptr,
96 bool computeDeriv = true) noexcept;
97
103 [[nodiscard]] Vector3<T> getRotationDerivative(size_t index, const Vector3<T>& ref) const;
104
109 [[nodiscard]] Vector3<T> getTranslationDerivative(size_t index) const;
110
115 [[nodiscard]] Vector3<T> getScaleDerivative(const Vector3<T>& ref) const noexcept;
116
121 template <typename T2>
122 void set(const JointStateT<T2>& rhs);
123
125 [[nodiscard]] const Quaternion<T>& localRotation() const {
126 return localTransform.rotation;
127 }
128
131 return localTransform.rotation;
132 }
133
135 [[nodiscard]] const Vector3<T>& localTranslation() const {
136 return localTransform.translation;
137 }
138
141 return localTransform.translation;
142 }
143
157 [[nodiscard]] const T& localScale() const {
158 return localTransform.scale;
159 }
160
163 return localTransform.scale;
164 }
165
167 [[nodiscard]] const Quaternion<T>& rotation() const {
168 return transform.rotation;
169 }
170
173 return transform.rotation;
174 }
175
177 [[nodiscard]] const Vector3<T>& translation() const {
178 return transform.translation;
179 }
180
183 return transform.translation;
184 }
185
187 [[nodiscard]] const T& x() const {
188 return transform.translation.x();
189 }
190
192 T& x() {
193 return transform.translation.x();
194 }
195
197 [[nodiscard]] const T& y() const {
198 return transform.translation.y();
199 }
200
202 T& y() {
203 return transform.translation.y();
204 }
205
207 [[nodiscard]] const T& z() const {
208 return transform.translation.z();
209 }
210
212 T& z() {
213 return transform.translation.z();
214 }
215
217 [[nodiscard]] const T& quatW() const {
218 return transform.rotation.w();
219 }
220
222 T& quatW() {
223 return transform.rotation.w();
224 }
225
227 [[nodiscard]] const T& quatX() const {
228 return transform.rotation.x();
229 }
230
232 T& quatX() {
233 return transform.rotation.x();
234 }
235
237 [[nodiscard]] const T& quatY() const {
238 return transform.rotation.y();
239 }
240
242 T& quatY() {
243 return transform.rotation.y();
244 }
245
247 [[nodiscard]] const T& quatZ() const {
248 return transform.rotation.z();
249 }
250
252 T& quatZ() {
253 return transform.rotation.z();
254 }
255
259 [[nodiscard]] const T& scale() const {
260 return transform.scale;
261 }
262
264 T& scale() {
265 return transform.scale;
266 }
267
268 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
269};
270
272template <typename T>
273using JointStateListT = std::vector<JointStateT<T>>;
274
277
278} // namespace momentum
JointStateListT< float > JointStateList
JointStateT< float > JointState
Definition fwd.h:225
Eigen::Matrix< T, 3, 3 > Matrix3
Definition types.h:96
Eigen::Matrix< T, kParametersPerJoint, 1 > JointVectorT
Definition types.h:27
Eigen::Quaternion< T > Quaternion
Unit quaternion representing a 3D rotation.
Definition types.h:385
std::vector< JointStateT< T > > JointStateListT
Structure describing the state of all joints in a skeleton.
Vector< T, 3 > Vector3
Definition types.h:236
Represents the state of a joint with local and global transformations.
Definition joint_state.h:50
const T & localScale() const
Access the joint's local scale factor.
Vector3< float > getTranslationDerivative(size_t index) const
TransformT< float > localTransform
Definition joint_state.h:54
Vector3< float > getRotationDerivative(size_t index, const Vector3< float > &ref) const
const Quaternion< float > & localRotation() const
Vector3< T > & translation()
Access the joint's global position vector (mutable).
T & quatY()
Access the Y component of the global rotation quaternion (mutable).
T & x()
Access the X component of the global position (mutable).
const T & scale() const
Access the joint's global scale factor.
T & quatW()
Access the W component of the global rotation quaternion (mutable).
T & quatZ()
Access the Z component of the global rotation quaternion (mutable).
const T & z() const
Access the Z component of the global position.
const T & quatW() const
Access the W component of the global rotation quaternion.
Vector3< float > getScaleDerivative(const Vector3< float > &ref) const noexcept
Matrix3< float > rotationAxis
Definition joint_state.h:69
Matrix3< float > translationAxis
Definition joint_state.h:64
TransformT< float > transform
Definition joint_state.h:59
T & y()
Access the Y component of the global position (mutable).
T & localScale()
Access the joint's local scale factor (mutable).
const T & x() const
Access the X component of the global position.
T & quatX()
Access the X component of the global rotation quaternion (mutable).
const Vector3< T > & translation() const
Access the joint's global position vector.
const T & y() const
Access the Y component of the global position.
Vector3< T > & localTranslation()
Access the joint's local translation vector (mutable).
T & scale()
Access the joint's global scale factor (mutable).
const Quaternion< T > & rotation() const
Access the joint's global rotation quaternion.
const Vector3< T > & localTranslation() const
Access the joint's local translation vector.
const T & quatX() const
Access the X component of the global rotation quaternion.
void set(const JointT< T > &joint, const JointVectorT< T > &parameters, const JointStateT< T > *parentState=nullptr, bool computeDeriv=true) noexcept
Updates joint state based on joint definition and parameters.
Quaternion< T > & localRotation()
Access the joint's local rotation quaternion (mutable).
T & z()
Access the Z component of the global position (mutable).
const T & quatY() const
Access the Y component of the global rotation quaternion.
const T & quatZ() const
Access the Z component of the global rotation quaternion.
Quaternion< T > & rotation()
Access the joint's global rotation quaternion (mutable).
A simplified version of a Maya joint with pre-rotation only (no post-rotation).
Definition joint.h:18
Lightweight transform with separate rotation, translation, and uniform scaling.
Definition transform.h:36