aux/util: Share joint width hand tracking function

This commit is contained in:
danwillm 2022-08-01 17:42:20 +01:00 committed by Moses Turner
parent 9e7f814328
commit 1dee288459
5 changed files with 44 additions and 66 deletions

View file

@ -5,6 +5,7 @@
* @brief Hand Tracking API interface.
* @author Christoph Haag <christoph.haag@collabora.com>
* @author Daniel Willmott <web@dan-w.com>
* @author Nick Klingensmith <programmerpichu@gmail.com>
* @ingroup aux_tracking
*/
@ -67,6 +68,38 @@ u_hand_joint_is_thumb(enum xrt_hand_joint joint)
joint == XRT_HAND_JOINT_THUMB_DISTAL || joint == XRT_HAND_JOINT_THUMB_TIP;
}
void
u_hand_joints_apply_joint_width(struct xrt_hand_joint_set *set)
{
// Thanks to Nick Klingensmith for this idea
struct xrt_hand_joint_value *gr = set->values.hand_joint_set_default;
static const float finger_joint_size[5] = {0.022f, 0.021f, 0.022f, 0.021f, 0.02f};
static const float hand_finger_size[5] = {1.0f, 1.0f, 0.83f, 0.75f};
static const float thumb_size[4] = {0.016f, 0.014f, 0.012f, 0.012f};
float mul = 1.0f;
for (int i = XRT_HAND_JOINT_THUMB_METACARPAL; i <= XRT_HAND_JOINT_THUMB_TIP; i++) {
int j = i - XRT_HAND_JOINT_THUMB_METACARPAL;
gr[i].radius = thumb_size[j] * mul;
}
for (int finger = 0; finger < 4; finger++) {
for (int joint = 0; joint < 5; joint++) {
int set_idx = finger * 5 + joint + XRT_HAND_JOINT_INDEX_METACARPAL;
float val = finger_joint_size[joint] * hand_finger_size[finger] * .5 * mul;
gr[set_idx].radius = val;
}
}
// The radius of each joint is the distance from the joint to the skin in meters. -OpenXR spec.
set->values.hand_joint_set_default[XRT_HAND_JOINT_PALM].radius =
.032f * .5f; // Measured my palm thickness with calipers
set->values.hand_joint_set_default[XRT_HAND_JOINT_WRIST].radius =
.040f * .5f; // Measured my wrist thickness with calipers
}
void
u_hand_joints_offset_valve_index_controller(enum xrt_hand hand,
const struct xrt_vec3 *static_offset,

View file

@ -118,6 +118,13 @@ struct u_hand_tracking
uint64_t timestamp_ns;
};
/*!
* Applies joint width to set.
* @ingroup aux_util
*/
void
u_hand_joints_apply_joint_width(struct xrt_hand_joint_set *set);
/*!
* @ingroup aux_util
*/

View file

