Commit b1febd89 authored by Jakob Bornecrantz's avatar Jakob Bornecrantz
Browse files

t/gui: Add a calibration scene

parent 4a0a95da
Pipeline #65520 passed with stages
in 2 minutes and 46 seconds
......@@ -21,6 +21,7 @@ set(SOURCE_FILES
gui_ogl.c
gui_prober.c
gui_scene.cpp
gui_scene_calibrate.c
gui_scene_debug.c
gui_scene_main_menu.c
gui_scene_video.c
......
......@@ -243,12 +243,20 @@ void
gui_scene_main_menu(struct program *p);
/*!
* Shows a UI that lets you select a video device and mode.
* Shows a UI that lets you select a video device and mode for calibration.
*
* @ingroup gui
*/
void
gui_scene_select_video(struct program *p);
gui_scene_select_video_calibrate(struct program *p);
/*!
* Shows a UI that lets you select a video device and mode for testing.
*
* @ingroup gui
*/
void
gui_scene_select_video_test(struct program *p);
/*!
* Regular debug UI.
......@@ -269,6 +277,17 @@ gui_scene_debug_video(struct program *p,
struct xrt_fs *xfs,
size_t mode);
/*!
* Given the frameserver runs the calibration code on it.
*
* @ingroup gui
*/
void
gui_scene_calibrate(struct program *p,
struct xrt_frame_context *xfctx,
struct xrt_fs *xfs,
size_t mode);
#ifdef __cplusplus
}
......
......@@ -35,6 +35,8 @@ main(int argc, char **argv)
// First scene to start with.
if (argc >= 2 && strcmp("debug", argv[1]) == 0) {
gui_scene_debug(&p);
} else if (argc >= 2 && strcmp("calibrate", argv[1]) == 0) {
gui_scene_select_video_calibrate(&p);
} else {
gui_scene_main_menu(&p);
}
......
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Calibration gui scene.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @ingroup gui
*/
#include "util/u_var.h"
#include "util/u_misc.h"
#include "util/u_sink.h"
#ifdef XRT_HAVE_OPENCV
#include "tracking/t_tracking.h"
#endif
#include "xrt/xrt_frame.h"
#include "xrt/xrt_prober.h"
#include "xrt/xrt_tracking.h"
#include "xrt/xrt_frameserver.h"
#include "gui_common.h"
#include "gui_imgui.h"
struct calibration_scene
{
struct gui_scene base;
struct xrt_frame_context *xfctx;
};
/*
*
* Internal functions.
*
*/
static void
draw_texture(struct gui_ogl_texture *tex, bool header)
{
if (tex == NULL) {
return;
}
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_None;
if (header && !igCollapsingHeader(tex->name, flags)) {
return;
}
gui_ogl_sink_update(tex);
int w = tex->w / (tex->half ? 2 : 1);
int h = tex->h / (tex->half ? 2 : 1);
ImVec2 size = {w, h};
ImVec2 uv0 = {0, 0};
ImVec2 uv1 = {1, 1};
ImVec4 white = {1, 1, 1, 1};
ImTextureID id = (ImTextureID)(intptr_t)tex->id;
igImage(id, size, uv0, uv1, white, white);
igText("Sequence %u", (uint32_t)tex->seq);
char temp[512];
snprintf(temp, 512, "Half (%s)", tex->name);
igCheckbox(temp, &tex->half);
}
static void
scene_render(struct gui_scene *scene, struct program *p)
{
struct calibration_scene *cs = (struct calibration_scene *)scene;
igBegin("Calibration", NULL, 0);
draw_texture(p->texs[0], false);
draw_texture(p->texs[1], true);
for (size_t i = 2; i < ARRAY_SIZE(p->texs); i++) {
draw_texture(p->texs[i], true);
}
igSeparator();
static ImVec2 button_dims = {0, 0};
if (igButton("Exit", button_dims)) {
gui_scene_delete_me(p, &cs->base);
}
igEnd();
}
static void
scene_destroy(struct gui_scene *scene, struct program *p)
{
struct calibration_scene *cs = (struct calibration_scene *)scene;
if (cs->xfctx != NULL) {
xrt_frame_context_destroy_nodes(cs->xfctx);
cs->xfctx = NULL;
}
free(cs);
}
/*
*
* 'Exported' functions.
*
*/
void
gui_scene_calibrate(struct program *p,
struct xrt_frame_context *xfctx,
struct xrt_fs *xfs,
size_t mode)
{
struct calibration_scene *cs = U_TYPED_CALLOC(struct calibration_scene);
cs->base.render = scene_render;
cs->base.destroy = scene_destroy;
cs->xfctx = xfctx;
gui_scene_push_front(p, &cs->base);
#ifdef XRT_HAVE_OPENCV
struct xrt_frame_sink *rgb = NULL;
struct xrt_frame_sink *raw = NULL;
struct xrt_frame_sink *cali = NULL;
p->texs[p->num_texs++] =
gui_ogl_sink_create("Calibration", xfctx, &rgb);
u_sink_create_format_converter(xfctx, XRT_FORMAT_R8G8B8, rgb, &rgb);
u_sink_queue_create(xfctx, rgb, &rgb);
p->texs[p->num_texs++] = gui_ogl_sink_create("Raw", xfctx, &raw);
u_sink_create_format_converter(xfctx, XRT_FORMAT_R8G8B8, raw, &raw);
u_sink_queue_create(xfctx, raw, &raw);
t_calibration_create(xfctx, rgb, &cali);
u_sink_create_to_yuv_or_yuyv(xfctx, cali, &cali);
u_sink_queue_create(xfctx, cali, &cali);
u_sink_split_create(xfctx, raw, cali, &cali);
// Now that we have setup a node graph, start it.
xrt_fs_stream_start(xfs, cali, mode);
#else
gui_scene_delete_me(p, &cs->base);
#endif
}
......@@ -23,18 +23,25 @@ struct main_menu
static void
scene_render(struct gui_scene *scene, struct program *p)
{
igBegin("Main Meun", NULL, 0);
igBegin("Main Menu", NULL, 0);
if (igButton("Debug", button_dims)) {
if (igButton("Calibrate", button_dims)) {
gui_scene_delete_me(p, scene);
gui_scene_select_video_calibrate(p);
}
if (igButton("Debug Test", button_dims)) {
gui_scene_delete_me(p, scene);
gui_scene_debug(p);
}
if (igButton("Select Video", button_dims)) {
if (igButton("Video (deprecated)", button_dims)) {
gui_scene_delete_me(p, scene);
gui_scene_select_video(p);
gui_scene_select_video_test(p);
}
igSeparator();
if (igButton("Exit", button_dims)) {
gui_scene_delete_me(p, scene);
}
......
......@@ -21,6 +21,9 @@ struct video_select
{
struct gui_scene base;
bool test;
bool calibrate;
struct xrt_frame_context *xfctx;
struct xrt_fs *xfs;
......@@ -91,7 +94,12 @@ scene_render(struct gui_scene *scene, struct program *p)
}
// User selected this mode, create the debug scene.
gui_scene_debug_video(p, vs->xfctx, vs->xfs, i);
if (vs->test) {
gui_scene_debug_video(p, vs->xfctx, vs->xfs, i);
} else if (vs->calibrate) {
gui_scene_calibrate(p, vs->xfctx, vs->xfs, i);
}
// We should not clean these up, zero them out.
vs->xfctx = NULL;
vs->xfs = NULL;
......@@ -136,12 +144,25 @@ scene_destroy(struct gui_scene *scene, struct program *p)
*/
void
gui_scene_select_video(struct program *p)
gui_scene_select_video_test(struct program *p)
{
struct video_select *vs = U_TYPED_CALLOC(struct video_select);
vs->base.render = scene_render;
vs->base.destroy = scene_destroy;
vs->test = true;
gui_scene_push_front(p, &vs->base);
}
void
gui_scene_select_video_calibrate(struct program *p)
{
struct video_select *vs = U_TYPED_CALLOC(struct video_select);
vs->base.render = scene_render;
vs->base.destroy = scene_destroy;
vs->calibrate = true;
gui_scene_push_front(p, &vs->base);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment