···11-// Copyright 2023, Collabora, Ltd.
11+// Copyright 2023-2024, Collabora, Ltd.
22// SPDX-License-Identifier: BSL-1.0
33/*!
44 * @file
···88 * @author Jakob Bornecrantz <jakob@collabora.com>
99 *
1010 * This file contains the declaration of the @ref vit_tracker struct. This
1111- * header is intended to appear in both Monado and external SLAM systems. The
1212- * implementation of `vit_interface` is provided by the external system.
1313- * Additional data types are declared for the communication between Monado and
1414- * the system.
1111+ * header is intended to appear in both consumers (e.g., Monado) and external
1212+ * visual-inertial tracking (VIT) systems (e.g., Basalt). The implementation of
1313+ * `vit_interface` is provided by the external system. Additional data types are
1414+ * declared for the communication between consumers and the system.
1515 */
16161717#pragma once
···2020extern "C" {
2121#endif
22222323-#include <stdint.h>
2423#include <stdbool.h>
2424+#include <stdint.h>
25252626-// For implementation: same as IMPLEMENTATION_VERSION_*
2727-// For user: expected IMPLEMENTATION_VERSION_*. Should be checked in runtime.
2626+//! Compatibility with these values should be checked against @ref vit_api_get_version.
2827#define VIT_HEADER_VERSION_MAJOR 1 //!< API Breakages
2928#define VIT_HEADER_VERSION_MINOR 0 //!< Backwards compatible API changes
3030-#define VIT_HEADER_VERSION_PATCH 0 //!< Backw. comp. .h-implemented changes
2929+#define VIT_HEADER_VERSION_PATCH 1 //!< Backw. comp. .h-implemented changes
3030+3131+#define VIT_CAMERA_CALIBRATION_DISTORTION_MAX_COUNT 32
31323233/*!
3334 * Result type used by the VIT system
3435 *
3536 * 0 is @ref VIT_SUCCESS, positive values are non fatal results and negative values are errors.
3637 */
3737-typedef enum vit_result
3838-{
3838+typedef enum vit_result {
3939 /*!
4040 * Operation suceeded
4141 */
···7070/*!
7171 * Image formats.
7272 */
7373-typedef enum vit_image_format
7474-{
7373+typedef enum vit_image_format {
7574 //! 8-bit luminance
7675 VIT_IMAGE_FORMAT_L8 = 1,
7776 //! 16-bit luminance
···8382/*!
8483 * Camera calibration types.
8584 */
8686-typedef enum vit_camera_distortion
8787-{
8585+typedef enum vit_camera_distortion {
8886 //! No distortion (pre-disotorted).
8987 VIT_CAMERA_DISTORTION_NONE,
9088 //! Distortion radial-tangential (OpenCV), 4 parameters.
···10098/*!
10199 * Capabilities of the tracker.
102100 */
103103-typedef enum vit_tracker_capability
104104-{
101101+typedef enum vit_tracker_capability {
105102 //! Does the tracker support per pose (frame) timing data.
106103 VIT_TRACKER_CAPABILITY_CAMERA_CALIBRATION = 1 << 0,
107104 //! Does the tracker support per pose (frame) and per camera features.
···111108/*!
112109 * Capabilities of the poses that this tracker produces.
113110 */
114114-typedef enum vit_tracker_pose_capability
115115-{
111111+typedef enum vit_tracker_pose_capability {
116112 //! Does the tracker support per pose (frame) timing data.
117113 VIT_TRACKER_POSE_CAPABILITY_TIMING = 1 << 0,
118114 //! Does the tracker support per pose (frame) and per camera features.
···134130/*!
135131 * @brief Names of the timestamps returned by `vit_pose_get_timings`
136132 */
137137-typedef struct vit_tracker_timing_titles
138138-{
139139- uint32_t count; //! Number of titles
133133+typedef struct vit_tracker_timing_titles {
134134+ uint32_t count; //! Number of titles
140135 const char **titles; //! Names of the measures timestamps
141136} vit_tracker_timing_titles;
142137···174169/*!
175170 * Region in image space that this mask covers.
176171 */
177177-typedef struct vit_mask
178178-{
172172+typedef struct vit_mask {
179173 //! In pixels.
180174 float x, y, w, h;
181175} vit_mask_t;
···253247typedef struct vit_camera_calibration {
254248 uint32_t camera_index; // <! For multi-camera setup. For stereo 0 ~ left, 1 ~ right.
255249256256- int width, height; //<! Resolution
257257- double frequency; //<! Frames per second
258258- double fx, fy; //<! Focal point
259259- double cx, cy; //<! Principal point
250250+ int width, height; //<! Resolution
251251+ double frequency; //<! Frames per second
252252+ double fx, fy; //<! Focal point
253253+ double cx, cy; //<! Principal point
260254 enum vit_camera_distortion model;
261255 uint32_t distortion_count;
262262- double distortion[32]; //!< Parameters for the distortion model
263263- double transform[16]; //!< Row-major 4x4 camera transform w.r.t. the IMU (i.e., T_imu_cam)
256256+ double distortion[VIT_CAMERA_CALIBRATION_DISTORTION_MAX_COUNT]; //!< Parameters for the distortion model
257257+ double transform[4 * 4]; //!< Row-major 4x4 camera transform w.r.t. the IMU (i.e., T_imu_cam)
264258} vit_camera_calibration_t;
265259266260typedef struct vit_inertial_calibration {
267261 // Calibration intrinsics to apply to each raw measurement.
268262269263 //! Row major 3x3 linear transformation for raw measurements alignment and scaling.
270270- double transform[9];
264264+ double transform[3 * 3];
271265272266 //! Offset to add to raw measurements; called bias in other contexts.
273267 double offset[3];
···297291 struct vit_inertial_calibration gyro;
298292} vit_imu_calibration_t;
299293300300-301294/*
302295 *
303296 * Function prototypes.
···307300typedef vit_result_t (*PFN_vit_api_get_version)(uint32_t *out_major, uint32_t *out_minor, uint32_t *out_patch);
308301typedef vit_result_t (*PFN_vit_tracker_create)(const vit_config_t *config, vit_tracker_t **out_tracker);
309302typedef void (*PFN_vit_tracker_destroy)(vit_tracker_t *tracker);
310310-typedef vit_result_t (*PFN_vit_tracker_has_image_format)(const vit_tracker_t *tracker, const vit_image_format_t image_format, bool *out_supported);
311311-typedef vit_result_t (*PFN_vit_tracker_get_capabilities)(const vit_tracker_t *tracker, vit_tracker_capability_t *out_caps);
312312-typedef vit_result_t (*PFN_vit_tracker_get_pose_capabilities)(const vit_tracker_t *tracker, vit_tracker_pose_capability_t *out_caps);
313313-typedef vit_result_t (*PFN_vit_tracker_set_pose_capabilities)(vit_tracker_t *tracker, const vit_tracker_pose_capability_t caps, bool value);
303303+typedef vit_result_t (*PFN_vit_tracker_has_image_format)(const vit_tracker_t *tracker, vit_image_format_t image_format,
304304+ bool *out_supported);
305305+typedef vit_result_t (*PFN_vit_tracker_get_capabilities)(const vit_tracker_t *tracker,
306306+ vit_tracker_capability_t *out_caps);
307307+typedef vit_result_t (*PFN_vit_tracker_get_pose_capabilities)(const vit_tracker_t *tracker,
308308+ vit_tracker_pose_capability_t *out_caps);
309309+typedef vit_result_t (*PFN_vit_tracker_set_pose_capabilities)(vit_tracker_t *tracker,
310310+ vit_tracker_pose_capability_t caps, bool value);
314311typedef vit_result_t (*PFN_vit_tracker_start)(vit_tracker_t *tracker);
315312typedef vit_result_t (*PFN_vit_tracker_stop)(vit_tracker_t *tracker);
316313typedef vit_result_t (*PFN_vit_tracker_reset)(vit_tracker_t *tracker);
317314typedef vit_result_t (*PFN_vit_tracker_is_running)(const vit_tracker_t *tracker, bool *out_bool);
318315typedef vit_result_t (*PFN_vit_tracker_push_imu_sample)(vit_tracker_t *tracker, const vit_imu_sample_t *sample);
319316typedef vit_result_t (*PFN_vit_tracker_push_img_sample)(vit_tracker_t *tracker, const vit_img_sample_t *sample);
320320-typedef vit_result_t (*PFN_vit_tracker_add_imu_calibration)(vit_tracker_t *tracker, const vit_imu_calibration_t *calibration);
321321-typedef vit_result_t (*PFN_vit_tracker_add_camera_calibration)(vit_tracker_t *tracker, const vit_camera_calibration_t *calibration);
317317+typedef vit_result_t (*PFN_vit_tracker_add_imu_calibration)(vit_tracker_t *tracker,
318318+ const vit_imu_calibration_t *calibration);
319319+typedef vit_result_t (*PFN_vit_tracker_add_camera_calibration)(vit_tracker_t *tracker,
320320+ const vit_camera_calibration_t *calibration);
322321typedef vit_result_t (*PFN_vit_tracker_pop_pose)(vit_tracker_t *tracker, vit_pose_t **out_pose);
323323-typedef vit_result_t (*PFN_vit_tracker_get_timing_titles)(const vit_tracker_t *tracker, vit_tracker_timing_titles *out_titles);
322322+typedef vit_result_t (*PFN_vit_tracker_get_timing_titles)(const vit_tracker_t *tracker,
323323+ vit_tracker_timing_titles *out_titles);
324324typedef void (*PFN_vit_pose_destroy)(vit_pose_t *pose);
325325typedef vit_result_t (*PFN_vit_pose_get_data)(const vit_pose_t *pose, vit_pose_data_t *out_data);
326326typedef vit_result_t (*PFN_vit_pose_get_timing)(const vit_pose_t *pose, vit_pose_timing_t *out_timing);
327327-typedef vit_result_t (*PFN_vit_pose_get_features)(const vit_pose_t *pose, uint32_t camera_index, vit_pose_features_t *out_features);
328328-327327+typedef vit_result_t (*PFN_vit_pose_get_features)(const vit_pose_t *pose, uint32_t camera_index,
328328+ vit_pose_features_t *out_features);
329329330330/*
331331 *
···338338/*!
339339 * @brief Returns the API version implemented by the VIT system.
340340 */
341341-vit_result_t
342342-vit_api_get_version(uint32_t *out_major, uint32_t *out_minor, uint32_t *out_patch);
341341+vit_result_t vit_api_get_version(uint32_t *out_major, uint32_t *out_minor, uint32_t *out_patch);
343342344343/*!
345344 * @brief Creates a new VIT tracker. The caller is responsible of destroying it when done.
346345 */
347347-vit_result_t
348348-vit_tracker_create(const vit_config_t *config, vit_tracker_t **out_tracker);
346346+vit_result_t vit_tracker_create(const vit_config_t *config, vit_tracker_t **out_tracker);
349347350348/*!
351349 * @brief Destroys the VIT tracker and free all resources allocated.
352350 */
353353-void
354354-vit_tracker_destroy(vit_tracker_t *tracker);
351351+void vit_tracker_destroy(vit_tracker_t *tracker);
355352356353/*!
357354 * @brief Verifies if the tracker supports a given `vit_image_format_t`.
358355 */
359359-vit_result_t
360360-vit_tracker_has_image_format(const vit_tracker_t *tracker, const vit_image_format_t image_format, bool *out_supported);
356356+vit_result_t vit_tracker_has_image_format(const vit_tracker_t *tracker, vit_image_format_t image_format,
357357+ bool *out_supported);
361358362359/*!
363360 * @brief Returns a bitfield of capabilities supported by the tracker.
···365362 * @see vit_tracker_capability_t
366363 */
367364368368-vit_result_t
369369-vit_tracker_get_capabilities(const vit_tracker_t *tracker, vit_tracker_capability_t *out_caps);
365365+vit_result_t vit_tracker_get_capabilities(const vit_tracker_t *tracker, vit_tracker_capability_t *out_caps);
370366371367/*!
372368 * @brief Returns a bitfield of pose capabilities supported by the tracker.
373369 *
374370 * @see vit_tracker_pose_capability_t
375371 */
376376-vit_result_t
377377-vit_tracker_get_pose_capabilities(const vit_tracker_t *tracker, vit_tracker_pose_capability_t *out_caps);
372372+vit_result_t vit_tracker_get_pose_capabilities(const vit_tracker_t *tracker, vit_tracker_pose_capability_t *out_caps);
378373379374/*!
380375 * @brief Enables or disables multiple tracker pose capabilities.
···383378 *
384379 * @see vit_tracker_pose_capability_t
385380 */
386386-vit_result_t
387387-vit_tracker_set_pose_capabilities(vit_tracker_t *tracker, const vit_tracker_pose_capability_t caps, bool value);
381381+vit_result_t vit_tracker_set_pose_capabilities(vit_tracker_t *tracker, vit_tracker_pose_capability_t caps, bool value);
388382389383/*!
390384 * @brief Starts the VIT tracker. Image and IMU samples can be pushed and pose can be retrieved.
391385 *
392386 * This function must be non blocking. The VIT system implementing it is expected to start its own event loop.
393387 */
394394-vit_result_t
395395-vit_tracker_start(vit_tracker_t *tracker);
388388+vit_result_t vit_tracker_start(vit_tracker_t *tracker);
396389397390/*!
398391 * @brief Stops the VIT tracker. The tracker wont accept image and IMU samples, and will not return poses.
399392 */
400400-vit_result_t
401401-vit_tracker_stop(vit_tracker_t *tracker);
393393+vit_result_t vit_tracker_stop(vit_tracker_t *tracker);
402394403395/*!
404396 * @brief Resets the VIT tracker. The tracker internal state will be set to its original state.
405397 */
406406-vit_result_t
407407-vit_tracker_reset(vit_tracker_t *tracker);
398398+vit_result_t vit_tracker_reset(vit_tracker_t *tracker);
408399409400/*!
410401 * @brief Verifies if the tracker is running.
411402 */
412412-vit_result_t
413413-vit_tracker_is_running(const vit_tracker_t *tracker, bool *out_bool);
403403+vit_result_t vit_tracker_is_running(const vit_tracker_t *tracker, bool *out_bool);
414404415405/*!
416406 * @brief Push an IMU sample into the tracker.
···420410 * The implementation must be non-blocking.
421411 * Thus, a separate consumer thread should process the samples.
422412 */
423423-vit_result_t
424424-vit_tracker_push_imu_sample(vit_tracker_t *tracker, const vit_imu_sample_t *sample);
413413+vit_result_t vit_tracker_push_imu_sample(vit_tracker_t *tracker, const vit_imu_sample_t *sample);
425414426415/*!
427416 * @brief Push an image sample into the tracker.
···430419 * When using N>1 cameras, the N frames must be pushed following @ref cam_index order.
431420 * The bundle of N frames must have the same timestamps.
432421 */
433433-vit_result_t
434434-vit_tracker_push_img_sample(vit_tracker_t *tracker, const vit_img_sample_t *sample);
422422+vit_result_t vit_tracker_push_img_sample(vit_tracker_t *tracker, const vit_img_sample_t *sample);
435423436424/*!
437425 * @brief Adds an inertial measurement unit calibration to the tracker. The tracker must not be started.
···441429 * @see vit_tracker_get_capabilities
442430 * @see vit_tracker_capability_t
443431 */
444444-vit_result_t
445445-vit_tracker_add_imu_calibration(vit_tracker_t *tracker, const vit_imu_calibration_t *calibration);
432432+vit_result_t vit_tracker_add_imu_calibration(vit_tracker_t *tracker, const vit_imu_calibration_t *calibration);
446433447434/*!
448435 * @brief Adds a camera calibration to the tracker. The tracker must not be started.
···452439 * @see vit_tracker_get_capabilities
453440 * @see vit_tracker_capability_t
454441 */
455455-vit_result_t
456456-vit_tracker_add_camera_calibration(vit_tracker_t *tracker, const vit_camera_calibration_t *calibration);
442442+vit_result_t vit_tracker_add_camera_calibration(vit_tracker_t *tracker, const vit_camera_calibration_t *calibration);
457443458444/*!
459445 * @brief Get the pose from the front of the tracking queue from the VIT tracker
···464450 *
465451 * @param[out] out_pose Pose returned to the caller, NULL if there is not pose available or on error.
466452 */
467467-vit_result_t
468468-vit_tracker_pop_pose(vit_tracker_t *tracker, vit_pose_t **out_pose);
453453+vit_result_t vit_tracker_pop_pose(vit_tracker_t *tracker, vit_pose_t **out_pose);
469454470455/*!
471456 * @brief Get the titles of the timestamps measured by the pose timings.
472457 *
473458 * Returns `VIT_ERROR_NOT_SUPPORTED` if the tracker doesn't offer the pose timing capability.
474459 */
475475-vit_result_t
476476-vit_tracker_get_timing_titles(const vit_tracker_t *tracker, vit_tracker_timing_titles *out_titles);
460460+vit_result_t vit_tracker_get_timing_titles(const vit_tracker_t *tracker, vit_tracker_timing_titles *out_titles);
477461478462/*!
479463 * @brief Destroys a pose. All of the data, timing and features associated to it will be invalidated.
480464 */
481481-void
482482-vit_pose_destroy(vit_pose_t *pose);
465465+void vit_pose_destroy(vit_pose_t *pose);
483466484467/*!
485468 * @brief Gets the data form a given `vit_pose_t`.
486469 *
487470 * The data becomes invalid when the associated pose gets destroyed.
488471 */
489489-vit_result_t
490490-vit_pose_get_data(const vit_pose_t *pose, vit_pose_data_t *out_data);
472472+vit_result_t vit_pose_get_data(const vit_pose_t *pose, vit_pose_data_t *out_data);
491473492474/*!
493475 * @brief Gets the timing form a given `vit_pose_t`.
494476 *
495477 * The timing data becomes invalid when the associated pose gets destroyed.
496478 */
497497-vit_result_t
498498-vit_pose_get_timing(const vit_pose_t *pose, vit_pose_timing_t *out_timing);
479479+vit_result_t vit_pose_get_timing(const vit_pose_t *pose, vit_pose_timing_t *out_timing);
499480500481/*!
501482 * @brief Gets the features form a given `vit_pose_t`.
502483 *
503484 * The features data becomes invalid when the associated pose gets destroyed.
504485 */
505505-vit_result_t
506506-vit_pose_get_features(const vit_pose_t *pose, uint32_t camera_index, vit_pose_features_t *out_features);
486486+vit_result_t vit_pose_get_features(const vit_pose_t *pose, uint32_t camera_index, vit_pose_features_t *out_features);
507487508488#endif
509489