Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
examples
sensor-control
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;
29
uint32_t
input
;
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
40
class
frame_viewer
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
}
48
~frame_viewer
()
49
{
50
if
(
_thread
&&
_thread
->joinable())
51
_thread
->join();
52
}
53
void
operator()
(
rs2::frame
f
)
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());
67
std::string
error
;
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
:
100
texture
renderer
;
101
rs2::colorizer
colorize
;
102
rs2::decimation_filter
decimate
;
103
std::string
_window_title
;
104
rs2::frame_queue
_frames
;
105
rs2::frame
_last_frame
;
106
std::unique_ptr<std::thread>
_thread
;
107
};
108
}
helper::prompt_yes_no
bool prompt_yes_no(const std::string &prompt_msg)
Definition:
helper.h:14
helper::frame_viewer::wait
void wait()
Definition:
helper.h:57
helper::frame_viewer::operator()
void operator()(rs2::frame f)
Definition:
helper.h:53
rs2::frame
Definition:
rs_frame.hpp:343
texture::render
void render(const rs2::frame &frame, const rect &rect, float alpha=1.f)
Definition:
example.hpp:471
helper
Definition:
helper.h:12
helper::frame_viewer::colorize
rs2::colorizer colorize
Definition:
helper.h:101
helper::frame_viewer
Definition:
helper.h:40
rs2::frame_queue::poll_for_frame
std::enable_if< std::is_base_of< rs2::frame, T >::value, bool >::type poll_for_frame(T *output) const
Definition:
rs_processing.hpp:183
rs2::frame_queue::enqueue
void enqueue(frame f) const
Definition:
rs_processing.hpp:158
helper::frame_viewer::renderer
texture renderer
Definition:
helper.h:100
rspy.test.fail
def fail()
Definition:
test.py:340
std
Definition:
android_helpers.h:13
helper::print_separator
void print_separator()
Definition:
helper.h:35
rs.hpp
string
GLsizei const GLchar *const * string
Definition:
glad/glad/glad.h:2862
rmse.e
e
Definition:
rmse.py:177
texture
The texture class.
Definition:
example.hpp:402
f
GLdouble f
Definition:
glad/glad/glad.h:1518
rs2::filter::process
rs2::frame process(rs2::frame frame) const override
Definition:
rs_processing.hpp:352
helper::frame_viewer::_last_frame
rs2::frame _last_frame
Definition:
helper.h:105
helper::frame_viewer::~frame_viewer
~frame_viewer()
Definition:
helper.h:48
helper::frame_viewer::_window_title
std::string _window_title
Definition:
helper.h:103
Catch::cout
std::ostream & cout()
uint32_t
unsigned int uint32_t
Definition:
stdint.h:80
helper::frame_viewer::decimate
rs2::decimation_filter decimate
Definition:
helper.h:102
helper::frame_viewer::frame_viewer
frame_viewer(const std::string &window_title)
Definition:
helper.h:43
helper::get_user_selection
uint32_t get_user_selection(const std::string &prompt_message)
Definition:
helper.h:26
helper::frame_viewer::_thread
std::unique_ptr< std::thread > _thread
Definition:
helper.h:106
rs2::colorizer
Definition:
rs_processing.hpp:708
unit-test-config.error
def error(args)
Definition:
unit-test-config.py:39
input
GLenum GLenum GLenum input
Definition:
glext.h:10805
helper::frame_viewer::_frames
rs2::frame_queue _frames
Definition:
helper.h:104
window
Definition:
example.hpp:498
draw_text
void draw_text(int x, int y, const char *text)
Definition:
example.hpp:109
rs2::frame_queue
Definition:
rs_processing.hpp:134
helper::frame_viewer::run
void run()
Definition:
helper.h:64
rs2::decimation_filter
Definition:
rs_processing.hpp:764
librealsense2
Author(s): Sergey Dorodnicov
, Doron Hirshberg
, Mark Horn
, Reagan Lopez
, Itay Carpis
autogenerated on Mon May 3 2021 02:47:16