Skip to content

Commit

Permalink
Tools and examples base update
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Oct 1, 2024
1 parent 0cb149a commit 805a964
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 37 deletions.
2 changes: 1 addition & 1 deletion examples/align-advanced/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8)
project(RealsenseExamplesAlignAdvanced)

if(BUILD_GRAPHICAL_EXAMPLES)
add_executable(rs-align-advanced rs-align-advanced.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
add_executable(rs-align-advanced rs-align-advanced.cpp ../../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)
set_property(TARGET rs-align-advanced PROPERTY CXX_STANDARD 11)
target_link_libraries(rs-align-advanced ${DEPENDENCIES})
include_directories(../../common ../../third-party/imgui ../../examples)
Expand Down
26 changes: 20 additions & 6 deletions examples/align-advanced/rs-align-advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <fstream>
#include <algorithm>
#include <cstring>
#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>

void render_slider(rect location, float& clipping_dist);
void remove_background(rs2::video_frame& other, const rs2::depth_frame& depth_frame, float depth_scale, float clipping_dist);
Expand All @@ -20,7 +23,11 @@ int main(int argc, char * argv[]) try
{
// Create and initialize GUI related objects
window app(1280, 720, "RealSense Align (Advanced) Example"); // Simple window handling
ImGui_ImplGlfw_Init(app, false); // ImGui library intializition
// Setup Dear ImGui context
ImGui::CreateContext();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(app, true);
ImGui_ImplOpenGL3_Init();
rs2::colorizer c; // Helper to colorize depth images
texture renderer; // Helper for renderig images

Expand Down Expand Up @@ -105,11 +112,18 @@ int main(int argc, char * argv[]) try
renderer.show(pip_stream);

// Using ImGui library to provide a slide controller to select the depth clipping distance
ImGui_ImplGlfw_NewFrame(1);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
render_slider({ 5.f, 0, w, h }, depth_clipping_distance);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
Expand Down Expand Up @@ -154,11 +168,11 @@ void render_slider(rect location, float& clipping_dist)

//Render the vertical slider
ImGui::Begin("slider", nullptr, flags);
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.2f, 0.3f, 0.7f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_SliderGrab, { 215.f / 255, 215.0f / 255, 215.0f / 255,1 });
ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, { 215.f / 255, 215.0f / 255, 215.0f / 255,1 });
auto slider_size = ImVec2(slider_window_width / 2, location.h - (pixels_to_buttom_of_stream_text * 2) - 20);
ImGui::VSliderFloat("", slider_size, &clipping_dist, 0.0f, 6.0f, "", 1.0f, true);
ImGui::VSliderFloat("##vslider", slider_size, &clipping_dist, 0.0f, 6.0f," % .2f");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Depth Clipping Distance: %.3f", clipping_dist);
ImGui::PopStyleColor(3);
Expand Down
2 changes: 1 addition & 1 deletion examples/align-gl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(RealsenseExamplesAlignGl )
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

