2021-09-15 17:12:43 +00:00
|
|
|
// Copyright 2021, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Small utility for keeping track of the history of an xrt_space_relation, ie. for knowing where a HMD or
|
|
|
|
* controller was in the past
|
|
|
|
* @author Moses Turner <moses@collabora.com>
|
|
|
|
* @ingroup drv_ht
|
|
|
|
*/
|
2021-12-02 21:11:11 +00:00
|
|
|
#pragma once
|
2021-09-15 17:12:43 +00:00
|
|
|
|
|
|
|
#include "xrt/xrt_defines.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-12-02 21:11:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Opaque type for storing the history of a space relation in a ring buffer
|
2021-09-15 17:12:43 +00:00
|
|
|
*
|
|
|
|
* @ingroup aux_util
|
|
|
|
*/
|
2021-12-02 21:11:11 +00:00
|
|
|
struct m_relation_history;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Describes how the resulting space relation for the desired time stamp was generated.
|
|
|
|
*
|
|
|
|
* @relates m_relation_history
|
|
|
|
*/
|
|
|
|
enum m_relation_history_result
|
|
|
|
{
|
|
|
|
M_RELATION_HISTORY_RESULT_INVALID = 0, //!< The supplied timestamp was invalid (0) or buffer was empty
|
|
|
|
M_RELATION_HISTORY_RESULT_EXACT, //!< The exact desired timestamp was found
|
|
|
|
M_RELATION_HISTORY_RESULT_INTERPOLATED, //!< The desired timestamp was between two entries
|
|
|
|
M_RELATION_HISTORY_RESULT_PREDICTED, //!< The desired timestamp was newer than the most recent entry
|
|
|
|
M_RELATION_HISTORY_RESULT_REVERSE_PREDICTED, //!< The desired timestamp was older than the oldest entry
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Creates an opaque relation_history object.
|
|
|
|
*
|
|
|
|
* @public @memberof m_relation_history
|
|
|
|
*/
|
2021-09-15 17:12:43 +00:00
|
|
|
void
|
|
|
|
m_relation_history_create(struct m_relation_history **rh);
|
|
|
|
|
|
|
|
/*!
|
2021-12-02 21:11:11 +00:00
|
|
|
* Pushes a new pose to the history.
|
2021-09-15 17:12:43 +00:00
|
|
|
*
|
2021-12-02 21:11:11 +00:00
|
|
|
* If the history is full, it will also pop a pose out of the other side of the buffer.
|
|
|
|
*
|
2021-12-09 19:44:12 +00:00
|
|
|
* @return false if the timestamp is earlier than the most recent timestamp already recorded
|
|
|
|
*
|
2021-12-02 21:11:11 +00:00
|
|
|
* @public @memberof m_relation_history
|
2021-09-15 17:12:43 +00:00
|
|
|
*/
|
2021-12-09 19:44:12 +00:00
|
|
|
bool
|
2021-12-03 13:28:46 +00:00
|
|
|
m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation const *in_relation, uint64_t ts);
|
2021-09-15 17:12:43 +00:00
|
|
|
|
|
|
|
/*!
|
2021-12-02 21:11:11 +00:00
|
|
|
* @brief Interpolates or extrapolates to the desired timestamp.
|
2021-09-15 17:12:43 +00:00
|
|
|
*
|
2021-12-02 21:11:11 +00:00
|
|
|
* Read-only operation - doesn't remove anything from the buffer or anything like that - you can call this as often as
|
|
|
|
* you want.
|
|
|
|
*
|
|
|
|
* @public @memberof m_relation_history
|
2021-09-15 17:12:43 +00:00
|
|
|
*/
|
2021-12-02 21:11:11 +00:00
|
|
|
enum m_relation_history_result
|
2021-12-03 13:38:53 +00:00
|
|
|
m_relation_history_get(struct m_relation_history *rh, uint64_t at_time_ns, struct xrt_space_relation *out_relation);
|
2021-09-15 17:12:43 +00:00
|
|
|
|
2021-12-10 16:34:59 +00:00
|
|
|
/*!
|
|
|
|
* @brief Get the latest report in the buffer, if any.
|
|
|
|
*
|
|
|
|
* @param rh self
|
|
|
|
* @param[out] out_time_ns Populated with the latest report time, if any
|
|
|
|
* @param[out] out_relation Populated with the latest relation, if any
|
|
|
|
*
|
|
|
|
* @return false if the history is empty.
|
|
|
|
*
|
|
|
|
* @public @memberof m_relation_history
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
m_relation_history_get_latest(struct m_relation_history *rh,
|
|
|
|
uint64_t *out_time_ns,
|
|
|
|
struct xrt_space_relation *out_relation);
|
|
|
|
|
2021-12-10 15:59:18 +00:00
|
|
|
/*!
|
|
|
|
* @brief Returns the number of items in the history.
|
|
|
|
*
|
|
|
|
* @public @memberof m_relation_history
|
|
|
|
*/
|
|
|
|
uint32_t
|
|
|
|
m_relation_history_get_size(const struct m_relation_history *rh);
|
|
|
|
|
2021-09-15 17:12:43 +00:00
|
|
|
/*!
|
|
|
|
* Destroys an opaque relation_history object.
|
|
|
|
*
|
2021-12-02 21:11:11 +00:00
|
|
|
* @public @memberof m_relation_history
|
2021-09-15 17:12:43 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
m_relation_history_destroy(struct m_relation_history **rh);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-03 13:30:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace xrt::auxiliary::math {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* C++ interface for @ref m_relation_history, non-copyable/deletable.
|
|
|
|
*
|
|
|
|
* @ingroup aux_math
|
|
|
|
*/
|
|
|
|
class RelationHistory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
* @copydoc m_relation_history_result
|
|
|
|
*/
|
|
|
|
typedef m_relation_history_result Result;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
m_relation_history *mPtr{nullptr};
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
// clang-format off
|
|
|
|
RelationHistory() noexcept { m_relation_history_create(&mPtr); }
|
|
|
|
~RelationHistory() { m_relation_history_destroy(&mPtr); }
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
// Special non-copyable reference.
|
|
|
|
RelationHistory(RelationHistory const &) = delete;
|
|
|
|
RelationHistory(RelationHistory &&) = delete;
|
|
|
|
RelationHistory &
|
|
|
|
operator=(RelationHistory const &) = delete;
|
|
|
|
RelationHistory &
|
|
|
|
operator=(RelationHistory &&) = delete;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @copydoc m_relation_history_push
|
|
|
|
*/
|
2021-12-09 19:44:12 +00:00
|
|
|
bool
|
2021-12-03 13:30:34 +00:00
|
|
|
push(xrt_space_relation const &relation, uint64_t ts) noexcept
|
|
|
|
{
|
2021-12-09 19:44:12 +00:00
|
|
|
return m_relation_history_push(mPtr, &relation, ts);
|
2021-12-03 13:30:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @copydoc m_relation_history_get
|
|
|
|
*/
|
|
|
|
Result
|
|
|
|
get(uint64_t at_time_ns, xrt_space_relation *out_relation) noexcept
|
|
|
|
{
|
|
|
|
return m_relation_history_get(mPtr, at_time_ns, out_relation);
|
|
|
|
}
|
2021-12-10 17:53:23 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @copydoc m_relation_history_get_latest
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
get_latest(uint64_t *out_time_ns, xrt_space_relation *out_relation) noexcept
|
|
|
|
{
|
|
|
|
return m_relation_history_get_latest(mPtr, out_time_ns, out_relation);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @copydoc m_relation_history_get_size
|
|
|
|
*/
|
|
|
|
size_t
|
|
|
|
size() const noexcept
|
|
|
|
{
|
|
|
|
return m_relation_history_get_size(mPtr);
|
|
|
|
}
|
2021-12-03 13:30:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace xrt::auxiliary::math
|
|
|
|
#endif
|