viewer.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 <unordered_set>
7 #include "model-views.h"
8 #include "notifications.h"
9 #include "skybox.h"
10 #include "measurement.h"
11 #include "updates-model.h"
13 
14 namespace rs2
15 {
16  struct popup
17  {
20  std::function<void()> custom_command;
21 
22  bool operator =(const popup& p)
23  {
24  return p.message == message;
25  }
26  };
27 
28  class viewer_model;
29 
30  class frameset_allocator : public filter
31  {
32  public:
34  private:
36  };
37 
38  struct export_model
39  {
40  template<typename T, size_t sz>
41  static export_model make_exporter(std::string name, std::string extension, T (&filters_str)[sz])
42  {
43  return export_model(name, extension, filters_str, sz);
44 
45  }
48  std::vector<char> filters;
49  std::map<rs2_option, int> options;
50 
51  private:
52  export_model(std::string name, std::string extension, const char* filters_str, size_t filters_size) : name(name),
53  extension(extension), filters(filters_str, filters_str + filters_size) {};
54  };
55 
57  {
58  public:
59  void reset_camera(float3 pos = { 0.0f, 0.0f, -1.0f });
60 
61  void update_configuration();
62 
63  const float panel_width = 340.f;
64  const float panel_y = 50.f;
65 
66  float get_output_height() const { return (float)(not_model->output.get_output_height()); }
67 
68  rs2::frame handle_ready_frames(const rect& viewer_rect, ux_window& window, int devices, std::string& error_message);
69 
71  {
72  // Stopping post processing filter rendering thread
73  ppf.stop();
74  streams.clear();
75  }
76 
77  void begin_stream(std::shared_ptr<subdevice_model> d, rs2::stream_profile p);
78 
79  std::shared_ptr<texture_buffer> get_last_texture();
80 
81  std::vector<frame> get_frames(frame set);
82  frame get_3d_depth_source(frame f);
83  frame get_3d_texture_source(frame f);
84 
85  bool is_3d_depth_source(frame f);
86  bool is_3d_texture_source(frame f) const;
87 
88  std::shared_ptr<texture_buffer> upload_frame(frame&& f);
89 
90  std::map<int, rect> calc_layout(const rect& r);
91 
92  void show_no_stream_overlay(ImFont* font, int min_x, int min_y, int max_x, int max_y);
93  void show_no_device_overlay(ImFont* font, int min_x, int min_y);
94  void show_rendering_not_supported(ImFont* font_18, int min_x, int min_y, int max_x, int max_y, rs2_format format);
95 
96  void show_paused_icon(ImFont* font, int x, int y, int id);
97  void show_recording_icon(ImFont* font_18, int x, int y, int id, float alpha_delta);
98 
99  void popup_if_error(const ux_window& window, std::string& error_message);
100 
101  void show_popup(const ux_window& window, const popup& p);
102 
103  void popup_firmware_update_progress(const ux_window& window, const float progress);
104 
105  void render_pose(rs2::rect stream_rect, float buttons_heights);
106  void try_select_pointcloud(ux_window& win);
107 
108  void show_3dviewer_header(ux_window& window, rs2::rect stream_rect, bool& paused, std::string& error_message);
109 
110  void update_3d_camera(ux_window& win, const rect& viewer_rect, bool force = false);
111 
112  void show_top_bar(ux_window& window, const rect& viewer_rect, const device_models_list& devices);
113 
114  void render_3d_view(const rect& view_rect, ux_window& win,
115  std::shared_ptr<texture_buffer> texture, rs2::points points);
116 
117  void render_2d_view(const rect& view_rect, ux_window& win, int output_height,
118  ImFont *font1, ImFont *font2, size_t dev_model_num, const mouse_info &mouse, std::string& error_message);
119 
120  void gc_streams();
121 
122  bool is_option_skipped(rs2_option opt) const;
123 
124  std::mutex streams_mutex;
125  std::map<int, stream_model> streams;
126  std::map<int, int> streams_origin;
127  bool fullscreen = false;
128  stream_model* selected_stream = nullptr;
129  std::shared_ptr<syncer_model> syncer;
131 
133  std::shared_ptr<notifications_model> not_model = std::make_shared<notifications_model>();
134  bool is_3d_view = false;
135  bool paused = false;
136  bool metric_system = true;
138 
140  {
142  };
143  std::map<export_type, export_model> exporters;
145 
146  void draw_viewport(const rect& viewer_rect,
147  ux_window& window, int devices, std::string& error_message,
148  std::shared_ptr<texture_buffer> texture, rs2::points f = rs2::points());
149 
150  bool allow_3d_source_change = true;
151  bool allow_stream_close = true;
152 
153  std::array<float3, 4> roi_rect;
154  bool draw_plane = false;
155 
156  bool draw_frustrum = true;
157  bool support_non_syncronized_mode = true;
158  std::atomic<bool> synchronization_enable;
160  std::atomic<int> zo_sensors;
161 
162  int selected_depth_source_uid = -1;
163  int selected_tex_source_uid = -1;
164  std::vector<int> last_tex_sources;
165  double texture_update_time = 0.0;
166 
167  enum class shader_type
168  {
169  points,
170  flat,
171  diffuse
172  };
173  shader_type selected_shader = shader_type::diffuse;
174 
175  float dim_level = 1.f;
176 
178 
179  bool select_3d_source = false;
180  bool select_tex_source = false;
181  bool select_shader_source = false;
182  bool show_help_screen = false;
184  bool glsl_available = false;
185  bool modal_notification_on = false; // a notification which was expanded
186 
187  press_button_model trajectory_button{ u8"\uf1b0", u8"\uf1b0","Draw trajectory", "Stop drawing trajectory", true };
188  press_button_model grid_object_button{ u8"\uf1cb", u8"\uf1cb", "Configure Grid", "Configure Grid", false };
189  press_button_model pose_info_object_button{ u8"\uf05a", u8"\uf05a", "Show pose stream info overlay", "Hide pose stream info overlay", false };
190 
191  viewer_model(context &ctx_);
192 
193  std::shared_ptr<updates_model> updates;
194 
195  std::unordered_set<int> _hidden_options;
197  private:
198 
199  void check_permissions();
200  void hide_common_options();
201  std::vector<popup> _active_popups;
202 
203  struct rgb {
205  };
206 
208  float depth_val;
210  };
211 
213  std::map<int, rect> get_interpolated_layout(const std::map<int, rect>& l);
214  void show_icon(ImFont* font_18, const char* label_str, const char* text, int x, int y,
215  int id, const ImVec4& color, const std::string& tooltip = "");
216  void draw_color_ruler(const mouse_info& mouse,
217  const stream_model& s_model,
218  const rect& stream_rect,
219  std::vector<rgb_per_distance> rgb_per_distance_vec,
220  float ruler_length,
221  const std::string& ruler_units);
222  float calculate_ruler_max_distance(const std::vector<float>& distances) const;
223 
224  void set_export_popup(ImFont* large_font, ImFont* font, rect stream_rect, std::string& error_message, config_file& temp_cfg);
225 
228  std::chrono::high_resolution_clock::time_point _transition_start_time;
229 
230  // 3D-Viewer state
231  float3 pos = { 0.0f, 0.0f, -0.5f };
232  float3 target = { 0.0f, 0.0f, 0.0f };
234  bool fixed_up = true;
235 
236  float view[16];
237  GLint texture_border_mode = GL_CLAMP_TO_EDGE;
238 
240  std::shared_ptr<texture_buffer> last_texture;
241 
242  // Infinite pan / rotate feature:
243  bool manipulating = false;
244  float2 overflow = { 0.f, 0.f };
245 
248 
249 
250  bool _pc_selected = false;
251 
252 
253  temporal_event origin_occluded { std::chrono::milliseconds(3000) };
254 
255  bool show_skybox = true;
257 
259 
260  };
261 }
rs2::gl::pointcloud_renderer _pc_renderer
Definition: viewer.h:247
streams_layout _old_layout
Definition: viewer.h:227
GLboolean GLboolean GLboolean b
GLboolean GLboolean g
GLint y
skybox _skybox
Definition: viewer.h:256
std::map< int, int > streams_origin
Definition: viewer.h:126
GLuint const GLchar * name
static export_model make_exporter(std::string name, std::string extension, T(&filters_str)[sz])
Definition: viewer.h:41
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
GLfloat GLfloat p
Definition: glext.h:12687
context & ctx
Definition: viewer.h:132
std::vector< char > filters
Definition: viewer.h:48
float get_output_height() const
Definition: viewer.h:66
std::map< int, stream_model > streams
Definition: viewer.h:125
std::unordered_set< int > _hidden_options
Definition: viewer.h:195
UINT8_TYPE u8
Definition: sqlite3.c:11450
#define GL_CLAMP_TO_EDGE
def progress(args)
Definition: log.py:43
Definition: cah-model.h:10
GLsizei const GLchar *const * string
d
Definition: rmse.py:171
std::atomic< bool > synchronization_enable
Definition: viewer.h:158
const std::string header
Definition: viewer.h:18
std::string name
Definition: viewer.h:46
The texture class.
Definition: example.hpp:402
rs2::gl::camera_renderer _cam_renderer
Definition: viewer.h:246
std::atomic< int > zo_sensors
Definition: viewer.h:160
std::chrono::high_resolution_clock::time_point _transition_start_time
Definition: viewer.h:228
bool _support_ir_reflectivity
Definition: viewer.h:196
GLdouble f
frameset_allocator frameset_alloc
Definition: viewer.h:144
static const char * metric_system
Definition: model-views.h:167
dictionary streams
Definition: t265_stereo.py:140
static const char * continue_with_current_fw
Definition: model-views.h:152
std::string extension
Definition: viewer.h:47
std::vector< int > last_tex_sources
Definition: viewer.h:164
export_model(std::string name, std::string extension, const char *filters_str, size_t filters_size)
Definition: viewer.h:52
GLdouble GLdouble r
int GLint
GLdouble x
unsigned int uint32_t
Definition: stdint.h:80
std::vector< rs2::frame > get_frames(std::vector< rs2::sensor > sensors)
devices
Definition: test-fg.py:9
GLint GLint GLsizei GLint GLenum format
GLenum target
Definition: glext.h:1565
std::shared_ptr< updates_model > updates
Definition: viewer.h:193
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
Definition: imgui.h:98
std::array< float3, 4 > roi_rect
Definition: viewer.h:153
std::map< export_type, export_model > exporters
Definition: viewer.h:143
measurement _measurements
Definition: viewer.h:258
std::map< int, rect > streams_layout
Definition: model-views.h:304
streams_layout _layout
Definition: viewer.h:226
post_processing_filters ppf
Definition: viewer.h:130
std::mutex streams_mutex
Definition: viewer.h:124
static const char * show_skybox
Definition: model-views.h:194
const std::string message
Definition: viewer.h:19
std::map< rs2_option, int > options
Definition: viewer.h:49
Definition: imgui.h:1392
std::function< void()> custom_command
Definition: viewer.h:20
static const char * ground_truth_r
Definition: model-views.h:148
std::atomic< bool > synchronization_enable_prev_state
Definition: viewer.h:159
std::vector< std::unique_ptr< device_model > > device_models_list
Definition: model-views.h:96
float rs2_vector::* pos
std::vector< popup > _active_popups
Definition: viewer.h:201
viewer_model * owner
Definition: viewer.h:35
std::array< float, 3 > color
Definition: model-views.h:449
static const char * is_3d_view
Definition: model-views.h:147
Definition: skybox.h:8
std::shared_ptr< syncer_model > syncer
Definition: viewer.h:129
rs2::points last_points
Definition: viewer.h:239
static const char * occlusion_invalidation
Definition: model-views.h:195
std::shared_ptr< texture_buffer > last_texture
Definition: viewer.h:240
GLdouble GLdouble GLint GLint const GLdouble * points
bool operator=(const popup &p)
Definition: viewer.h:22


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