From 7ea7cce930cdfc3b9fe687ae47acc551c03f4804 Mon Sep 17 00:00:00 2001 From: Mateo de Mayo Date: Sat, 14 May 2022 17:03:00 -0300 Subject: [PATCH] u/var: Add u_var_histogram_f32 --- src/xrt/auxiliary/util/u_var.h | 12 +++++++++++- src/xrt/state_trackers/gui/gui_scene_debug.c | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/xrt/auxiliary/util/u_var.h b/src/xrt/auxiliary/util/u_var.h index 59d0a81f4..fbc6e68ad 100644 --- a/src/xrt/auxiliary/util/u_var.h +++ b/src/xrt/auxiliary/util/u_var.h @@ -113,6 +113,14 @@ struct u_var_draggable_u16 uint16_t max; }; +struct u_var_histogram_f32 +{ + float *values; //!< Bin heights + int count; //!< Number of bins + float width; //!< Widget width or 0 for auto + float height; //!< Widget height or 0 for auto +}; + /*! * What kind of variable is this tracking. */ @@ -150,6 +158,7 @@ enum u_var_kind U_VAR_KIND_GUI_HEADER, U_VAR_KIND_BUTTON, U_VAR_KIND_COMBO, + U_VAR_KIND_HISTOGRAM_F32, U_VAR_KIND_DRAGGABLE_U16, }; @@ -257,7 +266,8 @@ u_var_force_on(void); ADD_FUNC(button, struct u_var_button, BUTTON) \ ADD_FUNC(combo, struct u_var_combo, COMBO) \ ADD_FUNC(draggable_f32, struct u_var_draggable_f32, DRAGGABLE_F32) \ - ADD_FUNC(draggable_u16, struct u_var_draggable_u16, DRAGGABLE_U16) + ADD_FUNC(draggable_u16, struct u_var_draggable_u16, DRAGGABLE_U16) \ + ADD_FUNC(histogram_f32, struct u_var_histogram_f32, HISTOGRAM_F32) #define ADD_FUNC(SUFFIX, TYPE, ENUM) void u_var_add_##SUFFIX(void *, TYPE *, const char *); diff --git a/src/xrt/state_trackers/gui/gui_scene_debug.c b/src/xrt/state_trackers/gui/gui_scene_debug.c index 22a83bb5e..24a13d726 100644 --- a/src/xrt/state_trackers/gui/gui_scene_debug.c +++ b/src/xrt/state_trackers/gui/gui_scene_debug.c @@ -237,6 +237,14 @@ on_combo_var(const char *name, void *ptr) igComboStr(name, combo->value, combo->options, combo->count); } +static void +on_histogram_f32_var(const char *name, void *ptr) +{ + struct u_var_histogram_f32 *h = (struct u_var_histogram_f32 *)ptr; + ImVec2 zero = {h->width, h->height}; + igPlotHistogramFloatPtr(name, h->values, h->count, 0, NULL, FLT_MAX, FLT_MAX, zero, sizeof(float)); +} + static void on_draggable_f32_var(const char *name, void *ptr) { @@ -384,6 +392,7 @@ on_elem(struct u_var_info *info, void *priv) case U_VAR_KIND_BUTTON: on_button_var(name, ptr); break; case U_VAR_KIND_COMBO: on_combo_var(name, ptr); break; case U_VAR_KIND_DRAGGABLE_U16: on_draggable_u16_var(name, ptr); break; + case U_VAR_KIND_HISTOGRAM_F32: on_histogram_f32_var(name, ptr); break; default: igLabelText(name, "Unknown tag '%i'", kind); break; } }