#include "image_viewer_impl.h" #include "core/imgui_utility.hpp" #include "render/render_texture.h" void image_viewer::impl::show_depth_only() { { auto guard = imgui_disable_guard(!depth_conf.manual_depth_range); static constexpr float dep_hard_min = 0.15; // TODO: config value static constexpr float dep_hard_max = 10.0; ImGui::DragFloat2("Depth Range (m)", (float *) &depth_conf.depth_range, 0.05f, dep_hard_min, dep_hard_max, "%.2f"); } ImGui::SameLine(); ImGui::Checkbox("##manual_dep_range", &depth_conf.manual_depth_range); } void image_viewer::impl::show_color_depth() { ImGui::RadioButton("Color", &chose_index, 0); ImGui::SameLine(); ImGui::RadioButton("Depth", &chose_index, 1); ImGui::SameLine(); ImGui::RadioButton("Both", &chose_index, 2); if (chose_index == 1 || chose_index == 2) { // depth or both show_depth_only(); } ImGui::PushItemWidth(150); if (chose_index == 2) { // both ImGui::SliderFloat("Depth Alpha", &depth_overlay_alpha, 0.f, 1.f, "%.2f"); } } void image_viewer::impl::show_stereo() { ImGui::RadioButton("Left", &chose_index, 0); ImGui::SameLine(); ImGui::RadioButton("Right", &chose_index, 1); } void image_viewer::impl::show() { ImGui::PushItemWidth(150); switch (conf.mode) { case VIEW_COLOR_ONLY: { break; } case VIEW_DEPTH_ONLY: { show_depth_only(); break; } case VIEW_COLOR_DEPTH: { show_color_depth(); break; } case VIEW_STEREO: { show_stereo(); break; } default: { RET_ERROR; } } ImGui::PopItemWidth(); } void image_viewer::impl::render_color_obj(obj_name_type name) { color_render.render(name, color_conf); } void image_viewer::impl::render_depth_obj(obj_name_type name, float alpha) { depth_conf.alpha = alpha; depth_render.render(name, depth_conf); } void image_viewer::impl::render_color_depth() { auto info = conf.extra.color_depth; if (chose_index == 0 || chose_index == 2) { // color or both color_conf.fmt = info.c_fmt; } switch (chose_index) { case 0: { // color render_color_obj(info.c_name); break; } case 1: { // depth render_depth_obj(info.d_name); break; } case 2: { // both render_color_obj(info.c_name); render_depth_obj(info.d_name, depth_overlay_alpha); break; } default: { RET_ERROR; } } } void image_viewer::impl::render_stereo() { auto info = conf.extra.stereo; color_conf.fmt = info.c_fmt; switch (chose_index) { case 0: { // left render_color_obj(info.left_name); break; } case 1: { render_color_obj(info.right_name); break; } default: { RET_ERROR; } } } void image_viewer::impl::render() { switch (conf.mode) { case VIEW_COLOR_ONLY: { color_conf.fmt = conf.extra.color.fmt; render_color_obj(conf.extra.color.name); break; } case VIEW_DEPTH_ONLY: { render_depth_obj(conf.extra.depth.name); break; } case VIEW_COLOR_DEPTH: { render_color_depth(); break; } case VIEW_STEREO: { render_stereo(); break; } default: { RET_ERROR; } } } image_viewer::impl::impl(create_config _conf) { conf = _conf; color_conf.flip_y = conf.flip_y; color_conf.stream = conf.stream; depth_conf.flip_y = conf.flip_y; depth_conf.stream = conf.stream; } image_viewer::image_viewer(create_config conf) : pimpl(std::make_unique(conf)) { } image_viewer::~image_viewer() = default; void image_viewer::show() { pimpl->show(); } void image_viewer::render() { pimpl->render(); }