Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
Variables names, Function separating
  • Loading branch information
Tamir91 committed Mar 4, 2024
1 parent a7eeea1 commit 8a95915
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 184 deletions.
2 changes: 0 additions & 2 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ set(COMMON_SRC
"${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}/accel-dashboard.cpp"
"${CMAKE_CURRENT_LIST_DIR}/gyro-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"
Expand Down
54 changes: 0 additions & 54 deletions common/accel-dashboard.cpp

This file was deleted.

54 changes: 0 additions & 54 deletions common/gyro-dashboard.cpp

This file was deleted.

94 changes: 69 additions & 25 deletions common/motion-dashboard.cpp
Original file line number Diff line number Diff line change
@@ -1,58 +1,102 @@
// 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 )
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 )
{
frame_rate = MAX_FRAME_RATE;
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();
auto it = frame_to_time.find( f.get_profile().unique_id() );

if( ts - last_time > dashboard_update_rate && it != frame_to_time.end() )
{
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;
}

frame_to_time[f.get_profile().unique_id()] = ts;
}
} );
}

void motion_dashboard::draw( ux_window & win, rect r )
{
if( accel_params[curr_accel_param_position] == "X" )
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, (float)x_hist[i] );
add_point( (float)i, x_hist[i] );
}
}

if( accel_params[curr_accel_param_position] == "Y" )
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, (float)y_hist[i] );
add_point( (float)i, y_hist[i] );
}
}

if( accel_params[curr_accel_param_position] == "Z" )
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, (float)z_hist[i] );
add_point( (float)i, z_hist[i] );
}
}

if( accel_params[curr_accel_param_position] == "N" )
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, (float)n_hist[i] );
add_point( (float)i, n_hist[i] );
}
}
r.h -= ImGui::GetTextLineHeightWithSpacing() + 10;
Expand Down Expand Up @@ -99,47 +143,47 @@ void motion_dashboard::clear( bool full )

void motion_dashboard::show_radiobuttons()
{
ImGui::PushStyleColor( ImGuiCol_Text, from_rgba( 233, 0, 0, 255, true ) );
ImGui::RadioButton( "X", &curr_accel_param_position, 0 );
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", "Show accel X" );
ImGui::SetTooltip( "%s", std::string( rsutils::string::from() << "Show " << x_axes_name ).c_str() );
ImGui::PopStyleColor();
ImGui::SameLine();

ImGui::PushStyleColor( ImGuiCol_Text, from_rgba( 0, 255, 0, 255, true ) );
ImGui::RadioButton( "Y", &curr_accel_param_position, 1 );
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", "Show accel Y" );
ImGui::SetTooltip( "%s", std::string( rsutils::string::from() << "Show " << y_axes_name ).c_str() );
ImGui::PopStyleColor();
ImGui::SameLine();

ImGui::PushStyleColor( ImGuiCol_Text, from_rgba( 85, 89, 245, 255, true ) );
ImGui::RadioButton( "Z", &curr_accel_param_position, 2 );
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", "Show accel Z" );
ImGui::SetTooltip( "%s", std::string( rsutils::string::from() << "Show " << z_axes_name ).c_str() );
ImGui::PopStyleColor();
ImGui::SameLine();

ImGui::PushStyleColor( ImGuiCol_Text, from_rgba( 255, 255, 255, 255, true ) );
ImGui::RadioButton( "N", &curr_accel_param_position, 3 );
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" );
ImGui::SetTooltip( "%s", "Show Normal - sqrt(x^2 + y^2 + z^2)" );
ImGui::PopStyleColor();
}

void motion_dashboard::show_data_rate_slider()
{
ImGui::PushItemWidth( 100 );
ImGui::SliderFloat( "##rate", &frame_rate, MIN_FRAME_RATE, MAX_FRAME_RATE, "%.2f" );
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()
<< "Frame rate "
<< "Dashboard update every "
<< std::fixed
<< std::setprecision(1)
<< frame_rate * 1000
<< dashboard_update_rate * 1000
<< " mSec"
).c_str() );
}
Expand Down
43 changes: 16 additions & 27 deletions common/motion-dashboard.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// 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"

namespace rs2
{
class stream_dashboard;

class motion_dashboard : public stream_dashboard
{
public:

motion_dashboard( std::string name );
motion_dashboard( std::string name, enum rs2_stream stream);

// Draw Accelerate dashboard and graph's lines
void draw( ux_window & window, rect rectangle ) override;
Expand All @@ -24,19 +22,28 @@ namespace rs2
// Show slider that change pause between acceleration values that we saving.
void show_data_rate_slider();

// Extract X, Y, Z and calculate N values from a frame
void process_frame( rs2::frame f ) override;

protected:
float x_value;
float y_value;
float z_value;
float n_value; // Norm ||V|| = SQRT(X^2 + Y^2 + Z^2)

float frame_rate;
float dashboard_update_rate;
double last_time;
std::map< float, double > frame_to_time;
std::map< int, double > frame_to_time;

std::vector< std::string > accel_params = { "X", "Y", "Z", "N" };
int curr_accel_param_position = 0;
const char * x_axes_name = "X";
const char * y_axes_name = "Y";
const char * z_axes_name = "Z";
const char * n_axes_name = "N";

std::vector< std::string > plots = { x_axes_name, y_axes_name, z_axes_name, n_axes_name };
int plot_index = 0;

enum rs2_stream stream_type;
const float MIN_FRAME_RATE = 0.01f;
const float MAX_FRAME_RATE = 0.1f;

Expand All @@ -46,22 +53,4 @@ namespace rs2
std::deque< float > z_history;
std::deque< float > n_history;
};

class accel_dashboard : public motion_dashboard
{
public:
accel_dashboard( std::string name );

// Extract X, Y, Z and calculate N values from a frame
void process_frame( rs2::frame f ) override;
};

class gyro_dashboard : public motion_dashboard
{
public:
gyro_dashboard( std::string name );

// Extract X, Y, Z and calculate N values from a frame
void process_frame( rs2::frame f ) override;
};
}
Loading

0 comments on commit 8a95915

Please sign in to comment.