Skip to content

Commit 48807d1

Browse files
committed
Tools and examples base update
1 parent 8e573ac commit 48807d1

File tree

17 files changed

+137
-38
lines changed

17 files changed

+137
-38
lines changed

examples/align-advanced/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ project( rs-align-advanced )
77
if( BUILD_GRAPHICAL_EXAMPLES )
88

99
add_executable( ${PROJECT_NAME} rs-align-advanced.cpp
10-
../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp
10+
../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp
11+
../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp
1112
)
1213
set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 )
1314
target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} )

examples/align-advanced/rs-align-advanced.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <fstream>
1111
#include <algorithm>
1212
#include <cstring>
13+
#include "imgui_impl_glfw.h"
14+
#include <imgui_impl_opengl3.h>
15+
#include<realsense_imgui.h>
1316

1417
void render_slider(rect location, float& clipping_dist);
1518
void remove_background(rs2::video_frame& other, const rs2::depth_frame& depth_frame, float depth_scale, float clipping_dist);
@@ -24,7 +27,11 @@ int main(int argc, char * argv[]) try
2427

2528
// Create and initialize GUI related objects
2629
window app(1280, 720, "RealSense Align (Advanced) Example"); // Simple window handling
27-
ImGui_ImplGlfw_Init(app, false); // ImGui library intializition
30+
// Setup Dear ImGui context
31+
ImGui::CreateContext();
32+
// Setup Platform/Renderer backends
33+
ImGui_ImplGlfw_InitForOpenGL(app, true);
34+
ImGui_ImplOpenGL3_Init();
2835
rs2::colorizer c; // Helper to colorize depth images
2936
texture renderer; // Helper for renderig images
3037

@@ -109,11 +116,18 @@ int main(int argc, char * argv[]) try
109116
renderer.show(pip_stream);
110117

111118
// Using ImGui library to provide a slide controller to select the depth clipping distance
112-
ImGui_ImplGlfw_NewFrame(1);
119+
ImGui_ImplOpenGL3_NewFrame();
120+
ImGui_ImplGlfw_NewFrame();
121+
ImGui::NewFrame();
113122
render_slider({ 5.f, 0, w, h }, depth_clipping_distance);
114123
ImGui::Render();
124+
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
115125

116126
}
127+
// Cleanup
128+
ImGui_ImplOpenGL3_Shutdown();
129+
ImGui_ImplGlfw_Shutdown();
130+
ImGui::DestroyContext();
117131
return EXIT_SUCCESS;
118132
}
119133
catch (const rs2::error & e)
@@ -158,11 +172,11 @@ void render_slider(rect location, float& clipping_dist)
158172

159173
//Render the vertical slider
160174
ImGui::Begin("slider", nullptr, flags);
161-
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
162-
ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
163-
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
175+
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.2f, 0.3f, 0.7f, 1.0f));
176+
ImGui::PushStyleColor(ImGuiCol_SliderGrab, { 215.f / 255, 215.0f / 255, 215.0f / 255,1 });
177+
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, { 215.f / 255, 215.0f / 255, 215.0f / 255,1 });
164178
auto slider_size = ImVec2(slider_window_width / 2, location.h - (pixels_to_buttom_of_stream_text * 2) - 20);
165-
ImGui::VSliderFloat("", slider_size, &clipping_dist, 0.0f, 6.0f, "", 1.0f, true);
179+
ImGui::VSliderFloat("##vslider", slider_size, &clipping_dist, 0.0f, 6.0f," % .2f");
166180
if (ImGui::IsItemHovered())
167181
ImGui::SetTooltip("Depth Clipping Distance: %.3f", clipping_dist);
168182
ImGui::PopStyleColor(3);

examples/align-gl/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
1010
if(BUILD_GRAPHICAL_EXAMPLES AND NOT APPLE)
1111

1212
add_executable( ${PROJECT_NAME} rs-align-gl.cpp
13-
../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp
13+
../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp
14+
../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp
1415
)
1516
set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 )
1617
target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} realsense2-gl )

examples/align-gl/rs-align-gl.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#include <librealsense2/rs.hpp>
55
#include "example-imgui.hpp"
66
#include <librealsense2-gl/rs_processing_gl.hpp> // Include GPU-Processing API
7-
#include <common/cli.h>
8-
7+
#include "imgui_impl_glfw.h"
8+
#include <imgui_impl_opengl3.h>
9+
#include<realsense_imgui.h>
910

