From c3a12c8a209d0173346b54f25c2d163e22df7610 Mon Sep 17 00:00:00 2001 From: Remi Bettan Date: Wed, 8 Mar 2023 10:48:20 +0200 Subject: [PATCH 1/2] multiple resolutions implementation added, never enabled --- common/device-model.cpp | 20 +- common/subdevice-model.cpp | 830 ++++++++++++++++++++++++++++--------- common/subdevice-model.h | 35 +- 3 files changed, 688 insertions(+), 197 deletions(-) diff --git a/common/device-model.cpp b/common/device-model.cpp index 1b3ad53009..c0f59ac786 100644 --- a/common/device-model.cpp +++ b/common/device-model.cpp @@ -2089,7 +2089,7 @@ namespace rs2 throw std::runtime_error( rsutils::string::from() << "No match found for requested format: " << requested_format ); } - sub->ui.selected_format_id[uid] = int(format_id); + sub->ui.selected_format_id[uid] = static_cast(format_id); //Find fps int requested_fps = kvp.second.fps; @@ -2104,7 +2104,7 @@ namespace rs2 throw std::runtime_error( rsutils::string::from() << "No match found for requested fps: " << requested_fps ); } - sub->ui.selected_shared_fps_id = int(fps_id); + sub->ui.selected_shared_fps_id = static_cast(fps_id); //Find Resolution std::pair requested_res{ kvp.second.width,kvp.second.height }; @@ -2120,7 +2120,21 @@ namespace rs2 << "No match found for requested resolution: " << requested_res.first << "x" << requested_res.second ); } - sub->ui.selected_res_id = int(res_id); + if (!sub->ui.is_multiple_resolutions) + sub->ui.selected_res_id = static_cast(res_id); + else + { + int depth_res_id, ir1_res_id, ir2_res_id; + sub->get_depth_ir_mismatch_resolutions_ids(depth_res_id, ir1_res_id, ir2_res_id); + + if (kvp.first.first == RS2_STREAM_DEPTH) + sub->ui.selected_res_id_map[depth_res_id] = static_cast(res_id); + else + { + sub->ui.selected_res_id_map[ir1_res_id] = static_cast(res_id); + sub->ui.selected_res_id_map[ir2_res_id] = static_cast(res_id); + } + } } } } diff --git a/common/subdevice-model.cpp b/common/subdevice-model.cpp index 7c525bea55..d19b93ac75 100644 --- a/common/subdevice-model.cpp +++ b/common/subdevice-model.cpp @@ -181,12 +181,12 @@ namespace rs2 auto filters = s->get_recommended_filters(); - auto it = std::find_if(filters.begin(), filters.end(), [&](const filter &f) - { - if (f.is()) - return true; - return false; - }); + auto it = std::find_if(filters.begin(), filters.end(), [&](const filter& f) + { + if (f.is()) + return true; + return false; + }); auto is_zo = it != filters.end(); @@ -227,7 +227,7 @@ namespace rs2 { if (s->supports(RS2_CAMERA_INFO_PRODUCT_ID)) { - // using short range for D405 + // using short range for D405 std::string device_pid = s->get_info(RS2_CAMERA_INFO_PRODUCT_ID); if (device_pid == "0B5B") { @@ -252,7 +252,7 @@ namespace rs2 if (is_rgb_camera) { - for (auto & create_filter : post_processing_filters_list::get()) + for (auto& create_filter : post_processing_filters_list::get()) { auto filter = create_filter(); if (!filter) @@ -291,10 +291,10 @@ namespace rs2 // The flag is set to true by colorizer constructor, but setting min/max_distance options above or during // restore_processing_block earlier, causes the registered observer to unset it, which is not the desired // behaviour. Observer should affect only if a user is setting the values after construction phase is over. - if( depth_colorizer->supports( RS2_OPTION_VISUAL_PRESET ) ) + if (depth_colorizer->supports(RS2_OPTION_VISUAL_PRESET)) { - auto option_value = depth_colorizer->get_option( RS2_OPTION_VISUAL_PRESET ); - depth_colorizer->set_option( RS2_OPTION_VISUAL_PRESET, option_value ); + auto option_value = depth_colorizer->get_option(RS2_OPTION_VISUAL_PRESET); + depth_colorizer->set_option(RS2_OPTION_VISUAL_PRESET, option_value); } ss.str(""); @@ -354,6 +354,7 @@ namespace rs2 push_back_if_not_exists(res_values, std::pair(vid_prof.width(), vid_prof.height())); push_back_if_not_exists(resolutions, res.str()); push_back_if_not_exists(resolutions_per_stream[profile.stream_type()], std::pair(vid_prof.width(), vid_prof.height())); + push_back_if_not_exists(profile_id_to_res[profile.unique_id()], std::pair(vid_prof.width(), vid_prof.height())); } std::stringstream fps; @@ -424,8 +425,23 @@ namespace rs2 } } - get_default_selection_index(res_values, default_resolution, &selection_index); - ui.selected_res_id = selection_index; + if (is_multiple_resolutions_supported()) + { + ui.is_multiple_resolutions = true; + auto default_res = std::make_pair(1280, 960); + for (auto res_array : profile_id_to_res) + { + if (get_default_selection_index(res_array.second, default_res, &selection_index)) + { + ui.selected_res_id_map[res_array.first] = selection_index; + } + } + } + else + { + get_default_selection_index(res_values, default_resolution, &selection_index); + ui.selected_res_id = selection_index; + } if (new_device_connected) { @@ -433,7 +449,7 @@ namespace rs2 // (closed) stream... // TODO we have no res_values when loading color rosbag, and color sensor isn't // even supposed to support SENSOR_MODE... see RS5-7726 - if( s->supports( RS2_OPTION_SENSOR_MODE ) && !res_values.empty() ) + if (s->supports(RS2_OPTION_SENSOR_MODE) && !res_values.empty()) { // Watch out for read-only options in the playback sensor! try @@ -447,14 +463,26 @@ namespace rs2 if (requested_sensor_mode != currest_sensor_mode) s->set_option(RS2_OPTION_SENSOR_MODE, requested_sensor_mode); } - catch( not_implemented_error const &) + catch (not_implemented_error const&) { // Just ignore for now: need to figure out a way to write to playback sensors... } } } - while (ui.selected_res_id >= 0 && !is_selected_combination_supported()) ui.selected_res_id--; + if (ui.is_multiple_resolutions) + { + for (auto it = ui.selected_res_id_map.begin(); it != ui.selected_res_id_map.end(); ++it) + { + while (it->second >= 0 && !is_selected_combination_supported()) + it->second--; + } + } + else + { + while (ui.selected_res_id >= 0 && !is_selected_combination_supported()) + ui.selected_res_id--; + } last_valid_ui = ui; } catch (const error& e) @@ -505,9 +533,9 @@ namespace rs2 auto it = std::find_if(std::begin(fps_group), std::end(fps_group), [&](const int& fps2) - { - return fps2 == fps1; - }); + { + return fps2 == fps1; + }); if (it != std::end(fps_group)) { break; @@ -518,25 +546,10 @@ namespace rs2 return true; } - bool subdevice_model::draw_stream_selection(std::string& error_message) + bool subdevice_model::draw_resolutions(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1) { bool res = false; - std::string label = rsutils::string::from() - << "Stream Selection Columns##" << dev.get_info( RS2_CAMERA_INFO_NAME ) - << s->get_info( RS2_CAMERA_INFO_NAME ); - - auto streaming_tooltip = [&]() { - if( ( ! allow_change_resolution_while_streaming && streaming ) - && ImGui::IsItemHovered() ) - ImGui::SetTooltip( "Can't modify while streaming" ); - }; - - //ImGui::Columns(2, label.c_str(), false); - //ImGui::SetColumnOffset(1, 135); - auto col0 = ImGui::GetCursorPosX(); - auto col1 = 155.f; - // Draw combo-box with all resolution options for this device auto res_chars = get_string_pointers(resolutions); if (res_chars.size() > 0) @@ -545,10 +558,10 @@ namespace rs2 streaming_tooltip(); ImGui::SameLine(); ImGui::SetCursorPosX(col1); - label = rsutils::string::from() << "##" << dev.get_info( RS2_CAMERA_INFO_NAME ) - << s->get_info( RS2_CAMERA_INFO_NAME ) << " resolution"; + label = rsutils::string::from() << "##" << dev.get_info(RS2_CAMERA_INFO_NAME) + << s->get_info(RS2_CAMERA_INFO_NAME) << " resolution"; - if( ! allow_change_resolution_while_streaming && streaming ) + if (!allow_change_resolution_while_streaming && streaming) { ImGui::Text("%s", res_chars[ui.selected_res_id]); streaming_tooltip(); @@ -585,11 +598,11 @@ namespace rs2 // Only update the cached value once set_option is done! That way, if it doesn't change anything... try { - int sensor_mode_val = static_cast(s->get_option( RS2_OPTION_SENSOR_MODE )); + int sensor_mode_val = static_cast(s->get_option(RS2_OPTION_SENSOR_MODE)); { ui.selected_res_id = get_resolution_id_from_sensor_mode( - static_cast< rs2_sensor_mode >( sensor_mode_val ), - res_values ); + static_cast(sensor_mode_val), + res_values); } } catch (...) {} @@ -597,7 +610,7 @@ namespace rs2 else { error_message = rsutils::string::from() << "Resolution " << width << "x" << height - << " is not supported on this device"; + << " is not supported on this device"; } } else @@ -610,144 +623,413 @@ namespace rs2 } ImGui::SetCursorPosX(col0); } + return res; + } - if (draw_fps_selector) + bool subdevice_model::draw_fps(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1) + { + bool res = false; + // FPS + if (show_single_fps_list) { - // FPS - if (show_single_fps_list) + auto fps_chars = get_string_pointers(shared_fpses); + ImGui::Text("Frame Rate (FPS):"); + streaming_tooltip(); + ImGui::SameLine(); ImGui::SetCursorPosX(col1); + + label = rsutils::string::from() + << "##" << dev.get_info(RS2_CAMERA_INFO_NAME) << s->get_info(RS2_CAMERA_INFO_NAME) << " fps"; + + if (!allow_change_fps_while_streaming && streaming) { - auto fps_chars = get_string_pointers(shared_fpses); - ImGui::Text("Frame Rate (FPS):"); + ImGui::Text("%s", fps_chars[ui.selected_shared_fps_id]); streaming_tooltip(); - ImGui::SameLine(); ImGui::SetCursorPosX(col1); + } + else + { + ImGui::PushItemWidth(-1); + ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); + if (ImGui::Combo(label.c_str(), &ui.selected_shared_fps_id, fps_chars.data(), + static_cast(fps_chars.size()))) + { + res = true; + } + ImGui::PopStyleColor(); + ImGui::PopItemWidth(); + } - label = rsutils::string::from() - << "##" << dev.get_info( RS2_CAMERA_INFO_NAME ) << s->get_info( RS2_CAMERA_INFO_NAME ) << " fps"; + ImGui::SetCursorPosX(col0); + } + return res; + } + + bool subdevice_model::draw_streams_and_formats(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1) + { + bool res = false; + + if (!streaming) + { + ImGui::Text("Available Streams:"); + } + + // Draw combo-box with all format options for current device + for (auto&& f : formats) + { + // Format + if (f.second.size() == 0) + continue; - if( ! allow_change_fps_while_streaming && streaming ) + auto formats_chars = get_string_pointers(f.second); + if (!streaming || (streaming && stream_enabled[f.first])) + { + if (streaming) { - ImGui::Text("%s", fps_chars[ui.selected_shared_fps_id]); + label = rsutils::string::from() + << stream_display_names[f.first] << (show_single_fps_list ? "" : " stream:"); + ImGui::Text("%s", label.c_str()); streaming_tooltip(); } else { - ImGui::PushItemWidth(-1); - ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); - if (ImGui::Combo(label.c_str(), &ui.selected_shared_fps_id, fps_chars.data(), - static_cast(fps_chars.size()))) + auto tmp = stream_enabled; + label = rsutils::string::from() << stream_display_names[f.first] << "##" << f.first; + if (ImGui::Checkbox(label.c_str(), &stream_enabled[f.first])) { - res = true; + prev_stream_enabled = tmp; } - ImGui::PopStyleColor(); - ImGui::PopItemWidth(); } - - ImGui::SetCursorPosX(col0); } - } - if (draw_streams_selector) - { - if (!streaming) + if (stream_enabled[f.first]) { - ImGui::Text("Available Streams:"); - } + if (show_single_fps_list) + { + ImGui::SameLine(); + ImGui::SetCursorPosX(col1); + } - // Draw combo-box with all format options for current device - for (auto&& f : formats) - { - // Format - if (f.second.size() == 0) - continue; + label = rsutils::string::from() + << "##" << dev.get_info(RS2_CAMERA_INFO_NAME) << s->get_info(RS2_CAMERA_INFO_NAME) << " " + << f.first << " format"; - auto formats_chars = get_string_pointers(f.second); - if (!streaming || (streaming && stream_enabled[f.first])) + if (!show_single_fps_list) { - if (streaming) - { - label = rsutils::string::from() - << stream_display_names[f.first] << ( show_single_fps_list ? "" : " stream:" ); - ImGui::Text("%s", label.c_str()); - streaming_tooltip(); - } - else - { - auto tmp = stream_enabled; - label = rsutils::string::from() << stream_display_names[f.first] << "##" << f.first; - if (ImGui::Checkbox(label.c_str(), &stream_enabled[f.first])) - { - prev_stream_enabled = tmp; - } - } + ImGui::Text("Format:"); + streaming_tooltip(); + ImGui::SameLine(); ImGui::SetCursorPosX(col1); } - if (stream_enabled[f.first]) + if (streaming) { - if (show_single_fps_list) - { - ImGui::SameLine(); - ImGui::SetCursorPosX(col1); - } - - label = rsutils::string::from() - << "##" << dev.get_info( RS2_CAMERA_INFO_NAME ) << s->get_info( RS2_CAMERA_INFO_NAME ) << " " - << f.first << " format"; + ImGui::Text("%s", formats_chars[ui.selected_format_id[f.first]]); + streaming_tooltip(); + } + else + { + ImGui::PushItemWidth(-1); + ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); + ImGui::Combo(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), + static_cast(formats_chars.size())); + ImGui::PopStyleColor(); + ImGui::PopItemWidth(); + } + ImGui::SetCursorPosX(col0); + // FPS + // Draw combo-box with all FPS options for this device + if (!show_single_fps_list && !fpses_per_stream[f.first].empty() && stream_enabled[f.first]) + { + auto fps_chars = get_string_pointers(fpses_per_stream[f.first]); + ImGui::Text("Frame Rate (FPS):"); + streaming_tooltip(); + ImGui::SameLine(); ImGui::SetCursorPosX(col1); - if (!show_single_fps_list) - { - ImGui::Text("Format:"); - streaming_tooltip(); - ImGui::SameLine(); ImGui::SetCursorPosX(col1); - } + label = rsutils::string::from() << "##" << s->get_info(RS2_CAMERA_INFO_NAME) + << s->get_info(RS2_CAMERA_INFO_NAME) << f.first << " fps"; if (streaming) { - ImGui::Text("%s", formats_chars[ui.selected_format_id[f.first]]); + ImGui::Text("%s", fps_chars[ui.selected_fps_id[f.first]]); streaming_tooltip(); } else { ImGui::PushItemWidth(-1); ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); - ImGui::Combo(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), - static_cast(formats_chars.size())); + ImGui::Combo(label.c_str(), &ui.selected_fps_id[f.first], fps_chars.data(), + static_cast(fps_chars.size())); ImGui::PopStyleColor(); ImGui::PopItemWidth(); } ImGui::SetCursorPosX(col0); - // FPS - // Draw combo-box with all FPS options for this device - if (!show_single_fps_list && !fpses_per_stream[f.first].empty() && stream_enabled[f.first]) - { - auto fps_chars = get_string_pointers(fpses_per_stream[f.first]); - ImGui::Text("Frame Rate (FPS):"); - streaming_tooltip(); - ImGui::SameLine(); ImGui::SetCursorPosX(col1); + } + } + } + + return res; + } + + bool subdevice_model::draw_resolutions_combo_box_multiple_resolutions(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1, + int stream_type_id, int depth_res_id) + { + bool res = false; + + rs2_stream stream_type = RS2_STREAM_DEPTH; + if (stream_type_id != depth_res_id) + stream_type = RS2_STREAM_INFRARED; - label = rsutils::string::from() << "##" << s->get_info( RS2_CAMERA_INFO_NAME ) - << s->get_info( RS2_CAMERA_INFO_NAME ) << f.first << " fps"; - if (streaming) + auto res_pairs = resolutions_per_stream[stream_type]; + std::vector resolutions_str; + for (int i = 0; i < res_pairs.size(); ++i) + { + std::stringstream ss; + ss << res_pairs[i].first << "x" << res_pairs[i].second; + resolutions_str.push_back(ss.str()); + } + + auto res_chars = get_string_pointers(resolutions_str); + if (res_chars.size() > 0) + { + if (!(streaming && !streaming_map[stream_type_id])) + { + // resolution + // Draw combo-box with all resolution options for this stream type + ImGui::Text("Resolution:"); + streaming_tooltip(); + ImGui::SameLine(); ImGui::SetCursorPosX(col1); + + label = rsutils::string::from() << "##" << dev.get_info(RS2_CAMERA_INFO_NAME) + << s->get_info(RS2_CAMERA_INFO_NAME) << " resolution for " << rs2_stream_to_string(stream_type); + + if (!allow_change_resolution_while_streaming && streaming) + { + ImGui::Text("%s", res_chars[ui.selected_res_id_map[stream_type_id]]); + streaming_tooltip(); + } + else + { + ImGui::PushItemWidth(-1); + ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); + auto tmp_selected_res_id = ui.selected_res_id_map[stream_type_id]; + if (ImGui::Combo(label.c_str(), &tmp_selected_res_id, res_chars.data(), + static_cast(res_chars.size()))) + { + res = true; + _options_invalidated = true; + + // Set sensor mode only at the Viewer app, + // DQT app will handle the sensor mode when the streaming is off (while reseting the stream) + if (s->supports(RS2_OPTION_SENSOR_MODE) && !allow_change_resolution_while_streaming) { - ImGui::Text("%s", fps_chars[ui.selected_fps_id[f.first]]); - streaming_tooltip(); + auto width = res_values[tmp_selected_res_id].first; + auto height = res_values[tmp_selected_res_id].second; + auto res = resolution_from_width_height(width, height); + if (res >= RS2_SENSOR_MODE_VGA && res < RS2_SENSOR_MODE_COUNT) + { + try + { + s->set_option(RS2_OPTION_SENSOR_MODE, float(res)); + } + catch (const error& e) + { + error_message = error_to_string(e); + } + + // Only update the cached value once set_option is done! That way, if it doesn't change anything... + try + { + int sensor_mode_val = static_cast(s->get_option(RS2_OPTION_SENSOR_MODE)); + { + ui.selected_res_id = get_resolution_id_from_sensor_mode( + static_cast(sensor_mode_val), + res_values); + } + } + catch (...) {} + } + else + { + error_message = rsutils::string::from() << "Resolution " << width << "x" << height + << " is not supported on this device"; + } } else { - ImGui::PushItemWidth(-1); - ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); - ImGui::Combo(label.c_str(), &ui.selected_fps_id[f.first], fps_chars.data(), - static_cast(fps_chars.size())); - ImGui::PopStyleColor(); - ImGui::PopItemWidth(); + ui.selected_res_id_map[stream_type_id] = tmp_selected_res_id; } - ImGui::SetCursorPosX(col0); } + ImGui::PopStyleColor(); + ImGui::PopItemWidth(); + } + } + ImGui::SetCursorPosX(col0); + } + + + return res; + } + + bool subdevice_model::draw_formats_combo_box_multiple_resolutions(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1, + int stream_type_id) + { + bool res = false; + + std::map> stream_to_index; + int depth_res_id, ir1_res_id, ir2_res_id; + get_depth_ir_mismatch_resolutions_ids(depth_res_id, ir1_res_id, ir2_res_id); + stream_to_index[RS2_STREAM_DEPTH] = { depth_res_id }; + stream_to_index[RS2_STREAM_INFRARED] = { ir1_res_id, ir2_res_id }; + + rs2_stream stream_type = RS2_STREAM_DEPTH; + if (stream_type_id != depth_res_id) + stream_type = RS2_STREAM_INFRARED; + + + for (auto&& f : formats) + { + if (f.second.size() == 0) + continue; + + if (std::find(stream_to_index[stream_type].begin(), stream_to_index[stream_type].end(), f.first) == stream_to_index[stream_type].end()) + continue; + + auto formats_chars = get_string_pointers(f.second); + if (!streaming || (streaming && stream_enabled[f.first])) + { + if (streaming) + { + label = rsutils::string::from() + << stream_display_names[f.first] << (show_single_fps_list ? "" : " stream:"); + ImGui::Text("%s", label.c_str()); + streaming_tooltip(); + } + else + { + res = true; + auto tmp = stream_enabled; + label = rsutils::string::from() << stream_display_names[f.first] << "##" << f.first; + if (ImGui::Checkbox(label.c_str(), &stream_enabled[f.first])) + { + prev_stream_enabled = tmp; + } + } + } + + if (stream_enabled[f.first]) + { + if (show_single_fps_list) + { + ImGui::SameLine(); + ImGui::SetCursorPosX(col1); + } + + label = rsutils::string::from() + << "##" << dev.get_info(RS2_CAMERA_INFO_NAME) << s->get_info(RS2_CAMERA_INFO_NAME) << " " + << f.first << " format"; + + if (!show_single_fps_list) + { + ImGui::Text("Format:"); + streaming_tooltip(); + ImGui::SameLine(); ImGui::SetCursorPosX(col1); + } + + if (streaming) + { + ImGui::Text("%s", formats_chars[ui.selected_format_id[f.first]]); + streaming_tooltip(); } else { - //ImGui::NextColumn(); + ImGui::PushItemWidth(-1); + ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); + ImGui::Combo(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), + static_cast(formats_chars.size())); + ImGui::PopStyleColor(); + ImGui::PopItemWidth(); + } + ImGui::SetCursorPosX(col0); + } + } + return res; + } + + + bool subdevice_model::draw_res_stream_formats(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1) + { + bool res = false; + + if (!ui.is_multiple_resolutions) + { + return false; + } + + int depth_res_id, ir1_res_id, ir2_res_id; + get_depth_ir_mismatch_resolutions_ids(depth_res_id, ir1_res_id, ir2_res_id); + + std::vector stream_types_ids; + stream_types_ids.push_back(depth_res_id); + stream_types_ids.push_back(ir1_res_id); + for (auto&& stream_type_id : stream_types_ids) + { + // resolution + // Draw combo-box with all resolution options for this stream type + res &= draw_resolutions_combo_box_multiple_resolutions(error_message, label, streaming_tooltip, col0, col1, stream_type_id, depth_res_id); + + // stream and formats + // Draw combo-box with all format options for current stream type + res &= draw_formats_combo_box_multiple_resolutions(error_message, label, streaming_tooltip, col0, col1, stream_type_id); + } + + return res; + } + + bool subdevice_model::draw_stream_selection(std::string& error_message) + { + bool res = false; + + std::string label = rsutils::string::from() + << "Stream Selection Columns##" << dev.get_info(RS2_CAMERA_INFO_NAME) + << s->get_info(RS2_CAMERA_INFO_NAME); + + auto streaming_tooltip = [&]() { + if ((!allow_change_resolution_while_streaming && streaming) + && ImGui::IsItemHovered()) + ImGui::SetTooltip("Can't modify while streaming"); + }; + + auto col0 = ImGui::GetCursorPosX(); + auto col1 = 155.f; + + if (ui.is_multiple_resolutions && !strcmp(s->get_info(RS2_CAMERA_INFO_NAME), "Stereo Module")) + { + if (draw_fps_selector) + { + res &= draw_fps(error_message, label, streaming_tooltip, col0, col1); + } + + if (draw_streams_selector) + { + if (!streaming) + { + ImGui::Text("Available Streams:"); } + + res &= draw_res_stream_formats(error_message, label, streaming_tooltip, col0, col1); + } + } + else + { + res &= draw_resolutions(error_message, label, streaming_tooltip, col0, col1); + + if (draw_fps_selector) + { + res &= draw_fps(error_message, label, streaming_tooltip, col0, col1); + } + + if (draw_streams_selector) + { + res &= draw_streams_and_formats(error_message, label, streaming_tooltip, col0, col1); } } @@ -777,6 +1059,7 @@ namespace rs2 { stream_enabled[p.unique_id()] = true; + // update format auto format_vec = format_values[p.unique_id()]; for (int i = 0; i < format_vec.size(); i++) { @@ -786,15 +1069,35 @@ namespace rs2 break; } } - for (int i = 0; i < res_values.size(); i++) + + // update resolution + if (!ui.is_multiple_resolutions) { - if (auto vid_prof = p.as()) - if (res_values[i].first == vid_prof.width() && res_values[i].second == vid_prof.height()) - { - ui.selected_res_id = i; - break; - } + for (int i = 0; i < res_values.size(); i++) + { + if (auto vid_prof = p.as()) + if (res_values[i].first == vid_prof.width() && res_values[i].second == vid_prof.height()) + { + ui.selected_res_id = i; + break; + } + } } + else + { + auto res_vec = profile_id_to_res[p.unique_id()]; + for (int i = 0; i < res_vec.size(); i++) + { + if (auto vid_prof = p.as()) + if (res_vec[i].first == vid_prof.width() && res_vec[i].second == vid_prof.height()) + { + ui.selected_res_id_map[p.unique_id()] = i; + break; + } + } + } + + // update fps for (int i = 0; i < shared_fps_values.size(); i++) { if (shared_fps_values[i] == p.fps()) @@ -845,8 +1148,21 @@ namespace rs2 void subdevice_model::get_sorted_profiles(std::vector& profiles) { auto fps = shared_fps_values[ui.selected_shared_fps_id]; - auto width = res_values[ui.selected_res_id].first; - auto height = res_values[ui.selected_res_id].second; + int width = 0; + int height = 0; + std::vector> selected_resolutions; + if (!ui.is_multiple_resolutions) + { + width = res_values[ui.selected_res_id].first; + height = res_values[ui.selected_res_id].second; + } + else + { + for (auto it = profile_id_to_res.begin(); it != profile_id_to_res.end(); ++it) + { + selected_resolutions.push_back(it->second[ui.selected_res_id_map[it->first]]); + } + } std::sort(profiles.begin(), profiles.end(), [&](stream_profile a, stream_profile b) { int score_a = 0, score_b = 0; if (a.fps() != fps) @@ -863,12 +1179,33 @@ namespace rs2 auto b_vp = a.as(); if (!a_vp || !b_vp) return score_a < score_b; - if (a_vp.width() != width || a_vp.height() != height) - score_a++; - if (b_vp.width() != width || b_vp.height() != height) - score_b++; + + if (!ui.is_multiple_resolutions) + { + if (a_vp.width() != width || a_vp.height() != height) + score_a++; + if (b_vp.width() != width || b_vp.height() != height) + score_b++; + } + else + { + bool a_same_res_found = false; + bool b_same_res_found = false; + for (int i = 0; i < selected_resolutions.size(); ++i) + { + if (a_vp.width() == selected_resolutions[i].first && a_vp.height() == selected_resolutions[i].second) + a_same_res_found = true; + if (b_vp.width() == selected_resolutions[i].first && b_vp.height() == selected_resolutions[i].second) + b_same_res_found = true; + } + if (!a_same_res_found) + score_a++; + if (!b_same_res_found) + score_b++; + } + return score_a < score_b; - }); + }); } std::vector subdevice_model::get_supported_profiles() @@ -883,18 +1220,52 @@ namespace rs2 num_streams++; stream_profile def_p; auto fps = shared_fps_values[ui.selected_shared_fps_id]; - auto width = res_values[ui.selected_res_id].first; - auto height = res_values[ui.selected_res_id].second; + int width = 0; + int height = 0; + std::vector> selected_resolutions; + if (!ui.is_multiple_resolutions) + { + width = res_values[ui.selected_res_id].first; + height = res_values[ui.selected_res_id].second; + } + else + { + for (auto it = profile_id_to_res.begin(); it != profile_id_to_res.end(); ++it) + { + selected_resolutions.push_back(it->second[ui.selected_res_id_map[it->first]]); + } + } + std::vector sorted_profiles = profiles; - if (ui.selected_res_id != last_valid_ui.selected_res_id) + if (!ui.is_multiple_resolutions && (ui.selected_res_id != last_valid_ui.selected_res_id)) { get_sorted_profiles(sorted_profiles); std::map> profiles_by_fps; for (auto&& p : sorted_profiles) { if (check_profile(p, [&](video_stream_profile vsp) - { return (vsp.width() == width && vsp.height() == height); }, + { return (vsp.width() == width && vsp.height() == height); }, + profiles_by_fps, results, p.fps(), num_streams, def_p)) + break; + } + } + else if (ui.is_multiple_resolutions && (ui.selected_res_id_map != last_valid_ui.selected_res_id_map)) + { + get_sorted_profiles(sorted_profiles); + std::map> profiles_by_fps; + for (auto&& p : sorted_profiles) + { + if (check_profile(p, [&](video_stream_profile vsp) + { + bool res = false; + std::pair cur_res; + if (p.stream_type() == RS2_STREAM_DEPTH) + cur_res = selected_resolutions[0]; + else + cur_res = selected_resolutions[1]; + return (vsp.width() == cur_res.first && vsp.height() == cur_res.second); + }, profiles_by_fps, results, p.fps(), num_streams, def_p)) break; } @@ -956,8 +1327,8 @@ namespace rs2 if (auto vid_prof = p.as()) { if (check_profile(p, [&](stream_profile prof) { return (std::find_if(matching_profiles.begin(), matching_profiles.end(), [&](stream_profile sp) - { return (stream_id != p.unique_id() && sp.fps() == p.fps() && sp.as().width() == vid_prof.width() && - sp.as().height() == vid_prof.height()); }) != matching_profiles.end()); }, + { return (stream_id != p.unique_id() && sp.fps() == p.fps() && sp.as().width() == vid_prof.width() && + sp.as().height() == vid_prof.height()); }) != matching_profiles.end()); }, profiles_by_fps_res, results, std::make_tuple(p.fps(), vid_prof.width(), vid_prof.height()), num_streams, def_p)) break; } @@ -973,11 +1344,33 @@ namespace rs2 for (auto&& p : sorted_profiles) { - // first try to find profile from the new stream to meatch the current configuration - if (check_profile(p, [&](video_stream_profile vid_prof) - { return (p.fps() == fps && vid_prof.width() == width && vid_prof.height() == height); }, - profiles_by_format, results, p.format(), num_streams, def_p)) - break; + // first try to find profile from the new stream to match the current configuration + if (!ui.is_multiple_resolutions) + { + if (check_profile(p, [&](video_stream_profile vid_prof) + { return (p.fps() == fps && vid_prof.width() == width && vid_prof.height() == height); }, + profiles_by_format, results, p.format(), num_streams, def_p)) + break; + } + else + { + if (check_profile(p, [&](video_stream_profile vid_prof) + { + bool res = false; + for (int i = 0; i < selected_resolutions.size(); ++i) + { + auto cur_res = selected_resolutions[i]; + if (p.fps() == fps && vid_prof.width() == cur_res.first && vid_prof.height() == cur_res.second) + { + res = true; + break; + } + } + return res; + }, + profiles_by_format, results, p.format(), num_streams, def_p)) + break; + } } if (results.size() < num_streams) { @@ -1076,12 +1469,27 @@ namespace rs2 { if (res_values.size() > 0) { - auto width = res_values[ui.selected_res_id].first; - auto height = res_values[ui.selected_res_id].second; - - error_message << "\n{" << stream_display_names[stream] << "," - << width << "x" << height << " at " << fps << "Hz, " - << rs2_format_to_string(format) << "} "; + int width = 0; + int height = 0; + std::vector> selected_resolutions; + if (!ui.is_multiple_resolutions) + { + width = res_values[ui.selected_res_id].first; + height = res_values[ui.selected_res_id].second; + error_message << "\n{" << stream_display_names[stream] << "," + << width << "x" << height << " at " << fps << "Hz, " + << rs2_format_to_string(format) << "} "; + } + else + { + for (auto it = profile_id_to_res.begin(); it != profile_id_to_res.end(); ++it) + { + selected_resolutions.push_back(it->second[ui.selected_res_id_map[it->first]]); + } + error_message << "\n{" << stream_display_names[stream] << "," + << selected_resolutions[0].first << "x" << selected_resolutions[0].second << " at " << fps << "Hz, " + << rs2_format_to_string(format) << "} "; + } if (p.unique_id() == stream && p.fps() == fps && p.format() == format) { @@ -1093,8 +1501,24 @@ namespace rs2 if (vid_prof.width() == max_color_res.first && vid_prof.height() == max_color_res.second) results.push_back(p); } - else if (vid_prof.width() == width && vid_prof.height() == height) - results.push_back(p); + else + { + if (!ui.is_multiple_resolutions) + { + if (vid_prof.width() == width && vid_prof.height() == height) + results.push_back(p); + } + else + { + std::pair cur_res; + if (p.stream_type() == RS2_STREAM_DEPTH) + cur_res = selected_resolutions[0]; + else + cur_res = selected_resolutions[1]; + if (vid_prof.width() == cur_res.first && vid_prof.height() == cur_res.second) + results.push_back(p); + } + } } } } @@ -1121,12 +1545,21 @@ namespace rs2 void subdevice_model::stop(std::shared_ptr not_model) { - if ( not_model ) + if (not_model) not_model->add_log("Stopping streaming"); streaming = false; _pause = false; + if (ui.is_multiple_resolutions) + { + int depth_res_id, ir1_res_id, ir2_res_id; + get_depth_ir_mismatch_resolutions_ids(depth_res_id, ir1_res_id, ir2_res_id); + streaming_map[depth_res_id] = false; + streaming_map[ir1_res_id] = false; + streaming_map[ir2_res_id] = false; + } + if (profiles[0].stream_type() == RS2_STREAM_COLOR) { std::lock_guard< std::mutex > lock(detected_objects->mutex); @@ -1143,10 +1576,10 @@ namespace rs2 _options_invalidated = true; queues.foreach([&](frame_queue& q) - { - frame f; - while (q.poll_for_frame(&f)); - }); + { + frame f; + while (q.poll_for_frame(&f)); + }); s->close(); } @@ -1177,9 +1610,9 @@ namespace rs2 void subdevice_model::verify_zero_order_conditions() { if (!can_enable_zero_order()) - throw std::runtime_error( rsutils::string::from() - << "Zero order filter requires both IR and Depth streams turned on.\nPlease " - "rectify the configuration and rerun" ); + throw std::runtime_error(rsutils::string::from() + << "Zero order filter requires both IR and Depth streams turned on.\nPlease " + "rectify the configuration and rerun"); } //The function decides if specific frame should be sent to the syncer @@ -1214,20 +1647,20 @@ namespace rs2 s->open(profiles); try { s->start([&, syncer](frame f) - { - // The condition here must match the condition inside render_loop()! - if( viewer.synchronization_enable ) - { - syncer->invoke(f); - } - else { - auto id = f.get_profile().unique_id(); - viewer.ppf.frames_queue[id].enqueue(f); + // The condition here must match the condition inside render_loop()! + if (viewer.synchronization_enable) + { + syncer->invoke(f); + } + else + { + auto id = f.get_profile().unique_id(); + viewer.ppf.frames_queue[id].enqueue(f); - on_frame(); - } - }); + on_frame(); + } + }); } catch (...) @@ -1238,6 +1671,16 @@ namespace rs2 _options_invalidated = true; streaming = true; + + if (ui.is_multiple_resolutions) + { + int depth_res_id, ir1_res_id, ir2_res_id; + get_depth_ir_mismatch_resolutions_ids(depth_res_id, ir1_res_id, ir2_res_id); + streaming_map[depth_res_id] = true; + streaming_map[ir1_res_id] = true; + streaming_map[ir2_res_id] = true; + } + if (s->is< color_sensor >()) { std::lock_guard< std::mutex > lock(detected_objects->mutex); @@ -1331,7 +1774,7 @@ namespace rs2 std::end(options_metadata), [&](const std::pair& p) {return p.second.supported && !viewer.is_option_skipped(p.second.opt); }); } - + bool subdevice_model::supports_on_chip_calib() { bool is_d400 = s->supports(RS2_CAMERA_INFO_PRODUCT_LINE) ? @@ -1346,4 +1789,21 @@ namespace rs2 return s->is() && is_d400 && supported_fw; // TODO: Once auto-calib makes it into the API, switch to querying camera info } + + void subdevice_model::get_depth_ir_mismatch_resolutions_ids(int& depth_res_id, int& ir1_res_id, int& ir2_res_id) const + { + auto it = profile_id_to_res.begin(); + if (it != profile_id_to_res.end()) + { + depth_res_id = it->first; + if (++it != profile_id_to_res.end()) + { + ir1_res_id = it->first; + if (++it != profile_id_to_res.end()) + { + ir2_res_id = it->first; + } + } + } + } } diff --git a/common/subdevice-model.h b/common/subdevice-model.h index 07e76af3fb..63820b8f70 100644 --- a/common/subdevice-model.h +++ b/common/subdevice-model.h @@ -64,6 +64,8 @@ namespace rs2 struct subdevice_ui_selection { int selected_res_id = 0; + std::map selected_res_id_map; // used for depth and ir mixed resolutions + bool is_multiple_resolutions = false; // used for depth and ir mixed resolutions int selected_shared_fps_id = 0; std::map selected_fps_id; std::map selected_format_id; @@ -82,7 +84,7 @@ namespace rs2 subdevice_model(device& dev, std::shared_ptr s, std::shared_ptr< atomic_objects_in_frame > objects, std::string& error_message, viewer_model& viewer, bool new_device_connected = true); ~subdevice_model(); - bool is_there_common_fps() ; + bool is_there_common_fps(); bool supports_on_chip_calib(); bool draw_stream_selection(std::string& error_message); bool is_selected_combination_supported(); @@ -93,13 +95,13 @@ namespace rs2 bool is_synchronized_frame(viewer_model& viewer, const frame& f); void update(std::string& error_message, notifications_model& model); void draw_options(const std::vector& drawing_order, - bool update_read_only_options, std::string& error_message, - notifications_model& model); + bool update_read_only_options, std::string& error_message, + notifications_model& model); uint64_t num_supported_non_default_options() const; bool draw_option(rs2_option opt, bool update_read_only_options, std::string& error_message, notifications_model& model) { - if(options_metadata.find(opt)!=options_metadata.end()) + if (options_metadata.find(opt) != options_metadata.end()) return options_metadata[opt].draw_option(update_read_only_options, streaming, error_message, model); return false; } @@ -121,8 +123,13 @@ namespace rs2 void restore_ui_selection() { ui = last_valid_ui; } void store_ui_selection() { last_valid_ui = ui; } + void get_depth_ir_mismatch_resolutions_ids(int& depth_res_id, int& ir1_res_id, int& ir2_res_id) const; + + bool is_multiple_resolutions_supported() { return false; } + + template - bool get_default_selection_index(const std::vector& values, const T & def, int* index) + bool get_default_selection_index(const std::vector& values, const T& def, int* index) { auto max_default = values.begin(); for (auto it = values.begin(); it != values.end(); it++) @@ -143,8 +150,8 @@ namespace rs2 } viewer_model& viewer; - std::function on_frame = []{}; - + std::function on_frame = [] {}; + std::ofstream _fout; std::shared_ptr s; @@ -164,6 +171,7 @@ namespace rs2 subdevice_ui_selection last_valid_ui; std::vector> res_values; + std::map>> profile_id_to_res; // used for depth and ir mixed resolutions std::map> fps_values_per_stream; std::vector shared_fps_values; bool show_single_fps_list = false; @@ -177,9 +185,10 @@ namespace rs2 int next_option = 0; std::vector supported_options; bool streaming = false; + std::map streaming_map; // used for depth and ir mixed resolutions bool allow_change_resolution_while_streaming = false; bool allow_change_fps_while_streaming = false; - rect normalized_zoom{0, 0, 1, 1}; + rect normalized_zoom{ 0, 0, 1, 1 }; rect roi_rect; bool auto_exposure_enabled = false; float depth_units = 1.f; @@ -211,10 +220,18 @@ namespace rs2 bool uvmapping_calib_full = false; private: + bool draw_resolutions(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1); + bool draw_fps(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1); + bool draw_streams_and_formats(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1); + bool draw_res_stream_formats(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1); + bool draw_resolutions_combo_box_multiple_resolutions(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1, + int stream_type_id, int depth_res_id); + bool draw_formats_combo_box_multiple_resolutions(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1, + int stream_type_id); std::pair get_max_resolution(rs2_stream stream) const; void sort_resolutions(std::vector>& resolutions) const; bool is_ir_calibration_profile() const; - + // used in method get_max_resolution per stream std::map>> resolutions_per_stream; From fc594576c67db760b2ada7af6aadfef6064d35ab Mon Sep 17 00:00:00 2001 From: Remi Bettan Date: Wed, 8 Mar 2023 11:02:51 +0200 Subject: [PATCH 2/2] moving method to private scope --- common/subdevice-model.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/subdevice-model.h b/common/subdevice-model.h index 63820b8f70..bdb5722c02 100644 --- a/common/subdevice-model.h +++ b/common/subdevice-model.h @@ -125,9 +125,6 @@ namespace rs2 void get_depth_ir_mismatch_resolutions_ids(int& depth_res_id, int& ir1_res_id, int& ir2_res_id) const; - bool is_multiple_resolutions_supported() { return false; } - - template bool get_default_selection_index(const std::vector& values, const T& def, int* index) { @@ -228,6 +225,7 @@ namespace rs2 int stream_type_id, int depth_res_id); bool draw_formats_combo_box_multiple_resolutions(std::string& error_message, std::string& label, std::function streaming_tooltip, float col0, float col1, int stream_type_id); + bool is_multiple_resolutions_supported() const { return false; } std::pair get_max_resolution(rs2_stream stream) const; void sort_resolutions(std::vector>& resolutions) const; bool is_ir_calibration_profile() const;