SDK UI Utils
-
class
Metavision
::
BaseWindow
: public Metavision::BaseGLFWWindow Base class for displaying images and handling events in a window, deriving from BaseGLFWUI.
This class cannot directly be used as is, instead, one needs to instantiate one of its derived class (i.e. Window or MTWindow).
Note
Each window has its own events queue that needs to be regularly processed, either explicitly by calling BaseWindow::poll_events or implicitly by calling Window::show or MTWindow::show_async with
auto_poll
= true (default behavior). Events are polled from the system and push to the windows’ internal queue by calling EventLoop::poll_and_dispatch.Warning
The constructor and destructor of this class must only be called from the main thread
Subclassed by Metavision::MTWindow, Metavision::Window
Public Functions
-
virtual
~BaseWindow
() Destructor.
Warning
Must only be called from the main thread
-
void
get_size
(int &width, int &height) const Gets the window’s current size.
- Parameters
width – The window’s width
height – The window’s height
-
RenderMode
get_rendering_mode
() const Gets the window’s color rendering mode.
- Returns
The window’s color rendering mode (Either RenderMode::GRAY or RenderMode::BGR)
-
void
set_keyboard_callback
(const KeyCallback &cb) Sets a callback that will be called when a key is pressed.
Note
See GLFW’s documentation (GLFWkeyfun) for more information
Warning
Due to a GLFW’s limitation, this callback returns key codes corresponding to the standard US keyboard layout. However, keys corresponding to unicode characters are mapped internally to match the current keyboard layout.
- Parameters
cb – The callback to call on a key event
-
void
set_mouse_callback
(const MouseCallback &cb) Sets a callback that will be called when a mouse’s button is pressed.
Note
See GLFW’s documentation (GLFWmousebuttonfun) for more information
- Parameters
cb – The callback to call on a mouse event
-
void
set_cursor_pos_callback
(const CursorPosCallback &cb) Sets a callback that will be called when the mouse’s cursor moves on the current window.
Note
See GLFW’s documentation (GLFWcursorposfun) for more information
- Parameters
cb – The callback to call on a mouse cursor event
-
void
poll_events
() Dequeues events in this window’s queue and calls corresponding callbacks.
Note
Calling this method is not mandatory when Window::show and MTWindow::show_async are called with
auto_poll
= true (i.e. default behavior). However, when the image to display is somehow generated from input events (e.g. drawing ROIs from mouse inputs), then it might be useful to call this method before both generating the image and calling Window::show or MTWindow::show_async (withauto_poll
= false) to reduce the latency between the moment when the events are generated and the moment when the image is actually displayed.Warning
The callbacks are called in the same thread as this method’s calling one. This means that if this method is called from a different thread than the one calling Window::show or MTWindow::show_async, a special care must be taken, in the callbacks, to avoid concurrency problems.
-
virtual
-
class
Metavision
::
EventLoop
A static class used to dispatch system events to the windows they belong to.
Public Static Functions
-
static void
poll_and_dispatch
(std::int64_t sleep_time_ms = 0) Polls events from the system and pushes them into the corresponding windows’ internal queue.
Warning
Must only be called from the main thread
- Parameters
sleep_time_ms – Amount of time in ms this call will wait after polling and dispatching the events
-
static void
-
class
Metavision
::
MTWindow
: public Metavision::BaseWindow Window using its own rendering thread to render images.
Images are displayed at a fixed frequency (i.e. the screen’s refresh one) by the internal rendering thread.
Warning
The constructor and destructor of this class must only be called from the main thread
Public Functions
-
MTWindow
(const std::string &title, int width, int height, RenderMode mode) Constructor.
Warning
Must only be called from the main thread
- Parameters
title – The window’s title
width – Width of the window at starting time (can be resized later on) and width of the images that will be displayed
height – Height of the window at starting time (can be resized later on) and height of the images that will be displayed
mode – The color rendering mode (i.e. either GRAY or BGR). Cannot be modified.
-
virtual
~MTWindow
() Destructor.
Warning
Must only be called from the main thread
-
void
show_async
(cv::Mat &image, bool auto_poll = true) Asynchronously displays an image.
Here asynchronously means that the image is not immediately displayed, but will be done later on by the internal rendering thread. This window uses a front/back buffers mechanism to avoid copying images.
Warning
If
auto_poll
is True, the events are processed in this method’s calling thread, not in the internal rendering one.- Parameters
image – The image to display. The image is passed as a non constant reference in order to be swapped with the front buffer and thus avoid useless copies.
auto_poll – If True, events in this window’s queue are dequeued and processed. If false, BaseWindow::poll_events must explicitly be called.
-
-
class
Metavision
::
Window
: public Metavision::BaseWindow A window that can be used to display images from any thread.
This window has no internal rendering thread, meaning that the images are displayed at the same frequency as the one of the Window::show method.
Warning
The constructor and destructor of this class must only be called from the main thread
Public Functions
-
Window
(const std::string &title, int width, int height, RenderMode mode) Constructs a new Window.
Warning
Must only be called from the main thread
- Parameters
title – The window’s title
width – Width of the window at starting time (can be resized later on) and width of the images that will be displayed
height – Height of the window at starting time (can be resized later on) and height of the images that will be displayed
mode – The color rendering mode (i.e. either GRAY or BGR). Cannot be modified.
-
virtual
~Window
() Destructor.
Warning
Must only be called from the main thread
-
void
show
(const cv::Mat &image, bool auto_poll = true) Displays an image.
- Parameters
image – The image to display
auto_poll – If True, events in this window’s queue are dequeued and processed. If false, BaseWindow::poll_events must explicitly be called.
-
-
enum
Metavision
::
UIMouseButton
Ids of the mouse buttons that can be triggered through the User Interface.
Values:
-
enumerator
MOUSE_BUTTON_1
-
enumerator
MOUSE_BUTTON_2
-
enumerator
MOUSE_BUTTON_3
-
enumerator
MOUSE_BUTTON_4
-
enumerator
MOUSE_BUTTON_5
-
enumerator
MOUSE_BUTTON_6
-
enumerator
MOUSE_BUTTON_7
-
enumerator
MOUSE_BUTTON_8
-
enumerator
MOUSE_BUTTON_LAST
-
enumerator
MOUSE_BUTTON_LEFT
-
enumerator
MOUSE_BUTTON_RIGHT
-
enumerator
MOUSE_BUTTON_MIDDLE
-
enumerator
-
enum
Metavision
::
UIKeyEvent
Ids of the keyboard events that can be triggered through the User Interface.
Values:
-
enumerator
KEY_UNKNOWN
-
enumerator
KEY_SPACE
-
enumerator
KEY_APOSTROPHE
-
enumerator
KEY_COMMA
-
enumerator
KEY_MINUS
-
enumerator
KEY_PERIOD
-
enumerator
KEY_SLASH
-
enumerator
KEY_0
-
enumerator
KEY_1
-
enumerator
KEY_2
-
enumerator
KEY_3
-
enumerator
KEY_4
-
enumerator
KEY_5
-
enumerator
KEY_6
-
enumerator
KEY_7
-
enumerator
KEY_8
-
enumerator
KEY_9
-
enumerator
KEY_SEMICOLON
-
enumerator
KEY_EQUAL
-
enumerator
KEY_A
-
enumerator
KEY_B
-
enumerator
KEY_C
-
enumerator
KEY_D
-
enumerator
KEY_E
-
enumerator
KEY_F
-
enumerator
KEY_G
-
enumerator
KEY_H
-
enumerator
KEY_I
-
enumerator
KEY_J
-
enumerator
KEY_K
-
enumerator
KEY_L
-
enumerator
KEY_M
-
enumerator
KEY_N
-
enumerator
KEY_O
-
enumerator
KEY_P
-
enumerator
KEY_Q
-
enumerator
KEY_R
-
enumerator
KEY_S
-
enumerator
KEY_T
-
enumerator
KEY_U
-
enumerator
KEY_V
-
enumerator
KEY_W
-
enumerator
KEY_X
-
enumerator
KEY_Y
-
enumerator
KEY_Z
-
enumerator
KEY_LEFT_BRACKET
-
enumerator
KEY_BACKSLASH
-
enumerator
KEY_RIGHT_BRACKET
-
enumerator
KEY_GRAVE_ACCENT
-
enumerator
KEY_WORLD_1
-
enumerator
KEY_WORLD_2
-
enumerator
KEY_ESCAPE
-
enumerator
KEY_ENTER
-
enumerator
KEY_TAB
-
enumerator
KEY_BACKSPACE
-
enumerator
KEY_INSERT
-
enumerator
KEY_DELETE
-
enumerator
KEY_RIGHT
-
enumerator
KEY_LEFT
-
enumerator
KEY_DOWN
-
enumerator
KEY_UP
-
enumerator
KEY_PAGE_UP
-
enumerator
KEY_PAGE_DOWN
-
enumerator
KEY_HOME
-
enumerator
KEY_END
-
enumerator
KEY_CAPS_LOCK
-
enumerator
KEY_SCROLL_LOCK
-
enumerator
KEY_NUM_LOCK
-
enumerator
KEY_PRINT_SCREEN
-
enumerator
KEY_PAUSE
-
enumerator
KEY_F1
-
enumerator
KEY_F2
-
enumerator
KEY_F3
-
enumerator
KEY_F4
-
enumerator
KEY_F5
-
enumerator
KEY_F6
-
enumerator
KEY_F7
-
enumerator
KEY_F8
-
enumerator
KEY_F9
-
enumerator
KEY_F10
-
enumerator
KEY_F11
-
enumerator
KEY_F12
-
enumerator
KEY_F13
-
enumerator
KEY_F14
-
enumerator
KEY_F15
-
enumerator
KEY_F16
-
enumerator
KEY_F17
-
enumerator
KEY_F18
-
enumerator
KEY_F19
-
enumerator
KEY_F20
-
enumerator
KEY_F21
-
enumerator
KEY_F22
-
enumerator
KEY_F23
-
enumerator
KEY_F24
-
enumerator
KEY_F25
-
enumerator
KEY_KP_0
-
enumerator
KEY_KP_1
-
enumerator
KEY_KP_2
-
enumerator
KEY_KP_3
-
enumerator
KEY_KP_4
-
enumerator
KEY_KP_5
-
enumerator
KEY_KP_6
-
enumerator
KEY_KP_7
-
enumerator
KEY_KP_8
-
enumerator
KEY_KP_9
-
enumerator
KEY_KP_DECIMAL
-
enumerator
KEY_KP_DIVIDE
-
enumerator
KEY_KP_MULTIPLY
-
enumerator
KEY_KP_SUBTRACT
-
enumerator
KEY_KP_ADD
-
enumerator
KEY_KP_ENTER
-
enumerator
KEY_KP_EQUAL
-
enumerator
KEY_LEFT_SHIFT
-
enumerator
KEY_LEFT_CONTROL
-
enumerator
KEY_LEFT_ALT
-
enumerator
KEY_LEFT_SUPER
-
enumerator
KEY_RIGHT_SHIFT
-
enumerator
KEY_RIGHT_CONTROL
-
enumerator
KEY_RIGHT_ALT
-
enumerator
KEY_RIGHT_SUPER
-
enumerator
KEY_MENU
-
enumerator
KEY_LAST
-
enumerator