diff --git a/src/core/advanced_mode.h b/src/core/advanced_mode.h index 74d78ff2d9..fd645558c8 100644 --- a/src/core/advanced_mode.h +++ b/src/core/advanced_mode.h @@ -208,7 +208,10 @@ namespace librealsense rsutils::lazy< bool > _amplitude_factor_support; preset get_all() const; - void set_all(const preset& p); + void set_all( const preset & p ); + void set_all_depth( const preset & p ); + void set_all_color( const preset & p ); + bool should_set_color_preset() const; std::vector send_receive(const std::vector& input) const; diff --git a/src/ds/advanced_mode/advanced_mode.cpp b/src/ds/advanced_mode/advanced_mode.cpp index 0aee47000c..16bb0a3d66 100644 --- a/src/ds/advanced_mode/advanced_mode.cpp +++ b/src/ds/advanced_mode/advanced_mode.cpp @@ -4,10 +4,9 @@ #include "core/advanced_mode.h" #include "json_loader.hpp" #include "ds/d400/d400-color.h" - +#include "ds/d500/d500-color.h" #include - namespace librealsense { void ds_advanced_mode_base::register_to_visual_preset_option() @@ -42,18 +41,23 @@ namespace librealsense if (is_enabled()) register_to_visual_preset_option(); - _color_sensor = [this]() { - auto& dev = _depth_sensor.get_device(); - for (size_t i = 0; i < dev.get_sensors_count(); ++i) + _color_sensor = [this]() -> synthetic_sensor * + { + auto & dev = _depth_sensor.get_device(); + for( size_t i = 0; i < dev.get_sensors_count(); ++i ) { - if (auto s = dynamic_cast(&(dev.get_sensor(i)))) + if( auto s = dynamic_cast< const d400_color_sensor * >( &( dev.get_sensor( i ) ) ) ) + { + return const_cast< d400_color_sensor * >( s ); + } + if( auto s = dynamic_cast< const d500_color_sensor * >( &( dev.get_sensor( i ) ) ) ) { - return const_cast(s); + return const_cast< d500_color_sensor * >( s ); } } - return (d400_color_sensor*)nullptr; + return nullptr; }; - + _amplitude_factor_support = [this]() { auto fw_ver = firmware_version(_depth_sensor.get_device().get_info(rs2_camera_info::RS2_CAMERA_INFO_FIRMWARE_VERSION)); return (fw_ver >= firmware_version("5.11.9.0")); @@ -753,15 +757,18 @@ namespace librealsense return p; } - void ds_advanced_mode_base::set_all(const preset& p) + void ds_advanced_mode_base::set_all( const preset & p ) + { + set_all_depth( p ); + if( should_set_color_preset() ) + set_all_color( p ); + } + + void ds_advanced_mode_base::set_all_depth(const preset& p) { set(p.depth_controls, advanced_mode_traits::group); set(p.rsm , advanced_mode_traits::group); set(p.rsvc , advanced_mode_traits::group); - set(p.color_control , advanced_mode_traits::group); - set(p.rctc , advanced_mode_traits::group); - set(p.sctc , advanced_mode_traits::group); - set(p.spc , advanced_mode_traits::group); set(p.hdad , advanced_mode_traits::group); // Setting auto-white-balance control before colorCorrection parameters @@ -784,6 +791,14 @@ namespace librealsense set_depth_gain(p.depth_gain); set_depth_exposure(p.depth_exposure); } + } + + void ds_advanced_mode_base::set_all_color( const preset & p ) + { + set( p.color_control, advanced_mode_traits< STColorControl >::group ); + set( p.rctc , advanced_mode_traits< STRauColorThresholdsControl >::group ); + set( p.sctc , advanced_mode_traits< STSloColorThresholdsControl >::group ); + set( p.spc , advanced_mode_traits< STSloPenaltyControl >::group ); set_color_auto_exposure(p.color_auto_exposure); if (p.color_auto_exposure.was_set && p.color_auto_exposure.auto_exposure == 0) @@ -808,6 +823,13 @@ namespace librealsense //set_color_power_line_frequency(p.color_power_line_frequency); } + bool ds_advanced_mode_base::should_set_color_preset() const + { + auto product_line = _depth_sensor.get_device().get_info( rs2_camera_info::RS2_CAMERA_INFO_PRODUCT_LINE ); + + return product_line != "D500"; + } + std::vector ds_advanced_mode_base::send_receive(const std::vector& input) const { auto res = _hw_monitor->send(input); diff --git a/unit-tests/live/options/test-presets.py b/unit-tests/live/options/test-presets.py new file mode 100644 index 0000000000..282239651d --- /dev/null +++ b/unit-tests/live/options/test-presets.py @@ -0,0 +1,56 @@ +# License: Apache 2.0. See LICENSE file in root directory. +# Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +# test:device each(D400*) + +import pyrealsense2 as rs +from rspy import test +from rspy import log + +dev = test.find_first_device_or_exit() +depth_sensor = dev.first_depth_sensor() +color_sensor = dev.first_color_sensor() +product_line = dev.get_info(rs.camera_info.product_line) + + +with test.closure( 'visual preset support', on_fail=test.ABORT ): # No use continuing the test if there is no preset support + test.check( depth_sensor.supports( rs.option.visual_preset ) ) + +with test.closure( 'set presets' ): + depth_sensor.set_option( rs.option.visual_preset, int(rs.rs400_visual_preset.high_accuracy ) ) + test.check( depth_sensor.get_option( rs.option.visual_preset ) == rs.rs400_visual_preset.high_accuracy ) + depth_sensor.set_option( rs.option.visual_preset, int(rs.rs400_visual_preset.default ) ) + test.check( depth_sensor.get_option( rs.option.visual_preset ) == rs.rs400_visual_preset.default ) + +with test.closure( 'save/load preset' ): + am_dev = rs.rs400_advanced_mode(dev) + saved_values = am_dev.serialize_json() + depth_control_group = am_dev.get_depth_control() + depth_control_group.textureCountThreshold = 250 + am_dev.set_depth_control( depth_control_group ) + test.check( depth_sensor.get_option( rs.option.visual_preset ) == rs.rs400_visual_preset.custom ) + + am_dev.load_json( saved_values ) + test.check( am_dev.get_depth_control().textureCountThreshold != 250 ) + +with test.closure( 'setting color options' ): + # Using Hue to test if setting visual preset changes color sensor settings. + # Not all cameras support Hue (e.g. D457) but using common setting like Gain or Exposure is dependant on auto-exposure logic + # This test is intended to check new D500 modules logic of not updating color sensor setting, while keeping legacy + # D400 devices behavior of updating it. For this purpose it is OK if not all module types will be tested. + if color_sensor.supports( rs.option.hue ): + color_sensor.set_option( rs.option.hue, 123 ) + test.check( color_sensor.get_option( rs.option.hue ) == 123 ) + + depth_sensor.set_option( rs.option.visual_preset, int(rs.rs400_visual_preset.default ) ) + if product_line == "D400": + # D400 devices set color options as part of preset setting + test.check( color_sensor.get_option( rs.option.hue ) != 123 ) + elif product_line == "D500": + # D500 devices do not set color options as part of preset setting + test.check( color_sensor.get_option( rs.option.hue ) == 123 ) + else: + raise RuntimeError( 'unsupported product line' ) + + +test.print_results_and_exit()