Jetson Inference
DNN Vision Library
|
OpenGL display window and image/video renderer with CUDA interoperability. More...
#include <glDisplay.h>
Classes | |
struct | eventHandler |
Public Member Functions | |
~glDisplay () | |
Destroy window. More... | |
virtual bool | Open () |
Open the window. More... | |
bool | IsOpen () const |
Returns true if the window is open. More... | |
bool | IsClosed () const |
Returns true if the window has been closed. More... | |
bool | IsRendering () const |
Returns true if between BeginRender() and EndRender() More... | |
float | GetFPS () const |
Get the average frame time (in milliseconds). More... | |
uint32_t | GetID () const |
Get the ID of this display instance into glGetDisplay() More... | |
virtual uint32_t | GetType () const |
Return the interface type (glDisplay::Type) More... | |
Frame Begin + End | |
void | BeginRender (bool processEvents=true) |
Clear window and begin rendering a frame. More... | |
void | EndRender () |
Finish rendering and refresh / flip the backbuffer. More... | |
Image Rendering | |
void | Render (glTexture *texture, float x=5.0f, float y=30.0f) |
Render an OpenGL texture. More... | |
void | Render (float *image, uint32_t width, uint32_t height, float x=0.0f, float y=30.0f, bool normalize=true) |
Render a CUDA float4 image using OpenGL interop If normalize is true, the image's pixel values will be rescaled from the range of [0-255] to [0-1] If normalize is false, the image's pixel values are assumed to already be in the range of [0-1] Note that if normalization is selected to be performed, it will be done in-place on the image. More... | |
template<typename T > | |
bool | Render (T *image, uint32_t width, uint32_t height) |
Render a CUDA image (uchar3, uchar4, float3, float4) using OpenGL interop. More... | |
virtual bool | Render (void *image, uint32_t width, uint32_t height, imageFormat format) |
Render a CUDA image (uchar3, uchar4, float3, float4) using OpenGL interop. More... | |
void | RenderImage (void *image, uint32_t width, uint32_t height, imageFormat format, float x=0.0f, float y=30.0f, bool normalize=true) |
Render a CUDA image (uchar3, uchar4, float3, float4) using OpenGL interop. More... | |
void | RenderOnce (void *image, uint32_t width, uint32_t height, imageFormat format, float x=5.0f, float y=30.0f, bool normalize=true) |
Begin the frame, render one CUDA image using OpenGL interop, and end the frame. More... | |
void | RenderOnce (float *image, uint32_t width, uint32_t height, float x=5.0f, float y=30.0f, bool normalize=true) |
Begin the frame, render one CUDA float4 image using OpenGL interop, and end the frame. More... | |
Vector Rendering | |
void | RenderLine (float x1, float y1, float x2, float y2, float r, float g, float b, float a=1.0f, float thickness=2.0f) |
Render a line in screen coordinates with the specified color. More... | |
void | RenderOutline (float x, float y, float width, float height, float r, float g, float b, float a=1.0f, float thickness=2.0f) |
Render the outline of a rect in screen coordinates with the specified color. More... | |
void | RenderRect (float x, float y, float width, float height, float r, float g, float b, float a=1.0f) |
Render a filled rect in screen coordinates with the specified color. More... | |
void | RenderRect (float r, float g, float b, float a=1.0f) |
Render a filled rect covering the current viewport with the specified color. More... | |
Window Resizing | |
void | SetSize (uint32_t width, uint32_t height) |
Set the window's size. More... | |
void | SetMaximized (bool maximized) |
Maximize or un-maximize the window. More... | |
bool | IsMaximized () |
Determine if the window is maximized or not. More... | |
void | SetFullscreen (bool fullscreen) |
Set the window to fullscreen mode or not. More... | |
bool | IsFullscreen () |
Determine if the window is fullscreen or not. More... | |
Viewport Options | |
void | GetBackgroundColor (float *r, float *g, float *b, float *a=NULL) |
Retrieve the window's background color. More... | |
void | SetBackgroundColor (float r, float g, float b, float a=1.0f) |
Set the window's background color. More... | |
void | SetViewport (int left, int top, int right, int bottom) |
Set the active viewport being rendered to. More... | |
void | ResetViewport () |
Reset to the full viewport (and change back GL_PROJECTION) More... | |
Event Handling | |
void | ProcessEvents () |
Process UI event messages. More... | |
void | AddEventHandler (glEventHandler callback, void *user=NULL) |
Register an event message handler that will be called by ProcessEvents() More... | |
void | RemoveEventHandler (glEventHandler callback, void *user=NULL) |
Remove an event message handler from being called by ProcessEvents() RemoveEventHandler() will search for previously registered event handlers that have the same function pointer and/or user pointer, and remove them for being called again in the future. More... | |
Mouse + Keyboard State | |
const int * | GetMousePosition () const |
Get the mouse position. More... | |
void | GetMousePosition (int *x, int *y) const |
Get the mouse position. More... | |
bool | GetMouseButton (uint32_t button) const |
Get the mouse button state. More... | |
bool | GetKey (uint32_t key) const |
Get the state of a key (lowercase, without modifiers applied) More... | |
Mouse Cursor | |
void | SetCursor (uint32_t cursor) |
Set the active mouse cursor. More... | |
void | SetDefaultCursor (uint32_t cursor, bool activate=true) |
Set the default mouse cursor that gets used by ResetCursor() More... | |
void | ResetCursor () |
Reset the mouse cursor back to it's default. More... | |
void | ResetDefaultCursor (bool activate=true) |
Reset the default cursor back to it's original, the arrow. More... | |
Widgets | |
glWidget * | AddWidget (glWidget *widget) |
Add a widget to the window that recieves events and is rendered. More... | |
void | RemoveWidget (glWidget *widget, bool deleteWidget=true) |
Remove a widget from the window (and optionally delete it) More... | |
void | RemoveWidget (uint32_t index, bool deleteWidget=true) |
Remove a widget from the window (and optionally delete it) More... | |
void | RemoveAllWidgets (bool deleteWidgets=true) |
Remove all widgets from the window (and optionally delete them) More... | |
uint32_t | GetNumWidgets () const |
Retrieve the number of widgets. More... | |
glWidget * | GetWidget (const uint32_t index) const |
Retrieve a widget. More... | |
int | GetWidgetIndex (const glWidget *widget) const |
Retrieve the index of a widget (or -1 if not found) More... | |
glWidget * | FindWidget (int x, int y) |
Find first widget by coordinate, or NULL if no widget overlaps with that coordinate. More... | |
std::vector< glWidget * > | FindWidgets (int x, int y) |
Find all widgets by coordinate, or NULL if no widget overlaps with that coordinate. More... | |
Public Member Functions inherited from videoOutput | |
virtual | ~videoOutput () |
Destroy interface and release all resources. More... | |
template<typename T > | |
bool | Render (T *image, uint32_t width, uint32_t height) |
Render and output the next frame to the stream. More... | |
virtual void | Close () |
Stop streaming the device. More... | |
bool | IsStreaming () const |
Check if the device is actively streaming or not. More... | |
uint32_t | GetWidth () const |
Return the width of the stream, in pixels. More... | |
uint32_t | GetHeight () const |
Return the height of the stream, in pixels. More... | |
float | GetFrameRate () const |
Return the framerate, in Hz or FPS. More... | |
uint64_t | GetFrameCount () const |
Return the number of frames output. More... | |
const URI & | GetResource () const |
Return the resource URI of the stream. More... | |
const videoOptions & | GetOptions () const |
Return the videoOptions of the stream. More... | |
void | AddOutput (videoOutput *output) |
Add an output sub-stream. More... | |
uint32_t | GetNumOutputs () const |
Return the number of sub-streams. More... | |
videoOutput * | GetOutput (uint32_t index) const |
Return a sub-stream. More... | |
bool | IsType (uint32_t type) const |
Check if this stream is of a particular type. More... | |
template<typename T > | |
bool | IsType () const |
Check if a this stream is of a particular type. More... | |
const char * | TypeToStr () const |
Convert this stream's class type to string. More... | |
Static Public Member Functions | |
static glDisplay * | Create (const char *title=NULL, int width=-1, int height=-1, float r=0.05f, float g=0.05f, float b=0.05f, float a=1.0f) |
Create a new OpenGL display window with the specified options. More... | |
static glDisplay * | Create (const videoOptions &options) |
Create a new OpenGL display window with the specified options. More... | |
Static Public Member Functions inherited from videoOutput | |
static videoOutput * | Create (const videoOptions &options) |
Create videoOutput interface from a videoOptions struct that's already been filled out. More... | |
static videoOutput * | Create (const char *URI, const videoOptions &options=videoOptions()) |
Create videoOutput interface from a resource URI string and optional videoOptions. More... | |
static videoOutput * | Create (const char *URI, const commandLine &cmdLine) |
Create videoOutput interface from a resource URI string and parsing command line arguments. More... | |
static videoOutput * | Create (const char *URI, const int argc, char **argv) |
Create videoOutput interface from a resource URI string and parsing command line arguments. More... | |
static videoOutput * | Create (const int argc, char **argv, int positionArg=-1) |
Create videoOutput interface by parsing command line arguments, including the resource URI. More... | |
static videoOutput * | Create (const commandLine &cmdLine, int positionArg=-1) |
Create videoOutput interface by parsing command line arguments, including the resource URI. More... | |
static videoOutput * | CreateNullOutput () |
Create videoOutput interface that acts as a NULL output and does nothing with incoming frames. More... | |
static const char * | Usage () |
Usage string for command line arguments to Create() More... | |
static const char * | TypeToStr (uint32_t type) |
Convert a class type to a string. More... | |
Static Public Attributes | |
static const uint32_t | Type = (1 << 3) |
Unique type identifier of glDisplay class. More... | |
Protected Member Functions | |
glDisplay (const videoOptions &options) | |
bool | initWindow () |
bool | initGL () |
glTexture * | allocTexture (uint32_t width, uint32_t height, imageFormat format) |
void | activateViewport () |
void | dispatchEvent (uint16_t msg, int a, int b) |
Protected Member Functions inherited from videoOutput | |
videoOutput (const videoOptions &options) | |
Static Protected Member Functions | |
static bool | onEvent (uint16_t msg, int a, int b, void *user) |
Protected Attributes | |
Display * | mDisplayX |
Screen * | mScreenX |
XVisualInfo * | mVisualX |
Window | mWindowX |
GLXContext | mContextGL |
Cursor | mCursors [256] |
int | mActiveCursor |
int | mDefaultCursor |
bool | mInitialShow |
bool | mRendering |
bool | mResizedToFeed |
Atom | mWindowClosedMsg |
DragMode | mDragMode |
uint32_t | mID |
uint32_t | mScreenWidth |
uint32_t | mScreenHeight |
timespec | mLastTime |
float | mAvgTime |
float | mBgColor [4] |
int | mViewport [4] |
int | mMousePos [2] |
int | mMouseDrag [2] |
int | mMouseDragOrigin [2] |
bool | mMouseButtons [16] |
bool | mKeyStates [1024] |
float * | mNormalizedCUDA |
uint32_t | mNormalizedWidth |
uint32_t | mNormalizedHeight |
std::vector< glWidget * > | mWidgets |
std::vector< glTexture * > | mTextures |
std::vector< eventHandler > | mEventHandlers |
Protected Attributes inherited from videoOutput | |
bool | mStreaming |
videoOptions | mOptions |
std::vector< videoOutput * > | mOutputs |
Static Protected Attributes | |
static const int | screenIdx = 0 |
Status Bar Text | |
static const char * | DEFAULT_TITLE |
Default title bar name. More... | |
virtual void | SetStatus (const char *str) |
Set the window title string. More... | |
void | SetTitle (const char *str) |
Set the window title string. More... | |
Mouse Dragging | |
enum | DragMode { DragDefault, DragDisabled, DragSelect, DragCreate } |
Drag behavior enum. More... | |
DragMode | GetDragMode () const |
Get the dragging behavior mode. More... | |
void | SetDragMode (DragMode mode) |
Set the dragging behavior mode. More... | |
bool | IsDragging (DragMode mode=DragDefault) const |
Is the mouse currently dragging in the specified mode? More... | |
bool | GetDragRect (int *x, int *y, int *width, int *height) |
Get the current dragging rectangle, or return false if not dragging. More... | |
bool | GetDragCoords (int *x1, int *y1, int *x2, int *y2) |
Get the current dragging coordinates, or return false if not dragging. More... | |
OpenGL display window and image/video renderer with CUDA interoperability.
enum glDisplay::DragMode |
Drag behavior enum.
glDisplay::~glDisplay | ( | ) |
Destroy window.
|
protected |
|
protected |
void glDisplay::AddEventHandler | ( | glEventHandler | callback, |
void * | user = NULL |
||
) |
Register an event message handler that will be called by ProcessEvents()
callback | function pointer to the event message handler callback |
user | optional user-specified pointer that will be passed to all invocations of this event handler (typically an object) |
Add a widget to the window that recieves events and is rendered.
|
protected |
void glDisplay::BeginRender | ( | bool | processEvents = true | ) |
Clear window and begin rendering a frame.
If processEvents is true, ProcessEvents() will automatically be called.
|
static |
Create a new OpenGL display window with the specified options.
title | window title bar string, or NULL for a default title |
width | desired width of the window, or -1 to be maximized |
height | desired height of the window, or -1 to be maximized |
r | default background RGBA color, red component (0.0-1.0f) |
g | default background RGBA color, green component (0.0-1.0f) |
b | default background RGBA color, blue component (0.0-1.0f) |
a | default background RGBA color, alpha component (0.0-1.0f) |
|
static |
Create a new OpenGL display window with the specified options.
|
protected |
void glDisplay::EndRender | ( | ) |
Finish rendering and refresh / flip the backbuffer.
glWidget* glDisplay::FindWidget | ( | int | x, |
int | y | ||
) |
Find first widget by coordinate, or NULL if no widget overlaps with that coordinate.
std::vector<glWidget*> glDisplay::FindWidgets | ( | int | x, |
int | y | ||
) |
Find all widgets by coordinate, or NULL if no widget overlaps with that coordinate.
void glDisplay::GetBackgroundColor | ( | float * | r, |
float * | g, | ||
float * | b, | ||
float * | a = NULL |
||
) |
Retrieve the window's background color.
bool glDisplay::GetDragCoords | ( | int * | x1, |
int * | y1, | ||
int * | x2, | ||
int * | y2 | ||
) |
Get the current dragging coordinates, or return false if not dragging.
|
inline |
Get the dragging behavior mode.
bool glDisplay::GetDragRect | ( | int * | x, |
int * | y, | ||
int * | width, | ||
int * | height | ||
) |
Get the current dragging rectangle, or return false if not dragging.
|
inline |
Get the average frame time (in milliseconds).
|
inline |
Get the ID of this display instance into glGetDisplay()
|
inline |
Get the state of a key (lowercase, without modifiers applied)
Similar to glEvent::KEY_STATE, GetKey() queries the raw key state without being translated by modifier keys such as Shift, CapsLock, NumLock, ect. Alphanumeric keys will be left as lowercase, so query lowercase keys - uppercase keys will always return false.
key | the XK_ key symbol (see /usr/include/X11/keysymdef.h ) Uppercase keys like XK_A or XK_plus will always return false. Instead, query the lowercase keys such as XK_a, XK_1, ect. Other keys like F1-F12, shift, tab, ctrl/alt, arrow keys, backspace, delete, escape, and enter can all be queried. GetKey() caches the first 1024 key symbols. Other keys will return false, but can be subscribed to through a glEventHander. |
|
inline |
Get the mouse button state.
button | the button number, starting with 1. In X11, the left mouse button is 1. Here are the mouse button numbers: |
2 MOUSE_MIDDLE (middle button / scroll wheel button)
|
inline |
Get the mouse position.
|
inline |
Get the mouse position.
|
inline |
Retrieve the number of widgets.
|
inlinevirtual |
Return the interface type (glDisplay::Type)
Reimplemented from videoOutput.
|
inline |
Retrieve a widget.
int glDisplay::GetWidgetIndex | ( | const glWidget * | widget | ) | const |
Retrieve the index of a widget (or -1 if not found)
|
protected |
|
protected |
|
inline |
Returns true if the window has been closed.
|
inline |
Is the mouse currently dragging in the specified mode?
bool glDisplay::IsFullscreen | ( | ) |
Determine if the window is fullscreen or not.
bool glDisplay::IsMaximized | ( | ) |
Determine if the window is maximized or not.
|
inline |
Returns true if the window is open.
|
inline |
Returns true if between BeginRender() and EndRender()
|
staticprotected |
|
virtual |
void glDisplay::ProcessEvents | ( | ) |
Process UI event messages.
Any queued events will be dispatched to the event message handlers that were registered with RegisterEventHandler()
ProcessEvents() usually gets called automatically by BeginFrame(), so it is not typically necessary to explicitly call it unless you passed false
to BeginFrame() and wish to process events at another time of your choosing.
void glDisplay::RemoveAllWidgets | ( | bool | deleteWidgets = true | ) |
Remove all widgets from the window (and optionally delete them)
void glDisplay::RemoveEventHandler | ( | glEventHandler | callback, |
void * | user = NULL |
||
) |
Remove an event message handler from being called by ProcessEvents() RemoveEventHandler() will search for previously registered event handlers that have the same function pointer and/or user pointer, and remove them for being called again in the future.
void glDisplay::RemoveWidget | ( | glWidget * | widget, |
bool | deleteWidget = true |
||
) |
Remove a widget from the window (and optionally delete it)
void glDisplay::RemoveWidget | ( | uint32_t | index, |
bool | deleteWidget = true |
||
) |
Remove a widget from the window (and optionally delete it)
void glDisplay::Render | ( | float * | image, |
uint32_t | width, | ||
uint32_t | height, | ||
float | x = 0.0f , |
||
float | y = 30.0f , |
||
bool | normalize = true |
||
) |
Render a CUDA float4 image using OpenGL interop If normalize is true, the image's pixel values will be rescaled from the range of [0-255] to [0-1] If normalize is false, the image's pixel values are assumed to already be in the range of [0-1] Note that if normalization is selected to be performed, it will be done in-place on the image.
void glDisplay::Render | ( | glTexture * | texture, |
float | x = 5.0f , |
||
float | y = 30.0f |
||
) |
|
inline |
Render a CUDA image (uchar3, uchar4, float3, float4) using OpenGL interop.
This is similar to RenderOnce(), in that it will begin/end the frame also.
|
virtual |
Render a CUDA image (uchar3, uchar4, float3, float4) using OpenGL interop.
This is similar to RenderOnce(), in that it will begin/end the frame also.
Reimplemented from videoOutput.
void glDisplay::RenderImage | ( | void * | image, |
uint32_t | width, | ||
uint32_t | height, | ||
imageFormat | format, | ||
float | x = 0.0f , |
||
float | y = 30.0f , |
||
bool | normalize = true |
||
) |
Render a CUDA image (uchar3, uchar4, float3, float4) using OpenGL interop.
If normalize is true, the image's pixel values will be rescaled from the range of [0-255] to [0-1] If normalize is false, the image's pixel values are assumed to already be in the range of [0-1] Note that if normalization is selected to be performed, it will be done in-place on the image
void glDisplay::RenderLine | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2, | ||
float | r, | ||
float | g, | ||
float | b, | ||
float | a = 1.0f , |
||
float | thickness = 2.0f |
||
) |
Render a line in screen coordinates with the specified color.
void glDisplay::RenderOnce | ( | float * | image, |
uint32_t | width, | ||
uint32_t | height, | ||
float | x = 5.0f , |
||
float | y = 30.0f , |
||
bool | normalize = true |
||
) |
Begin the frame, render one CUDA float4 image using OpenGL interop, and end the frame.
Note that this function is only useful if you are rendering a single texture per frame. If normalize is true, the image's pixel values will be rescaled from the range of [0-255] to [0-1] If normalize is false, the image's pixel values are assumed to already be in the range of [0-1] Note that if normalization is selected to be performed, it will be done in-place on the image
void glDisplay::RenderOnce | ( | void * | image, |
uint32_t | width, | ||
uint32_t | height, | ||
imageFormat | format, | ||
float | x = 5.0f , |
||
float | y = 30.0f , |
||
bool | normalize = true |
||
) |
Begin the frame, render one CUDA image using OpenGL interop, and end the frame.
Note that this function is only useful if you are rendering a single texture per frame. If normalize is true, the image's pixel values will be rescaled from the range of [0-255] to [0-1] If normalize is false, the image's pixel values are assumed to already be in the range of [0-1] Note that if normalization is selected to be performed, it will be done in-place on the image
void glDisplay::RenderOutline | ( | float | x, |
float | y, | ||
float | width, | ||
float | height, | ||
float | r, | ||
float | g, | ||
float | b, | ||
float | a = 1.0f , |
||
float | thickness = 2.0f |
||
) |
Render the outline of a rect in screen coordinates with the specified color.
void glDisplay::RenderRect | ( | float | r, |
float | g, | ||
float | b, | ||
float | a = 1.0f |
||
) |
Render a filled rect covering the current viewport with the specified color.
void glDisplay::RenderRect | ( | float | x, |
float | y, | ||
float | width, | ||
float | height, | ||
float | r, | ||
float | g, | ||
float | b, | ||
float | a = 1.0f |
||
) |
Render a filled rect in screen coordinates with the specified color.
void glDisplay::ResetCursor | ( | ) |
Reset the mouse cursor back to it's default.
The default mouse cursor is defined by SetDefaultCursor().
void glDisplay::ResetDefaultCursor | ( | bool | activate = true | ) |
Reset the default cursor back to it's original, the arrow.
activate | if true (default), the active cursor will be changed to this new default cursor immediately. If false , the active cursor will stay the same until ResetCursor() gets called in the future. |
void glDisplay::ResetViewport | ( | ) |
Reset to the full viewport (and change back GL_PROJECTION)
void glDisplay::SetBackgroundColor | ( | float | r, |
float | g, | ||
float | b, | ||
float | a = 1.0f |
||
) |
Set the window's background color.
r | background RGBA color, red component (0.0-1.0f) |
g | background RGBA color, green component (0.0-1.0f) |
b | background RGBA color, blue component (0.0-1.0f) |
a | background RGBA color, alpha component (0.0-1.0f) |
void glDisplay::SetCursor | ( | uint32_t | cursor | ) |
Set the active mouse cursor.
cursor | one of the cursor ID's from X11/cursorfont.h |
void glDisplay::SetDefaultCursor | ( | uint32_t | cursor, |
bool | activate = true |
||
) |
Set the default mouse cursor that gets used by ResetCursor()
cursor | one of the cursor ID's from X11/cursorfont.h . This will be the default cursor that gets set when ResetCursor() is called. |
activate | if true (default), the active cursor will be changed to this new default cursor immediately. If false , the active cursor will stay the same until ResetCursor() gets called in the future. |
|
inline |
Set the dragging behavior mode.
void glDisplay::SetFullscreen | ( | bool | fullscreen | ) |
Set the window to fullscreen mode or not.
void glDisplay::SetMaximized | ( | bool | maximized | ) |
Maximize or un-maximize the window.
void glDisplay::SetSize | ( | uint32_t | width, |
uint32_t | height | ||
) |
Set the window's size.
width | the desired width of the window, in pixels. |
height | the desired height of the window, in pixels. |
|
virtual |
Set the window title string.
Reimplemented from videoOutput.
void glDisplay::SetTitle | ( | const char * | str | ) |
Set the window title string.
void glDisplay::SetViewport | ( | int | left, |
int | top, | ||
int | right, | ||
int | bottom | ||
) |
Set the active viewport being rendered to.
SetViewport() will update the GL_PROJECTION matrix with a new ortho matrix to reflect these changes.
After done rendering to this viewport, you should reset it back to it's original with ResetViewport()
|
static |
Default title bar name.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
static |
Unique type identifier of glDisplay class.