Skip to content

Commit

Permalink
PR IntelRealSense#12671 from Tamir91: Viewer Accel and Gyro dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir authored Mar 6, 2024
2 parents 1acf84c + 8b16100 commit c7c104d
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 190 deletions.
4 changes: 4 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ set(COMMON_SRC
"${CMAKE_CURRENT_LIST_DIR}/processing-block-model.cpp"
"${CMAKE_CURRENT_LIST_DIR}/stream-model.h"
"${CMAKE_CURRENT_LIST_DIR}/stream-model.cpp"
"${CMAKE_CURRENT_LIST_DIR}/motion-dashboard.h"
"${CMAKE_CURRENT_LIST_DIR}/motion-dashboard.cpp"
"${CMAKE_CURRENT_LIST_DIR}/frame-drops-dashboard.h"
"${CMAKE_CURRENT_LIST_DIR}/frame-drops-dashboard.cpp"
"${CMAKE_CURRENT_LIST_DIR}/post-processing-filters.h"
"${CMAKE_CURRENT_LIST_DIR}/post-processing-filters.cpp"
)
Expand Down
1 change: 1 addition & 0 deletions common/device-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ namespace rs2
static const char* is_measuring{ "viewer_model.is_measuring" };
static const char* output_open{ "viewer_model.output_open" };
static const char* dashboard_open{ "viewer_model.dashboard_open" };
static const char* last_opened_dashboard{ "viewer_model.last_opened_dashboard" };
static const char* search_term{ "viewer_model.search_term" };

static const char* log_to_console{ "viewer_model.log_to_console" };
Expand Down
103 changes: 103 additions & 0 deletions common/frame-drops-dashboard.cpp
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 );
}
} );
}
41 changes: 41 additions & 0 deletions common/frame-drops-dashboard.h
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;
};
}
191 changes: 191 additions & 0 deletions common/motion-dashboard.cpp
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() );
}
}
Loading

0 comments on commit c7c104d

Please sign in to comment.