Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMake/lrs_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ option(USE_EXTERNAL_LZ4 "Use externally build LZ4 library instead of building an
option(BUILD_ASAN "Enable AddressSanitizer" OFF)
option(BUILD_ROSBAG2 "Build and use rosbag2 recording system" ON) # temporary flag, should be removed when deprecated ROSBAG1 recording system is removed
mark_as_advanced(BUILD_ASAN)
option(BUILD_VIEWPORT_GRID_OVERLAY "Build 2D viewport grid overlay for realsense-viewer (configurable via config-settings.xml)" OFF)
11 changes: 11 additions & 0 deletions common/device-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ namespace rs2
static const char* lpc_point_size{ "viewer_model.lpc_point_size" };
static const char* show_safety_zones_3d{ "viewer_model.show_safety_zones_3d" };
static const char* show_safety_zones_2d{ "viewer_model.show_safety_zones_2d" };
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
namespace viewport_grid
{
static const char* horizontal_lines{ "viewer_model.grid.horizontal_lines" };
static const char* vertical_lines { "viewer_model.grid.vertical_lines" };
static const char* line_width { "viewer_model.grid.line_width" };
static const char* line_color_r { "viewer_model.grid.line_color_r" };
static const char* line_color_g { "viewer_model.grid.line_color_g" };
static const char* line_color_b { "viewer_model.grid.line_color_b" };
}
#endif
}
namespace window
{
Expand Down
1 change: 0 additions & 1 deletion common/rs-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ config_file::config_file( std::string const & filename )
}
catch(...)
{

}
}

Expand Down
4 changes: 3 additions & 1 deletion common/rs-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ namespace rs2
}

bool contains(const char* key) const;

void save(const char* filename);

void reset();

void remove(const char* key);

bool is_new_file() const { return _j.empty(); }

static config_file& instance();

// Retrieves a value from a nested JSON structure using dot notation
Expand Down
86 changes: 86 additions & 0 deletions common/stream-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "os.h"
#include <imgui_internal.h>
#include <realsense_imgui.h>
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
#include <iomanip>
#include <sstream>
#endif

struct attribute
{
Expand All @@ -28,6 +32,23 @@ namespace rs2
configurations::viewer::show_stream_details, false);
show_safety_zones_2d = config_file::instance().get_or_default(
configurations::viewer::show_safety_zones_2d, true);
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
{
namespace cfg = configurations::viewer::viewport_grid;
auto& cf = config_file::instance();

auto valid_lines = []( int v ) { return ( v >= 1 && v <= 5 ) ? v : 1; };
grid_h_lines = valid_lines( cf.get_nested<int>( cfg::horizontal_lines, 1 ) );
grid_v_lines = valid_lines( cf.get_nested<int>( cfg::vertical_lines, 1 ) );
int w = cf.get_nested<int>( cfg::line_width, 1 );
if ( w >= 1 ) grid_line_width = w;
int r = cf.get_nested<int>( cfg::line_color_r, 255 );
int g = cf.get_nested<int>( cfg::line_color_g, 255 );
int b = cf.get_nested<int>( cfg::line_color_b, 255 );
if ( r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255 )
{ grid_color_r = r; grid_color_g = g; grid_color_b = b; }
}
#endif
}

std::shared_ptr<texture_buffer> stream_model::upload_frame(frame&& f)
Expand Down Expand Up @@ -131,6 +152,34 @@ namespace rs2
glPopAttrib();
}

#ifdef BUILD_VIEWPORT_GRID_OVERLAY
static void draw_2d_grid(const rect& r, int h_lines, int v_lines, int line_width,
int cr, int cg, int cb)
{
glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);
glLineWidth(static_cast<GLfloat>(line_width));
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(cr / 255.f, cg / 255.f, cb / 255.f, 0.7f);
glBegin(GL_LINES);
for (int c = 1; c <= v_lines; ++c)
{
float x = r.x + r.w * c / static_cast<float>(v_lines + 1);
glVertex2f(x, r.y);
glVertex2f(x, r.y + r.h);
}
for (int row = 1; row <= h_lines; ++row)
{
float y = r.y + r.h * row / static_cast<float>(h_lines + 1);
glVertex2f(r.x, y);
glVertex2f(r.x + r.w, y);
}
glEnd();
glPopAttrib();
}

#endif

