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#define XRT_CONSTELLATION_MAX_DEVICES 4
24
25#define XRT_CONSTELLATION_INVALID_DEVICE_ID -1
26#define XRT_CONSTELLATION_INVALID_LED_ID -1
27
28/*!
29 * A blob is a 2d position in a camera sensor's view that is being tracked. Generally used to
30 * represent found LEDs in a camera's sensor.
31 *
32 * Blobs are given in pixel coordinates, with the origin at the top left of the image, and x
33 * going right and y going down. The units are in pixels, but may be subpixel accurate. The tracking
34 * system is expected to handle the undistortion of the blob positions.
35 */
36struct t_blob
37{
38 /*!
39 * The ID of a blob, which may be used to track it across frames. The meaning of the ID is
40 * up to the tracking system, but it attempts to be consistent across frames for the same
41 * blob.
42 */
43 uint32_t blob_id;
44
45 /*!
46 * The device ID this blob is associated with, if any. XRT_CONSTELLATION_INVALID_DEVICE_ID
47 * for unmatched. The tracker is expected to fill this in.
48 */
49 t_constellation_device_id_t matched_device_id;
50
51 /*!
52 * The LED ID this blob is associated with, if any. XRT_CONSTELLATION_INVALID_LED_ID for
53 * unmatched. The tracker is expected to fill this in.
54 */
55 t_constellation_led_id_it matched_device_led_id;
56
57 //! Centre of blob
59
60 /*!
61 * Estimated motion vector of blob, in pixels per second. Only valid if the tracking system
62 * provides it.
63 */
65
66 //! The bounding box of the blob in pixel coordinates.
68
69 //! The size of the blob, in pixels. May be {0,0}, and may be subpixel accurate.
70 struct xrt_vec2 size;
71
72 /*!
73 * The brightness of the brightest pixel of the blob, on a scale from 0.0 (black) to 1.0 (pure white).
74 * Set to 1.0 for non-brightness-aware blobwatches.
75 */
77};
78
80{
81 struct t_blobwatch *source;
82
83 /*!
84 * Internal ID for this observation, may be set by the blobwatch implementation if it needs
85 * to know this.
86 */
87 uint64_t id;
88
89 int64_t timestamp_ns;
90 struct t_blob *blobs;
91 uint32_t num_blobs;
92};
93
94/*!
95 * @interface t_blob_sink
96 *
97 * A generic interface to allow a tracking system to receive "snapshots" of seen @ref t_blob in a
98 * frame.
99 */
101{
102 /*!
103 * Push a set of blobs into the sink. The tracking system will typically call this once per
104 * frame for each camera view.
105 *
106 * @param[in] tbs The sink to push the blobs into.
107 * @param[in] observation The blob observation to push into the sink.
108 */
109 void (*push_blobs)(struct t_blob_sink *tbs, struct t_blob_observation *observation);
110
111 /*!
112 * Destroy this blob sink.
113 */
114 void (*destroy)(struct t_blob_sink *tbs);
115};
116
117/*!
118 * Helper function for @ref t_blob_sink::push_blobs.
119 *
120 * @copydoc t_blob_sink::push_blobs
121 *
122 * @public @memberof t_blob_sink
123 */
124XRT_NONNULL_ALL static inline void
126{
127 tbs->push_blobs(tbs, tbo);
128}
129
130/*!
131 * Helper function for @ref t_blob_sink::destroy.
132 *
133 * Handles nulls, sets your pointer to null.
134 *
135 * @public @memberof t_blob_sink
136 */
137XRT_NONNULL_ALL static inline void
139{
140 struct t_blob_sink *tbs = *tbs_ptr;
141
142 if (tbs == NULL) {
143 return;
144 }
145
146 tbs->destroy(tbs);
147 *tbs_ptr = NULL;
148}
149
150
152{
153 /*!
154 * Notify the blobwatch that the blobs in the given observation with the correct ID set are
155 * associated with the given device. The blobwatch can use this information to track which
156 * blobs are associated with which devices across frames, and to provide this information to
157 * the tracker across frames to save it from doing that work again.
158 *
159 * @param[in] tbw The blobwatch to mark the blobs for.
160 * @param[in] tbo The observation containing the blobs to mark. The blobwatch will look at
161 * the blob IDs and the matched_device_id field to determine which blobs
162 * internally to mark with the given device ID.
163 * @param[in] device_id The device ID to mark
164 */
165 void (*mark_blob_device)(struct t_blobwatch *tbw,
166 const struct t_blob_observation *tbo,
167 t_constellation_device_id_t device_id);
168
169 /*!
170 * Destroy this blobwatch.
171 */
172 void (*destroy)(struct t_blobwatch *tbw);
173};
174
175/*!
176 * Helper function for @ref t_blobwatch::mark_blob_device.
177 *
178 * @copydoc t_blobwatch::mark_blob_device
179 *
180 * @public @memberof t_blobwatch
181 */
182XRT_NONNULL_ALL static inline void
184 const struct t_blob_observation *tbo,
185 t_constellation_device_id_t device_id)
186{
187 tbw->mark_blob_device(tbw, tbo, device_id);
188}
189
190/*!
191 * Helper function for @ref t_blobwatch::destroy.
192 *
193 * Handles nulls, sets your pointer to null.
194 *
195 * @public @memberof t_blobwatch
196 */
197XRT_NONNULL_ALL static inline void
199{
200 struct t_blobwatch *tbw = *tbw_ptr;
201
202 if (tbw == NULL) {
203 return;
204 }
205
206 tbw->destroy(tbw);
207 *tbw_ptr = NULL;
208}
209
210
211/*!
212 * @interface t_constellation_tracker_tracking_source
213 *
214 * A constellation tracker tracking source is an arbitrary source of tracking data for the
215 * constellation tracker. This is used by the constellation tracker to get the current pose of a
216 * device to eliminate bad guesses, or if a camera is anchored to a tracking source (a camera on a
217 * headset device), this can be used by the constellation tracker to locate that camera relative to
218 * the world.
219 */
221{
222 void (*get_tracked_pose)(struct t_constellation_tracker_tracking_source *,
223 int64_t when_ns,
224 struct xrt_space_relation *out_relation);
225};
226
227/*!
228 * Helper function for @ref t_constellation_tracker_tracking_source::get_tracked_pose.
229 *
230 * @copydoc t_constellation_tracker_tracking_source::get_tracked_pose
231 *
232 * @public @memberof t_constellation_tracker_tracking_source
233 */
234XRT_NONNULL_ALL static inline void
236 struct t_constellation_tracker_tracking_source *tracking_source,
237 int64_t when_ns,
238 struct xrt_space_relation *out_relation)
239{
240 tracking_source->get_tracked_pose(tracking_source, when_ns, out_relation);
241}
242
243
245{
246 //! The position of the LED in the model.
248 //! The normal of the LED, determines where it is facing
250 //! The visible radius of the LED in meters.
251 float radius_m;
252 //! The angle from dead on where the LED is no longer visible, in radians.
254 //! A unique ID for this LED, which distinguishes it from all other LEDs.
255 t_constellation_led_id_it id;
256};
257
258/*!
259 * @interface t_constellation_tracker_led_model
260 *
261 * The LED model is a series of points which define the real-world positions of all LEDs. Some LED
262 * models may have self-occluding areas, such as WMR, where inner LEDs can be blocked by the ring,
263 * such occlusions are modelled through the LED visibility computation function.
264 */
266{
267 //! The LEDs in this model.
269 //! The number of LEDs in this model.
270 size_t led_count;
271
272 /*!
273 * A function to compute whether a given LED is visible from a given position. This is used
274 * to allow devices to better model complex occlusion scenarios, like the inward facing LEDs
275 * on the WMR rings.
276 *
277 * @param led_model The LED model containing the LED in question.
278 * @param led The index of the LED in question in the model.
279 * @param T_obj_cam The transform from the root of the LED model to the camera. Assume
280 * camera is facing the origin of the LED model.
281 *
282 * @return Whether the LED is visible from the given position.
283 */
285 size_t led,
286 struct xrt_vec3 T_obj_cam);
287};
288
289/*!
290 * Helper function for @ref t_constellation_tracker_led_model::compute_led_visibility.
291 *
292 * @copydoc t_constellation_tracker_led_model::compute_led_visibility
293 *
294 * @public @memberof t_constellation_tracker_led_model
295 */
296XRT_NONNULL_ALL static inline bool
298 size_t led,
299 struct xrt_vec3 T_obj_cam)
300{
301 return led_model->compute_led_visibility(led_model, led, T_obj_cam);
302}
303
304
306{
307 //! The time the original blobservation was made.
309 //! The pose of the device at the time of the blobservation.
311 //! The mosaic index of the camera that made the blobservation in question.
313 //! The index of the camera in the mosaic that made the blobservation in question.
315 //! Average brightness of the detected blobs, from 0 (black) to 1 (pure white).
317};
318
319/*!
320 * @interface t_constellation_tracker_device
321 *
322 * A constellation tracker device is a device that the constellation tracker will attempt to track
323 * in 6dof. The constellation tracker will provide the device with samples of it's current pose as
324 * it tracks it.
325 */
327{
328 /*!
329 * A function that the constellation tracker will call to push a new sample of the device's
330 * pose as it tracks it.
331 *
332 * @param connection The device to push the sample to.
333 * @param sample The sample containing the current pose of the device and the timestamp of
334 * the original blobservation that led to this pose being computed.
335 */
337 struct t_constellation_tracker_sample *sample);
338};
339
340/*!
341 * Helper function for @ref t_constellation_tracker_device::push_constellation_tracker_sample.
342 *
343 * @copydoc t_constellation_tracker_device::push_constellation_tracker_sample
344 *
345 * @public @memberof t_constellation_tracker_device
346 */
347XRT_NONNULL_ALL static inline void
353
354#ifdef __cplusplus
355}
356#endif
Definition t_constellation.h:80
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:87
A generic interface to allow a tracking system to receive "snapshots" of seen t_blob in a frame.
Definition t_constellation.h:101
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:109
void(* destroy)(struct t_blob_sink *tbs)
Destroy this blob sink.
Definition t_constellation.h:114
static XRT_NONNULL_ALL void t_blob_sink_push_blobs(struct t_blob_sink *tbs, struct t_blob_observation *tbo)
Helper function for t_blob_sink::push_blobs.
Definition t_constellation.h:125
static XRT_NONNULL_ALL void t_blob_sink_destroy(struct t_blob_sink **tbs_ptr)
Helper function for t_blob_sink::destroy.
Definition t_constellation.h:138
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:37
float brightness
The brightness of the brightest pixel of the blob, on a scale from 0.0 (black) to 1....
Definition t_constellation.h:76
t_constellation_led_id_it matched_device_led_id
The LED ID this blob is associated with, if any.
Definition t_constellation.h:55
t_constellation_device_id_t matched_device_id
The device ID this blob is associated with, if any.
Definition t_constellation.h:49
struct xrt_vec2 motion_vector
Estimated motion vector of blob, in pixels per second.
Definition t_constellation.h:64
uint32_t blob_id
The ID of a blob, which may be used to track it across frames.
Definition t_constellation.h:43
struct xrt_vec2 center
Centre of blob.
Definition t_constellation.h:58
struct xrt_rect bounding_box
The bounding box of the blob in pixel coordinates.
Definition t_constellation.h:67
Definition t_constellation.h:152
static XRT_NONNULL_ALL void t_blobwatch_mark_blob_device(struct t_blobwatch *tbw, const struct t_blob_observation *tbo, t_constellation_device_id_t device_id)
Helper function for t_blobwatch::mark_blob_device.
Definition t_constellation.h:183
static XRT_NONNULL_ALL void t_blobwatch_destroy(struct t_blobwatch **tbw_ptr)
Helper function for t_blobwatch::destroy.
Definition t_constellation.h:198
void(* destroy)(struct t_blobwatch *tbw)
Destroy this blobwatch.
Definition t_constellation.h:172
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:165
A constellation tracker device is a device that the constellation tracker will attempt to track in 6d...
Definition t_constellation.h:327
static XRT_NONNULL_ALL void t_constellation_tracker_device_push_sample(struct t_constellation_tracker_device *device, struct t_constellation_tracker_sample *sample)
Helper function for t_constellation_tracker_device::push_constellation_tracker_sample.
Definition t_constellation.h:348
void(* push_constellation_tracker_sample)(struct t_constellation_tracker_device *connection, struct t_constellation_tracker_sample *sample)
A function that the constellation tracker will call to push a new sample of the device's pose as it t...
Definition t_constellation.h:336
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:266
bool(* compute_led_visibility)(struct t_constellation_tracker_led_model *led_model, size_t led, struct xrt_vec3 T_obj_cam)
A function to compute whether a given LED is visible from a given position.
Definition t_constellation.h:284
static XRT_NONNULL_ALL bool t_constellation_tracker_led_model_compute_led_visibility(struct t_constellation_tracker_led_model *led_model, size_t led, struct xrt_vec3 T_obj_cam)
Helper function for t_constellation_tracker_led_model::compute_led_visibility.
Definition t_constellation.h:297
size_t led_count
The number of LEDs in this model.
Definition t_constellation.h:270
struct t_constellation_tracker_led * leds
The LEDs in this model.
Definition t_constellation.h:268
Definition t_constellation.h:245
float radius_m
The visible radius of the LED in meters.
Definition t_constellation.h:251
float visibility_angle
The angle from dead on where the LED is no longer visible, in radians.
Definition t_constellation.h:253
struct xrt_vec3 position
The position of the LED in the model.
Definition t_constellation.h:247
t_constellation_led_id_it id
A unique ID for this LED, which distinguishes it from all other LEDs.
Definition t_constellation.h:255
struct xrt_vec3 normal
The normal of the LED, determines where it is facing.
Definition t_constellation.h:249
Definition t_constellation.h:306
float average_brightness
Average brightness of the detected blobs, from 0 (black) to 1 (pure white).
Definition t_constellation.h:316
int64_t timestamp_ns
The time the original blobservation was made.
Definition t_constellation.h:308
struct xrt_pose pose
The pose of the device at the time of the blobservation.
Definition t_constellation.h:310
size_t mosaic_index
The mosaic index of the camera that made the blobservation in question.
Definition t_constellation.h:312
size_t camera_index
The index of the camera in the mosaic that made the blobservation in question.
Definition t_constellation.h:314
A constellation tracker tracking source is an arbitrary source of tracking data for the constellation...
Definition t_constellation.h:221
static XRT_NONNULL_ALL void t_constellation_tracker_tracking_source_get_tracked_pose(struct t_constellation_tracker_tracking_source *tracking_source, int64_t when_ns, struct xrt_space_relation *out_relation)
Helper function for t_constellation_tracker_tracking_source::get_tracked_pose.
Definition t_constellation.h:235
A pose composed of a position and orientation.
Definition xrt_defines.h:492
Image rectangle.
Definition xrt_defines.h:457
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:683
A 2 element vector with single floats.
Definition xrt_defines.h:268
A 3 element vector with single floats.
Definition xrt_defines.h:289
Common defines and enums for XRT.