Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reflectivity tool to Depth Quality Tool application #7675

Merged
merged 2 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ set(COMMON_SRC
"${CMAKE_CURRENT_LIST_DIR}/sw-update/versions-db-manager.h"
"${CMAKE_CURRENT_LIST_DIR}/sw-update/versions-db-manager.cpp"
)

set(REFLECTIVITY_FILES
"${CMAKE_CURRENT_LIST_DIR}/reflectivity/reflectivity.h"
"${CMAKE_CURRENT_LIST_DIR}/reflectivity/reflectivity.cpp"
)
set(COMMON_SRC
${COMMON_SRC}
${SW_UPDATE_FILES})
${SW_UPDATE_FILES}
${REFLECTIVITY_FILES})

146 changes: 128 additions & 18 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ namespace rs2
for (auto i = 0; i < RS2_OPTION_COUNT; i++)
{
auto opt = static_cast<rs2_option>(i);
if (skip_option(opt)) continue;
if (viewer.is_option_skipped(opt)) continue;
if (std::find(drawing_order.begin(), drawing_order.end(), opt) == drawing_order.end())
{
draw_option(opt, update_read_only_options, error_message, notifications);
Expand All @@ -2037,7 +2037,7 @@ namespace rs2
return (uint64_t)std::count_if(
std::begin(options_metadata),
std::end(options_metadata),
[](const std::pair<int, option_model>& p) {return p.second.supported && !skip_option(p.second.opt); });
[&](const std::pair<int, option_model>& p) {return p.second.supported && !viewer.is_option_skipped(p.second.opt); });
}

bool option_model::draw_option(bool update_read_only_options,
Expand Down Expand Up @@ -2174,7 +2174,7 @@ namespace rs2
return !_stream_not_alive.eval();
}

void stream_model::begin_stream(std::shared_ptr<subdevice_model> d, rs2::stream_profile p)
void stream_model::begin_stream(std::shared_ptr<subdevice_model> d, rs2::stream_profile p, const viewer_model& viewer)
{
dev = d;
original_profile = p;
Expand All @@ -2195,7 +2195,82 @@ namespace rs2
static_cast<float>(vd.height()) };
}
_stream_not_alive.reset();

try
{
if( ! viewer.is_option_skipped( RS2_OPTION_ENABLE_IR_REFLECTIVITY ) )
{
auto ds = d->dev.first< depth_sensor >();
if( ds.supports( RS2_OPTION_ENABLE_IR_REFLECTIVITY )
&& ds.supports( RS2_OPTION_ENABLE_MAX_USABLE_RANGE )
&& ( ( p.stream_type() == RS2_STREAM_INFRARED ) || ( p.stream_type() == RS2_STREAM_DEPTH ) ) )
{
_reflectivity = std::unique_ptr< reflectivity >( new reflectivity() );
}
}
}
catch(...) {};

}

bool stream_model::draw_reflectivity( int x,
int y,
rs2::depth_sensor ds,
const std::map< int, stream_model > & streams,
std::stringstream & ss,
bool same_line )
{
bool reflectivity_valid = false;

// Get IR sample for getting current reflectivity
auto ir_stream
= std::find_if( streams.cbegin(),
streams.cend(),
[]( const std::pair< const int, stream_model > & stream ) {
return stream.second.profile.stream_type() == RS2_STREAM_INFRARED;
} );

// Get depth sample for adding to reflectivity history
auto depth_stream
= std::find_if( streams.cbegin(),
streams.cend(),
[]( const std::pair< const int, stream_model > & stream ) {
return stream.second.profile.stream_type() == RS2_STREAM_DEPTH;
} );

if( ir_stream != streams.end() && depth_stream != streams.end() )
{
auto depth_val = 0.0f;
auto ir_val = 0.0f;
depth_stream->second.texture->try_pick( x, y, &depth_val );
ir_stream->second.texture->try_pick( x, y, &ir_val );

_reflectivity->add_depth_sample( depth_val, x, y ); // Add depth sample to the history

float noise_est = ds.get_option( RS2_OPTION_NOISE_ESTIMATION );
auto mur_sensor = ds.as< max_usable_range_sensor >();
if( mur_sensor )
{
auto max_usable_range = mur_sensor.get_max_usable_depth_range();
reflectivity_valid = true;
std::string ref_str = "N/A";
try
{
auto pixel_ref = _reflectivity->get_reflectivity( noise_est, max_usable_range, ir_val );
ref_str = to_string() << std::dec << round( pixel_ref * 100 ) << "%";
}
catch( ... )
{
}

if( same_line )
ss << ", Reflectivity: " << ref_str;
else
ss << "\nReflectivity: " << ref_str;
}
}

return reflectivity_valid;
}

