diff --git a/examples/C/color/CMakeLists.txt b/examples/C/color/CMakeLists.txt index c00a018dd4..4383cea3ee 100644 --- a/examples/C/color/CMakeLists.txt +++ b/examples/C/color/CMakeLists.txt @@ -9,6 +9,7 @@ project(RealsenseExamples-Color) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) add_executable(rs-color rs-color.c ../example.h) +include_directories(../../common ../../third-party/imgui ../../C) target_link_libraries(rs-color ${DEPENDENCIES}) set_target_properties (rs-color PROPERTIES FOLDER "Examples/C" diff --git a/examples/C/color/rs-color.c b/examples/C/color/rs-color.c index d4f91dfafd..4ed963a938 100644 --- a/examples/C/color/rs-color.c +++ b/examples/C/color/rs-color.c @@ -9,7 +9,7 @@ #include #include #include -#include "../example.h" +#include "example.h" //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/examples/C/depth/CMakeLists.txt b/examples/C/depth/CMakeLists.txt index adb504a2aa..c3ea773a4c 100644 --- a/examples/C/depth/CMakeLists.txt +++ b/examples/C/depth/CMakeLists.txt @@ -9,6 +9,7 @@ project(RealsenseExamples-Depth) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) add_executable(rs-depth rs-depth.c ../example.h) +include_directories(../../C) target_link_libraries(rs-depth ${DEPENDENCIES}) set_target_properties (rs-depth PROPERTIES FOLDER "Examples/C" diff --git a/examples/C/depth/rs-depth.c b/examples/C/depth/rs-depth.c index 27eac8f57d..337b71cfe2 100644 --- a/examples/C/depth/rs-depth.c +++ b/examples/C/depth/rs-depth.c @@ -6,7 +6,7 @@ #include #include #include -#include "../example.h" +#include "example.h" #include #include diff --git a/examples/C/distance/CMakeLists.txt b/examples/C/distance/CMakeLists.txt index 2e2214e3b0..bfda2a4432 100644 --- a/examples/C/distance/CMakeLists.txt +++ b/examples/C/distance/CMakeLists.txt @@ -9,6 +9,7 @@ project(RealsenseExamples-Distance) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) add_executable(rs-distance rs-distance.c ../example.h) +include_directories(../../C) target_link_libraries(rs-distance ${DEPENDENCIES}) set_target_properties (rs-distance PROPERTIES FOLDER "Examples/C" diff --git a/examples/C/distance/rs-distance.c b/examples/C/distance/rs-distance.c index 54752cd2d9..8bb0e73c2b 100644 --- a/examples/C/distance/rs-distance.c +++ b/examples/C/distance/rs-distance.c @@ -6,7 +6,7 @@ #include #include #include -#include "../example.h" +#include "example.h" #include #include diff --git a/examples/align-advanced/CMakeLists.txt b/examples/align-advanced/CMakeLists.txt index a8549a3121..f174e64706 100644 --- a/examples/align-advanced/CMakeLists.txt +++ b/examples/align-advanced/CMakeLists.txt @@ -9,7 +9,7 @@ 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) set_property(TARGET rs-align-advanced PROPERTY CXX_STANDARD 11) target_link_libraries(rs-align-advanced ${DEPENDENCIES}) - include_directories(../../common ../../third-party/imgui) + include_directories(../../common ../../third-party/imgui ../../examples) set_target_properties (rs-align-advanced PROPERTIES FOLDER Examples) install(TARGETS rs-align-advanced RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/align-advanced/rs-align-advanced.cpp b/examples/align-advanced/rs-align-advanced.cpp index 978b5dd877..ee09444474 100644 --- a/examples/align-advanced/rs-align-advanced.cpp +++ b/examples/align-advanced/rs-align-advanced.cpp @@ -2,9 +2,7 @@ // Copyright(c) 2017 Intel Corporation. All Rights Reserved. #include -#include "../example.hpp" -#include -#include "imgui_impl_glfw.h" +#include "example-imgui.hpp" #include #include diff --git a/examples/align/CMakeLists.txt b/examples/align/CMakeLists.txt index e1d2e0e021..58e01d1348 100644 --- a/examples/align/CMakeLists.txt +++ b/examples/align/CMakeLists.txt @@ -9,7 +9,7 @@ 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) set_property(TARGET rs-align PROPERTY CXX_STANDARD 11) target_link_libraries(rs-align ${DEPENDENCIES}) - include_directories(../../common ../../third-party/imgui) + include_directories(../../common ../../third-party/imgui ../../examples) set_target_properties (rs-align PROPERTIES FOLDER Examples) install(TARGETS rs-align RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/align/rs-align.cpp b/examples/align/rs-align.cpp index 09c0a5e15b..bfb27d7c0d 100644 --- a/examples/align/rs-align.cpp +++ b/examples/align/rs-align.cpp @@ -2,9 +2,7 @@ // Copyright(c) 2019 Intel Corporation. All Rights Reserved. #include -#include "../example.hpp" -#include "imgui.h" -#include "imgui_impl_glfw.h" +#include "example-imgui.hpp" /* This example introduces the concept of spatial stream alignment. diff --git a/examples/ar-advanced/CMakeLists.txt b/examples/ar-advanced/CMakeLists.txt index e56532a41e..60c44c5b13 100644 --- a/examples/ar-advanced/CMakeLists.txt +++ b/examples/ar-advanced/CMakeLists.txt @@ -19,7 +19,7 @@ endif() if(BUILD_GRAPHICAL_EXAMPLES) add_executable(rs-ar-advanced rs-ar-advanced.cpp ../example.hpp) - target_include_directories(rs-ar-advanced PUBLIC ../) + target_include_directories(rs-ar-advanced PUBLIC ../../examples) target_link_libraries(rs-ar-advanced ${DEPENDENCIES}) set_target_properties (rs-ar-advanced PROPERTIES FOLDER Examples) install(TARGETS rs-ar-advanced RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/ar-basic/rs-ar-basic.cpp b/examples/ar-basic/rs-ar-basic.cpp index 468506fdb1..b81e371205 100644 --- a/examples/ar-basic/rs-ar-basic.cpp +++ b/examples/ar-basic/rs-ar-basic.cpp @@ -81,7 +81,7 @@ int main(int argc, char * argv[]) try // Create the vertices of a simple virtual object. // This virtual object is 4 points in 3D space that describe 3 XYZ 20cm long axes. // These vertices are relative to the object's own coordinate system. - const float length = 0.20; + const float length = 0.20f; const object virtual_object = {{ { 0, 0, 0 }, // origin { length, 0, 0 }, // X @@ -139,7 +139,7 @@ int main(int argc, char * argv[]) try for (size_t i = 1; i < object_in_sensor.size(); ++i) { // Discretize the virtual object line into smaller 1cm long segments - std::vector points_in_sensor = raster_line(object_in_sensor[0], object_in_sensor[i], 0.01); + std::vector points_in_sensor = raster_line(object_in_sensor[0], object_in_sensor[i], 0.01f); std::vector projected_line; projected_line.reserve(points_in_sensor.size()); for (auto& point : points_in_sensor) @@ -153,11 +153,11 @@ int main(int argc, char * argv[]) try } } // Display the line in the image - render_line(projected_line, i); + render_line(projected_line, static_cast(i)); } // Display text in the image - render_text(app.height(), "Press spacebar to reset the pose of the virtual object. Press ESC to exit"); + render_text(static_cast(app.height()), "Press spacebar to reset the pose of the virtual object. Press ESC to exit"); // Check if some key is pressed switch (key_watcher.get_key()) @@ -289,7 +289,7 @@ std::vector raster_line(const point3d& a, const point3d& b, float step) { rs2_vector direction = { b.x() - a.x(), b.y() - a.y(), b.z() - a.z() }; float distance = std::sqrt(direction.x*direction.x + direction.y*direction.y + direction.z*direction.z); - int npoints = distance / step + 1; + int npoints = static_cast(distance / step + 1); std::vector points; if (npoints > 0) diff --git a/examples/capture/CMakeLists.txt b/examples/capture/CMakeLists.txt index 0dd964ce32..42f2fd0d99 100644 --- a/examples/capture/CMakeLists.txt +++ b/examples/capture/CMakeLists.txt @@ -9,7 +9,7 @@ if(BUILD_GRAPHICAL_EXAMPLES) add_executable(rs-capture rs-capture.cpp ../example.hpp) set_property(TARGET rs-capture PROPERTY CXX_STANDARD 11) target_link_libraries(rs-capture ${DEPENDENCIES}) - include_directories(../ ../../third-party/tclap/include) + include_directories(../ ../../third-party/tclap/include ../../examples) set_target_properties (rs-capture PROPERTIES FOLDER "Examples") install(TARGETS rs-capture RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/example-imgui.hpp b/examples/example-imgui.hpp new file mode 100644 index 0000000000..2083f400e0 --- /dev/null +++ b/examples/example-imgui.hpp @@ -0,0 +1,210 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2021 Intel Corporation. All Rights Reserved. + +#pragma once + +#include +#include +#include + +#include "example.hpp" +#include +#include + + +////////////////////////////// +// ImGui Helpers // +////////////////////////////// + +//slider for ImGui +class slider { +public: + slider(const char* name, int seq_id, float init_value, float min_value, float max_value, ImVec2 position, ImVec2 size) : + _name(name), _seq_id(seq_id), _value(init_value), _min_value(min_value), _max_value(max_value), _position(position), _size(size) {} + + void virtual show()=0; + +public: + const char* _name; + int _seq_id; + float _value; + float _max_value; + float _min_value; + ImVec2 _position; + ImVec2 _size; + +}; + +class hdr_slider : public slider { +public: + hdr_slider(const char* name, int seq_id, float init_value, rs2::sensor& sensor, + rs2_option option, rs2::option_range range, ImVec2 position, ImVec2 size) : slider(name, seq_id, init_value, range.min, range.max, position, size), + _sensor(sensor), _option(option), _range(range){} + + void show() override + { + ImGui::SetNextWindowSize(_size); + ImGui::SetNextWindowPos(_position); + //concate the name given with seq_id in order to make a unique name (uniqeness is needed for Begin()) + std::string name_id = std::string(_name) + std::to_string(_seq_id); + 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 + if (is_changed) { + _sensor.set_option(RS2_OPTION_SEQUENCE_ID, float(_seq_id)); + _sensor.set_option(_option, _value); + } + ImGui::End(); + } + +public: + rs2::sensor& _sensor; + rs2_option _option; + rs2::option_range _range; + //flags for the sliders + const static int _sliders_flags = ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_NoScrollbar + | ImGuiWindowFlags_NoSavedSettings + | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoMove + | ImGuiWindowFlags_NoTitleBar + | ImGuiWindowFlags_NoBringToFrontOnFocus; +}; + +//text box for ImGui +class text_box { +public: + text_box(const char* name, ImVec2 position, ImVec2 size) : _name(name), _position(position), _size(size) {} + + void show(const char* text) + { + ImGui::SetNextWindowSize(_size); + ImGui::SetNextWindowPos(_position); + ImGui::Begin(_name, nullptr, _text_box_flags); + ImGui::Text("%s",text); + + ImGui::End(); + } + void remove_title_bar() { + _text_box_flags |= ImGuiWindowFlags_NoTitleBar; + } + +public: + const char* _name; + ImVec2 _position; + ImVec2 _size; + // flags for displaying text box + int _text_box_flags = ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_NoScrollbar + | ImGuiWindowFlags_NoSavedSettings + | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoMove + | ImGuiWindowFlags_NoFocusOnAppearing + | ImGuiWindowFlags_AlwaysUseWindowPadding + | ImGuiWindowFlags_NoBringToFrontOnFocus + | ImGuiWindowFlags_AlwaysAutoResize; +}; + + +class hdr_widgets { +public: + // c'tor that creats all 4 sliders and text boxes + // needed to init in an init list because no default c'tor for sliders and they are allocated inside hdr_widgets + hdr_widgets(rs2::depth_sensor& depth_sensor): + _exposure_slider_seq_1("Exposure", 1, 8000, + depth_sensor, RS2_OPTION_EXPOSURE, depth_sensor.get_option_range(RS2_OPTION_EXPOSURE), { 130, 180 }, { 350, 40 }), + _exposure_slider_seq_2("Exposure", 2, 18, + depth_sensor, RS2_OPTION_EXPOSURE, depth_sensor.get_option_range(RS2_OPTION_EXPOSURE), { 390, 180 }, { 350, 40 }), + _gain_slider_seq_1("Gain", 1, 25, + depth_sensor, RS2_OPTION_GAIN, depth_sensor.get_option_range(RS2_OPTION_GAIN), { 130, 220 }, { 350, 40 }), + _gain_slider_seq_2("Gain", 2, 16, + depth_sensor, RS2_OPTION_GAIN, depth_sensor.get_option_range(RS2_OPTION_GAIN), { 390, 220 }, { 350, 40 }), + _text_box_hdr_explain("HDR Tutorial", { 120, 20 }, { 1000, 140 }), + _text_box_first_frame("frame 1", { 200, 150 }, { 170, 40 }), + _text_box_second_frame("frame 2", { 460, 150 }, { 170, 40 }), + _text_box_hdr_frame("hdr", { 850, 280 }, { 170, 40 }) + { + // init frames map + //for initilize only - an empty frame with its properties + rs2::frame frame; + + //set each frame with its properties: + // { tile's x coordinate, tiles's y coordinate, tile's width (in tiles), tile's height (in tiles), priority (default value=0) }, (x=0,y=0) <-> left bottom corner + //priority sets the order of drawing frame when two frames share part of the same tile, + //meaning if there are two frames: frame1 with priority=-1 and frame2 with priority=0, both with { 0,0,1,1 } as property, + //frame2 will be drawn on top of frame1 + _frames_map[IR1] = frame_and_tile_property(frame, { 0,0,1,1,Priority::high }); + _frames_map[IR2] = frame_and_tile_property(frame, { 1,0,1,1,Priority::high }); + _frames_map[DEPTH1] = frame_and_tile_property(frame,{ 0,1,1,1,Priority::high }); + _frames_map[DEPTH2] = frame_and_tile_property(frame, { 1,1,1,1,Priority::high }); + _frames_map[HDR] = frame_and_tile_property(frame, { 2,0,2,2,Priority::high }); + } + + //show the features of the ImGui we have created + //we need slider 2 to be showen before slider 1 (otherwise slider 1 padding is covering slider 2) + void render_widgets() { + + //start a new frame of ImGui + ImGui_ImplGlfw_NewFrame(1); + + _exposure_slider_seq_2.show(); + _exposure_slider_seq_1.show(); + _gain_slider_seq_2.show(); + _gain_slider_seq_1.show(); + + _text_box_first_frame.remove_title_bar(); + _text_box_first_frame.show("Sequence 1"); + + _text_box_second_frame.remove_title_bar(); + _text_box_second_frame.show("Sequence 2"); + + _text_box_hdr_frame.remove_title_bar(); + _text_box_hdr_frame.show("HDR Stream"); + _text_box_hdr_explain.show("This demo provides a quick overview of the High Dynamic Range (HDR) feature.\nThe HDR configures and operates on sequences of two frames configurations, for which separate exposure and gain values are defined.\nBoth configurations are streamed and the HDR feature uses both frames in order to provide the best depth image.\nChange the values of the sliders to see the impact on the HDR Depth Image."); + + //render the ImGui features: sliders and text + ImGui::Render(); + + } + + // return a reference to frames map + frames_mosaic& get_frames_map() { + return _frames_map; + } + + void update_frames_map(const rs2::video_frame& infrared_frame, const rs2::frame& depth_frame, + const rs2::frame& hdr_frame, rs2_metadata_type hdr_seq_id, rs2_metadata_type hdr_seq_size) { + + // frame index in frames_map are according to hdr_seq_id and hdr_seq_size + int infrared_index = int(hdr_seq_id); + int depth_index = int(hdr_seq_id + hdr_seq_size); + int hdr_index = int(hdr_seq_id + hdr_seq_size + 1); + + //work-around, 'get_frame_metadata' sometimes (after changing exposure or gain values) sets hdr_seq_size to 0 even though it 2 for few frames + //so we update the frames only if hdr_seq_size > 0. (hdr_seq_size==0 <-> frame is invalid) + if (hdr_seq_size > 0) { + _frames_map[infrared_index].first = infrared_frame; + _frames_map[depth_index].first = depth_frame; + _frames_map[hdr_index].first = hdr_frame; //HDR shall be after IR1/2 & DEPTH1/2 + } + } + +public: + + frames_mosaic _frames_map; + + hdr_slider _exposure_slider_seq_1; + hdr_slider _gain_slider_seq_1; + hdr_slider _exposure_slider_seq_2; + hdr_slider _gain_slider_seq_2; + + text_box _text_box_hdr_explain; + text_box _text_box_first_frame; + text_box _text_box_second_frame; + text_box _text_box_hdr_frame; + + enum frame_id { IR1, IR2, DEPTH1, DEPTH2, HDR }; + +}; + diff --git a/examples/example.hpp b/examples/example.hpp index 2c4a32e6be..9d4a2fbe66 100644 --- a/examples/example.hpp +++ b/examples/example.hpp @@ -3,14 +3,12 @@ #pragma once -#include +#include // Include RealSense Cross Platform API #define GL_SILENCE_DEPRECATION #define GLFW_INCLUDE_GLU #include -#include // Include RealSense Cross Platform API - #include #include #include @@ -23,12 +21,11 @@ #include "../third-party/stb_easy_font.h" #ifndef PI -const double PI = 3.14159265358979323846; +#define PI 3.14159265358979323846 +#define PI_FL 3.141592f #endif -#include "../third-party/imgui/imgui.h" -#include "../third-party/imgui/imgui_impl_glfw.h" -const size_t IMU_FRAME_WIDTH = 1280; -const size_t IMU_FRAME_HEIGHT = 720; +const float IMU_FRAME_WIDTH = 1280.f; +const float IMU_FRAME_HEIGHT = 720.f; enum class Priority { high = 0, medium = -1, low = -2 }; ////////////////////////////// @@ -103,202 +100,6 @@ struct tile_properties using frame_and_tile_property = std::pair; using frames_mosaic = std::map; -////////////////////////////// -// Class Helpers // -////////////////////////////// - -//slider for ImGui -class slider { -public: - slider(const char* name, int seq_id, float init_value, float min_value, float max_value, ImVec2 position, ImVec2 size) : - _name(name), _seq_id(seq_id), _value(init_value), _min_value(min_value), _max_value(max_value), _position(position), _size(size) {} - - void virtual show()=0; - -public: - const char* _name; - int _seq_id; - float _value; - float _max_value; - float _min_value; - ImVec2 _position; - ImVec2 _size; - -}; - -class hdr_slider : public slider { -public: - hdr_slider(const char* name, int seq_id, float init_value, rs2::sensor& sensor, - rs2_option option, rs2::option_range range, ImVec2 position, ImVec2 size) : slider(name, seq_id, init_value, range.min, range.max, position, size), - _sensor(sensor), _option(option), _range(range){} - - void show() override - { - ImGui::SetNextWindowSize(_size); - ImGui::SetNextWindowPos(_position); - //concate the name given with seq_id in order to make a unique name (uniqeness is needed for Begin()) - std::string name_id = std::string(_name) + std::to_string(_seq_id); - 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 - if (is_changed) { - _sensor.set_option(RS2_OPTION_SEQUENCE_ID, float(_seq_id)); - _sensor.set_option(_option, _value); - } - ImGui::End(); - } - -public: - rs2::sensor& _sensor; - rs2_option _option; - rs2::option_range _range; - //flags for the sliders - const static int _sliders_flags = ImGuiWindowFlags_NoCollapse - | ImGuiWindowFlags_NoScrollbar - | ImGuiWindowFlags_NoSavedSettings - | ImGuiWindowFlags_NoResize - | ImGuiWindowFlags_NoMove - | ImGuiWindowFlags_NoTitleBar - | ImGuiWindowFlags_NoBringToFrontOnFocus; -}; - -//text box for ImGui -class text_box { -public: - text_box(const char* name, ImVec2 position, ImVec2 size) : _name(name), _position(position), _size(size) {} - - void show(const char* text) - { - ImGui::SetNextWindowSize(_size); - ImGui::SetNextWindowPos(_position); - ImGui::Begin(_name, nullptr, _text_box_flags); - ImGui::Text("%s",text); - - ImGui::End(); - } - void remove_title_bar() { - _text_box_flags |= ImGuiWindowFlags_NoTitleBar; - } - -public: - const char* _name; - ImVec2 _position; - ImVec2 _size; - // flags for displaying text box - int _text_box_flags = ImGuiWindowFlags_NoCollapse - | ImGuiWindowFlags_NoScrollbar - | ImGuiWindowFlags_NoSavedSettings - | ImGuiWindowFlags_NoResize - | ImGuiWindowFlags_NoMove - | ImGuiWindowFlags_NoFocusOnAppearing - | ImGuiWindowFlags_AlwaysUseWindowPadding - | ImGuiWindowFlags_NoBringToFrontOnFocus - | ImGuiWindowFlags_AlwaysAutoResize; -}; - - -class hdr_widgets { -public: - // c'tor that creats all 4 sliders and text boxes - // needed to init in an init list because no default c'tor for sliders and they are allocated inside hdr_widgets - hdr_widgets(rs2::depth_sensor& depth_sensor): - _exposure_slider_seq_1("Exposure", 1, 8000, - depth_sensor, RS2_OPTION_EXPOSURE, depth_sensor.get_option_range(RS2_OPTION_EXPOSURE), { 130, 180 }, { 350, 40 }), - _exposure_slider_seq_2("Exposure", 2, 18, - depth_sensor, RS2_OPTION_EXPOSURE, depth_sensor.get_option_range(RS2_OPTION_EXPOSURE), { 390, 180 }, { 350, 40 }), - _gain_slider_seq_1("Gain", 1, 25, - depth_sensor, RS2_OPTION_GAIN, depth_sensor.get_option_range(RS2_OPTION_GAIN), { 130, 220 }, { 350, 40 }), - _gain_slider_seq_2("Gain", 2, 16, - depth_sensor, RS2_OPTION_GAIN, depth_sensor.get_option_range(RS2_OPTION_GAIN), { 390, 220 }, { 350, 40 }), - _text_box_hdr_explain("HDR Tutorial", { 120, 20 }, { 1000, 140 }), - _text_box_first_frame("frame 1", { 200, 150 }, { 170, 40 }), - _text_box_second_frame("frame 2", { 460, 150 }, { 170, 40 }), - _text_box_hdr_frame("hdr", { 850, 280 }, { 170, 40 }) - { - // init frames map - //for initilize only - an empty frame with its properties - rs2::frame frame; - - //set each frame with its properties: - // { tile's x coordinate, tiles's y coordinate, tile's width (in tiles), tile's height (in tiles), priority (default value=0) }, (x=0,y=0) <-> left bottom corner - //priority sets the order of drawing frame when two frames share part of the same tile, - //meaning if there are two frames: frame1 with priority=-1 and frame2 with priority=0, both with { 0,0,1,1 } as property, - //frame2 will be drawn on top of frame1 - _frames_map[IR1] = frame_and_tile_property(frame, { 0,0,1,1,Priority::high }); - _frames_map[IR2] = frame_and_tile_property(frame, { 1,0,1,1,Priority::high }); - _frames_map[DEPTH1] = frame_and_tile_property(frame,{ 0,1,1,1,Priority::high }); - _frames_map[DEPTH2] = frame_and_tile_property(frame, { 1,1,1,1,Priority::high }); - _frames_map[HDR] = frame_and_tile_property(frame, { 2,0,2,2,Priority::high }); - } - - //show the features of the ImGui we have created - //we need slider 2 to be showen before slider 1 (otherwise slider 1 padding is covering slider 2) - void render_widgets() { - - //start a new frame of ImGui - ImGui_ImplGlfw_NewFrame(1); - - _exposure_slider_seq_2.show(); - _exposure_slider_seq_1.show(); - _gain_slider_seq_2.show(); - _gain_slider_seq_1.show(); - - _text_box_first_frame.remove_title_bar(); - _text_box_first_frame.show("Sequence 1"); - - _text_box_second_frame.remove_title_bar(); - _text_box_second_frame.show("Sequence 2"); - - _text_box_hdr_frame.remove_title_bar(); - _text_box_hdr_frame.show("HDR Stream"); - _text_box_hdr_explain.show("This demo provides a quick overview of the High Dynamic Range (HDR) feature.\nThe HDR configures and operates on sequences of two frames configurations, for which separate exposure and gain values are defined.\nBoth configurations are streamed and the HDR feature uses both frames in order to provide the best depth image.\nChange the values of the sliders to see the impact on the HDR Depth Image."); - - //render the ImGui features: sliders and text - ImGui::Render(); - - } - - // return a reference to frames map - frames_mosaic& get_frames_map() { - return _frames_map; - } - - void update_frames_map(const rs2::video_frame& infrared_frame, const rs2::frame& depth_frame, - const rs2::frame& hdr_frame, rs2_metadata_type hdr_seq_id, rs2_metadata_type hdr_seq_size) { - - // frame index in frames_map are according to hdr_seq_id and hdr_seq_size - int infrared_index = int(hdr_seq_id); - int depth_index = int(hdr_seq_id + hdr_seq_size); - int hdr_index = int(hdr_seq_id + hdr_seq_size + 1); - - //work-around, 'get_frame_metadata' sometimes (after changing exposure or gain values) sets hdr_seq_size to 0 even though it 2 for few frames - //so we update the frames only if hdr_seq_size > 0. (hdr_seq_size==0 <-> frame is invalid) - if (hdr_seq_size > 0) { - _frames_map[infrared_index].first = infrared_frame; - _frames_map[depth_index].first = depth_frame; - _frames_map[hdr_index].first = hdr_frame; //HDR shall be after IR1/2 & DEPTH1/2 - } - } - -public: - - frames_mosaic _frames_map; - - hdr_slider _exposure_slider_seq_1; - hdr_slider _gain_slider_seq_1; - hdr_slider _exposure_slider_seq_2; - hdr_slider _gain_slider_seq_2; - - text_box _text_box_hdr_explain; - text_box _text_box_first_frame; - text_box _text_box_second_frame; - text_box _text_box_hdr_frame; - - enum frame_id { IR1, IR2, DEPTH1, DEPTH2, HDR }; - -}; - ////////////////////////////// // Simple font loading code // diff --git a/examples/hdr/rs-hdr.cpp b/examples/hdr/rs-hdr.cpp index ffd6ddcfd1..fa16404502 100644 --- a/examples/hdr/rs-hdr.cpp +++ b/examples/hdr/rs-hdr.cpp @@ -2,10 +2,8 @@ // Copyright(c) 2020 Intel Corporation. All Rights Reserved. #include // Include RealSense Cross Platform API -#include "example.hpp" // Include short list of convenience functions for rendering +#include "example-imgui.hpp" // Include short list of convenience functions for rendering #include -#include "imgui.h" -#include "imgui_impl_glfw.h" // HDR Example demonstrates how to use the HDR feature - only for D400 product line devices diff --git a/examples/hello-realsense/rs-hello-realsense.cpp b/examples/hello-realsense/rs-hello-realsense.cpp index 13cf8dc400..46be1804f4 100644 --- a/examples/hello-realsense/rs-hello-realsense.cpp +++ b/examples/hello-realsense/rs-hello-realsense.cpp @@ -23,8 +23,8 @@ int main(int argc, char * argv[]) try rs2::depth_frame depth = frames.get_depth_frame(); // Get the depth frame's dimensions - float width = depth.get_width(); - float height = depth.get_height(); + auto width = depth.get_width(); + auto height = depth.get_height(); // Query the distance from the camera to the object in the center of the image float dist_to_center = depth.get_distance(width / 2, height / 2); diff --git a/examples/measure/rs-measure.cpp b/examples/measure/rs-measure.cpp index d14170e232..b2675d1b72 100644 --- a/examples/measure/rs-measure.cpp +++ b/examples/measure/rs-measure.cpp @@ -33,8 +33,8 @@ struct toggle // Move from [0,1] space to pixel space of specific frame pixel get_pixel(rs2::depth_frame frm) const { - int px = x * frm.get_width(); - int py = y * frm.get_height(); + int px = static_cast(x * frm.get_width()); + int py = static_cast(y * frm.get_height()); return{ px, py }; } @@ -53,7 +53,7 @@ struct toggle glBegin(GL_TRIANGLE_STRIP); for (auto i = 0; i <= segments; i++) { - auto t = 2 * M_PI * float(i) / segments; + auto t = 2 * PI_FL * float(i) / segments; glVertex2f(x * app.width() + cos(t) * r, y * app.height() + sin(t) * r); @@ -69,7 +69,7 @@ struct toggle // Since we are only comparing this distance, sqrt can be safely skipped float dist_2d(const toggle& other) const { - return pow(x - other.x, 2) + pow(y - other.y, 2); + return static_cast(pow(x - other.x, 2) + pow(y - other.y, 2)); } float x; @@ -265,18 +265,18 @@ float dist_3d(const rs2::depth_frame& frame, pixel u, pixel v) float vpoint[3]; // To point (in 3D) // Copy pixels into the arrays (to match rsutil signatures) - upixel[0] = u.first; - upixel[1] = u.second; - vpixel[0] = v.first; - vpixel[1] = v.second; + upixel[0] = static_cast(u.first); + upixel[1] = static_cast(u.second); + vpixel[0] = static_cast(v.first); + vpixel[1] = static_cast(v.second); // Query the frame for distance // Note: this can be optimized // It is not recommended to issue an API call for each pixel // (since the compiler can't inline these) // However, in this example it is not one of the bottlenecks - auto udist = frame.get_distance(upixel[0], upixel[1]); - auto vdist = frame.get_distance(vpixel[0], vpixel[1]); + auto udist = frame.get_distance(static_cast(upixel[0]), static_cast(upixel[1])); + auto vdist = frame.get_distance(static_cast(vpixel[0]), static_cast(vpixel[1])); // Deproject from pixel to point in 3D rs2_intrinsics intr = frame.get_profile().as().get_intrinsics(); // Calibration data @@ -284,9 +284,9 @@ float dist_3d(const rs2::depth_frame& frame, pixel u, pixel v) rs2_deproject_pixel_to_point(vpoint, &intr, vpixel, vdist); // Calculate euclidean distance between the two points - return sqrt(pow(upoint[0] - vpoint[0], 2) + - pow(upoint[1] - vpoint[1], 2) + - pow(upoint[2] - vpoint[2], 2)); + return sqrt(pow(upoint[0] - vpoint[0], 2.f) + + pow(upoint[1] - vpoint[1], 2.f) + + pow(upoint[2] - vpoint[2], 2.f)); } void draw_line(float x0, float y0, float x1, float y1, int width) @@ -294,7 +294,7 @@ void draw_line(float x0, float y0, float x1, float y1, int width) glPushAttrib(GL_ENABLE_BIT); glLineStipple(1, 0x00ff); glEnable(GL_LINE_STIPPLE); - glLineWidth(width); + glLineWidth(static_cast(width)); glBegin(GL_LINE_STRIP); glVertex2f(x0, y0); glVertex2f(x1, y1); @@ -354,10 +354,10 @@ void render_simple_distance(const rs2::depth_frame& depth, // Draw white text label glColor4f(1.f, 1.f, 1.f, 1.f); - draw_text(x, y, str.c_str()); + draw_text(static_cast(x), static_cast(y), str.c_str()); } -// Implement drag&drop behaviour for the buttons: +// Implement drag & drop behavior for the buttons: void register_glfw_callbacks(window& app, state& app_state) { app.on_left_mouse = [&](bool pressed) diff --git a/examples/motion/rs-motion.cpp b/examples/motion/rs-motion.cpp index 06f2aa3e86..c280d62074 100644 --- a/examples/motion/rs-motion.cpp +++ b/examples/motion/rs-motion.cpp @@ -81,14 +81,14 @@ class camera_renderer glPushMatrix(); // Set the rotation, converting theta to degrees - glRotatef(theta.x * 180 / PI, 0, 0, -1); - glRotatef(theta.y * 180 / PI, 0, -1, 0); - glRotatef((theta.z - PI / 2) * 180 / PI, -1, 0, 0); + glRotatef(theta.x * 180 / PI_FL, 0, 0, -1); + glRotatef(theta.y * 180 / PI_FL, 0, -1, 0); + glRotatef((theta.z - PI_FL / 2) * 180 / PI_FL, -1, 0, 0); draw_axes(); // Scale camera drawing - glScalef(0.035, 0.035, 0.035); + glScalef(0.035f, 0.035f, 0.035f); glBegin(GL_TRIANGLES); // Draw the camera @@ -116,7 +116,7 @@ class rotation_estimator std::mutex theta_mtx; /* alpha indicates the part that gyro and accelerometer take in computation of theta; higher alpha gives more weight to gyro, but too high values cause drift; lower alpha gives more weight to accelerometer, which is more sensitive to disturbances */ - float alpha = 0.98; + float alpha = 0.98f; bool firstGyro = true; bool firstAccel = true; // Keeps the arrival time of previous gyro frame @@ -144,7 +144,7 @@ class rotation_estimator last_ts_gyro = ts; // Change in angle equals gyro measures * time passed since last measurement - gyro_angle = gyro_angle * dt_gyro; + gyro_angle = gyro_angle * static_cast(dt_gyro); // Apply the calculated change of angle to the current angle (theta) std::lock_guard lock(theta_mtx); @@ -167,7 +167,7 @@ class rotation_estimator firstAccel = false; theta = accel_angle; // Since we can't infer the angle around Y axis using accelerometer data, we'll use PI as a convetion for the initial pose - theta.y = PI; + theta.y = PI_FL; } else { diff --git a/examples/pose-predict/rs-pose-predict.cpp b/examples/pose-predict/rs-pose-predict.cpp index cf27513495..fd237f0161 100644 --- a/examples/pose-predict/rs-pose-predict.cpp +++ b/examples/pose-predict/rs-pose-predict.cpp @@ -63,7 +63,7 @@ int main(int argc, char * argv[]) try if (rs2::pose_frame fp = frame.as()) { rs2_pose pose_data = fp.get_pose_data(); auto now = std::chrono::system_clock::now().time_since_epoch(); - double now_ms = std::chrono::duration_cast(now).count(); + double now_ms = static_cast(std::chrono::duration_cast(now).count()); double pose_time_ms = fp.get_timestamp(); float dt_s = static_cast(std::max(0., (now_ms - pose_time_ms)/1000.)); rs2_pose predicted_pose = predict_pose(pose_data, dt_s); diff --git a/third-party/imgui/imgui_impl_glfw.cpp b/third-party/imgui/imgui_impl_glfw.cpp index ca0b45bbbe..93e4a75ac1 100644 --- a/third-party/imgui/imgui_impl_glfw.cpp +++ b/third-party/imgui/imgui_impl_glfw.cpp @@ -10,7 +10,7 @@ // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // https://github.com/ocornut/imgui -#include +#include "imgui.h" #include "imgui_impl_glfw.h" // GLFW