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