50 int main(
int argc,
char * argv[])
try 53 window app(1280, 720,
"RealSense Post Processing Example");
79 const std::string disparity_filter_name =
"Disparity";
84 std::vector<filter_options>
filters;
87 filters.emplace_back(
"Decimate", dec_filter);
88 filters.emplace_back(
"Threshold", thr_filter);
89 filters.emplace_back(disparity_filter_name, depth_to_disparity);
90 filters.emplace_back(
"Spatial", spat_filter);
91 filters.emplace_back(
"Temporal", temp_filter);
101 std::atomic_bool stopped(
false);
105 std::thread processing_thread([&]() {
125 bool revert_disparity =
false;
126 for (
auto&&
filter : filters)
130 filtered =
filter.filter.process(filtered);
131 if (
filter.filter_name == disparity_filter_name)
133 revert_disparity =
true;
137 if (revert_disparity)
139 filtered = disparity_to_depth.
process(filtered);
147 filtered_data.
enqueue(filtered);
148 original_data.
enqueue(depth_frame);
164 const double max_angle = 15.0;
166 float rotation_velocity = 0.3f;
170 float w =
static_cast<float>(app.
width());
171 float h =
static_cast<float>(app.
height());
177 update_data(original_data, colored_depth, original_points, original_pc, original_view_orientation, color_map);
178 update_data(filtered_data, colored_filtered, filtered_points, filtered_pc, filtered_view_orientation, color_map);
181 draw_text(static_cast<int>(w / 2), 50,
"Filtered");
184 if (colored_depth && original_points)
186 glViewport(0,
int(h) / 2,
int(w) / 2,
int(h) / 2);
187 draw_pointcloud(
int(w) / 2.
f,
int(h) / 2.
f, original_view_orientation, original_points);
189 if (colored_filtered && filtered_points)
191 glViewport(
int(w) / 2,
int(h) / 2,
int(w) / 2,
int(h) / 2);
192 draw_pointcloud(
int(w) / 2.
f,
int(h) / 2.
f, filtered_view_orientation, filtered_points);
198 const std::chrono::milliseconds rotation_delta(40);
202 if (curr - last_time > rotation_delta)
204 if (fabs(filtered_view_orientation.yaw) > max_angle)
206 rotation_velocity = -rotation_velocity;
208 original_view_orientation.yaw += rotation_velocity;
209 filtered_view_orientation.yaw += rotation_velocity;
217 processing_thread.join();
226 catch (
const std::exception& e)
238 colorized_depth = color_map.
process(f);
239 pc.
map_to(colorized_depth);
259 const float offset_x = w / 4;
260 const int offset_from_checkbox = 120;
261 float offset_y = h / 2;
262 float elements_margin = 45;
263 for (
auto&
filter : filters)
268 bool tmp_value =
filter.is_enabled;
270 filter.is_enabled = tmp_value;
273 if (
filter.supported_options.size() == 0)
275 offset_y += elements_margin;
278 for (
auto& option_slider_pair :
filter.supported_options)
281 if (slider.
render({ offset_x + offset_from_checkbox, offset_y, w / 4 },
filter.is_enabled))
283 filter.filter.set_option(option_slider_pair.first, slider.
value);
285 offset_y += elements_margin;
295 bool value_changed =
false;
317 int value_as_int =
static_cast<int>(
value);
319 value =
static_cast<float>(value_as_int);
334 return value_changed;
359 const std::array<rs2_option, 5> possible_filter_options = {
368 for (
rs2_option opt : possible_filter_options)
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val)
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
int main(int argc, char *argv[])
IMGUI_API void SetTooltip(const char *fmt,...) IM_PRINTFARGS(1)
GLuint const GLchar * name
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
filter_options(const std::string name, rs2::filter &filter)
IMGUI_API void SetCursorPos(const ImVec2 &local_pos)
bool render(const float3 &location, bool enabled)
std::atomic_bool is_enabled
std::map< rs2_option, filter_slider_ui > supported_options
std::enable_if< std::is_base_of< rs2::frame, T >::value, bool >::type poll_for_frame(T *output) const
void enqueue(frame f) const
GLint GLint GLsizei GLsizei GLsizei depth
bool supports(rs2_camera_info info) const
void map_to(frame mapped)
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
IMGUI_API bool SliderInt(const char *label, int *v, int v_min, int v_max, const char *display_format="%.0f", bool render_bg=false)
depth_frame get_depth_frame() const
const std::string & get_failed_args() const
rs2::frame process(rs2::frame frame) const override
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
IMGUI_API void PopStyleVar(int count=1)
IMGUI_API void TextUnformatted(const char *text, const char *text_end=NULL)
const char * get_option_description(rs2_option option) const
const char * get_option_name(rs2_option option) const
void upload(const rs2::video_frame &frame)
bool ImGui_ImplGlfw_Init(GLFWwindow *window, bool install_callbacks)
points calculate(frame depth) const
IMGUI_API void SetNextWindowSize(const ImVec2 &size, ImGuiSetCond cond=0)
GLenum GLenum GLsizei const GLuint GLboolean enabled
IMGUI_API void PushItemWidth(float item_width)
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4 &col)
static bool is_all_integers(const rs2::option_range &range)
void ImGui_ImplGlfw_NewFrame(float scale_factor)
IMGUI_API bool SliderFloat(const char *label, float *v, float v_min, float v_max, const char *display_format="%.3f", float power=1.0f, bool render_bg=false)
void draw_pointcloud(float width, float height, glfw_state &app_state, rs2::points &points)
IMGUI_API void PopItemWidth()
GLuint GLsizei const GLchar * label
void draw_text(int x, int y, const char *text)
IMGUI_API bool Checkbox(const char *label, bool *v)
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
option_range get_option_range(rs2_option option) const
IMGUI_API ImGuiStyle & GetStyle()
IMGUI_API bool IsItemHovered()
const std::string & get_failed_function() const
GLdouble GLdouble GLint GLint const GLdouble * points
void render_ui(float w, float h, std::vector< filter_options > &filters)
IMGUI_API void PopStyleColor(int count=1)
void update_data(rs2::frame_queue &data, rs2::frame &depth, rs2::points &points, rs2::pointcloud &pc, glfw_state &view, rs2::colorizer &color_map)