Skip to content

Commit

Permalink
PR IntelRealSense#13219 from Eran: Viewer displays options in the ord…
Browse files Browse the repository at this point in the history
…er reported by librealsense
  • Loading branch information
maloel authored Aug 1, 2024
2 parents 06af7e6 + f229ed0 commit b7ba086
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 26 deletions.
6 changes: 3 additions & 3 deletions common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2620,11 +2620,11 @@ namespace rs2

std::vector<rs2_option> so_ordered;

for (auto const & id_model : supported_options)
for( auto const id_model : sub->supported_options )
{
auto it = find( color_options.begin(), color_options.end(), id_model.first );
auto it = find( color_options.begin(), color_options.end(), id_model );
if (it == color_options.end())
so_ordered.push_back( id_model.first );
so_ordered.push_back( id_model );
}

std::for_each( color_options.begin(),
Expand Down
42 changes: 36 additions & 6 deletions src/core/options-container.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.
// Copyright(c) 2023-4 Intel Corporation. All Rights Reserved.

#include "options-container.h"
#include "enum-helpers.h"
Expand All @@ -12,8 +12,8 @@ namespace librealsense {

const option & options_container::get_option( rs2_option id ) const
{
auto it = _options.find( id );
if( it == _options.end() )
auto it = _options_by_id.find( id );
if( it == _options_by_id.end() )
{
throw invalid_value_exception( rsutils::string::from()
<< "option '" << get_option_name( id ) << "' not supported" );
Expand All @@ -27,17 +27,47 @@ void options_container::update( std::shared_ptr< extension_snapshot > ext )
auto ctr = As< options_container >( ext );
if( ! ctr )
return;
for( auto && opt : ctr->_options )
for( auto id : ctr->_ordered_options )
{
_options[opt.first] = opt.second;
auto & opt = _options_by_id[id];
if( ! opt )
_ordered_options.push_back( id );
opt = ctr->_options_by_id[id];
}
}


void options_container::register_option( rs2_option id, std::shared_ptr< option > option )
{
auto & opt = _options_by_id[id];
if( ! opt )
_ordered_options.push_back( id );
opt = option;
_recording_function( *this );
}


void options_container::unregister_option( rs2_option id )
{
for( auto it = _ordered_options.begin(); it != _ordered_options.end(); ++it )
{
if( *it == id )
{
_ordered_options.erase( it );
break;
}
}
_options_by_id.erase( id );
}


std::vector< rs2_option > options_container::get_supported_options() const
{
// Return options ordered by their ID values! This means custom options will be first!
// Kept for backwards compatibility with existing devices; software sensors will return the _ordered_options

std::vector< rs2_option > options;
for( auto option : _options )
for( auto option : _options_by_id )
options.push_back( option.first );

return options;
Expand Down
30 changes: 13 additions & 17 deletions src/core/options-container.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.
// Copyright(c) 2015-24 Intel Corporation. All Rights Reserved.
#pragma once

#include "options-interface.h"
Expand All @@ -24,8 +24,9 @@ class LRS_EXTENSION_API options_container : public virtual options_interface, pu
public:
bool supports_option(rs2_option id) const override
{
auto it = _options.find(id);
if (it == _options.end()) return false;
auto it = _options_by_id.find( id );
if( it == _options_by_id.end() )
return false;
return it->second->is_enabled();
}

Expand All @@ -41,22 +42,16 @@ class LRS_EXTENSION_API options_container : public virtual options_interface, pu
return (const_cast<const options_container*>(this)->get_option_handler(id));
}

std::shared_ptr<option> get_option_handler(rs2_option id) const
std::shared_ptr<option> get_option_handler( rs2_option id ) const
{
auto it = _options.find(id);
return (it == _options.end() ? std::shared_ptr<option>(nullptr) : it->second);
auto it = _options_by_id.find( id );
if( it == _options_by_id.end() )
return {};
return it->second;
}

void register_option(rs2_option id, std::shared_ptr<option> option)
{
_options[id] = option;
_recording_function(*this);
}

void unregister_option(rs2_option id)
{
_options.erase(id);
}
void register_option( rs2_option id, std::shared_ptr< option > option );
void unregister_option( rs2_option id );

void create_snapshot(std::shared_ptr<options_interface>& snapshot) const override
{
Expand All @@ -75,7 +70,8 @@ class LRS_EXTENSION_API options_container : public virtual options_interface, pu
std::string const & get_option_name( rs2_option option ) const override;

protected:
std::map<rs2_option, std::shared_ptr<option>> _options;
std::vector< rs2_option > _ordered_options;
std::map< rs2_option, std::shared_ptr< option > > _options_by_id;
std::function<void(const options_interface&)> _recording_function = [](const options_interface&) {};
};

Expand Down
8 changes: 8 additions & 0 deletions src/software-sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,12 @@ void software_sensor::add_processing_block( std::shared_ptr< processing_block_in
}


std::vector< rs2_option > software_sensor::get_supported_options() const
{
// Override the default options_container behavior: software sensors return the options in the same order they were
// registered!
return _ordered_options;
}


} // namespace librealsense
4 changes: 4 additions & 0 deletions src/software-sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class software_sensor
void set_metadata( rs2_frame_metadata_value key, rs2_metadata_type value );
void erase_metadata( rs2_frame_metadata_value key );

// options_container
public:
std::vector< rs2_option > get_supported_options() const override;

protected:
frame_interface * allocate_new_frame( rs2_extension, stream_profile_interface *, frame_additional_data && );
frame_interface * allocate_new_video_frame( video_stream_profile_interface *, int stride, int bpp, frame_additional_data && );
Expand Down

0 comments on commit b7ba086

Please sign in to comment.