helper.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include <iostream>
7 #include <string>
8 #include <thread>
9 #include <librealsense2/rs.hpp>
10 #include "../example.hpp"
11 
12 namespace helper
13 {
14  inline bool prompt_yes_no(const std::string& prompt_msg)
15  {
16  char ans;
17  do
18  {
19  std::cout << prompt_msg << "[y/n]: ";
20  std::cin >> ans;
21  std::cout << std::endl;
22  } while (!std::cin.fail() && ans != 'y' && ans != 'n');
23  return ans == 'y';
24  }
25 
26  inline uint32_t get_user_selection(const std::string& prompt_message)
27  {
28  std::cout << "\n" << prompt_message;
30  std::cin >> input;
31  std::cout << std::endl;
32  return input;
33  }
34 
35  inline void print_separator()
36  {
37  std::cout << "\n======================================================\n" << std::endl;
38  }
39 
41  {
42  public:
43  frame_viewer(const std::string& window_title) :
44  _window_title(window_title),
45  _thread(new std::thread(&frame_viewer::run, this))
46  {
47  }
49  {
50  if (_thread && _thread->joinable())
51  _thread->join();
52  }
54  {
55  _frames.enqueue(f);
56  }
57  void wait()
58  {
59  //Wait for the windows to close
60  if (_thread)
61  _thread->join();
62  }
63  private:
64  void run()
65  {
66  window app(640, 480, _window_title.c_str());
68  while (app)
69  {
70  float view_width = app.width();
71  float view_height = app.height();
72  if (error.empty())
73  {
74  rs2::frame frame;
75  if (!_frames.poll_for_frame(&frame))
76  {
77  frame = _last_frame;
78  }
79  _last_frame = frame;
80  if (frame)
81  {
82  try
83  {
84  renderer.render(colorize.process(decimate.process(frame)).as<rs2::video_frame>(), { 0, 0, view_width, view_height });
85  }
86  catch (const std::exception& e)
87  {
88  error = e.what();
89  }
90  }
91  }
92  else
93  {
94  draw_text(int(std::max(0.f, (view_width / 2) - error.length() * 3)),
95  int(view_height / 2), error.c_str());
96  }
97  }
98  }
99  private:
106  std::unique_ptr<std::thread> _thread;
107  };
108 }
bool prompt_yes_no(const std::string &prompt_msg)
Definition: helper.h:14
void operator()(rs2::frame f)
Definition: helper.h:53
void render(const rs2::frame &frame, const rect &rect, float alpha=1.f)
Definition: example.hpp:471
Definition: helper.h:12
rs2::colorizer colorize
Definition: helper.h:101
std::enable_if< std::is_base_of< rs2::frame, T >::value, bool >::type poll_for_frame(T *output) const
void enqueue(frame f) const
texture renderer
Definition: helper.h:100
def fail()
Definition: test.py:340
void print_separator()
Definition: helper.h:35
GLsizei const GLchar *const * string
e
Definition: rmse.py:177
The texture class.
Definition: example.hpp:402
GLdouble f
rs2::frame process(rs2::frame frame) const override
rs2::frame _last_frame
Definition: helper.h:105
std::string _window_title
Definition: helper.h:103
std::ostream & cout()
unsigned int uint32_t
Definition: stdint.h:80
rs2::decimation_filter decimate
Definition: helper.h:102
frame_viewer(const std::string &window_title)
Definition: helper.h:43
uint32_t get_user_selection(const std::string &prompt_message)
Definition: helper.h:26
std::unique_ptr< std::thread > _thread
Definition: helper.h:106
GLenum GLenum GLenum input
Definition: glext.h:10805
rs2::frame_queue _frames
Definition: helper.h:104
void draw_text(int x, int y, const char *text)
Definition: example.hpp:109


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:16