if(BUILD_GRAPHICAL_EXAMPLES AND NOT APPLE)
add_executable(rs-align-gl rs-align-gl.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
add_executable(rs-align-gl rs-align-gl.cpp ../../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)
set_property(TARGET rs-align-gl PROPERTY CXX_STANDARD 11)
target_link_libraries(rs-align-gl ${DEPENDENCIES} realsense2-gl)
include_directories(../../common ../../third-party/imgui ../../examples)
Expand Down
20 changes: 16 additions & 4 deletions examples/align-gl/rs-align-gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <librealsense2/rs.hpp>
#include "example-imgui.hpp"
#include <librealsense2-gl/rs_processing_gl.hpp> // Include GPU-Processing API

#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>

/*
This example introduces the concept of spatial stream alignment.
Expand Down Expand Up @@ -45,7 +47,11 @@ int main(int argc, char * argv[]) try

// Create and initialize GUI related objects
window app(1280, 720, "RealSense Align Example"); // Simple window handling
ImGui_ImplGlfw_Init(app, false); // ImGui library intializition
// Setup Dear ImGui context
ImGui::CreateContext();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(app, true);
ImGui_ImplOpenGL3_Init();

// Once we have a window, initialize GL module
// Pass our window to enable sharing of textures between processed frames and the window
Expand Down Expand Up @@ -119,11 +125,17 @@ int main(int argc, char * argv[]) try
glDisable(GL_BLEND);

// Render the UI:
ImGui_ImplGlfw_NewFrame(1);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
Expand Down
3 changes: 2 additions & 1 deletion examples/align/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ cmake_minimum_required(VERSION 3.8)
project(RealsenseExamplesAlign)

if(BUILD_GRAPHICAL_EXAMPLES)
add_executable(rs-align rs-align.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
add_executable(rs-align rs-align.cpp ../../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)
set_property(TARGET rs-align PROPERTY CXX_STANDARD 11)
target_link_libraries(rs-align ${DEPENDENCIES})
include_directories(../../common ../../third-party/imgui ../../examples)
Expand Down
20 changes: 17 additions & 3 deletions examples/align/rs-align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <librealsense2/rs.hpp>
#include "example-imgui.hpp"

#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>

/*
This example introduces the concept of spatial stream alignment.
For example usecase of alignment, please check out align-advanced and measure demos.
Expand Down Expand Up @@ -39,7 +43,11 @@ int main(int argc, char * argv[]) try

// Create and initialize GUI related objects
window app(1280, 720, "RealSense Align Example"); // Simple window handling
ImGui_ImplGlfw_Init(app, false); // ImGui library intializition
// Setup Dear ImGui context
ImGui::CreateContext();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(app, true);
ImGui_ImplOpenGL3_Init();
rs2::colorizer c; // Helper to colorize depth images
texture depth_image, color_image; // Helpers for renderig images

Expand Down Expand Up @@ -106,11 +114,17 @@ int main(int argc, char * argv[]) try
glDisable(GL_BLEND);

// Render the UI:
ImGui_ImplGlfw_NewFrame(1);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
Expand Down
4 changes: 2 additions & 2 deletions examples/example-imgui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class hdr_slider : public slider {
ImGui::Begin(name_id.c_str(), nullptr, _sliders_flags);
ImGui::Text("%s",_name);
bool is_changed =
ImGui::SliderFloat("", &_value, _min_value, _max_value, "%.3f", 5.0f, false); //5.0f for logarithmic scale
ImGui::SliderFloat("Slider Label", &_value, _min_value, _max_value, "%.3f", ImGuiSliderFlags_Logarithmic); //5.0f for logarithmic scale
if (is_changed) {
_sensor.set_option(RS2_OPTION_SEQUENCE_ID, float(_seq_id));
_sensor.set_option(_option, _value);
Expand Down Expand Up @@ -146,7 +146,7 @@ class hdr_widgets {
void render_widgets() {

//start a new frame of ImGui
ImGui_ImplGlfw_NewFrame(1);
ImGui_ImplGlfw_NewFrame();

_exposure_slider_seq_2.show();
_exposure_slider_seq_1.show();
Expand Down
2 changes: 1 addition & 1 deletion examples/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8)
project(RealsenseExamplesHdr)

if(BUILD_GRAPHICAL_EXAMPLES)
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)
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)
set_property(TARGET rs-hdr PROPERTY CXX_STANDARD 11)
target_link_libraries( rs-hdr ${DEPENDENCIES} tclap )
include_directories(../ ../../third-party/imgui ../../third-party/glfw/include)
Expand Down
23 changes: 18 additions & 5 deletions examples/hdr/rs-hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "example-imgui.hpp" // Include short list of convenience functions for rendering
#include <iostream>

#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>

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

// init ImGui with app (window object)
ImGui_ImplGlfw_Init(app, false);
// Setup Dear ImGui context
ImGui::CreateContext();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(app, true);
ImGui_ImplOpenGL3_Init();

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

while (app) // application is still alive
{

data = pipe.wait_for_frames(); // Wait for next set of frames from the camera

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

//update frames in frames map in hdr_widgets
hdr_widgets.update_frames_map(infrared_frame, depth_frame, hdr_frame, hdr_seq_id, hdr_seq_size);

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
//render hdr widgets sliders and text boxes
hdr_widgets.render_widgets();

//the show method, when applied on frame map, break it to frames and upload each frame into its specific tile
app.show(hdr_widgets.get_frames_map());

ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return EXIT_SUCCESS;
}
catch (const rs2::error& e)
Expand Down
2 changes: 1 addition & 1 deletion examples/post-processing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8)
project(RealsenseExamplesPost-Processing)

if(BUILD_GRAPHICAL_EXAMPLES)
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)
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)
set_property(TARGET rs-post-processing PROPERTY CXX_STANDARD 11)
target_link_libraries( rs-post-processing ${DEPENDENCIES} tclap )
include_directories(../ ../../third-party/imgui)
Expand Down
19 changes: 16 additions & 3 deletions examples/post-processing/rs-post-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include <imgui.h>
#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include <realsense_imgui.h>


/**
Helper class for controlling the filter's GUI element
Expand Down Expand Up @@ -51,7 +54,11 @@ int main(int argc, char * argv[]) try
{
// Create a simple OpenGL window for rendering:
window app(1280, 720, "RealSense Post Processing Example");
ImGui_ImplGlfw_Init(app, false);
// Setup Dear ImGui context
ImGui::CreateContext();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(app, true);
ImGui_ImplOpenGL3_Init();

// Construct objects to manage view state
glfw_state original_view_orientation{};
Expand Down Expand Up @@ -215,7 +222,10 @@ int main(int argc, char * argv[]) try
// (Not the safest way to join a thread, please wrap your threads in some RAII manner)
stopped = true;
processing_thread.join();

// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
Expand Down Expand Up @@ -251,7 +261,9 @@ void render_ui(float w, float h, std::vector<filter_options>& filters)
| ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoMove;

ImGui_ImplGlfw_NewFrame(1);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::SetNextWindowSize({ w, h });
ImGui::Begin("app", nullptr, flags);

Expand Down Expand Up @@ -288,6 +300,7 @@ void render_ui(float w, float h, std::vector<filter_options>& filters)

ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

bool filter_slider_ui::render(const float3& location, bool enabled)
Expand Down
2 changes: 1 addition & 1 deletion examples/record-playback/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.8)
project(RealsenseExamplesRecord-Playback)

if(BUILD_GRAPHICAL_EXAMPLES)
add_executable(rs-record-playback rs-record-playback.cpp ../example.hpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
add_executable(rs-record-playback rs-record-playback.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)
set_property(TARGET rs-record-playback PROPERTY CXX_STANDARD 11)
target_link_libraries( rs-record-playback ${DEPENDENCIES} tclap )
include_directories(../ ../../third-party/imgui)
Expand Down
18 changes: 16 additions & 2 deletions examples/record-playback/rs-record-playback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include <imgui.h>
#include "imgui_impl_glfw.h"
#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>

// Includes for time display
#include <sstream>
Expand All @@ -23,7 +26,11 @@ int main(int argc, char * argv[]) try
{
// Create a simple OpenGL window for rendering:
window app(1280, 720, "RealSense Record and Playback Example");
ImGui_ImplGlfw_Init(app, false);
// Setup Dear ImGui context
ImGui::CreateContext();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(app, true);
ImGui_ImplOpenGL3_Init();

// Create booleans to control GUI (recorded - allow play button, recording - show 'recording to file' text)
bool recorded = false;
Expand Down Expand Up @@ -61,7 +68,9 @@ int main(int argc, char * argv[]) try
| ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoMove;

ImGui_ImplGlfw_NewFrame(1);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::SetNextWindowSize({ app.width(), app.height() });
ImGui::Begin("app", nullptr, flags);

Expand Down Expand Up @@ -192,10 +201,15 @@ int main(int argc, char * argv[]) try

ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

// Render depth frames from the default configuration, the recorder or the playback
depth_image.render(depth, { app.width() * 0.25f, app.height() * 0.25f, app.width() * 0.5f, app.height() * 0.75f });
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
Expand Down
5 changes: 5 additions & 0 deletions tools/depth-quality/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ if(BUILD_GRAPHICAL_EXAMPLES)
../../third-party/imgui/imgui.cpp
../../third-party/imgui/imgui_draw.cpp
../../third-party/imgui/imgui_impl_glfw.cpp
../../third-party/imgui/imgui_impl_opengl3.cpp
../../third-party/imgui/imgui_widgets.cpp
../../third-party/imgui/imgui_tables.cpp
../../third-party/imgui/realsense_imgui.cpp
../../third-party/imgui/imgui-fonts-karla.hpp
../../third-party/imgui/imgui-fonts-fontawesome.hpp
../../third-party/glad/glad.c
Expand Down Expand Up @@ -64,6 +68,7 @@ if(BUILD_GRAPHICAL_EXAMPLES)
../../third-party/imgui/imgui.cpp
../../third-party/imgui/imgui_draw.cpp
../../third-party/imgui/imgui_impl_glfw.cpp
../../third-party/imgui/imgui_impl_opengl3.cpp
../../third-party/imgui/imgui-fonts-karla.hpp
../../third-party/imgui/imgui-fonts-fontawesome.hpp)

Expand Down
Loading

0 comments on commit 805a964

Please sign in to comment.