Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
skeleton.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 <string>
16#include <string_view>
17
18namespace momentum {
19
21template <typename T>
22struct SkeletonT {
26
27 SkeletonT() = default;
28
32
33 SkeletonT(const SkeletonT& other) = default;
34 SkeletonT(SkeletonT&& other) noexcept = default;
35 SkeletonT& operator=(const SkeletonT& other) = default;
36 SkeletonT& operator=(SkeletonT&& other) noexcept = default;
37 ~SkeletonT() = default;
38
40 [[nodiscard]] size_t getJointIdByName(std::string_view name) const;
41
42 [[nodiscard]] std::vector<std::string> getJointNames() const;
43
49 [[nodiscard]] std::vector<size_t> getChildrenJoints(size_t jointId, bool recursive = true) const;
50
54 [[nodiscard]] bool isAncestor(size_t jointId, size_t ancestorJointId) const;
55
60 [[nodiscard]] bool isSameOrAdjacentJoints(size_t joint1, size_t joint2) const;
61
64 [[nodiscard]] size_t commonAncestor(size_t joint1, size_t joint2) const;
65
67 template <typename U>
68 [[nodiscard]] SkeletonT<U> cast() const {
69 if constexpr (std::is_same_v<T, U>) {
70 return *this;
71 } else {
72 SkeletonT<U> newSkeleton;
73 newSkeleton.joints = ::momentum::cast<U>(joints);
74 return newSkeleton;
75 }
76 }
77};
78
79} // namespace momentum
JointListT< float > JointList
Definition joint.h:81
decltype(auto) cast(const ContainerType< ObjectType > &originalContainer)
Casts the scalar type of objects in a container that support the cast<>() method.
Definition types.h:466
SkeletonT< U > cast() const
Returns a copy of this skeleton with all numeric values converted to scalar type U.
Definition skeleton.h:68
size_t commonAncestor(size_t joint1, size_t joint2) const
Returns the lowest common ancestor of two joints in the hierarchy, or kInvalidIndex if either joint i...
Definition skeleton.cpp:97
size_t getJointIdByName(std::string_view name) const
Returns the index of a joint with the given name, or kInvalidIndex if not found.
Definition skeleton.cpp:25
SkeletonT(JointList joints)
Definition skeleton.cpp:16
SkeletonT(const SkeletonT &other)=default
SkeletonT & operator=(SkeletonT &&other) noexcept=default
SkeletonT(SkeletonT &&other) noexcept=default
std::vector< size_t > getChildrenJoints(size_t jointId, bool recursive=true) const
Returns indices of child joints of the specified joint.
Definition skeleton.cpp:45
SkeletonT & operator=(const SkeletonT &other)=default
std::vector< std::string > getJointNames() const
Definition skeleton.cpp:35
bool isAncestor(size_t jointId, size_t ancestorJointId) const
Returns true if ancestorJointId is an ancestor of jointId.
Definition skeleton.cpp:73
bool isSameOrAdjacentJoints(size_t joint1, size_t joint2) const
Returns true if the two joints are the same, or one is the direct parent of the other.
Definition skeleton.cpp:87