void stream_model::update_ae_roi_rect(const rect& stream_rect, const mouse_info& mouse, std::string& error_message)
Expand Down Expand Up @@ -2860,7 +2935,7 @@ namespace rs2
ImGui::PopStyleColor(5);
}

void stream_model::show_stream_footer(ImFont* font, const rect &stream_rect, const mouse_info& mouse, viewer_model& viewer)
void stream_model::show_stream_footer(ImFont* font, const rect &stream_rect, const mouse_info& mouse, const std::map<int, stream_model> &streams, viewer_model& viewer)
{
auto non_visual_stream = (profile.stream_type() == RS2_STREAM_GYRO)
|| (profile.stream_type() == RS2_STREAM_ACCEL)
Expand All @@ -2885,29 +2960,33 @@ namespace rs2
}

bool show_max_range = false;
bool show_reflectivity = false;

if (texture->get_last_frame().is<depth_frame>())
{
// Draw pixel distance
auto meters = texture->get_last_frame().as<depth_frame>().get_distance(x, y);

if (viewer.metric_system)
ss << std::dec << " = " << std::setprecision(3) << meters << " meters";
else
ss << std::dec << " = " << std::setprecision(3) << meters / FEET_TO_METER << " feet";

// Draw maximum usable depth range
auto ds = sensor_from_frame(texture->get_last_frame())->as<depth_sensor>();

if (viewer.draw_max_usable_range)
if (!viewer.is_option_skipped(RS2_OPTION_ENABLE_MAX_USABLE_RANGE))
{
if (ds.supports(RS2_OPTION_ENABLE_MAX_USABLE_RANGE))
if (ds.supports(RS2_OPTION_ENABLE_MAX_USABLE_RANGE) &&
(ds.get_option(RS2_OPTION_ENABLE_MAX_USABLE_RANGE) == 1.0f))
{
if (ds.get_option(RS2_OPTION_ENABLE_MAX_USABLE_RANGE) == 1.0)
auto mur_sensor = ds.as<max_usable_range_sensor>();
if (mur_sensor)
{
show_max_range = true;
auto mur_sensor = ds.as<max_usable_range_sensor>();
auto max_usable_range = mur_sensor.get_max_usable_depth_range();
const float MIN_RANGE = 3.0f;
const float MAX_RANGE = 9.0f;
// display maximu, usable range in range 3-9 [m] at 1 [m] resolution (rounded)
// display maximum usable range in range 3-9 [m] at 1 [m] resolution (rounded)
auto max_usable_range_rounded = round(std::min(std::max(max_usable_range, MIN_RANGE), MAX_RANGE));

if (viewer.metric_system)
Expand All @@ -2917,6 +2996,34 @@ namespace rs2
}
}
}

// Draw IR reflectivity on depth frame
if (_reflectivity)
{
maloel marked this conversation as resolved.
Show resolved Hide resolved
if (ds.get_option(RS2_OPTION_ENABLE_IR_REFLECTIVITY) == 1.0f)
{
// Add reflectivity information on frame, if max usable range is displayed, display reflectivity on the same line
show_reflectivity = draw_reflectivity(x, y, ds, streams, ss, show_max_range);
}
}
}

// Draw IR reflectivity on IR frame
if (_reflectivity)
{
bool lf_exist = texture->get_last_frame();
if (lf_exist)
{
auto ds = sensor_from_frame(texture->get_last_frame())->as<depth_sensor>();
if (ds.get_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY ) == 1.0f )
{
bool lf_exist = texture->get_last_frame();
if (is_stream_alive() && texture->get_last_frame().get_profile().stream_type() == RS2_STREAM_INFRARED)
{
show_reflectivity = draw_reflectivity(x, y, ds, streams, ss, show_max_range);
}
}
}
}

std::string msg(ss.str().c_str());
Expand All @@ -2929,7 +3036,7 @@ namespace rs2
auto width = float(msg.size() * 8);

// adjust width according to the longest line
if (show_max_range)
if (show_max_range || show_reflectivity)
{
footer_vertical_size = 50;
auto first_line_size = msg.find_first_of('\n') + 1;
Expand All @@ -2954,6 +3061,13 @@ namespace rs2
ImGui::Text("%s", msg.c_str());
ImGui::PopStyleColor(2);
}
else
{
if (_reflectivity)
{
_reflectivity->reset_history();
}
}
}