@ -6,12 +6,12 @@
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Moses Turner <moses@collabora.com>
* @author Charlton Rodda <charlton.rodda@collabora.com>
* @author Nick Klingensmith <programmerpichu@gmail.com>
* @ingroup tracking
*/
#include "hg_sync.hpp"
#include "hg_image_math.inl"
#include "util/u_hand_tracking.h"
#include "math/m_vec2.h"
#include "util/u_misc.h"
@ -163,38 +163,6 @@ getModelsFolder(struct HandTracking *hgt)
#endif
}
static void
applyJointWidths(struct HandTracking *hgt, struct xrt_hand_joint_set *set)
{
// Thanks to Nick Klingensmith for this idea
struct xrt_hand_joint_value *gr = set->values.hand_joint_set_default;
static const float finger_joint_size[5] = {0.022f, 0.021f, 0.022f, 0.021f, 0.02f};
static const float hand_finger_size[5] = {1.0f, 1.0f, 0.83f, 0.75f};
static const float thumb_size[4] = {0.016f, 0.014f, 0.012f, 0.012f};
float mul = 1.0f;
for (int i = XRT_HAND_JOINT_THUMB_METACARPAL; i <= XRT_HAND_JOINT_THUMB_TIP; i++) {
int j = i - XRT_HAND_JOINT_THUMB_METACARPAL;
gr[i].radius = thumb_size[j] * mul;
}
for (int finger = 0; finger < 4; finger++) {
for (int joint = 0; joint < 5; joint++) {
int set_idx = finger * 5 + joint + XRT_HAND_JOINT_INDEX_METACARPAL;
float val = finger_joint_size[joint] * hand_finger_size[finger] * .5 * mul;
gr[set_idx].radius = val;
}
}
// The radius of each joint is the distance from the joint to the skin in meters. -OpenXR spec.
set->values.hand_joint_set_default[XRT_HAND_JOINT_PALM].radius =
.032f * .5f; // Measured my palm thickness with calipers
set->values.hand_joint_set_default[XRT_HAND_JOINT_WRIST].radius =
.040f * .5f; // Measured my wrist thickness with calipers
}
template <typename Vec>
static inline bool
check_outside_view(struct HandTracking *hgt, struct t_image_boundary_info_one_view boundary, Vec &keypoint)
@ -876,7 +844,7 @@ HandTracking::cCallbackProcess(struct t_hand_tracking_sync *ht_sync,
applyJointWidths(hgt, put_in_set);
u_hand_joints_apply_joint_width(put_in_set);
// Just debug scribbling - remove this in hard production environment
if (hgt->tuneable_values.scribble_optimizer_outputs && hgt->debug_scribble) {

View file

@ -51,37 +51,6 @@ errHandDisparity(const Hand2D &left_rays, const Hand2D &right_rays)
return error_y_diff;
}
void
applyJointWidths(struct xrt_hand_joint_set *set)
{
// Thanks to Nick Klingensmith for this idea
struct xrt_hand_joint_value *gr = set->values.hand_joint_set_default;
static const float finger_joint_size[5] = {0.022f, 0.021f, 0.022f, 0.021f, 0.02f};
static const float hand_finger_size[5] = {1.0f, 1.0f, 0.83f, 0.75f};
static const float thumb_size[4] = {0.016f, 0.014f, 0.012f, 0.012f};
static const float mul = 1.0f;
for (int i = XRT_HAND_JOINT_THUMB_METACARPAL; i <= XRT_HAND_JOINT_THUMB_TIP; i++) {
int j = i - XRT_HAND_JOINT_THUMB_METACARPAL;
gr[i].radius = thumb_size[j] * mul;
}
for (int finger = 0; finger < 4; finger++) {
for (int joint = 0; joint < 5; joint++) {
int set_idx = finger * 5 + joint + XRT_HAND_JOINT_INDEX_METACARPAL;
float val = finger_joint_size[joint] * hand_finger_size[finger] * .5 * mul;
gr[set_idx].radius = val;
}
}
// The radius of each joint is the distance from the joint to the skin in meters. -OpenXR spec.
set->values.hand_joint_set_default[XRT_HAND_JOINT_PALM].radius =
.032f * .5f; // Measured my palm thickness with calipers
set->values.hand_joint_set_default[XRT_HAND_JOINT_WRIST].radius =
.040f * .5f; // Measured my wrist thickness with calipers
}
void
applyThumbIndexDrag(Hand3D *hand)
{

View file

@ -55,6 +55,7 @@ using namespace xrt::tracking::hand::old_rgb;
#include "util/u_device.h"
#include "util/u_frame.h"
#include "util/u_hand_tracking.h"
#include "util/u_sink.h"
#include "util/u_format.h"
#include "util/u_logging.h"
@ -1187,7 +1188,7 @@ HandTracking::cCallbackProcess(struct t_hand_tracking_sync *ht_sync,
put_in_set->hand_pose.relation_flags = valid_flags_ht;
applyJointWidths(put_in_set);
u_hand_joints_apply_joint_width(put_in_set);
applyJointOrientations(put_in_set, xr_indices[i]);
}
htExitFrame(htd, false, final_hands_ordered_by_handedness, filtered_hands[0].timestamp, out_left_hand,