Monado OpenXR Runtime
Loading...
Searching...
No Matches
t_constellation.h
Go to the documentation of this file.
1// Copyright 2026, Beyley Cardellio
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header defining the tracking system integration in Monado.
6 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
7 * @ingroup xrt_iface
8 */
9
10#pragma once
11
12#include "xrt/xrt_defines.h"
13
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19typedef int8_t t_constellation_device_id_t;
20typedef int8_t t_constellation_led_id_it;
21
22#define XRT_CONSTELLATION_MAX_BLOBS_PER_FRAME 250
23
24#define XRT_CONSTELLATION_INVALID_DEVICE_ID -1
25#define XRT_CONSTELLATION_INVALID_LED_ID -1
26
27/*!
28 * A blob is a 2d position in a camera sensor's view that is being tracked. Generally used to represent found LEDs in a
29 * camera's sensor.
30 *
31 * Blobs are given in pixel coordinates, with the origin at the top left of the image, and x going right and y going
32 * down. The units are in pixels, but may be subpixel accurate. The tracking system is expected to handle the
33 * undistortion of the blob positions.
34 */
35struct t_blob
36{
37 /*!
38 * The ID of a blob, which may be used to track it across frames. The meaning of the ID is up to the tracking
39 * system, but it attempts to be consistent across frames for the same blob.
40 */
41 uint32_t blob_id;
42
43 /*!
44 * The device ID this blob is associated with, if any. XRT_CONSTELLATION_INVALID_DEVICE_ID for unmatched.
45 * The tracker is expected to fill this in.
46 */
47 t_constellation_device_id_t matched_device_id;
48
49 /*!
50 * The LED ID this blob is associated with, if any. XRT_CONSTELLATION_INVALID_LED_ID for unmatched.
51 * The tracker is expected to fill this in.
52 */
53 t_constellation_led_id_it matched_device_led_id;
54
55 //! Centre of blob
57
58 //! Estimated motion vector of blob, in pixels per second. Only valid if the tracking system provides it.
60
61 //! The bounding box of the blob in pixel coordinates.
63
64 //! The size of the blob, in pixels. May be {0,0}, and may be subpixel accurate.
65 struct xrt_vec2 size;
66};
67
69{
70 struct t_blobwatch *source;
71
72 //! Internal ID for this observation, may be set by the blobwatch implementation if it needs to know this.
73 uint64_t id;
74
75 int64_t timestamp_ns;
76 struct t_blob *blobs;
77 uint32_t num_blobs;
78};
79
80/*!
81 * @interface t_blob_sink
82 *
83 * A generic interface to allow a tracking system to receive "snapshots" of seen @ref t_blob in a frame.
84 */
86{
87 /*!
88 * Push a set of blobs into the sink. The tracking system will typically call this once per frame for each
89 * camera view.
90 *
91 * @param[in] tbs The sink to push the blobs into.
92 * @param[in] observation The blob observation to push into the sink.
93 */
94 void (*push_blobs)(struct t_blob_sink *tbs, struct t_blob_observation *observation);
95
96 /*!
97 * Destroy this blob sink.
98 */
99 void (*destroy)(struct t_blob_sink *tbs);
100};
101
103{
104 /*!
105 * Notify the blobwatch that the blobs in the given observation with the correct ID set are associated with the
106 * given device. The blobwatch can use this information to track which blobs are associated with which devices
107 * across frames, and to provide this information to the tracker across frames to save it from doing that work
108 * again.
109 *
110 * @param[in] tbw The blobwatch to mark the blobs for.
111 * @param[in] tbo The observation containing the blobs to mark. The blobwatch will look at the blob IDs and the
112 * matched_device_id field to determine which blobs internally to mark with the given device ID.
113 * @param[in] device_id The device ID to mark
114 */
115 void (*mark_blob_device)(struct t_blobwatch *tbw,
116 const struct t_blob_observation *tbo,
117 t_constellation_device_id_t device_id);
118
119 /*!
120 * Destroy this blobwatch.
121 */
122 void (*destroy)(struct t_blobwatch *tbw);
123};
124
125
126//! @public @memberof t_blob_sink
127XRT_NONNULL_ALL static inline void
128t_blob_sink_push_blobs(struct t_blob_sink *tbs, struct t_blob_observation *tbo)
129{
130 tbs->push_blobs(tbs, tbo);
131}
132
133//! @public @memberof t_blob_sink
134XRT_NONNULL_ALL static inline void
135t_blob_sink_destroy(struct t_blob_sink **tbs_ptr)
136{
137 struct t_blob_sink *tbs = *tbs_ptr;
138
139 if (tbs == NULL) {
140 return;
141 }
142
143 tbs->destroy(tbs);
144 *tbs_ptr = NULL;
145}
146
147//! @public @memberof t_blobwatch
148XRT_NONNULL_ALL static inline void
149t_blobwatch_mark_blob_device(struct t_blobwatch *tbw,
150 const struct t_blob_observation *tbo,
151 t_constellation_device_id_t device_id)
152{
153 tbw->mark_blob_device(tbw, tbo, device_id);
154}
155
156//! @public @memberof t_blobwatch
157XRT_NONNULL_ALL static inline void
158t_blobwatch_destroy(struct t_blobwatch **tbw_ptr)
159{
160 struct t_blobwatch *tbw = *tbw_ptr;
161
162 if (tbw == NULL) {
163 return;
164 }
165
166 tbw->destroy(tbw);
167 *tbw_ptr = NULL;
168}
169
170#ifdef __cplusplus
171}
172#endif
Definition t_constellation.h:69
uint64_t id
Internal ID for this observation, may be set by the blobwatch implementation if it needs to know this...
Definition t_constellation.h:73
A generic interface to allow a tracking system to receive "snapshots" of seen t_blob in a frame.
Definition t_constellation.h:86
void(* push_blobs)(struct t_blob_sink *tbs, struct t_blob_observation *observation)
Push a set of blobs into the sink.
Definition t_constellation.h:94
void(* destroy)(struct t_blob_sink *tbs)
Destroy this blob sink.
Definition t_constellation.h:99
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:36
struct xrt_vec2 size
The size of the blob, in pixels. May be {0,0}, and may be subpixel accurate.
Definition t_constellation.h:65
t_constellation_led_id_it matched_device_led_id
The LED ID this blob is associated with, if any.
Definition t_constellation.h:53
t_constellation_device_id_t matched_device_id
The device ID this blob is associated with, if any.
Definition t_constellation.h:47
struct xrt_vec2 motion_vector
Estimated motion vector of blob, in pixels per second. Only valid if the tracking system provides it.
Definition t_constellation.h:59
uint32_t blob_id
The ID of a blob, which may be used to track it across frames.
Definition t_constellation.h:41
struct xrt_vec2 center
Centre of blob.
Definition t_constellation.h:56
struct xrt_rect bounding_box
The bounding box of the blob in pixel coordinates.
Definition t_constellation.h:62
Definition t_constellation.h:103
void(* destroy)(struct t_blobwatch *tbw)
Destroy this blobwatch.
Definition t_constellation.h:122
void(* mark_blob_device)(struct t_blobwatch *tbw, const struct t_blob_observation *tbo, t_constellation_device_id_t device_id)
Notify the blobwatch that the blobs in the given observation with the correct ID set are associated w...
Definition t_constellation.h:115
Image rectangle.
Definition xrt_defines.h:444
A 2 element vector with single floats.
Definition xrt_defines.h:268
Common defines and enums for XRT.