void stream_model::show_stream_imu(ImFont* font, const rect &stream_rect, const rs2_vector& axis, const mouse_info& mouse)
Expand Down Expand Up @@ -6201,15 +6315,11 @@ namespace rs2
for (auto&& i : sub->s->get_supported_options())
{
auto opt = static_cast<rs2_option>(i);
if (skip_option(opt)) continue;
if (viewer.is_option_skipped(opt)) continue;
if (std::find(drawing_order.begin(), drawing_order.end(), opt) == drawing_order.end())
{
if (serialize && opt == RS2_OPTION_VISUAL_PRESET)
continue;
if (opt == RS2_OPTION_ENABLE_MAX_USABLE_RANGE && !viewer.draw_max_usable_range)
{
continue;
}

if (sub->draw_option(opt, dev.is<playback>() || update_read_only_options, error_message, *viewer.not_model))
{
Expand Down Expand Up @@ -6242,7 +6352,7 @@ namespace rs2
for (auto i = 0; i < RS2_OPTION_COUNT; i++)
{
auto opt = static_cast<rs2_option>(i);
if (skip_option(opt)) continue;
if (viewer.is_option_skipped(opt)) continue;
pb->get_option(opt).draw_option(
dev.is<playback>() || update_read_only_options,
false, error_message, *viewer.not_model);
Expand Down Expand Up @@ -6445,7 +6555,7 @@ namespace rs2
{
for (auto&& opt : pb->get_option_list())
{
if (skip_option(opt)) continue;
if (viewer.is_option_skipped(opt)) continue;
pb->get_option(opt).draw_option(
dev.is<playback>() || update_read_only_options,
false, error_message, *viewer.not_model);
Expand Down
25 changes: 8 additions & 17 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "calibration-model.h"
#include "cah-model.h"
#include "../common/utilities/time/periodic_timer.h"
#include "reflectivity/reflectivity.h"

ImVec4 from_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a, bool consistent_color = false);
ImVec4 operator+(const ImVec4& c, float v);
Expand Down Expand Up @@ -264,20 +265,6 @@ namespace rs2

void imgui_easy_theming(ImFont*& font_14, ImFont*& font_18, ImFont*& monofont);

// avoid display the following options
bool static skip_option(rs2_option opt)
{
if (opt == RS2_OPTION_STREAM_FILTER ||
opt == RS2_OPTION_STREAM_FORMAT_FILTER ||
opt == RS2_OPTION_STREAM_INDEX_FILTER ||
opt == RS2_OPTION_FRAMES_QUEUE_SIZE ||
opt == RS2_OPTION_SENSOR_MODE ||
opt == RS2_OPTION_TRIGGER_CAMERA_ACCURACY_HEALTH ||
opt == RS2_OPTION_RESET_CAMERA_ACCURACY_HEALTH)
return true;
return false;
}

template<class T>
void sort_together(std::vector<T>& vec, std::vector<std::string>& names)
{
Expand Down Expand Up @@ -700,16 +687,16 @@ namespace rs2
rect get_normalized_zoom(const rect& stream_rect, const mouse_info& g, bool is_middle_clicked, float zoom_val);

bool is_stream_alive();

void show_stream_footer(ImFont* font, const rect& stream_rect,const mouse_info& mouse, viewer_model& viewer);
void show_stream_footer(ImFont* font, const rect &stream_rect, const mouse_info& mouse, const std::map<int, stream_model> &streams, viewer_model& viewer);
void show_stream_header(ImFont* font, const rect& stream_rect, viewer_model& viewer);
void show_stream_imu(ImFont* font, const rect& stream_rect, const rs2_vector& axis, const mouse_info& mouse);
void show_stream_pose(ImFont* font, const rect& stream_rect, const rs2_pose& pose_data,
rs2_stream stream_type, bool fullScreen, float y_offset, viewer_model& viewer);

void snapshot_frame(const char* filename,viewer_model& viewer) const;

void begin_stream(std::shared_ptr<subdevice_model> d, rs2::stream_profile p);
void begin_stream(std::shared_ptr<subdevice_model> d, rs2::stream_profile p, const viewer_model& viewer);
bool draw_reflectivity(int x, int y, rs2::depth_sensor ds, const std::map<int, stream_model> &streams, std::stringstream &ss, bool same_line = false);
rect layout;
std::shared_ptr<texture_buffer> texture;
float2 size;
Expand Down Expand Up @@ -742,6 +729,10 @@ namespace rs2
bool show_metadata = false;

animated<float> _info_height{ 0.f };

private:
std::unique_ptr< reflectivity > _reflectivity;

};

std::pair<std::string, std::string> get_device_name(const device& dev);
Expand Down