1use super::smpl_x::NUM_HAND_JOINTS;
2use crate::common::pose_hands::{HandPair, HandType};
3use enum_map::EnumMap;
4use ndarray as nd;
5pub struct SmplXHands {
6 pub type2pose: EnumMap<HandType, HandPair>,
7}
8impl Default for SmplXHands {
9 #[allow(clippy::too_many_lines)]
10 fn default() -> Self {
11 #[allow(clippy::unreadable_literal)]
12 let left_hand_relaxed = nd::Array2::<f32>::from_shape_vec(
13 (NUM_HAND_JOINTS, 3),
14 vec![
15 -0.0423, 0.0847, -0.2358, 0.1241, -0.0303, -0.5961, -0.0841, -0.0879, -0.0305, -0.2895, -0.0021, -0.6499, 0.0655, 0.0457, -0.1250,
16 0.0112, -0.0282, -0.0638, -0.3319, -0.2805, -0.4219, -0.3363, -0.0655, -0.2898, -0.0872, -0.0354, -0.3104, -0.1407, -0.1648, -0.7088,
17 -0.1462, -0.0815, -0.1202, -0.0698, 0.0568, -0.1203, 0.2577, 0.1510, -0.0714, -0.0241, -0.0153, 0.0633, 0.2703, 0.1708, -0.2459,
18 ],
19 )
20 .unwrap();
21 #[allow(clippy::unreadable_literal)]
22 let left_hand_curled = nd::Array2::<f32>::from_shape_vec(
23 (NUM_HAND_JOINTS, 3),
24 vec![
25 0.0591, 0.0117, -0.4014, 0.1519, -0.0621, -0.8565, -0.1639, -0.1507, -0.1877, -0.3072, 0.0422, -0.5385, -0.0167, 0.0520, -0.7455,
26 0.0346, -0.1012, -0.4068, -0.7777, -0.0944, -0.5858, -0.0486, -0.0812, -0.4150, -0.2891, 0.0228, -0.3434, -0.3063, -0.1109, -0.6556,
27 -0.2111, -0.0969, -0.6347, -0.1052, -0.0272, -0.4207, 0.5913, 0.3559, -0.2171, -0.1058, -0.0210, 0.3505, 0.3081, 0.0842, -0.4556,
28 ],
29 )
30 .unwrap();
31 #[allow(clippy::unreadable_literal)]
32 #[allow(clippy::excessive_precision)]
33 let left_hand_fist = nd::Array2::<f32>::from_shape_vec(
34 (NUM_HAND_JOINTS, 3),
35 vec![
36 -0.17432889342308044,
37 0.2899666428565979,
38 -1.682339072227478,
39 0.7156379222869873,
40 -0.06946949660778046,
41 -1.6961337327957153,
42 -0.5035868883132935,
43 -0.06818924844264984,
44 -0.36969465017318726,
45 -0.4608190059661865,
46 0.11983983218669891,
47 -2.01084303855896,
48 -0.111131951212883,
49 0.24615702033042908,
50 -0.8789557814598083,
51 -0.12609277665615082,
52 0.18146048486232758,
53 -1.2574352025985718,
54 -1.0199159383773804,
55 -0.8440185189247131,
56 -1.488898754119873,
57 -0.8425631523132324,
58 -0.17709890007972717,
59 -0.49536100029945374,
60 -0.6223214864730835,
61 0.12810452282428741,
62 -0.7870318293571472,
63 -0.3238529860973358,
64 -0.5304823517799377,
65 -1.7103344202041626,
66 -0.644635796546936,
67 -0.325455904006958,
68 -1.0210907459259033,
69 -0.15834343433380127,
70 -0.04439852386713028,
71 -1.03395676612854,
72 0.9578915238380432,
73 0.24371644854545593,
74 -0.25406309962272644,
75 0.22801567614078522,
76 0.4293811023235321,
77 -0.06814373284578323,
78 0.5744239091873169,
79 0.638904869556427,
80 -0.679925262928009,
81 ],
82 )
83 .unwrap();
84 let right_hand_relaxed = Self::left2right_hand(&left_hand_relaxed);
85 let right_hand_curled = Self::left2right_hand(&left_hand_curled);
86 let right_hand_fist = Self::left2right_hand(&left_hand_fist);
87 let flat_pair = HandPair {
88 left: nd::Array2::<f32>::zeros((NUM_HAND_JOINTS, 3)),
89 right: nd::Array2::<f32>::zeros((NUM_HAND_JOINTS, 3)),
90 };
91 let relaxed_pair = HandPair {
92 left: left_hand_relaxed,
93 right: right_hand_relaxed,
94 };
95 let curled_pair = HandPair {
96 left: left_hand_curled,
97 right: right_hand_curled,
98 };
99 let fist_pair = HandPair {
100 left: left_hand_fist,
101 right: right_hand_fist,
102 };
103 let mut type2pose: EnumMap<HandType, HandPair> = EnumMap::default();
104 type2pose[HandType::Flat] = flat_pair;
105 type2pose[HandType::Relaxed] = relaxed_pair;
106 type2pose[HandType::Curled] = curled_pair;
107 type2pose[HandType::Fist] = fist_pair;
108 Self { type2pose }
109 }
110}
111impl SmplXHands {
112 pub fn left2right_hand(left_hand_pose: &nd::Array2<f32>) -> nd::Array2<f32> {
113 let mut right_hand_pose = left_hand_pose.clone();
114 right_hand_pose.column_mut(1).map_inplace(|x| *x = -*x);
115 right_hand_pose.column_mut(2).map_inplace(|x| *x = -*x);
116 right_hand_pose
117 }
118}