1011
/*
1112
This example introduces the concept of spatial stream alignment.
@@ -50,7 +51,11 @@ int main(int argc, char * argv[]) try
5051

5152
// Create and initialize GUI related objects
5253
window app(1280, 720, "RealSense Align Example"); // Simple window handling
53-
ImGui_ImplGlfw_Init(app, false); // ImGui library intializition
54+
// Setup Dear ImGui context
55+
ImGui::CreateContext();
56+
// Setup Platform/Renderer backends
57+
ImGui_ImplGlfw_InitForOpenGL(app, true);
58+
ImGui_ImplOpenGL3_Init();
5459

5560
// Once we have a window, initialize GL module
5661
// Pass our window to enable sharing of textures between processed frames and the window
@@ -124,11 +129,17 @@ int main(int argc, char * argv[]) try
124129
glDisable(GL_BLEND);
125130

126131
// Render the UI:
127-
ImGui_ImplGlfw_NewFrame(1);
132+
ImGui_ImplOpenGL3_NewFrame();
133+
ImGui_ImplGlfw_NewFrame();
134+
ImGui::NewFrame();
128135
render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir);
129136
ImGui::Render();
137+
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
130138
}
131-
139+
// Cleanup
140+
ImGui_ImplOpenGL3_Shutdown();
141+
ImGui_ImplGlfw_Shutdown();
142+
ImGui::DestroyContext();
132143
return EXIT_SUCCESS;
133144
}
134145
catch (const rs2::error & e)

examples/align/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ project( rs-align )
66

77
if(BUILD_GRAPHICAL_EXAMPLES)
88

9-
add_executable( ${PROJECT_NAME} rs-align.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
9+
add_executable( ${PROJECT_NAME} rs-align.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp
10+
../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp)
1011
set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 )
1112
target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} )
1213
include_directories( ../../third-party/imgui ../../examples )

examples/align/rs-align.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include "example-imgui.hpp"
66
#include <common/cli.h>
77

8+
#include "imgui_impl_glfw.h"
9+
#include <imgui_impl_opengl3.h>
10+
#include<realsense_imgui.h>
11+
812
/*
913
This example introduces the concept of spatial stream alignment.
1014
For example usecase of alignment, please check out align-advanced and measure demos.
@@ -44,7 +48,11 @@ int main(int argc, char * argv[]) try
4448

4549
// Create and initialize GUI related objects
4650
window app(1280, 720, "RealSense Align Example"); // Simple window handling
47-
ImGui_ImplGlfw_Init(app, false); // ImGui library intializition
51+
// Setup Dear ImGui context
52+
ImGui::CreateContext();
53+
// Setup Platform/Renderer backends
54+
ImGui_ImplGlfw_InitForOpenGL(app, true);
55+
ImGui_ImplOpenGL3_Init();
4856
rs2::colorizer c; // Helper to colorize depth images
4957
texture depth_image, color_image; // Helpers for renderig images
5058

@@ -111,11 +119,17 @@ int main(int argc, char * argv[]) try
111119
glDisable(GL_BLEND);
112120

113121
// Render the UI:
114-
ImGui_ImplGlfw_NewFrame(1);
122+
ImGui_ImplOpenGL3_NewFrame();
123+
ImGui_ImplGlfw_NewFrame();
124+
ImGui::NewFrame();
115125
render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir);
116126
ImGui::Render();
127+
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
117128
}
118-
129+
// Cleanup
130+
ImGui_ImplOpenGL3_Shutdown();
131+
ImGui_ImplGlfw_Shutdown();
132+
ImGui::DestroyContext();
119133
return EXIT_SUCCESS;
120134
}
121135
catch (const rs2::error & e)

examples/example-imgui.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class hdr_slider : public slider {
5050
ImGui::Begin(name_id.c_str(), nullptr, _sliders_flags);
5151
ImGui::Text("%s",_name);
5252
bool is_changed =
53-
ImGui::SliderFloat("", &_value, _min_value, _max_value, "%.3f", 5.0f, false); //5.0f for logarithmic scale
53+
ImGui::SliderFloat("Slider Label", &_value, _min_value, _max_value, "%.3f", ImGuiSliderFlags_Logarithmic); //5.0f for logarithmic scale
5454
if (is_changed) {
5555
_sensor.set_option(RS2_OPTION_SEQUENCE_ID, float(_seq_id));
5656
_sensor.set_option(_option, _value);
@@ -146,7 +146,7 @@ class hdr_widgets {
146146
void render_widgets() {
147147

148148
//start a new frame of ImGui
149-
ImGui_ImplGlfw_NewFrame(1);
149+
ImGui_ImplGlfw_NewFrame();
150150

151151
_exposure_slider_seq_2.show();
152152
_exposure_slider_seq_1.show();

examples/hdr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8)
55
project(RealsenseExamplesHdr)
66

77
if(BUILD_GRAPHICAL_EXAMPLES)
8-
add_executable(rs-hdr rs-hdr.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
8+
add_executable(rs-hdr rs-hdr.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp ../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp)
99
set_property(TARGET rs-hdr PROPERTY CXX_STANDARD 11)
1010
target_link_libraries( rs-hdr ${DEPENDENCIES} tclap )
1111
include_directories(../ ../../third-party/imgui ../../third-party/glfw/include)

examples/hdr/rs-hdr.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "example-imgui.hpp" // Include short list of convenience functions for rendering
66
#include <iostream>
77

8+
#include "imgui_impl_glfw.h"
9+
#include <imgui_impl_opengl3.h>
10+
#include<realsense_imgui.h>
811

912
// HDR Example demonstrates how to use the HDR feature - only for D400 product line devices
1013
int main() try
@@ -103,15 +106,19 @@ int main() try
103106
// init view window
104107
window app(width, height, title.c_str(), tiles_in_row, tiles_in_col);
105108

106-
// init ImGui with app (window object)
107-
ImGui_ImplGlfw_Init(app, false);
109+
// Setup Dear ImGui context
110+
ImGui::CreateContext();
111+
// Setup Platform/Renderer backends
112+
ImGui_ImplGlfw_InitForOpenGL(app, true);
113+
ImGui_ImplOpenGL3_Init();
108114

109115
// init hdr_widgets object
110116
// hdr_widgets holds the sliders, the text boxes and the frames_map
111117
hdr_widgets hdr_widgets(depth_sensor);
112118

113119
while (app) // application is still alive
114120
{
121+
115122
data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
116123

117124
auto frame = data.get_depth_frame();
@@ -143,15 +150,21 @@ int main() try
143150

144151
//update frames in frames map in hdr_widgets
145152
hdr_widgets.update_frames_map(infrared_frame, depth_frame, hdr_frame, hdr_seq_id, hdr_seq_size);
146-
153+
ImGui_ImplOpenGL3_NewFrame();
154+
ImGui_ImplGlfw_NewFrame();
155+
ImGui::NewFrame();
147156
//render hdr widgets sliders and text boxes
148157
hdr_widgets.render_widgets();
149158

150159
//the show method, when applied on frame map, break it to frames and upload each frame into its specific tile
151160
app.show(hdr_widgets.get_frames_map());
152-
161+
ImGui::Render();
162+
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
153163
}
154-
164+
// Cleanup
165+
ImGui_ImplOpenGL3_Shutdown();
166+
ImGui_ImplGlfw_Shutdown();
167+
ImGui::DestroyContext();
155168
return EXIT_SUCCESS;
156169
}
157170
catch (const rs2::error& e)

examples/post-processing/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8)
55
project(RealsenseExamplesPost-Processing)
66

77
if(BUILD_GRAPHICAL_EXAMPLES)
8-
add_executable(rs-post-processing rs-post-processing.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
8+
add_executable(rs-post-processing rs-post-processing.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp ../../third-party/imgui/realsense_imgui.cpp ../../third-party/imgui/imgui_impl_opengl3.cpp ../../third-party/imgui/imgui_widgets.cpp ../../third-party/imgui/imgui_tables.cpp)
99
set_property(TARGET rs-post-processing PROPERTY CXX_STANDARD 11)
1010
target_link_libraries( rs-post-processing ${DEPENDENCIES} tclap )
1111
include_directories(../ ../../third-party/imgui)

0 commit comments

Comments
 (0)