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 brightest pixel of the blob, on a scale from 0.0 (black) to 1.0 (pure white).
94 * Set to 1.0 for non-brightness-aware blobwatches.
95 */
97};
98
99struct xrt_frame;
100
102{
103 struct t_blobwatch *source;
104
105 /*!
106 * Internal ID for this observation, may be set by the blobwatch implementation if it needs
107 * to know this.
108 */
109 uint64_t id;
110
111 //! The sequence ID of this mosaic, must be stable across all frames of a mosaic. Monotonically increases.
112 uint64_t sequence_id;
113
114 int64_t timestamp_ns;
115 struct t_blob *blobs;
116 uint32_t num_blobs;
117
118 /*!
119 * Optional reference to the frame the blobs were extracted from, may be NULL.
120 *
121 * The reference is owned by the observation: the blob sink receiving it takes ownership and must release it
122 * with @ref xrt_frame_reference (or pass it on to another sink that does).
123 */
125};
126
127/*!
128 * @interface t_blob_sink
129 *
130 * A generic interface to allow a tracking system to receive "snapshots" of seen @ref t_blob in a
131 * frame.
132 */
134{
135 /*!
136 * Push a set of blobs into the sink. The tracking system will typically call this once per
137 * frame for each camera view.
138 *
139 * @param[in] tbs The sink to push the blobs into.
140 * @param[in] observation The blob observation to push into the sink.
141 */
142 void (*push_blobs)(struct t_blob_sink *tbs, struct t_blob_observation *observation);
143
144 /*!
145 * Destroy this blob sink.
146 */
147 void (*destroy)(struct t_blob_sink *tbs);
148};
149
150/*!
151 * Helper function for @ref t_blob_sink::push_blobs.
152 *
153 * @copydoc t_blob_sink::push_blobs
154 *
155 * @public @memberof t_blob_sink
156 */
157XRT_NONNULL_ALL static inline void
159{
160 tbs->push_blobs(tbs, tbo);
161}
162
163/*!
164 * Helper function for @ref t_blob_sink::destroy.
165 *
166 * Handles nulls, sets your pointer to null.
167 *
168 * @public @memberof t_blob_sink
169 */
170XRT_NONNULL_ALL static inline void
172{
173 struct t_blob_sink *tbs = *tbs_ptr;
174
175 if (tbs == NULL) {
176 return;
177 }
178
179 tbs->destroy(tbs);
180 *tbs_ptr = NULL;
181}
182
183
185{
186 /*!
187 * Notify the blobwatch that the blobs in the given observation with the correct ID set are
188 * associated with the given device. The blobwatch can use this information to track which
189 * blobs are associated with which devices across frames, and to provide this information to
190 * the tracker across frames to save it from doing that work again.
191 *
192 * @param[in] tbw The blobwatch to mark the blobs for.
193 * @param[in] tbo The observation containing the blobs to mark. The blobwatch will look at
194 * the blob IDs and the matched_device_id field to determine which blobs
195 * internally to mark with the given device ID.
196 * @param[in] device_id The device ID to mark
197 */
198 void (*mark_blob_device)(struct t_blobwatch *tbw,
199 const struct t_blob_observation *tbo,
200 t_constellation_device_id_t device_id);
201
202 /*!
203 * Destroy this blobwatch.
204 */
205 void (*destroy)(struct t_blobwatch *tbw);
206};
207
208/*!
209 * Helper function for @ref t_blobwatch::mark_blob_device.
210 *
211 * @copydoc t_blobwatch::mark_blob_device
212 *
213 * @public @memberof t_blobwatch
214 */
215XRT_NONNULL_ALL static inline void
217 const struct t_blob_observation *tbo,
218 t_constellation_device_id_t device_id)
219{
220 tbw->mark_blob_device(tbw, tbo, device_id);
221}
222
223/*!
224 * Helper function for @ref t_blobwatch::destroy.
225 *
226 * Handles nulls, sets your pointer to null.
227 *
228 * @public @memberof t_blobwatch
229 */
230XRT_NONNULL_ALL static inline void
232{
233 struct t_blobwatch *tbw = *tbw_ptr;
234
235 if (tbw == NULL) {
236 return;
237 }
238
239 tbw->destroy(tbw);
240 *tbw_ptr = NULL;
241}
242
243
244/*!
245 * @interface t_constellation_tracker_tracking_source
246 *
247 * A constellation tracker tracking source is an arbitrary source of tracking data for the
248 * constellation tracker. This is used by the constellation tracker to get the current pose of a
249 * device to eliminate bad guesses, or if a camera is anchored to a tracking source (a camera on a
250 * headset device), this can be used by the constellation tracker to locate that camera relative to
251 * the world.
252 */
254{
255 void (*get_tracked_pose)(struct t_constellation_tracker_tracking_source *,
256 int64_t when_ns,
257 struct xrt_space_relation *out_relation);
258};
259
260/*!
261 * Helper function for @ref t_constellation_tracker_tracking_source::get_tracked_pose.
262 *
263 * @copydoc t_constellation_tracker_tracking_source::get_tracked_pose
264 *
265 * @public @memberof t_constellation_tracker_tracking_source
266 */
267XRT_NONNULL_ALL static inline void
269 struct t_constellation_tracker_tracking_source *tracking_source,
270 int64_t when_ns,
271 struct xrt_space_relation *out_relation)
272{
273 tracking_source->get_tracked_pose(tracking_source, when_ns, out_relation);
274}
275
276
278{
279 //! The position of the LED in the model.
281 //! The normal of the LED, determines where it is facing
283 //! The visible radius of the LED in meters.
284 float radius_m;
285 //! The angle from dead on where the LED is no longer visible, in radians.
287 //! A unique ID for this LED, which distinguishes it from all other LEDs.
288 t_constellation_led_id_it id;
289};
290
292{
293 //! The minimum number of LEDs required to accept a brute-force solve without a prior.
295 /*!
296 * The minimum number of LEDs required to accept a brute-force solve with a prior that said solve agrees with.
297 * If the solve has this many LEDs, but it doesn't agree with the prior, then the solve is only accepted if it
298 * has @ref min_leds_for_correspondence_search_without_prior LEDs matched.
299 */
301};
302
303/*!
304 * @interface t_constellation_tracker_led_model
305 *
306 * The LED model is a series of points which define the real-world positions of all LEDs. Some LED
307 * models may have self-occluding areas, such as WMR, where inner LEDs can be blocked by the ring,
308 * such occlusions are modelled through the LED visibility computation function.
309 */
311{
312 //! The LEDs in this model.
314 //! The number of LEDs in this model.
315 uint32_t led_count;
316
317 //! The match parameters to tweak how the tracker works.
319
320 /*!
321 * A function to compute whether a given LED is visible from a given position. This is used
322 * to allow devices to better model complex occlusion scenarios, like the inward facing LEDs
323 * on the WMR rings.
324 *
325 * @param led_model The LED model containing the LED in question.
326 * @param led The index of the LED in question in the model.
327 * @param T_obj_cam The transform from the root of the LED model to the camera. Assume
328 * camera is facing the origin of the LED model.
329 *
330 * @return Whether the LED is visible from the given position.
331 */
333 uint32_t led,
334 struct xrt_vec3 T_obj_cam);
335};
336
337/*!
338 * Helper function for @ref t_constellation_tracker_led_model::compute_led_visibility.
339 *
340 * @copydoc t_constellation_tracker_led_model::compute_led_visibility
341 *
342 * @public @memberof t_constellation_tracker_led_model
343 */
344XRT_NONNULL_ALL static inline bool
346 uint32_t led,
347 struct xrt_vec3 T_obj_cam)
348{
349 return led_model->compute_led_visibility(led_model, led, T_obj_cam);
350}
351
352
354{
355 //! The amount of blobs that were matched
357 //! The amount of LEDs that should be visible
359 //! The reprojection error of the solve's LEDs to the blobs, in pixels.
361};
362
364{
365 //! The time the original blobservation was made.
367 //! The sequence ID of the mosaic
368 uint64_t sequence_id;
369 /*!
370 * Whether the `world_pose` field is valid or not.
371 *
372 * In certain cases, cameras are able to observe a device without themselves knowing where they are yet.
373 */
375 //! The pose of the device at the time of the blobservation.
376
378 //! The mosaic index of the camera that made the blobservation in question.
379 uint32_t mosaic_index;
380 //! The index of the camera in the mosaic that made the blobservation in question.
381 uint32_t camera_index;
382 //! Average brightness of the detected blobs, from 0 (black) to 1 (pure white).
384 //! Metrics about the sample, such as reprojection error and matched LED count.
386};
387
388/*!
389 * @interface t_constellation_tracker_device
390 *
391 * A constellation tracker device is a device that the constellation tracker will attempt to track
392 * in 6dof. The constellation tracker will provide the device with samples of it's current pose as
393 * it tracks it.
394 */
396{
397 /*!
398 * A function that the constellation tracker will call to push the latest sample.
399 *
400 * This isn't intended to be used for tracking, but rather for
401 * precise feedback about which LEDs are seen for systems like LED sync.
402 *
403 * @param connection The device to push the sample to.
404 * @param sample The sample containing the solved sample of the device and the timestamp of
405 * the original blobservation that led to this pose being computed.
406 */
408 struct t_constellation_tracker_sample *sample);
409};
410
411/*!
412 * Helper function for @ref t_constellation_tracker_device::push_constellation_tracker_sample.
413 *
414 * @copydoc t_constellation_tracker_device::push_constellation_tracker_sample
415 *
416 * @public @memberof t_constellation_tracker_device
417 */
418XRT_NONNULL_ALL static inline void
424
425#ifdef __cplusplus
426}
427#endif
Definition t_constellation.h:102
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:109
struct xrt_frame * frame
Optional reference to the frame the blobs were extracted from, may be NULL.
Definition t_constellation.h:124
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:112
A generic interface to allow a tracking system to receive "snapshots" of seen t_blob in a frame.
Definition t_constellation.h:134
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:142
void(* destroy)(struct t_blob_sink *tbs)
Destroy this blob sink.
Definition t_constellation.h:147
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:158
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:171
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 brightest pixel of the blob, on a scale from 0.0 (black) to 1....
Definition t_constellation.h:96
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:185
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:216
static XRT_NONNULL_ALL void t_blobwatch_destroy(struct t_blobwatch **tbw_ptr)
Helper function for t_blobwatch::destroy.
Definition t_constellation.h:231
void(* destroy)(struct t_blobwatch *tbw)
Destroy this blobwatch.
Definition t_constellation.h:205
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:198
A constellation tracker device is a device that the constellation tracker will attempt to track in 6d...
Definition t_constellation.h:396
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:419
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:407
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:300
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:294
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:311
struct t_constellation_tracker_led_model_match_parameters match_parameters
The match parameters to tweak how the tracker works.
Definition t_constellation.h:318
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:345
uint32_t led_count
The number of LEDs in this model.
Definition t_constellation.h:315
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:332
struct t_constellation_tracker_led * leds
The LEDs in this model.
Definition t_constellation.h:313
Definition t_constellation.h:278
float radius_m
The visible radius of the LED in meters.
Definition t_constellation.h:284
float visibility_angle
The angle from dead on where the LED is no longer visible, in radians.
Definition t_constellation.h:286
struct xrt_vec3 position
The position of the LED in the model.
Definition t_constellation.h:280
t_constellation_led_id_it id
A unique ID for this LED, which distinguishes it from all other LEDs.
Definition t_constellation.h:288
struct xrt_vec3 normal
The normal of the LED, determines where it is facing.
Definition t_constellation.h:282
Definition t_constellation.h:354
uint32_t visible_led_count
The amount of LEDs that should be visible.
Definition t_constellation.h:358
double reprojection_error
The reprojection error of the solve's LEDs to the blobs, in pixels.
Definition t_constellation.h:360
uint32_t matched_blob_count
The amount of blobs that were matched.
Definition t_constellation.h:356
Definition t_constellation.h:364
float average_brightness
Average brightness of the detected blobs, from 0 (black) to 1 (pure white).
Definition t_constellation.h:383
int64_t timestamp_ns
The time the original blobservation was made.
Definition t_constellation.h:366
uint32_t camera_index
The index of the camera in the mosaic that made the blobservation in question.
Definition t_constellation.h:381
bool has_world_pose
Whether the world_pose field is valid or not.
Definition t_constellation.h:374
struct t_constellation_tracker_sample_metrics metrics
Metrics about the sample, such as reprojection error and matched LED count.
Definition t_constellation.h:385
uint32_t mosaic_index
The mosaic index of the camera that made the blobservation in question.
Definition t_constellation.h:379
struct xrt_pose world_pose
The pose of the device at the time of the blobservation.
Definition t_constellation.h:377
uint64_t sequence_id
The sequence ID of the mosaic.
Definition t_constellation.h:368
A constellation tracker tracking source is an arbitrary source of tracking data for the constellation...
Definition t_constellation.h:254
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:268
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:522
Image rectangle.
Definition xrt_defines.h:487
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:713
A 2 element vector with single floats.
Definition xrt_defines.h:279
A 3 element vector with single floats.
Definition xrt_defines.h:310
Common defines and enums for XRT.