mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-05 13:28:16 +00:00
d/ht; aux/util: Move ringbuffer implementation into aux/util
This commit is contained in:
parent
9960f0ab22
commit
7f69dc795f
|
@ -153,6 +153,7 @@ set(UTIL_SOURCE_FILES
|
|||
util/u_sink_queue.c
|
||||
util/u_sink_quirk.c
|
||||
util/u_sink_split.c
|
||||
util/u_template_historybuf.hpp
|
||||
util/u_time.cpp
|
||||
util/u_time.h
|
||||
util/u_timing.h
|
||||
|
|
|
@ -64,6 +64,7 @@ lib_aux_util = static_library(
|
|||
'util/u_timing_fake.c',
|
||||
'util/u_timing_frame.c',
|
||||
'util/u_timing_render.c',
|
||||
'util/u_template_historybuf.hpp',
|
||||
'util/u_trace_marker.c',
|
||||
'util/u_trace_marker.h',
|
||||
'util/u_var.cpp',
|
||||
|
|
|
@ -2,16 +2,14 @@
|
|||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Camera based hand tracking ringbuffer implementation.
|
||||
* @brief Ringbuffer implementation for keeping track of the past state of things
|
||||
* @author Moses Turner <moses@collabora.com>
|
||||
* @ingroup drv_ht
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
|
@ -19,23 +17,28 @@
|
|||
// OR
|
||||
//| -4 | -3 | -2 | -1 | Top | -7 | -6 | -5 |
|
||||
|
||||
namespace xrt::auxiliary::util {
|
||||
|
||||
|
||||
template <typename T, int maxSize> struct DiscardLastBuffer
|
||||
template <typename T, int maxSize> struct HistoryBuffer
|
||||
{
|
||||
T internalBuffer[maxSize];
|
||||
int topIdx = 0;
|
||||
int length = 0;
|
||||
|
||||
/* Put something at the top, overwrite whatever was at the back*/
|
||||
void
|
||||
push(const T inElement);
|
||||
|
||||
T *operator[](int inIndex);
|
||||
|
||||
// Lazy convenience.
|
||||
T *
|
||||
last();
|
||||
};
|
||||
|
||||
template <typename T, int maxSize>
|
||||
void
|
||||
DiscardLastBuffer<T, maxSize>::push(const T inElement)
|
||||
HistoryBuffer<T, maxSize>::push(const T inElement)
|
||||
{
|
||||
topIdx++;
|
||||
if (topIdx == maxSize) {
|
||||
|
@ -43,10 +46,16 @@ DiscardLastBuffer<T, maxSize>::push(const T inElement)
|
|||
}
|
||||
|
||||
memcpy(&internalBuffer[topIdx], &inElement, sizeof(T));
|
||||
length++;
|
||||
length = std::min(length, maxSize);
|
||||
// U_LOG_E("new length is %zu", length);
|
||||
}
|
||||
|
||||
template <typename T, int maxSize> T *DiscardLastBuffer<T, maxSize>::operator[](int inIndex)
|
||||
template <typename T, int maxSize> T *HistoryBuffer<T, maxSize>::operator[](int inIndex)
|
||||
{
|
||||
if (length == 0) {
|
||||
return NULL;
|
||||
}
|
||||
assert(inIndex <= maxSize);
|
||||
assert(inIndex >= 0);
|
||||
|
||||
|
@ -62,3 +71,4 @@ template <typename T, int maxSize> T *DiscardLastBuffer<T, maxSize>::operator[](
|
|||
|
||||
return &internalBuffer[index];
|
||||
}
|
||||
} // namespace xrt::auxiliary::util
|
|
@ -261,7 +261,6 @@ if(XRT_BUILD_DRIVER_HANDTRACKING)
|
|||
ht/ht_hand_math.hpp
|
||||
ht/ht_image_math.hpp
|
||||
ht/ht_nms.hpp
|
||||
ht/templates/DiscardLastBuffer.hpp
|
||||
ht/templates/NaivePermutationSort.hpp
|
||||
)
|
||||
add_library(drv_ht STATIC ${HT_SOURCE_FILES})
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "util/u_debug.h"
|
||||
#include "util/u_device.h"
|
||||
|
||||
#include "templates/DiscardLastBuffer.hpp"
|
||||
#include "util/u_template_historybuf.hpp"
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
|
@ -44,8 +44,7 @@ DEBUG_GET_ONCE_LOG_OPTION(ht_log, "HT_LOG", U_LOGGING_WARN)
|
|||
#define HT_WARN(htd, ...) U_LOG_XDEV_IFL_W(&htd->base, htd->ll, __VA_ARGS__)
|
||||
#define HT_ERROR(htd, ...) U_LOG_XDEV_IFL_E(&htd->base, htd->ll, __VA_ARGS__)
|
||||
|
||||
// #define ht_
|
||||
|
||||
using namespace xrt::auxiliary::util;
|
||||
|
||||
// To make clang-tidy happy
|
||||
#define opencv_distortion_param_num 4
|
||||
|
@ -148,7 +147,7 @@ struct HandHistory3D
|
|||
// Index 0 is current frame, index 1 is last frame, index 2 is second to last frame.
|
||||
// No particular reason to keep the last 5 frames. we only really only use the current and last one.
|
||||
float handedness;
|
||||
DiscardLastBuffer<Hand3D, 5> last_hands;
|
||||
HistoryBuffer<Hand3D, 5> last_hands;
|
||||
// Euro filter for 21kps.
|
||||
m_filter_euro_vec3 filters[21];
|
||||
};
|
||||
|
@ -158,8 +157,8 @@ struct HandHistory2DBBox
|
|||
m_filter_euro_vec2 m_filter_wrist;
|
||||
m_filter_euro_vec2 m_filter_middle;
|
||||
|
||||
DiscardLastBuffer<xrt_vec2, 50> wrist_unfiltered;
|
||||
DiscardLastBuffer<xrt_vec2, 50> middle_unfiltered;
|
||||
HistoryBuffer<xrt_vec2, 50> wrist_unfiltered;
|
||||
HistoryBuffer<xrt_vec2, 50> middle_unfiltered;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -94,7 +94,6 @@ lib_drv_ht = static_library(
|
|||
'ht/ht_hand_math.hpp',
|
||||
'ht/ht_image_math.hpp',
|
||||
'ht/ht_nms.hpp',
|
||||
'ht/templates/DiscardLastBuffer.hpp',
|
||||
'ht/templates/NaivePermutationSort.hpp',
|
||||
),
|
||||
include_directories: [xrt_include, cjson_include],
|
||||
|
|
Loading…
Reference in a new issue