Skip to content

Commit 7b3eed9

Browse files
Evgeni Raikhelclaude
andcommitted
refactor(viewer): make viewport grid overlay a built-in capability
Drop BUILD_VIEWPORT_GRID_OVERLAY cmake option and remove all #ifdef guards — the feature is now always compiled into realsense-viewer. Rename draw_2d_grid to draw_crosshair per review request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 70df9f3 commit 7b3eed9

7 files changed

Lines changed: 4 additions & 29 deletions

File tree

CMake/lrs_options.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,3 @@ option(USE_EXTERNAL_LZ4 "Use externally build LZ4 library instead of building an
6363
option(BUILD_ASAN "Enable AddressSanitizer" OFF)
6464
option(BUILD_ROSBAG2 "Build and use rosbag2 recording system" ON) # temporary flag, should be removed when deprecated ROSBAG1 recording system is removed
6565
mark_as_advanced(BUILD_ASAN)
66-
option(BUILD_VIEWPORT_GRID_OVERLAY "Build 2D viewport grid overlay for realsense-viewer (configurable via the per-user realsense-config.json)" OFF)

common/device-model.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ namespace rs2
150150
static const char* lpc_point_size{ "viewer_model.lpc_point_size" };
151151
static const char* show_safety_zones_3d{ "viewer_model.show_safety_zones_3d" };
152152
static const char* show_safety_zones_2d{ "viewer_model.show_safety_zones_2d" };
153-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
154153
namespace viewport_grid
155154
{
156155
static const char* horizontal_lines{ "viewer_model.grid.horizontal_lines" };
@@ -160,7 +159,6 @@ namespace rs2
160159
static const char* line_color_g { "viewer_model.grid.line_color_g" };
161160
static const char* line_color_b { "viewer_model.grid.line_color_b" };
162161
}
163-
#endif
164162
}
165163
namespace window
166164
{

common/stream-model.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace rs2
3030
configurations::viewer::show_stream_details, false);
3131
show_safety_zones_2d = config_file::instance().get_or_default(
3232
configurations::viewer::show_safety_zones_2d, true);
33-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
3433
{
3534
namespace cfg = configurations::viewer::viewport_grid;
3635
auto& cf = config_file::instance();
@@ -46,7 +45,6 @@ namespace rs2
4645
if ( r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255 )
4746
{ grid_color_r = r; grid_color_g = g; grid_color_b = b; }
4847
}
49-
#endif
5048
}
5149

5250
std::shared_ptr<texture_buffer> stream_model::upload_frame(frame&& f)
@@ -150,9 +148,8 @@ namespace rs2
150148
glPopAttrib();
151149
}
152150

153-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
154-
static void draw_2d_grid(const rect& r, int h_lines, int v_lines, int line_width,
155-
int cr, int cg, int cb)
151+
static void draw_crosshair(const rect& r, int h_lines, int v_lines, int line_width,
152+
int cr, int cg, int cb)
156153
{
157154
glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);
158155
glLineWidth(static_cast<GLfloat>(line_width));
@@ -176,8 +173,6 @@ namespace rs2
176173
glPopAttrib();
177174
}
178175

179-
#endif
180-
181176
bool stream_model::is_stream_visible() const
182177
{
183178
if (dev &&
@@ -460,9 +455,7 @@ namespace rs2
460455
if (RS2_STREAM_DEPTH == profile.stream_type()) ++num_of_buttons; // Color map ruler button
461456
if (RS2_FORMAT_MOTION_XYZ32F == profile.format()) ++num_of_buttons; // Motion graph button
462457
if (RS2_STREAM_OCCUPANCY == profile.stream_type() && _normalized_zoom.w == 1) ++num_of_buttons; // Safety zones button
463-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
464458
++num_of_buttons; // Grid overlay button
465-
#endif
466459

467460
RsImGui_ScopePushFont(font);
468461
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
@@ -598,7 +591,6 @@ namespace rs2
598591
}
599592
ImGui::SameLine();
600593

601-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
602594
label = rsutils::string::from() << textual_icons::grid << "##Grid " << profile.unique_id();
603595
if (show_grid)
604596
{
@@ -622,7 +614,6 @@ namespace rs2
622614
RsImGui::CustomTooltip("Show grid overlay");
623615
}
624616
ImGui::SameLine();
625-
#endif
626617

627618

628619
if (RS2_STREAM_DEPTH == profile.stream_type())
@@ -2114,11 +2105,9 @@ namespace rs2
21142105

21152106
update_ae_roi_rect(stream_rect, g, error_message);
21162107

2117-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
21182108
if (show_grid)
2119-
draw_2d_grid(stream_rect, grid_h_lines, grid_v_lines, grid_line_width,
2120-
grid_color_r, grid_color_g, grid_color_b);
2121-
#endif
2109+
draw_crosshair(stream_rect, grid_h_lines, grid_v_lines, grid_line_width,
2110+
grid_color_r, grid_color_g, grid_color_b);
21222111

21232112
}
21242113
texture->show_preview(stream_rect, _normalized_zoom);

common/stream-model.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ namespace rs2
106106
bool show_metadata = false;
107107
bool show_safety_zones_2d = true;
108108

109-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
110109
bool show_grid = false;
111110
int grid_h_lines = 1;
112111
int grid_v_lines = 1;
113112
int grid_line_width = 1;
114113
int grid_color_r = 255;
115114
int grid_color_g = 255;
116115
int grid_color_b = 255;
117-
#endif
118116

119117
std::shared_ptr<graph_model> graph;
120118
bool show_graph = false;

common/ux-window.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ namespace rs2
8787
config_file::instance().set_default(configurations::viewer::commands_xml, "./Commands.xml");
8888
config_file::instance().set_default(configurations::viewer::hwlogger_xml, "./HWLoggerEvents.xml");
8989

90-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
9190
if( config_file::instance().is_empty() )
9291
{
9392
namespace cfg = configurations::viewer::viewport_grid;
@@ -99,7 +98,6 @@ namespace rs2
9998
cf.set_nested_default( cfg::line_color_g, 255 );
10099
cf.set_nested_default( cfg::line_color_b, 255 );
101100
}
102-
#endif
103101

104102
std::string path;
105103
try

common/viewer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,7 +2983,6 @@ namespace rs2
29832983
{
29842984
reload_required = true;
29852985
temp_cfg = config_file();
2986-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
29872986
{
29882987
namespace cfg = configurations::viewer::viewport_grid;
29892988
temp_cfg.set_nested_default( cfg::horizontal_lines, 1 );
@@ -2993,7 +2992,6 @@ namespace rs2
29932992
temp_cfg.set_nested_default( cfg::line_color_g, 255 );
29942993
temp_cfg.set_nested_default( cfg::line_color_b, 255 );
29952994
}
2996-
#endif
29972995
}
29982996
ImGui::SameLine();
29992997
if (ImGui::Button(" Export Settings "))

tools/realsense-viewer/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ if(OPENVINO_NGRAPH)
241241
target_compile_definitions(realsense-viewer PRIVATE OPENVINO_NGRAPH)
242242
endif()
243243

244-
if(BUILD_VIEWPORT_GRID_OVERLAY)
245-
message(STATUS "Viewport grid overlay enabled for realsense-viewer")
246-
target_compile_definitions(realsense-viewer PRIVATE BUILD_VIEWPORT_GRID_OVERLAY)
247-
endif()
248-
249244
source_group("SW-Update" FILES ${SW_UPDATE_FILES})
250245

251246
include_directories(

0 commit comments

Comments
 (0)