output-model.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include <functional>
7 #include <string>
8 
9 #include "ux-window.h"
10 #include "rendering.h"
11 
12 #include "../src/concurrency.h"
13 
14 namespace rs2
15 {
16  class device_model;
17 
19  {
20  public:
21  stream_dashboard(std::string name, int size) : q(size), name(name), t([this](){ thread_function(); }) {}
23  {
24  stop = true;
25  t.join();
26  }
27 
28  std::string get_name() const { return name; }
29 
30  void add_frame(rs2::frame f) { q.enqueue(f); }
31 
32  virtual void draw(ux_window& win, rect r) = 0;
33 
34  virtual int get_height() const { return 150; }
35 
36  virtual void clear(bool full = false) {}
37 
38  void close() { to_close = true; }
39  bool closing() const { return to_close; }
40 
41  protected:
42  virtual void process_frame(rs2::frame f) = 0;
43 
44  void write_shared_data(std::function<void()> action)
45  {
46  std::lock_guard<std::mutex> lock(m);
47  action();
48  }
49 
50  template<class T>
51  T read_shared_data(std::function<T()> action)
52  {
53  std::lock_guard<std::mutex> lock(m);
54  T res = action();
55  return res;
56  }
57 
58  void add_point(float x, float y) { xy.push_back(std::make_pair(x, y)); }
59 
60  void draw_dashboard(ux_window& win, rect& r);
61 
62  private:
64  {
65  while(!stop)
66  {
67  rs2::frame f;
68  if (q.try_wait_for_frame(&f, 100))
69  process_frame(f);
70  }
71  }
74  std::mutex m;
75  std::atomic<int> stop { false };
76  std::thread t;
77  std::vector<std::pair<float, float>> xy;
78  bool to_close = false;
79  };
80 
82  {
83  public:
84  frame_drops_dashboard(std::string name, int* frame_drop_count, int* total)
85  : stream_dashboard(name, 30),
86  last_time(glfwGetTime()), frame_drop_count(frame_drop_count), total(total)
87  {
88  clear(true);
89  }
90 
91  void process_frame(rs2::frame f) override;
92  void draw(ux_window& win, rect r) override;
93  int get_height() const override;
94 
95  void clear(bool full) override;
96 
97  private:
98  std::map<int, double> stream_to_time;
99  int drops = 0;
100  double last_time;
101  std::deque<int> drops_history;
102  int *frame_drop_count, *total;
103  int counter = 0;
104  int method = 0;
105  };
106 
108  {
109  public:
110  struct log_entry
111  {
115  int line_number = 0;
116  double time_added = 0.0;
118  bool selected = false;
119  };
120 
121  void update_dashboards(rs2::frame f);
122 
123  output_model();
124  ~output_model();
125 
126  void add_log(rs2_log_severity severity, std::string filename, int line_number, std::string line);
127 
128  void draw(ux_window& win, rect view_rect, std::vector<std::unique_ptr<device_model>> & device_models);
129 
130  int get_output_height() const { return default_log_h; }
131 
132  void run_command(std::string command, std::vector<std::unique_ptr<device_model>> & device_models);
133  bool user_defined_command(std::string command, std::vector<std::unique_ptr<device_model>> & device_models);
134 
135 
136  private:
137  void open(ux_window& win);
138 
139  void foreach_log(std::function<void(log_entry& line)> action);
140  bool round_indicator(ux_window& win, std::string icon, int count,
141  ImVec4 color, std::string tooltip, bool& highlighted, std::string suffix = "");
142 
143  bool new_log = false;
144  std::recursive_mutex m;
145 
147  std::deque<log_entry> notification_logs;
148 
149  animated<int> default_log_h { 36 };
150  bool is_output_open = true;
151 
152  bool enable_firmware_logs = false;
153 
154  bool errors_selected = false;
155  bool warnings_selected = false;
156  bool info_selected = false;
157 
158  bool errors_highlighted = false;
159  bool warnings_highlighted = false;
160  bool info_highlighted = false;
161  bool drops_highlighted = false;
162 
163  int number_of_errors = 0;
164  int number_of_warnings = 0;
165  int number_of_info = 0;
166  int number_of_drops = 0;
167  int total_frames = 0;
168 
169  animated<int> search_width { 0, std::chrono::milliseconds(400) };
170  bool search_open = false;
171 
172  std::deque<std::string> autocomplete;
173 
174  std::mutex devices_mutex;
175  std::vector<rs2::device> devices;
176 
177  std::string search_line { "" };
178  std::string command_line { "" };
179  std::deque<std::string> commands_histroy;
180  int history_offset = 0;
181  bool command_focus = true;
182 
183  std::vector<std::shared_ptr<stream_dashboard>> dashboards;
184  std::map<std::string, std::function<std::shared_ptr<stream_dashboard>(std::string)>> available_dashboards;
185 
186  std::atomic<int> to_stop { 0 };
187  std::thread fw_logger;
188 
189  void thread_loop();
190  };
191 }
void add_point(float x, float y)
Definition: output-model.h:58
static const textual_icon lock
Definition: model-views.h:218
GLint y
virtual void clear(bool full=false)
Definition: output-model.h:36
Definition: output-model.h:110
GLenum GLuint GLenum severity
GLuint const GLchar * name
frame_drops_dashboard(std::string name, int *frame_drop_count, int *total)
Definition: output-model.h:84
std::mutex devices_mutex
Definition: output-model.h:174
std::vector< std::pair< float, float > > xy
Definition: output-model.h:77
T read_shared_data(std::function< T()> action)
Definition: output-model.h:51
std::map< int, double > stream_to_time
Definition: output-model.h:98
const GLfloat * m
Definition: glext.h:6814
Definition: lz4.c:398
int get_output_height() const
Definition: output-model.h:130
Definition: cah-model.h:10
GLsizei const GLchar *const * string
std::thread fw_logger
Definition: output-model.h:187
GLdouble t
GLdouble f
rs2::frame_queue q
Definition: output-model.h:73
GLsizeiptr size
std::recursive_mutex m
Definition: output-model.h:144
GLuint counter
Definition: glext.h:5684
GLdouble GLdouble r
void write_shared_data(std::function< void()> action)
Definition: output-model.h:44
GLdouble x
std::deque< std::string > commands_histroy
Definition: output-model.h:179
virtual int get_height() const
Definition: output-model.h:34
std::vector< std::shared_ptr< stream_dashboard > > dashboards
Definition: output-model.h:183
stream_dashboard(std::string name, int size)
Definition: output-model.h:21
Definition: imgui.h:98
void add_frame(rs2::frame f)
Definition: output-model.h:30
std::deque< log_entry > notification_logs
Definition: output-model.h:147
action
Definition: enums.py:62
std::deque< std::string > autocomplete
Definition: output-model.h:172
GLFWAPI double glfwGetTime(void)
Returns the value of the GLFW timer.
Definition: input.c:1275
GLdouble GLdouble GLdouble q
bool closing() const
Definition: output-model.h:39
void draw_dashboard(ux_window &win, rect &r)
virtual void draw(ux_window &win, rect r)=0
GLint GLsizei count
std::atomic< int > stop
Definition: output-model.h:75
std::deque< int > drops_history
Definition: output-model.h:101
std::vector< rs2::device > devices
Definition: output-model.h:175
GLuint res
Definition: glext.h:8856
std::array< float, 3 > color
Definition: model-views.h:449
single_consumer_queue< log_entry > incoming_log_queue
Definition: output-model.h:146
virtual void process_frame(rs2::frame f)=0
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:153
virtual ~stream_dashboard()
Definition: output-model.h:22
std::string get_name() const
Definition: output-model.h:28


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