Monado OpenXR Runtime
m_filter_fifo.c File Reference

A fifo that also lets you dynamically filter. More...

#include "util/u_misc.h"
#include "math/m_filter_fifo.h"
#include <assert.h>
Include dependency graph for m_filter_fifo.c:

Data Structures

struct  m_ff_vec3_f32
 
struct  m_ff_f64
 

Functions

static void vec3_f32_init (struct m_ff_vec3_f32 *ff, size_t num)
 
static void vec3_f32_destroy (struct m_ff_vec3_f32 *ff)
 
void m_ff_vec3_f32_alloc (struct m_ff_vec3_f32 **ff_out, size_t num)
 Allocates a filter fifo tracking num samples and fills it with num samples at timepoint zero. More...
 
void m_ff_vec3_f32_free (struct m_ff_vec3_f32 **ff_ptr)
 Frees the given filter fifo and all its samples. More...
 
size_t m_ff_vec3_f32_get_num (struct m_ff_vec3_f32 *ff)
 Return the number of samples that can fill the fifo. More...
 
void m_ff_vec3_f32_push (struct m_ff_vec3_f32 *ff, const struct xrt_vec3 *sample, uint64_t timestamp_ns)
 Pushes a sample at the given timepoint, pushing samples out of order yields unspecified behaviour, so samples must be pushed in time order. More...
 
bool m_ff_vec3_f32_get (struct m_ff_vec3_f32 *ff, size_t num, struct xrt_vec3 *out_sample, uint64_t *out_timestamp_ns)
 Return the sample at the index, zero means the last sample push, one second last and so on. More...
 
size_t m_ff_vec3_f32_filter (struct m_ff_vec3_f32 *ff, uint64_t start_ns, uint64_t stop_ns, struct xrt_vec3 *out_average)
 Averages all samples in the fifo between the two timepoints, returns number of samples sampled, if no samples was found between the timpoints returns 0 and sets out_average to all zeros. More...
 
static void ff_f64_init (struct m_ff_f64 *ff, size_t num)
 
static void ff_f64_destroy (struct m_ff_f64 *ff)
 
void m_ff_f64_alloc (struct m_ff_f64 **ff_out, size_t num)
 Allocates a filter fifo tracking num samples and fills it with num samples at timepoint zero. More...
 
void m_ff_f64_free (struct m_ff_f64 **ff_ptr)
 Frees the given filter fifo and all its samples. More...
 
size_t m_ff_f64_get_num (struct m_ff_f64 *ff)
 Return the number of samples that can fill the fifo. More...
 
void m_ff_f64_push (struct m_ff_f64 *ff, const double *sample, uint64_t timestamp_ns)
 Pushes a sample at the given timepoint, pushing samples out of order yields unspecified behaviour, so samples must be pushed in time order. More...
 
bool m_ff_f64_get (struct m_ff_f64 *ff, size_t num, double *out_sample, uint64_t *out_timestamp_ns)
 Return the sample at the index, 0 means the last sample push, 1 second-to-last, etc. More...
 
size_t m_ff_f64_filter (struct m_ff_f64 *ff, uint64_t start_ns, uint64_t stop_ns, double *out_average)
 Averages all samples in the fifo between the two timepoints, returns number of samples sampled, if no samples was found between the timpoints returns 0 and sets out_average to all zeros. More...
 

Detailed Description

A fifo that also lets you dynamically filter.

Author
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Function Documentation

◆ m_ff_f64_alloc()

void m_ff_f64_alloc ( struct m_ff_f64 **  ff_out,
size_t  num 
)

Allocates a filter fifo tracking num samples and fills it with num samples at timepoint zero.

References U_TYPED_CALLOC.

◆ m_ff_f64_filter()

size_t m_ff_f64_filter ( struct m_ff_f64 ff,
uint64_t  start_ns,
uint64_t  stop_ns,
double *  out_average 
)

Averages all samples in the fifo between the two timepoints, returns number of samples sampled, if no samples was found between the timpoints returns 0 and sets out_average to all zeros.

Parameters
ffFilter fifo to search in.
start_nsTimepoint furthest in the past, to start searching for samples.
stop_nsTimepoint closest in the past, or now, to stop searching for samples.
out_averageAverage of all samples in the given timeframe.

◆ m_ff_f64_free()

void m_ff_f64_free ( struct m_ff_f64 **  ff_ptr)

Frees the given filter fifo and all its samples.

◆ m_ff_f64_get()

bool m_ff_f64_get ( struct m_ff_f64 ff,
size_t  num,
double *  out_sample,
uint64_t *  out_timestamp_ns 
)

Return the sample at the index, 0 means the last sample push, 1 second-to-last, etc.

◆ m_ff_f64_get_num()

size_t m_ff_f64_get_num ( struct m_ff_f64 ff)

Return the number of samples that can fill the fifo.

◆ m_ff_f64_push()

void m_ff_f64_push ( struct m_ff_f64 ff,
const double *  sample,
uint64_t  timestamp_ns 
)

Pushes a sample at the given timepoint, pushing samples out of order yields unspecified behaviour, so samples must be pushed in time order.

◆ m_ff_vec3_f32_alloc()

void m_ff_vec3_f32_alloc ( struct m_ff_vec3_f32 **  ff_out,
size_t  num 
)

Allocates a filter fifo tracking num samples and fills it with num samples at timepoint zero.

References U_TYPED_CALLOC.

◆ m_ff_vec3_f32_filter()

size_t m_ff_vec3_f32_filter ( struct m_ff_vec3_f32 ff,
uint64_t  start_ns,
uint64_t  stop_ns,
struct xrt_vec3 out_average 
)

Averages all samples in the fifo between the two timepoints, returns number of samples sampled, if no samples was found between the timpoints returns 0 and sets out_average to all zeros.

Parameters
ffFilter fifo to search in.
start_nsTimepoint furthest in the past, to start searching for samples.
stop_nsTimepoint closest in the past, or now, to stop searching for samples.
out_averageAverage of all samples in the given timeframe.

◆ m_ff_vec3_f32_free()

void m_ff_vec3_f32_free ( struct m_ff_vec3_f32 **  ff_ptr)

Frees the given filter fifo and all its samples.

◆ m_ff_vec3_f32_get()

bool m_ff_vec3_f32_get ( struct m_ff_vec3_f32 ff,
size_t  num,
struct xrt_vec3 out_sample,
uint64_t *  out_timestamp_ns 
)

Return the sample at the index, zero means the last sample push, one second last and so on.

Referenced by xrt::auxiliary::tracking::slam::predict_pose_from_imu().

◆ m_ff_vec3_f32_get_num()

size_t m_ff_vec3_f32_get_num ( struct m_ff_vec3_f32 ff)

Return the number of samples that can fill the fifo.

◆ m_ff_vec3_f32_push()

void m_ff_vec3_f32_push ( struct m_ff_vec3_f32 ff,
const struct xrt_vec3 sample,
uint64_t  timestamp_ns 
)

Pushes a sample at the given timepoint, pushing samples out of order yields unspecified behaviour, so samples must be pushed in time order.