forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR IntelRealSense#12671 from Tamir91: Viewer Accel and Gyro dashboards
- Loading branch information
Showing
9 changed files
with
463 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2024 Intel Corporation. All Rights Reserved. | ||
|
||
#include "frame-drops-dashboard.h" | ||
|
||
using namespace rs2; | ||
using namespace rsutils::string; | ||
|
||
void frame_drops_dashboard::process_frame( rs2::frame f ) | ||
{ | ||
write_shared_data( | ||
[&]() | ||
{ | ||
double ts = glfwGetTime(); | ||
if( method == 1 ) | ||
ts = f.get_timestamp() / 1000.f; | ||
auto it = stream_to_time.find( f.get_profile().unique_id() ); | ||
if( it != stream_to_time.end() ) | ||
{ | ||
auto last = stream_to_time[f.get_profile().unique_id()]; | ||
|
||
double fps = (double)f.get_profile().fps(); | ||
|
||
if( f.supports_frame_metadata( RS2_FRAME_METADATA_ACTUAL_FPS ) ) | ||
fps = f.get_frame_metadata( RS2_FRAME_METADATA_ACTUAL_FPS ) / 1000.; | ||
|
||
if( 1000. * ( ts - last ) > 1.5 * ( 1000. / fps ) ) | ||
{ | ||
drops++; | ||
} | ||
} | ||
|
||
counter++; | ||
|
||
if( ts - last_time > 1.f ) | ||
{ | ||
if( drops_history.size() > 100 ) | ||
drops_history.pop_front(); | ||
drops_history.push_back( drops ); | ||
*total = counter; | ||
*frame_drop_count = drops; | ||
drops = 0; | ||
last_time = ts; | ||
counter = 0; | ||
} | ||
|
||
stream_to_time[f.get_profile().unique_id()] = ts; | ||
} ); | ||
} | ||
|
||
void frame_drops_dashboard::draw( ux_window & win, rect r ) | ||
{ | ||
auto hist = read_shared_data< std::deque< int > >( [&]() { return drops_history; } ); | ||
for( int i = 0; i < hist.size(); i++ ) | ||
{ | ||
add_point( (float)i, (float)hist[i] ); | ||
} | ||
r.h -= ImGui::GetTextLineHeightWithSpacing() + 10; | ||
|
||
draw_dashboard( win, r ); | ||
|
||
ImGui::SetCursorPosX( ImGui::GetCursorPosX() + ImGui::GetTextLineHeightWithSpacing() * 2 ); | ||
ImGui::SetCursorPosY( ImGui::GetCursorPosY() + 3 ); | ||
ImGui::Text( "%s", "Measurement Metric:" ); | ||
ImGui::SameLine(); | ||
ImGui::SetCursorPosY( ImGui::GetCursorPosY() - 3 ); | ||
|
||
ImGui::SetCursorPosX( 11.5f * win.get_font_size() ); | ||
|
||
std::vector< const char * > methods; | ||
methods.push_back( "Viewer Processing Rate" ); | ||
methods.push_back( "Camera Timestamp Rate" ); | ||
|
||
ImGui::PushItemWidth( -1.f ); | ||
if( ImGui::Combo( "##fps_method", &method, methods.data(), (int)( methods.size() ) ) ) | ||
{ | ||
clear( false ); | ||
} | ||
ImGui::PopItemWidth(); | ||
} | ||
|
||
int frame_drops_dashboard::get_height() const | ||
{ | ||
return (int)( 10 * ImGui::GetTextLineHeight() + ImGui::GetTextLineHeightWithSpacing() ); | ||
} | ||
|
||
void frame_drops_dashboard::clear( bool full ) | ||
{ | ||
write_shared_data( | ||
[&]() | ||
{ | ||
stream_to_time.clear(); | ||
last_time = 0; | ||
*total = 0; | ||
*frame_drop_count = 0; | ||
if( full ) | ||
{ | ||
drops_history.clear(); | ||
for( int i = 0; i < 100; i++ ) | ||
drops_history.push_back( 0 ); | ||
} | ||
} ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2024 Intel Corporation. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "output-model.h" | ||
#include "device-model.h" | ||
|
||
#include <rs-config.h> | ||
#include "ux-window.h" | ||
|
||
namespace rs2 | ||
{ | ||
class frame_drops_dashboard : public stream_dashboard | ||
{ | ||
public: | ||
frame_drops_dashboard( std::string name, int * frame_drop_count, int * total ) | ||
: stream_dashboard( name, 30 ) | ||
, last_time( glfwGetTime() ) | ||
, frame_drop_count( frame_drop_count ) | ||
, total( total ) | ||
{ | ||
clear( true ); | ||
} | ||
|
||
void process_frame( rs2::frame f ) override; | ||
void draw( ux_window & win, rect r ) override; | ||
int get_height() const override; | ||
|
||
void clear( bool full ) override; | ||
|
||
private: | ||
std::map< int, double > stream_to_time; | ||
int drops = 0; | ||
double last_time; | ||
std::deque< int > drops_history; | ||
int *frame_drop_count, *total; | ||
int counter = 0; | ||
int method = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2024 Intel Corporation. All Rights Reserved. | ||
|
||
#include "output-model.h" | ||
#include "motion-dashboard.h" | ||
|
||
using namespace rs2; | ||
using namespace rsutils::string; | ||
|
||
motion_dashboard::motion_dashboard( std::string name, enum rs2_stream stream) | ||
: stream_dashboard( name, 30 ) | ||
, last_time( glfwGetTime() ) | ||
, x_value( 0 ) | ||
, y_value( 0 ) | ||
, z_value( 0 ) | ||
, n_value( 0 ) | ||
{ | ||
dashboard_update_rate = MAX_FRAME_RATE; | ||
stream_type = stream; | ||
clear( true ); | ||
} | ||
|
||
void motion_dashboard::process_frame( rs2::frame f ) | ||
{ | ||
write_shared_data( | ||
[&]() | ||
{ | ||
if( f && f.is< rs2::motion_frame >() | ||
&& ( f.as< rs2::motion_frame >() ).get_profile().stream_type() == stream_type ) | ||
{ | ||
double ts = glfwGetTime(); | ||
|
||
if( ts - last_time > dashboard_update_rate ) | ||
{ | ||
rs2::motion_frame frame = f.as< rs2::motion_frame >(); | ||
|
||
x_value = frame.get_motion_data().x; | ||
y_value = frame.get_motion_data().y; | ||
z_value = frame.get_motion_data().z; | ||
n_value = std::sqrt( ( x_value * x_value ) + ( y_value * y_value ) + ( z_value * z_value ) ); | ||
|
||
if( x_history.size() > DEQUE_SIZE ) | ||
x_history.pop_front(); | ||
if( y_history.size() > DEQUE_SIZE ) | ||
y_history.pop_front(); | ||
if( z_history.size() > DEQUE_SIZE ) | ||
z_history.pop_front(); | ||
if( n_history.size() > DEQUE_SIZE ) | ||
n_history.pop_front(); | ||
|
||
x_history.push_back( x_value ); | ||
y_history.push_back( y_value ); | ||
z_history.push_back( z_value ); | ||
n_history.push_back( n_value ); | ||
|
||
last_time = ts; | ||
} | ||
} | ||
} ); | ||
} | ||
|
||
void motion_dashboard::draw( ux_window & win, rect r ) | ||
{ | ||
if( plots[plot_index] == x_axes_name ) | ||
{ | ||
auto x_hist = read_shared_data< std::deque< float > >( [&]() { return x_history; } ); | ||
for( int i = 0; i < x_hist.size(); i++ ) | ||
{ | ||
add_point( (float)i, x_hist[i] ); | ||
} | ||
} | ||
|
||
if( plots[plot_index] == y_axes_name ) | ||
{ | ||
auto y_hist = read_shared_data< std::deque< float > >( [&]() { return y_history; } ); | ||
for( int i = 0; i < y_hist.size(); i++ ) | ||
{ | ||
add_point( (float)i, y_hist[i] ); | ||
} | ||
} | ||
|
||
if( plots[plot_index] == z_axes_name ) | ||
{ | ||
auto z_hist = read_shared_data< std::deque< float > >( [&]() { return z_history; } ); | ||
for( int i = 0; i < z_hist.size(); i++ ) | ||
{ | ||
add_point( (float)i, z_hist[i] ); | ||
} | ||
} | ||
|
||
if( plots[plot_index] == n_axes_name ) | ||
{ | ||
auto n_hist = read_shared_data< std::deque< float > >( [&]() { return n_history; } ); | ||
for( int i = 0; i < n_hist.size(); i++ ) | ||
{ | ||
add_point( (float)i, n_hist[i] ); | ||
} | ||
} | ||
r.h -= ImGui::GetTextLineHeightWithSpacing() + 10; | ||
draw_dashboard( win, r ); | ||
|
||
ImGui::SetCursorPosX( ImGui::GetCursorPosX() + ImGui::GetTextLineHeightWithSpacing() * 2 ); | ||
show_radiobuttons(); | ||
|
||
ImGui::SameLine(); | ||
|
||
show_data_rate_slider(); | ||
} | ||
|
||
int motion_dashboard::get_height() const | ||
{ | ||
return (int)( 10 * ImGui::GetTextLineHeight() + ImGui::GetTextLineHeightWithSpacing() ); | ||
} | ||
|
||
void motion_dashboard::clear( bool full ) | ||
{ | ||
write_shared_data( | ||
[&]() | ||
{ | ||
if( full ) | ||
{ | ||
x_history.clear(); | ||
for( int i = 0; i < DEQUE_SIZE; i++ ) | ||
x_history.push_back( 0 ); | ||
|
||
y_history.clear(); | ||
for( int i = 0; i < DEQUE_SIZE; i++ ) | ||
y_history.push_back( 0 ); | ||
|
||
z_history.clear(); | ||
for( int i = 0; i < DEQUE_SIZE; i++ ) | ||
z_history.push_back( 0 ); | ||
|
||
n_history.clear(); | ||
for( int i = 0; i < DEQUE_SIZE; i++ ) | ||
n_history.push_back( 0 ); | ||
} | ||
} ); | ||
} | ||
|
||
void motion_dashboard::show_radiobuttons() | ||
{ | ||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.0f, 0.0f, 0.0f, 1.0f ) ); // -> Red | ||
ImGui::RadioButton( "X", &plot_index, 0 ); | ||
if( ImGui::IsItemHovered() ) | ||
ImGui::SetTooltip( "%s", std::string( rsutils::string::from() << "Show " << x_axes_name ).c_str() ); | ||
ImGui::PopStyleColor(); | ||
ImGui::SameLine(); | ||
|
||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.00f, 1.00f, 0.00f, 1.00f ) ); // -> Green | ||
ImGui::RadioButton( "Y", &plot_index, 1 ); | ||
if( ImGui::IsItemHovered() ) | ||
ImGui::SetTooltip( "%s", std::string( rsutils::string::from() << "Show " << y_axes_name ).c_str() ); | ||
ImGui::PopStyleColor(); | ||
ImGui::SameLine(); | ||
|
||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.00f, 0.00f, 1.00f, 1.00f ) ); // -> Blue | ||
ImGui::RadioButton( "Z", &plot_index, 2 ); | ||
if( ImGui::IsItemHovered() ) | ||
ImGui::SetTooltip( "%s", std::string( rsutils::string::from() << "Show " << z_axes_name ).c_str() ); | ||
ImGui::PopStyleColor(); | ||
ImGui::SameLine(); | ||
|
||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1.00f, 1.00f, 1.00f, 1.00f ) ); // -> White | ||
ImGui::RadioButton( "N", &plot_index, 3 ); | ||
if( ImGui::IsItemHovered() ) | ||
ImGui::SetTooltip( "%s", "Show Normal - sqrt(x^2 + y^2 + z^2)" ); | ||
ImGui::PopStyleColor(); | ||
} | ||
|
||
void motion_dashboard::show_data_rate_slider() | ||
{ | ||
if( ( ImGui::GetContentRegionMax().x - ImGui::GetCursorPosX() - 10.f ) < 100 ) | ||
ImGui::PushItemWidth( ImGui::GetContentRegionMax().x - ImGui::GetCursorPosX() - 10.f ); | ||
else | ||
ImGui::PushItemWidth( 100 ); | ||
|
||
ImGui::SliderFloat( "##rate", &dashboard_update_rate, MIN_FRAME_RATE, MAX_FRAME_RATE, "%.2f" ); | ||
ImGui::GetWindowWidth(); | ||
|
||
if (ImGui::IsItemHovered()) | ||
{ | ||
ImGui::SetTooltip( "%s", std::string( rsutils::string::from() | ||
<< "Dashboard update every " | ||
<< std::fixed | ||
<< std::setprecision(1) | ||
<< dashboard_update_rate * 1000 | ||
<< " mSec" | ||
).c_str() ); | ||
} | ||
} |
Oops, something went wrong.