Skip to content

Commit

Permalink
PR #13549 from Noy-Zini: Deprecate RS2_OPTION_SENSOR_MODE
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az authored Nov 28, 2024
2 parents f82b2ff + c5ac1c6 commit 5ea5ca2
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 210 deletions.
12 changes: 0 additions & 12 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@

#include "opengl3.h"

rs2_sensor_mode rs2::resolution_from_width_height(int width, int height)
{
if ((width == 240 && height == 320) || (width == 320 && height == 240))
return RS2_SENSOR_MODE_QVGA;
else if ((width == 640 && height == 480) || (height == 640 && width == 480))
return RS2_SENSOR_MODE_VGA;
else if ((width == 1024 && height == 768) || (height == 1024 && width == 768))
return RS2_SENSOR_MODE_XGA;
else
return RS2_SENSOR_MODE_COUNT;
}

ImVec4 flip(const ImVec4& c)
{
return{ c.y, c.x, c.z, c.w };
Expand Down
2 changes: 0 additions & 2 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ namespace rs2

static const float FEET_TO_METER = 0.3048f;

rs2_sensor_mode resolution_from_width_height(int width, int height);

template<class T>
void sort_together(std::vector<T>& vec, std::vector<std::string>& names)
{
Expand Down
152 changes: 3 additions & 149 deletions common/subdevice-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,6 @@

namespace rs2
{
static void width_height_from_resolution(rs2_sensor_mode mode, int& width, int& height)
{
switch (mode)
{
case RS2_SENSOR_MODE_VGA:
width = 640;
height = 480;
break;
case RS2_SENSOR_MODE_XGA:
width = 1024;
height = 768;
break;
case RS2_SENSOR_MODE_QVGA:
width = 320;
height = 240;
break;
default:
width = height = 0;
break;
}
}

static int get_resolution_id_from_sensor_mode(rs2_sensor_mode sensor_mode,
const std::vector< std::pair< int, int > >& res_values)
{
int width = 0, height = 0;
width_height_from_resolution(sensor_mode, width, height);
auto iter = std::find_if(res_values.begin(),
res_values.end(),
[width, height](std::pair< int, int > res) {
if (((res.first == width) && (res.second == height))
|| ((res.first == height) && (res.second == width)))
return true;
return false;
});
if (iter != res_values.end())
{
return static_cast<int>(std::distance(res_values.begin(), iter));
}

throw std::runtime_error("cannot convert sensor mode to resolution ID");
}

std::vector<const char*> get_string_pointers(const std::vector<std::string>& vec)
{
std::vector<const char*> res;
Expand Down Expand Up @@ -436,33 +393,6 @@ namespace rs2
ui.selected_res_id = selection_index;
}

if (new_device_connected)
{
// Have the various preset options automatically update based on the resolution of the
// (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())
{
// Watch out for read-only options in the playback sensor!
try
{
auto requested_sensor_mode = static_cast<float>(resolution_from_width_height(
res_values[ui.selected_res_id].first,
res_values[ui.selected_res_id].second));

auto currest_sensor_mode = s->get_option(RS2_OPTION_SENSOR_MODE);

if (requested_sensor_mode != currest_sensor_mode)
s->set_option(RS2_OPTION_SENSOR_MODE, requested_sensor_mode);
}
catch (not_implemented_error const&)
{
// Just ignore for now: need to figure out a way to write to playback sensors...
}
}
}

if (ui.is_multiple_resolutions)
{
for (auto it = ui.selected_res_id_map.begin(); it != ui.selected_res_id_map.end(); ++it)
Expand Down Expand Up @@ -568,46 +498,8 @@ namespace rs2
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)
{
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);
}
ui.selected_res_id = tmp_selected_res_id;

// 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<int>(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);
}
}
catch (...) {}
}
else
{
error_message = rsutils::string::from() << "Resolution " << width << "x" << height
<< " is not supported on this device";
}
}
else
{
ui.selected_res_id = tmp_selected_res_id;
}
}
ImGui::PopStyleColor();
ImGui::PopItemWidth();
Expand Down Expand Up @@ -807,47 +699,9 @@ namespace rs2
{
res = true;
_options_invalidated = true;

ui.selected_res_id_map[stream_type_id] = tmp_selected_res_id;

// 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)
{
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<int>(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);
}
}
catch (...) {}
}
else
{
error_message = rsutils::string::from() << "Resolution " << width << "x" << height
<< " is not supported on this device";
}
}
else
{
ui.selected_res_id_map[stream_type_id] = tmp_selected_res_id;
}
}
ImGui::PopStyleColor();
ImGui::PopItemWidth();
Expand Down
1 change: 0 additions & 1 deletion common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,6 @@ namespace rs2
_hidden_options.emplace(RS2_OPTION_STREAM_FORMAT_FILTER);
_hidden_options.emplace(RS2_OPTION_STREAM_INDEX_FILTER);
_hidden_options.emplace(RS2_OPTION_FRAMES_QUEUE_SIZE);
_hidden_options.emplace(RS2_OPTION_SENSOR_MODE);
_hidden_options.emplace(RS2_OPTION_NOISE_ESTIMATION);
_hidden_options.emplace(RS2_OPTION_REGION_OF_INTEREST);
}
Expand Down
4 changes: 2 additions & 2 deletions include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extern "C" {
RS2_OPTION_INVALIDATION_BYPASS, /**< Enable\disable pixel invalidation */
RS2_OPTION_AMBIENT_LIGHT, /**< DEPRECATED! - Use RS2_OPTION_DIGITAL_GAIN instead. */
RS2_OPTION_DIGITAL_GAIN = RS2_OPTION_AMBIENT_LIGHT, /**< Change the depth digital gain see rs2_digital_gain for values */
RS2_OPTION_SENSOR_MODE, /**< The resolution mode: see rs2_sensor_mode for values */
RS2_OPTION_SENSOR_MODE, /**< DEPRECATED! - The resolution mode: see rs2_sensor_mode for values */
RS2_OPTION_EMITTER_ALWAYS_ON, /**< Enable Laser On constantly (GS SKU Only) */
RS2_OPTION_THERMAL_COMPENSATION, /**< Depth Thermal Compensation for selected D400 SKUs */
RS2_OPTION_TRIGGER_CAMERA_ACCURACY_HEALTH, /**< DEPRECATED as of 2.46! */
Expand Down Expand Up @@ -237,7 +237,7 @@ extern "C" {
} rs2_l500_visual_preset;
const char* rs2_l500_visual_preset_to_string(rs2_l500_visual_preset preset);

/** \brief For setting the camera_mode option */
/** \brief DEPRECATED! - For setting the camera_mode option */
typedef enum rs2_sensor_mode
{
RS2_SENSOR_MODE_VGA,
Expand Down
11 changes: 0 additions & 11 deletions tools/depth-quality/depth-quality-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,17 +580,6 @@ namespace rs2
{
try // Retries are needed to cope with HW stability issues
{

auto dev = cfg.resolve(_pipe);
auto depth_sensor = dev.get_device().first< rs2::depth_sensor >();
if (depth_sensor.supports(RS2_OPTION_SENSOR_MODE))
{
auto depth_profile = dev.get_stream(RS2_STREAM_DEPTH);
auto w = depth_profile.as<video_stream_profile>().width();
auto h = depth_profile.as<video_stream_profile>().height();
depth_sensor.set_option(RS2_OPTION_SENSOR_MODE, (float)(resolution_from_width_height(w, h)));
}

auto profile = _pipe.start(cfg);
success = profile;
}
Expand Down
28 changes: 0 additions & 28 deletions unit-tests/live/live-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,34 +207,6 @@ inline stream_profile find_confidence_corresponding_to_depth(rs2::depth_sensor d
return *confidence_profile;
}

inline stream_profile
find_profile( rs2::depth_sensor depth_sens, rs2_stream stream, rs2_sensor_mode mode )
{
std::vector< stream_profile > stream_profiles;
REQUIRE_NOTHROW( stream_profiles = depth_sens.get_stream_profiles() );

std::map< rs2_sensor_mode, std::pair< uint32_t, uint32_t > > sensor_mode_to_resolution
= { { { RS2_SENSOR_MODE_VGA }, { 640, 480 } },
{ { RS2_SENSOR_MODE_XGA }, { 1024, 768 } },
{ { RS2_SENSOR_MODE_QVGA }, { 320, 240 } } };


auto profile
= std::find_if( stream_profiles.begin(), stream_profiles.end(), [&]( stream_profile sp ) {
auto vp = sp.as< video_stream_profile >();
if( vp )
{
return sp.stream_type() == stream
&& vp.width() == sensor_mode_to_resolution[mode].first
&& vp.height() == sensor_mode_to_resolution[mode].second;
}
return false;
} );

REQUIRE( profile != stream_profiles.end() );
return *profile;
}

inline void do_while_streaming( rs2::sensor depth_sens,
std::vector< stream_profile > profiles,
std::function< void() > action )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public enum Option {
INVALIDATION_BYPASS(68),
AMBIENT_LIGHT(69), // Deprecated - Use DIGITAL_GAIN instead
DIGITAL_GAIN(69),
SENSOR_MODE(70),
SENSOR_MODE(70), // Deprecated
EMITTER_ALWAYS_ON(71),
THERMAL_COMPENSATION(72),
TRIGGER_CAMERA_ACCURACY_HEALTH(73),
Expand Down
2 changes: 1 addition & 1 deletion wrappers/csharp/Intel.RealSense/Types/Enums/Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public enum Option
/// <summary>Change the depth digital gain see rs2_digital_gain for values</summary>
DigitalGain = 69,

/// <summary>The resolution mode: see rs2_sensor_mode for values</summary>
/// <summary>Deprecated - The resolution mode: see rs2_sensor_mode for values</summary>
SensorMode = 70,

/// <summary>Enable Laser On constantly (GS SKU Only)</summary>
Expand Down
2 changes: 1 addition & 1 deletion wrappers/matlab/option.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
invalidation_bypass (68)
ambient_light_env_level (69) % Deprecated - Use DIGITAL_GAIN instead
digital_gain (69)
sensor_mode (70)
sensor_mode (70) % Deprecated
emitter_always_on (71)
thermal_compensation (72)
trigger_camera_accuracy_health (73)
Expand Down
2 changes: 1 addition & 1 deletion wrappers/python/pybackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ PYBIND11_MODULE(NAME, m) {
.value("activate_pixel_invalidation", RS2_OPTION_INVALIDATION_BYPASS)
.value("ambient_light_environment_level", RS2_OPTION_AMBIENT_LIGHT)
.value("digital_gain", RS2_OPTION_DIGITAL_GAIN)
.value("sensor_resolution_mode", RS2_OPTION_SENSOR_MODE)
.value("sensor_resolution_mode", RS2_OPTION_SENSOR_MODE) // Deprecated
.value("emitter_always_on", RS2_OPTION_EMITTER_ALWAYS_ON)
.value("thermal_compensation", RS2_OPTION_THERMAL_COMPENSATION)
.value("host_performance", RS2_OPTION_HOST_PERFORMANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ enum class ERealSenseOptionType : uint8
INVALIDATION_BYPASS , /**< Enable\disable pixel invalidation */
AMBIENT_LIGHT , /**< Change the depth ambient light see rs2_ambient_light for values */
DIGITAL_GAIN = AMBIENT_LIGHT , /**< Change the depth digital gain see rs2_digital_gain for values */
SENSOR_MODE , /**< The resolution mode: see rs2_sensor_mode for values */
SENSOR_MODE , /**< Deprecated!! - The resolution mode: see rs2_sensor_mode for values */
EMITTER_ALWAYS_ON , /**< Enable Laser On constantly (GS SKU Only) */
THERMAL_COMPENSATION , /**< Depth Thermal Compensation for selected D400 SKUs */
TRIGGER_CAMERA_ACCURACY_HEALTH , /**< DEPRECATED! */
Expand Down

0 comments on commit 5ea5ca2

Please sign in to comment.