bool stream_model::is_stream_visible() const
{
if (dev &&
Expand Down Expand Up @@ -413,6 +462,9 @@ namespace rs2
if (RS2_STREAM_DEPTH == profile.stream_type()) ++num_of_buttons; // Color map ruler button
if (RS2_FORMAT_MOTION_XYZ32F == profile.format()) ++num_of_buttons; // Motion graph button
if (RS2_STREAM_OCCUPANCY == profile.stream_type() && _normalized_zoom.w == 1) ++num_of_buttons; // Safety zones button
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
++num_of_buttons; // Grid overlay button
#endif

RsImGui_ScopePushFont(font);
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
Expand Down Expand Up @@ -548,6 +600,33 @@ namespace rs2
}
ImGui::SameLine();

#ifdef BUILD_VIEWPORT_GRID_OVERLAY
label = rsutils::string::from() << textual_icons::grid << "##Grid " << profile.unique_id();
if (show_grid)
{
ImGui::PushStyleColor(ImGuiCol_Text, light_blue);
ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_blue);
if (ImGui::Button(label.c_str(), { 24, top_bar_height }))
{
show_grid = false;
}
if (ImGui::IsItemHovered())
RsImGui::CustomTooltip("Hide grid overlay");
ImGui::PopStyleColor(2);
}
else
{
if (ImGui::Button(label.c_str(), { 24, top_bar_height }))
{
show_grid = true;
}
if (ImGui::IsItemHovered())
RsImGui::CustomTooltip("Show grid overlay");
}
ImGui::SameLine();
#endif


if (RS2_STREAM_DEPTH == profile.stream_type())
{
label = rsutils::string::from() << textual_icons::bar_chart << "##Color map";
Expand Down Expand Up @@ -2036,6 +2115,13 @@ namespace rs2
}

update_ae_roi_rect(stream_rect, g, error_message);

#ifdef BUILD_VIEWPORT_GRID_OVERLAY
if (show_grid)
draw_2d_grid(stream_rect, grid_h_lines, grid_v_lines, grid_line_width,
grid_color_r, grid_color_g, grid_color_b);
#endif

}
texture->show_preview(stream_rect, _normalized_zoom);

Expand Down
10 changes: 10 additions & 0 deletions common/stream-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ namespace rs2
bool show_metadata = false;
bool show_safety_zones_2d = true;

#ifdef BUILD_VIEWPORT_GRID_OVERLAY
bool show_grid = false;
int grid_h_lines = 1;
int grid_v_lines = 1;
int grid_line_width = 1;
int grid_color_r = 255;
int grid_color_g = 255;
int grid_color_b = 255;
#endif

std::shared_ptr<graph_model> graph;
bool show_graph = false;
bool graph_initialized = false;
Expand Down
1 change: 1 addition & 0 deletions common/textual-icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace rs2
// A note to a maintainer - preserve order when adding values to avoid duplicates
static const textual_icon search{ u8"\uf002" };
static const textual_icon file_movie{ u8"\uf008" };
static const textual_icon grid{ u8"\uf00a" }; // fa-th: 3x3 grid of squares (viewport grid overlay)
static const textual_icon check{ u8"\uf00c" };
static const textual_icon times{ u8"\uf00d" };
static const textual_icon power_off{ u8"\uf011" };
Expand Down
14 changes: 14 additions & 0 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ namespace rs2
config_file::instance().set_default(configurations::viewer::commands_xml, "./Commands.xml");
config_file::instance().set_default(configurations::viewer::hwlogger_xml, "./HWLoggerEvents.xml");

#ifdef BUILD_VIEWPORT_GRID_OVERLAY
if( config_file::instance().is_new_file() )
{
namespace cfg = configurations::viewer::viewport_grid;
auto& cf = config_file::instance();
cf.set_nested( cfg::horizontal_lines, 1 );
cf.set_nested( cfg::vertical_lines, 1 );
cf.set_nested( cfg::line_width, 1 );
cf.set_nested( cfg::line_color_r, 255 );
cf.set_nested( cfg::line_color_g, 255 );
cf.set_nested( cfg::line_color_b, 255 );
}
#endif

std::string path;
try
{
Expand Down
11 changes: 11 additions & 0 deletions common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,17 @@ namespace rs2
{
reload_required = true;
temp_cfg = config_file();
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
{
namespace cfg = configurations::viewer::viewport_grid;
temp_cfg.set_nested( cfg::horizontal_lines, 1 );
temp_cfg.set_nested( cfg::vertical_lines, 1 );
temp_cfg.set_nested( cfg::line_width, 1 );
temp_cfg.set_nested( cfg::line_color_r, 255 );
temp_cfg.set_nested( cfg::line_color_g, 255 );
temp_cfg.set_nested( cfg::line_color_b, 255 );
}
#endif
}
ImGui::SameLine();
if (ImGui::Button(" Export Settings "))
Expand Down
5 changes: 5 additions & 0 deletions tools/realsense-viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ if(OPENVINO_NGRAPH)
target_compile_definitions(realsense-viewer PRIVATE OPENVINO_NGRAPH)
endif()

if(BUILD_VIEWPORT_GRID_OVERLAY)
message(STATUS "Viewport grid overlay enabled for realsense-viewer")
target_compile_definitions(realsense-viewer PRIVATE BUILD_VIEWPORT_GRID_OVERLAY)
endif()

source_group("SW-Update" FILES ${SW_UPDATE_FILES})

include_directories(
Expand Down
Loading