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 * The maximum amount of devices the constellation tracker is able to track at once.
25 *
26 * @note This value is dictated by the device bitmask in the sensor fusion, update that there when this is changed to
27 * another power of two.
28 */
29#define XRT_CONSTELLATION_MAX_DEVICES 4
30
31/*!
32 * The maximum number of LEDs that a single device can have.
33 *
34 * This is a hard limit since we use some bitfields to track LEDs in the pose optimization.
35 * If this ever needs to be raised, you need to go update pose_optimize.cpp to use some other data type.
36 */
37#define XRT_CONSTELLATION_MAX_LEDS_PER_DEVICE 64
38
39#define XRT_CONSTELLATION_INVALID_DEVICE_ID -1
40#define XRT_CONSTELLATION_INVALID_LED_ID -1
41
42/*!
43 * A blob is a 2d position in a camera sensor's view that is being tracked. Generally used to
44 * represent found LEDs in a camera's sensor.
45 *
46 * Blobs are given in pixel coordinates, with the origin at the top left of the image, and x
47 * going right and y going down. The units are in pixels, but may be subpixel accurate. The tracking
48 * system is expected to handle the undistortion of the blob positions.
49 */
50struct t_blob
51{
52 /*!
53 * The ID of a blob, which may be used to track it across frames. The meaning of the ID is
54 * up to the tracking system, but it attempts to be consistent across frames for the same
55 * blob.
56 */
57 uint32_t blob_id;
58
59 /*!
60 * The device ID this blob is associated with, if any. XRT_CONSTELLATION_INVALID_DEVICE_ID
61 * for unmatched. The tracker is expected to fill this in.
62 */
63 t_constellation_device_id_t matched_device_id;
64
65 /*!
66 * The LED ID this blob is associated with, if any. XRT_CONSTELLATION_INVALID_LED_ID for
67 * unmatched. The tracker is expected to fill this in.
68 */
69 t_constellation_led_id_it matched_device_led_id;
70
71 //! Centre of blob, in distorted pixels
73
74 //! Center of blob, in undistorted pixels
76
77 //! Center of blob, in homogenized coordinates
79
80 /*!
81 * Estimated motion vector of blob, in distorted pixels per second. Only valid if the tracking system
82 * provides it.
83 */
85
86 //! The bounding box of the blob in distorted pixel coordinates.
88
89 //! The size of the blob, in distorted pixels. May be {0,0}, and may be subpixel accurate.
90 struct xrt_vec2 size;
91
92 /*!
93 * The brightness of the blob, from 0-1, taken by dividing the greysum over it's area.
94 */
96
97 //! The total light of the blob above the noise floor, in full-scale pixels.
98 float greysum;
99};
100
101struct xrt_frame;
102
104{
105 struct t_blobwatch *source;
106
107 /*!
108 * Internal ID for this observation, may be set by the blobwatch implementation if it needs
109 * to know this.
110 */
111 uint64_t id;
112
113 //! The sequence ID of this mosaic, must be stable across all frames of a mosaic. Monotonically increases.
114 uint64_t sequence_id;
115
116 int64_t timestamp_ns;
117 struct t_blob *blobs;
118 uint32_t num_blobs;
119
120 /*!
121 * Optional reference to the frame the blobs were extracted from, may be NULL.
122 *
123 * The reference is owned by the observation: the blob sink receiving it takes ownership and must release it
124 * with @ref xrt_frame_reference (or pass it on to another sink that does).
125 */
127};
128
129/*!
130 * @interface t_blob_sink
131 *
132 * A generic interface to allow a tracking system to receive "snapshots" of seen @ref t_blob in a
133 * frame.
134 */
136{
137 /*!
138 * Push a set of blobs into the sink. The tracking system will typically call this once per
139 * frame for each camera view.
140 *
141 * @param[in] tbs The sink to push the blobs into.
142 * @param[in] observation The blob observation to push into the sink.
143 */
144 void (*push_blobs)(struct t_blob_sink *tbs, struct t_blob_observation *observation);
145
146 /*!
147 * Destroy this blob sink.
148 */
149 void (*destroy)(struct t_blob_sink *tbs);
150};
151
152/*!
153 * Helper function for @ref t_blob_sink::push_blobs.
154 *
155 * @copydoc t_blob_sink::push_blobs
156 *
157 * @public @memberof t_blob_sink
158 */
159XRT_NONNULL_ALL static inline void
161{
162 tbs->push_blobs(tbs, tbo);
163}
164
165/*!
166 * Helper function for @ref t_blob_sink::destroy.
167 *
168 * Handles nulls, sets your pointer to null.
169 *
170 * @public @memberof t_blob_sink
171 */
172XRT_NONNULL_ALL static inline void
174{
175 struct t_blob_sink *tbs = *tbs_ptr;
176
177 if (tbs == NULL) {
178 return;
179 }
180
181 tbs->destroy(tbs);
182 *tbs_ptr = NULL;
183}
184
185
187{
188 /*!
189 * Notify the blobwatch that the blobs in the given observation with the correct ID set are
190 * associated with the given device. The blobwatch can use this information to track which
191 * blobs are associated with which devices across frames, and to provide this information to
192 * the tracker across frames to save it from doing that work again.
193 *
194 * @param[in] tbw The blobwatch to mark the blobs for.
195 * @param[in] tbo The observation containing the blobs to mark. The blobwatch will look at
196 * the blob IDs and the matched_device_id field to determine which blobs
197 * internally to mark with the given device ID.
198 * @param[in] device_id The device ID to mark
199 */
200 void (*mark_blob_device)(struct t_blobwatch *tbw,
201 const struct t_blob_observation *tbo,
202 t_constellation_device_id_t device_id);
203
204 /*!
205 * Destroy this blobwatch.
206 */
207 void (*destroy)(struct t_blobwatch *tbw);
208};
209
210/*!
211 * Helper function for @ref t_blobwatch::mark_blob_device.
212 *
213 * @copydoc t_blobwatch::mark_blob_device
214 *
215 * @public @memberof t_blobwatch
216 */
217XRT_NONNULL_ALL static inline void
219 const struct t_blob_observation *tbo,
220 t_constellation_device_id_t device_id)
221{
222 tbw->mark_blob_device(tbw, tbo, device_id);
223}
224
225/*!
226 * Helper function for @ref t_blobwatch::destroy.
227 *
228 * Handles nulls, sets your pointer to null.
229 *
230 * @public @memberof t_blobwatch
231 */
232XRT_NONNULL_ALL static inline void
234{
235 struct t_blobwatch *tbw = *tbw_ptr;
236
237 if (tbw == NULL) {
238 return;
239 }
240
241 tbw->destroy(tbw);
242 *tbw_ptr = NULL;
243}
244
245
246/*!
247 * @interface t_constellation_tracker_tracking_source
248 *
249 * A constellation tracker tracking source is an arbitrary source of tracking data for the
250 * constellation tracker. This is used by the constellation tracker to get the current pose of a
251 * device to eliminate bad guesses, or if a camera is anchored to a tracking source (a camera on a
252 * headset device), this can be used by the constellation tracker to locate that camera relative to
253 * the world.
254 */
256{
257 void (*get_tracked_pose)(struct t_constellation_tracker_tracking_source *,
258 int64_t when_ns,
259 struct xrt_space_relation *out_relation);
260};
261
262/*!
263 * Helper function for @ref t_constellation_tracker_tracking_source::get_tracked_pose.
264 *
265 * @copydoc t_constellation_tracker_tracking_source::get_tracked_pose
266 *
267 * @public @memberof t_constellation_tracker_tracking_source
268 */
269XRT_NONNULL_ALL static inline void
271 struct t_constellation_tracker_tracking_source *tracking_source,
272 int64_t when_ns,
273 struct xrt_space_relation *out_relation)
274{
275 tracking_source->get_tracked_pose(tracking_source, when_ns, out_relation);
276}
277
278
280{
281 //! The position of the LED in the model.
283 //! The normal of the LED, determines where it is facing
285 //! The visible radius of the LED in meters.
286 float radius_m;
287 //! The angle from dead on where the LED is no longer visible, in radians.
289 //! A unique ID for this LED, which distinguishes it from all other LEDs.
290 t_constellation_led_id_it id;
291};
292
294{
295 //! The minimum number of LEDs required to accept a brute-force solve without a prior.
297 /*!
298 * The minimum number of LEDs required to accept a brute-force solve with a prior that said solve agrees with.
299 * If the solve has this many LEDs, but it doesn't agree with the prior, then the solve is only accepted if it
300 * has @ref min_leds_for_correspondence_search_without_prior LEDs matched.
301 */
303};
304
305/*!
306 * @interface t_constellation_tracker_led_model
307 *
308 * The LED model is a series of points which define the real-world positions of all LEDs. Some LED
309 * models may have self-occluding areas, such as WMR, where inner LEDs can be blocked by the ring,
310 * such occlusions are modelled through the LED visibility computation function.
311 */
313{
314 //! The LEDs in this model.
316 //! The number of LEDs in this model.
317 uint32_t led_count;
318
319 //! The match parameters to tweak how the tracker works.
321
322 /*!
323 * A function to compute whether a given LED is visible from a given position. This is used
324 * to allow devices to better model complex occlusion scenarios, like the inward facing LEDs
325 * on the WMR rings.
326 *
327 * @param led_model The LED model containing the LED in question.
328 * @param led The index of the LED in question in the model.
329 * @param T_obj_cam The transform from the root of the LED model to the camera. Assume
330 * camera is facing the origin of the LED model.
331 *
332 * @return Whether the LED is visible from the given position.
333 */
335 uint32_t led,
336 struct xrt_vec3 T_obj_cam);
337};
338
339/*!
340 * Helper function for @ref t_constellation_tracker_led_model::compute_led_visibility.
341 *
342 * @copydoc t_constellation_tracker_led_model::compute_led_visibility
343 *
344 * @public @memberof t_constellation_tracker_led_model
345 */
346XRT_NONNULL_ALL static inline bool
348 uint32_t led,
349 struct xrt_vec3 T_obj_cam)
350{
351 return led_model->compute_led_visibility(led_model, led, T_obj_cam);
352}
353
354
356{
357 //! The amount of blobs that were matched
359 //! The amount of LEDs that should be visible
361 //! The reprojection error of the solve's LEDs to the blobs, in pixels.
363};
364
366{
367 //! Whether the LED was observed in this sample.
369 //! The observed brightness of the LED, taken by dividing the greysum by the blob's area.
371 //! The total light of the LED's blob above the noise floor, in full-scale pixels.
372 float greysum;
373 //! The facing dot product of the LED.
375};
376
378{
379 //! The time the original blobservation was made.
381 //! The sequence ID of the mosaic
382 uint64_t sequence_id;
383 /*!
384 * Whether the `world_pose` field is valid or not.
385 *
386 * In certain cases, cameras are able to observe a device without themselves knowing where they are yet.
387 */
389 //! The pose of the device at the time of the blobservation.
390
392 //! The mosaic index of the camera that made the blobservation in question.
393 uint32_t mosaic_index;
394 //! The index of the camera in the mosaic that made the blobservation in question.
395 uint32_t camera_index;
396 /*!
397 * Average brightness of the detected blobs, from 0 (black) to 1 (pure white).
398 * This is the averaged greysum of all LEDs.
399 */
401 //! Metrics about the sample, such as reprojection error and matched LED count.
403 //! The LEDs that were observed in this solve.
405};
406
407/*!
408 * @interface t_constellation_tracker_device
409 *
410 * A constellation tracker device is a device that the constellation tracker will attempt to track
411 * in 6dof. The constellation tracker will provide the device with samples of it's current pose as
412 * it tracks it.
413 */
415{
416 /*!
417 * A function that the constellation tracker will call to push the latest sample.
418 *
419 * This isn't intended to be used for tracking, but rather for
420 * precise feedback about which LEDs are seen for systems like LED sync.
421 *
422 * @param connection The device to push the sample to.
423 * @param sample The sample containing the solved sample of the device and the timestamp of
424 * the original blobservation that led to this pose being computed.
425 */
427 struct t_constellation_tracker_sample *sample);
428};
429
430/*!
431 * Helper function for @ref t_constellation_tracker_device::push_constellation_tracker_sample.
432 *
433 * @copydoc t_constellation_tracker_device::push_constellation_tracker_sample
434 *
435 * @public @memberof t_constellation_tracker_device
436 */
437XRT_NONNULL_ALL static inline void
443
444#ifdef __cplusplus
445}
446#endif
Definition t_constellation.h:104
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:111
struct xrt_frame * frame
Optional reference to the frame the blobs were extracted from, may be NULL.
Definition t_constellation.h:126
uint64_t sequence_id
The sequence ID of this mosaic, must be stable across all frames of a mosaic. Monotonically increases...
Definition t_constellation.h:114
A generic interface to allow a tracking system to receive "snapshots" of seen t_blob in a frame.
Definition t_constellation.h:136
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:144
void(* destroy)(struct t_blob_sink *tbs)
Destroy this blob sink.
Definition t_constellation.h:149
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:160
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:173
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:51
float brightness
The brightness of the blob, from 0-1, taken by dividing the greysum over it's area.
Definition t_constellation.h:95
float greysum
The total light of the blob above the noise floor, in full-scale pixels.
Definition t_constellation.h:98
t_constellation_led_id_it matched_device_led_id
The LED ID this blob is associated with, if any.
Definition t_constellation.h:69
t_constellation_device_id_t matched_device_id
The device ID this blob is associated with, if any.
Definition t_constellation.h:63
struct xrt_vec2 center_undistorted
Center of blob, in undistorted pixels.
Definition t_constellation.h:75
struct xrt_vec2 motion_vector
Estimated motion vector of blob, in distorted pixels per second.
Definition t_constellation.h:84
struct xrt_vec3 center_homogenized
Center of blob, in homogenized coordinates.
Definition t_constellation.h:78
uint32_t blob_id
The ID of a blob, which may be used to track it across frames.
Definition t_constellation.h:57
struct xrt_vec2 center_distorted
Centre of blob, in distorted pixels.
Definition t_constellation.h:72
struct xrt_rect bounding_box
The bounding box of the blob in distorted pixel coordinates.
Definition t_constellation.h:87
Definition t_constellation.h:187
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:218
static XRT_NONNULL_ALL void t_blobwatch_destroy(struct t_blobwatch **tbw_ptr)
Helper function for t_blobwatch::destroy.
Definition t_constellation.h:233
void(* destroy)(struct t_blobwatch *tbw)
Destroy this blobwatch.
Definition t_constellation.h:207
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:200
A constellation tracker device is a device that the constellation tracker will attempt to track in 6d...
Definition t_constellation.h:415
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:438
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 the latest sample.
Definition t_constellation.h:426
uint32_t min_leds_for_correspondence_search_with_prior
The minimum number of LEDs required to accept a brute-force solve with a prior that said solve agrees...
Definition t_constellation.h:302
uint32_t min_leds_for_correspondence_search_without_prior
The minimum number of LEDs required to accept a brute-force solve without a prior.
Definition t_constellation.h:296
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:313
struct t_constellation_tracker_led_model_match_parameters match_parameters
The match parameters to tweak how the tracker works.
Definition t_constellation.h:320
static XRT_NONNULL_ALL bool t_constellation_tracker_led_model_compute_led_visibility(struct t_constellation_tracker_led_model *led_model, uint32_t led, struct xrt_vec3 T_obj_cam)
Helper function for t_constellation_tracker_led_model::compute_led_visibility.
Definition t_constellation.h:347
uint32_t led_count
The number of LEDs in this model.
Definition t_constellation.h:317
bool(* compute_led_visibility)(struct t_constellation_tracker_led_model *led_model, uint32_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:334
struct t_constellation_tracker_led * leds
The LEDs in this model.
Definition t_constellation.h:315
Definition t_constellation.h:280
float radius_m
The visible radius of the LED in meters.
Definition t_constellation.h:286
float visibility_angle
The angle from dead on where the LED is no longer visible, in radians.
Definition t_constellation.h:288
struct xrt_vec3 position
The position of the LED in the model.
Definition t_constellation.h:282
t_constellation_led_id_it id
A unique ID for this LED, which distinguishes it from all other LEDs.
Definition t_constellation.h:290
struct xrt_vec3 normal
The normal of the LED, determines where it is facing.
Definition t_constellation.h:284
Definition t_constellation.h:366
bool observed
Whether the LED was observed in this sample.
Definition t_constellation.h:368
float brightness
The observed brightness of the LED, taken by dividing the greysum by the blob's area.
Definition t_constellation.h:370
float greysum
The total light of the LED's blob above the noise floor, in full-scale pixels.
Definition t_constellation.h:372
float facing_dot
The facing dot product of the LED.
Definition t_constellation.h:374
Definition t_constellation.h:356
uint32_t visible_led_count
The amount of LEDs that should be visible.
Definition t_constellation.h:360
double reprojection_error
The reprojection error of the solve's LEDs to the blobs, in pixels.
Definition t_constellation.h:362
uint32_t matched_blob_count
The amount of blobs that were matched.
Definition t_constellation.h:358
Definition t_constellation.h:378
float average_brightness
Average brightness of the detected blobs, from 0 (black) to 1 (pure white).
Definition t_constellation.h:400
struct t_constellation_tracker_observed_led leds[64]
The LEDs that were observed in this solve.
Definition t_constellation.h:404
int64_t timestamp_ns
The time the original blobservation was made.
Definition t_constellation.h:380
uint32_t camera_index
The index of the camera in the mosaic that made the blobservation in question.
Definition t_constellation.h:395
bool has_world_pose
Whether the world_pose field is valid or not.
Definition t_constellation.h:388
struct t_constellation_tracker_sample_metrics metrics
Metrics about the sample, such as reprojection error and matched LED count.
Definition t_constellation.h:402
uint32_t mosaic_index
The mosaic index of the camera that made the blobservation in question.
Definition t_constellation.h:393
struct xrt_pose world_pose
The pose of the device at the time of the blobservation.
Definition t_constellation.h:391
uint64_t sequence_id
The sequence ID of the mosaic.
Definition t_constellation.h:382
A constellation tracker tracking source is an arbitrary source of tracking data for the constellation...
Definition t_constellation.h:256
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:270
Basic frame data structure - holds a pointer to buffer.
Definition xrt_frame.h:25
A pose composed of a position and orientation.
Definition xrt_defines.h:535
Image rectangle.
Definition xrt_defines.h:500
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:726
A 2 element vector with single floats.
Definition xrt_defines.h:292
A 3 element vector with single floats.
Definition xrt_defines.h:323
#define XRT_CONSTELLATION_MAX_LEDS_PER_DEVICE
The maximum number of LEDs that a single device can have.
Definition t_constellation.h:37
Common defines and enums for XRT.