Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
pose_shape.cpp
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
9
12
13namespace momentum {
14
15std::vector<Vector3f> PoseShape::compute(const SkeletonState& state) const {
17 baseShape.size() == shapeVectors.rows(),
18 "{} is not {}",
19 baseShape.size(),
20 shapeVectors.rows());
21
22 VectorXf coefficients(shapeVectors.cols());
23
24 // If baseJoint is out of range, fall back to baseRot directly (no relative rotation).
25 const Quaternionf base = (baseJoint < state.jointState.size())
26 ? baseRot * state.jointState.at(baseJoint).rotation().inverse()
27 : baseRot;
28
29 // Pack each driving joint's rotation (relative to base) as a 4-vector of quaternion
30 // coefficients (x, y, z, w). Out-of-range joints leave their segment uninitialized.
31 // TODO: zero-initialize `coefficients` so out-of-range joint indices don't read garbage.
32 for (size_t i = 0; i < jointMap.size(); i++) {
33 const auto& jid = jointMap[i];
34 if (jid < state.jointState.size()) {
35 coefficients.segment<4>(i * 4) = (base * state.jointState.at(jid).rotation()).coeffs();
36 }
37 }
38
39 std::vector<Vector3f> output(baseShape.size() / 3);
40 if (output.empty()) {
41 return output;
42 }
43 Map<VectorXf> outputVec(&output[0][0], output.size() * 3);
44
45 outputVec = baseShape + shapeVectors * coefficients;
46
47 return output;
48}
49
50} // namespace momentum
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
Definition checks.h:36
Quaternion< float > Quaternionf
Definition types.h:386
SkeletonStateT< float > SkeletonState
Definition fwd.h:282
VectorX< float > VectorXf
Definition types.h:209
Eigen::Map< T > Map
Definition types.h:40
size_t baseJoint
Index of the joint used as reference for computing relative rotations.
Definition pose_shape.h:22
MatrixXf shapeVectors
Shape deformation vectors for each quaternion component of each joint.
Definition pose_shape.h:41
std::vector< Vector3f > compute(const SkeletonState &state) const
Computes the deformed shape vertices for the given skeleton pose.
VectorXf baseShape
Base shape vertices stored as a flat vector [x1,y1,z1,x2,y2,z2,...].
Definition pose_shape.h:35
std::vector< size_t > jointMap
Indices of joints whose rotations drive the shape deformation.
Definition pose_shape.h:30
Quaternionf baseRot
Base rotation used as reference for computing rotation differences.
Definition pose_shape.h:27
JointStateListT< T > jointState
Computed joint states for all joints in the skeleton.