Monado OpenXR Runtime
t_hand_tracking.h
Go to the documentation of this file.
1// Copyright 2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Hand tracking interfaces.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup xrt_iface
8 */
9
10#pragma once
11
12#include "xrt/xrt_defines.h"
13#include "xrt/xrt_frame.h"
14#include "xrt/xrt_tracking.h"
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/*!
22 * @brief Image boundary type.
23 *
24 * Currently used by hand-tracking to determine if parts of the hand are not visible to the camera, ie. they are outside
25 * of the camera's vignette.
26 *
27 * Feel free to move this out of t_hand_tracking if this becomes more generally applicable.
28 *
29 * @ingroup xrt_iface
30 */
32{
33 HT_IMAGE_BOUNDARY_NONE,
34 HT_IMAGE_BOUNDARY_CIRCLE,
35};
36
37/*!
38 * @brief Circular image boundary.
39 *
40 * Currently used by hand-tracking to determine if parts of the hand are not visible to the camera, ie. they are outside
41 * of the camera's vignette.
42 *
43 * Feel free to move this out of t_hand_tracking if this becomes more generally applicable.
44 *
45 * @ingroup xrt_iface
46 */
48{
49 // The center, in normalized 0-1 UV coordinates.
50 // Should probably be between 0 and 1 in pixel coordinates.
51 struct xrt_vec2 normalized_center;
52 // The radius, divided by the image width.
53 // For Index, should be around 0.5.
54 float normalized_radius;
55};
56
57/*!
58 * @brief Logical orientation of the camera image, relative to the user's head.
59 * For example, Rift S uses CAMERA_ORIENTATION_90 for the two front cameras.
60 *
61 * Feel free to move this out of t_hand_tracking if this becomes more generally applicable.
62 *
63 */
65{
66 CAMERA_ORIENTATION_0 = 0, // Normal "horizontal" orientation
67 CAMERA_ORIENTATION_90 = 90, // Camera rotated 90° to the right
68 CAMERA_ORIENTATION_180 = 180, // Camera rotated 180° upside down
69 CAMERA_ORIENTATION_270 = 270, // Camera rotated 270° to the left
70};
71
72
73/*!
74 * @brief Information about image boundary and camera orientation for one view.
75 *
76 * Currently used by hand-tracking to determine if parts of the hand are not
77 * visible to the camera, ie. they are outside of the camera's vignette.
78 *
79 * @ingroup xrt_iface
80 */
82{
83 enum t_image_boundary_type boundary_type;
84
85 union {
86 struct t_image_boundary_circle circle;
87 } boundary;
88
89 enum t_camera_orientation camera_orientation;
90};
91
92/*!
93 * @brief Information about image boundaries and camera orientations for all the
94 * cameras used in a tracking system.
95 *
96 * Currently used by hand-tracking to determine if parts of the hand are not
97 * visible to the camera, ie. they are outside of the camera's vignette.
98 *
99 * @ingroup xrt_iface
100 */
102{
103 //!@todo Hardcoded to 2 - needs to increase as we support headsets with more cameras.
105};
106
107/*!
108 * Creation info for the creation of a hand tracker
109 */
111{
112 struct t_camera_extra_info cams_info; //!< Extra camera info
113 struct xrt_hand_masks_sink *masks_sink; //!< Optional sink to stream hand bounding boxes to
114};
115
116/*!
117 * Synchronously processes frames and returns two hands.
118 */
120{
121 /*!
122 * Process left and right view and get back a result synchronously.
123 */
124 void (*process)(struct t_hand_tracking_sync *ht_sync,
125 struct xrt_frame *left_frame,
126 struct xrt_frame *right_frame,
127 struct xrt_hand_joint_set *out_left_hand,
128 struct xrt_hand_joint_set *out_right_hand,
129 int64_t *out_timestamp_ns);
130
131 /*!
132 * Destroy this hand tracker sync object.
133 */
134 void (*destroy)(struct t_hand_tracking_sync *ht_sync);
135};
136
137/*!
138 * @copydoc t_hand_tracking_sync::process
139 *
140 * @public @memberof t_hand_tracking_sync
141 */
142static inline void
144 struct xrt_frame *left_frame,
145 struct xrt_frame *right_frame,
146 struct xrt_hand_joint_set *out_left_hand,
147 struct xrt_hand_joint_set *out_right_hand,
148 int64_t *out_timestamp_ns)
149{
150 ht_sync->process(ht_sync, left_frame, right_frame, out_left_hand, out_right_hand, out_timestamp_ns);
151}
152
153/*!
154 * @copydoc t_hand_tracking_sync::destroy
155 *
156 * Helper for calling through the function pointer: does a null check and sets
157 * ht_sync_ptr to null if freed.
158 *
159 * @public @memberof t_hand_tracking_sync
160 */
161static inline void
163{
164 struct t_hand_tracking_sync *ht_sync = *ht_sync_ptr;
165 if (ht_sync == NULL) {
166 return;
167 }
168
169 ht_sync->destroy(ht_sync);
170 *ht_sync_ptr = NULL;
171}
172
174{
175 struct xrt_frame_node node;
176 struct xrt_frame_sink left;
177 struct xrt_frame_sink right;
178 struct xrt_slam_sinks sinks; //!< Pointers to `left` and `right` sinks
179
180 void (*get_hand)(struct t_hand_tracking_async *ht_async,
181 enum xrt_input_name name,
182 int64_t desired_timestamp_ns,
183 struct xrt_hand_joint_set *out_value,
184 int64_t *out_timestamp_ns);
185};
186
189
190
191#ifdef __cplusplus
192} // extern "C"
193#endif
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition: xrt_defines.h:1298
t_image_boundary_type
Image boundary type.
Definition: t_hand_tracking.h:32
Information about image boundary and camera orientation for one view.
Definition: t_hand_tracking.h:82
Information about image boundaries and camera orientations for all the cameras used in a tracking sys...
Definition: t_hand_tracking.h:102
struct t_camera_extra_info_one_view views[2]
Definition: t_hand_tracking.h:104
Definition: t_hand_tracking.h:174
struct xrt_slam_sinks sinks
Pointers to left and right sinks.
Definition: t_hand_tracking.h:178
Creation info for the creation of a hand tracker.
Definition: t_hand_tracking.h:111
struct t_camera_extra_info cams_info
Extra camera info.
Definition: t_hand_tracking.h:112
struct xrt_hand_masks_sink * masks_sink
Optional sink to stream hand bounding boxes to.
Definition: t_hand_tracking.h:113
Synchronously processes frames and returns two hands.
Definition: t_hand_tracking.h:120
static void t_ht_sync_destroy(struct t_hand_tracking_sync **ht_sync_ptr)
Destroy this hand tracker sync object.
Definition: t_hand_tracking.h:162
void(* destroy)(struct t_hand_tracking_sync *ht_sync)
Destroy this hand tracker sync object.
Definition: t_hand_tracking.h:134
static void t_ht_sync_process(struct t_hand_tracking_sync *ht_sync, struct xrt_frame *left_frame, struct xrt_frame *right_frame, struct xrt_hand_joint_set *out_left_hand, struct xrt_hand_joint_set *out_right_hand, int64_t *out_timestamp_ns)
Process left and right view and get back a result synchronously.
Definition: t_hand_tracking.h:143
void(* process)(struct t_hand_tracking_sync *ht_sync, struct xrt_frame *left_frame, struct xrt_frame *right_frame, struct xrt_hand_joint_set *out_left_hand, struct xrt_hand_joint_set *out_right_hand, int64_t *out_timestamp_ns)
Process left and right view and get back a result synchronously.
Definition: t_hand_tracking.h:124
Circular image boundary.
Definition: t_hand_tracking.h:48
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:108
A interface object used for destroying a frame graph.
Definition: xrt_frame.h:87
A object that is sent frames.
Definition: xrt_frame.h:58
Basic frame data structure - holds a pointer to buffer.
Definition: xrt_frame.h:25
Joint set type used for hand tracking.
Definition: xrt_defines.h:1397
An object to push xrt_hand_masks_sample to.
Definition: xrt_tracking.h:192
Container of pointers to sinks that could be used for a SLAM system.
Definition: xrt_tracking.h:202
A 2 element vector with single floats.
Definition: xrt_defines.h:250
struct t_hand_tracking_async * t_hand_tracking_async_default_create(struct xrt_frame_context *xfctx, struct t_hand_tracking_sync *sync)
Definition: t_hand_tracking_async.c:322
t_camera_orientation
Logical orientation of the camera image, relative to the user's head.
Definition: t_hand_tracking.h:65
Common defines and enums for XRT.
Data frame header.
Header defining the tracking system integration in Monado.