JeVois  1.18
JeVois Smart Embedded Machine Vision Toolkit
Share this page:

#include <jevois/GPU/GUIhelper.H>

Helper class to assist modules in creating graphical and GUI elements.

This class only works on JeVois-Pro.

Definition at line 122 of file GUIhelper.H.

Inheritance diagram for jevois::GUIhelper:
Collaboration diagram for jevois::GUIhelper:

Classes

struct  ErrorData
 

Public Member Functions

 GUIhelper (std::string const &instance, bool conslock=false)
 Constructor. More...
 
virtual ~GUIhelper ()
 Destructor. More...
 
bool startFrame (unsigned short &w, unsigned short &h)
 Start a new rendering frame. More...
 
bool frameStarted () const
 Helper to indicate that startFrame() was called, and thus endFrame() should be called. More...
 
void drawImage (char const *name, RawImage const &img, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool isoverlay=false)
 Draw a RawImage, copying pixel data to an OpenGL texture. More...
 
void drawImage (char const *name, cv::Mat const &img, bool rgb, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool isoverlay=false)
 Draw an OpenCV image, copying pixel data to an OpenGL texture. More...
 
void drawInputFrame (char const *name, InputFrame const &frame, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool casync=false)
 Draw the input video frame from the camera using zero-copy. More...
 
void drawInputFrame2 (char const *name, InputFrame const &frame, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool casync=false)
 Draw the second (scaled) input video frame from the camera using zero-copy. More...
 
ImVec2 i2d (ImVec2 p, char const *name=nullptr)
 Convert coordinates of a point from within a rendered image to on-screen. More...
 
ImVec2 i2d (float x, float y, char const *name=nullptr)
 Convert coordinates of a point from within a rendered image to on-screen. More...
 
ImVec2 i2ds (ImVec2 p, char const *name=nullptr)
 Convert a 2D size from within a rendered image to on-screen. More...
 
ImVec2 i2ds (float x, float y, char const *name=nullptr)
 Convert a 2D size from within a rendered image to on-screen. More...
 
void drawLine (float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
 Draw line over an image. More...
 
void drawRect (float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
 Draw rectangular box over an image. More...
 
void drawPoly (std::vector< cv::Point > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
 Draw polygon over an image. More...
 
void drawPoly (std::vector< cv::Point2f > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
 Draw polygon over an image. More...
 
void drawCircle (float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
 Draw circle over an image. More...
 
void drawText (float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
 Draw text over an image. More...
 
void drawText (float x, float y, std::string const &txt, ImU32 col=IM_COL32(128, 255, 128, 255))
 Draw text over an image. More...
 
ImVec2 iline (int line=-1, char const *name=nullptr)
 Get coordinates of the start of a given line of text to be drawn as overlay on top of an image. More...
 
void itext (char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
 Draw some overlay text on top of an image. More...
 
void itext (std::string const &txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
 Draw some overlay text on top of an image. More...
 
void iinfo (jevois::InputFrame const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
 Display processing and video info at bottom of screen. More...
 
void releaseImage (char const *name)
 Release an image. More...
 
void releaseImage2 (char const *name)
 Release an image, second video stream. More...
 
void endFrame ()
 Finish current frame and render it. More...
 
void reset (bool modulechanged=true)
 Reset to default state, typically called on Module or video format change. More...
 
void reportError (std::string const &err)
 Report an error in an overlay window. More...
 
void reportAndIgnoreException (std::string const &prefix="")
 Report current exception in a modal dialog, then ignore it. More...
 
void reportAndRethrowException (std::string const &prefix="")
 Report current exception in a modal dialog, then re-throw it. More...
 
void clearErrors ()
 Clear all errors currently displayed in the JeVois-Pro GUI. More...
 
void helpMarker (char const *msg, char const *msg2=nullptr, char const *msg3=nullptr)
 Display a (?) label and show tooltip when it is hovered. More...
 
bool toggleButton (char const *name, bool *val)
 Helper to draw a toggle button. More...
 
int modal (std::string const &title, char const *text, int *default_val=nullptr, char const *b1txt="Ok", char const *b2txt="Cancel")
 Helper to draw a modal with 2 choices. More...
 
void headlessDisplay ()
 Show a message that we are running headless. More...
 
bool serlogEnabled () const
 Tell whether user enabled serlog messages to GUI console. More...
 
bool seroutEnabled () const
 Tell whether user enabled serout messages to GUI console. More...
 
ImVec2 d2i (ImVec2 p, char const *name=nullptr)
 Convert coordinates of a point from on-screen to within a rendered image. More...
 
ImVec2 d2i (float x, float y, char const *name=nullptr)
 Convert coordinates of a point from on-screen to within a rendered image. More...
 
ImVec2 d2is (ImVec2 p, char const *name=nullptr)
 Convert a 2D size from on-screen to within a rendered image. More...
 
ImVec2 d2is (float x, float y, char const *name=nullptr)
 Convert a 2D size from on-screen to within a rendered image. More...
 
- Public Member Functions inherited from jevois::Component
 Component (std::string const &instance)
 Constructor. More...
 
virtual ~Component ()
 Virtual destructor for safe inheritance. More...
 
template<class Comp , typename... Args>
std::shared_ptr< Comp > addSubComponent (std::string const &instance, Args &&...args)
 Pseudo-constructor: construct and add another component as a subcomponent of this one. More...
 
template<class Comp >
void removeSubComponent (std::shared_ptr< Comp > &component)
 Remove a sub-Component from this Component, by shared_ptr. More...
 
void removeSubComponent (std::string const &instance, bool warnIfNotFound=true)
 Remove a sub-Component from this Component, by instance name. More...
 
template<class Comp = jevois::Component>
std::shared_ptr< Comp > getSubComponent (std::string const &instance) const
 Get a sub-component by instance name. More...
 
bool isTopLevel () const
 Returns true if this component is top-level, i.e., its parent is jevois::Manager. More...
 
Engineengine () const
 Get a handle to our Engine, or throw if we do not have an Engine as root ancestor. More...
 
bool initialized () const
 Has this component been initialized yet? More...
 
const std::string & className () const
 The class name of this component. More...
 
const std::string & instanceName () const
 The instance name of this component. More...
 
template<typename T >
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 Set a parameter value. More...
 
template<typename T >
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 Set a parameter value, simple version assuming only one parameter match. More...
 
template<typename T >
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 Get parameter(s) value(s) by descriptor. More...
 
template<typename T >
getParamValUnique (std::string const &paramdescriptor) const
 Get a parameter value, simple version assuming only one parameter match. More...
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 Set a parameter value, by string. More...
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 Set a parameter value by string, simple version assuming only one parameter match. More...
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 Get a parameter value, by string. More...
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 Get a parameter value by string, simple version assuming only one parameter match. More...
 
void freezeParam (std::string const &paramdescriptor)
 Freeze a parameter, by name, see ParameterBase::freeze() More...
 
void unFreezeParam (std::string const &paramdescriptor)
 Unfreeze a parameter, by name, see ParameterBase::unFreeze() More...
 
void freezeAllParams ()
 Freeze all parameters. More...
 
void unFreezeAllParams ()
 Unfreeze all parameters. More...
 
std::string descriptor () const
 Get our full descriptor (including all parents) as [Instancename]:[...]:[...]. More...
 
void setParamsFromFile (std::string const &filename)
 Set some parameters from a file. More...
 
std::istream & setParamsFromStream (std::istream &is, std::string const &absfile)
 Set some parameters from an open stream. More...
 
virtual void paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="")
 Get machine-oriented descriptions of all parameters. More...
 
void foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="")
 Run a function on every param we hold. More...
 
template<typename T >
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category)
 Add a new parameter after the Component has already been constructed. More...
 
template<typename T , template< typename > class ValidValuesSpec>
std::shared_ptr< DynamicParameter< T > > addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category)
 Add a new parameter after the Component has already been constructed. More...
 
template<typename T >
void setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true)
 Register a callback with a previously created dynamic parameter. More...
 
void removeDynamicParameter (std::string const &name)
 Remove a previously added dynamic parameter. More...
 
void setPath (std::string const &path)
 Assign a filesystem path to this component. More...
 
std::filesystem::path absolutePath (std::filesystem::path const &path="")
 If given path is relative (not starting with /), prepend the Component path to it. More...
 
- Public Member Functions inherited from jevois::ParameterRegistry
virtual ~ParameterRegistry ()
 Virtual destructor for safe inheritance. More...
 

Public Attributes

const float pixel_perfect_z
 Z distance from camera to image plane to achieve pixel-perfect rendering. More...
 
glm::mat4 proj
 Our projection matrix. More...
 
glm::mat4 view
 Our view matrix. More...
 

Protected Member Functions

void drawPolyInternal (ImVec2 const *pts, size_t npts, ImU32 col, bool filled)
 
ImU32 applyFillAlpha (ImU32 col) const
 
void drawJeVoisGUI ()
 
void drawInfo ()
 
void drawParameters ()
 
void drawConsole ()
 
void drawCamCtrls ()
 
void drawTweaks ()
 
void drawSystem ()
 
void drawMenuBar ()
 
void drawModuleSelect ()
 
void drawErrorPopup ()
 
void drawNewModuleForm ()
 
void newModEntry (char const *wname, std::string &str, char const *desc, char const *hint, char const *hlp)
 
void setparstr (std::string const &descriptor, std::string const &val)
 
template<class T >
void setparval (std::string const &descriptor, T const &val)
 
void onParamChange (gui::scale const &param, float const &newval) override
 
void onParamChange (gui::rounding const &param, int const &newval) override
 
void onParamChange (gui::style const &param, gui::GuiStyle const &newval) override
 
- Protected Member Functions inherited from jevois::Component
virtual void preInit ()
 Called before all sub-Components are init()ed. More...
 
virtual void postInit ()
 Called after all sub-Components are init()ed. More...
 
virtual void preUninit ()
 Called before all sub-Components are uninit()ed. More...
 
virtual void postUninit ()
 Called after all sub-Components are uninit()ed. More...
 
- Protected Member Functions inherited from jevois::ParameterRegistry
void addParameter (ParameterBase *const param)
 The Parameter class uses this method to register itself on construction with its owning Component. More...
 
void removeParameter (ParameterBase *const param)
 The Parameter class uses this method to un-register itself on destruction with its owning Component. More...
 
void callbackInitCall ()
 For all parameters that have a callback which has never been called, call it with the default param value. More...
 

Protected Attributes

std::map< std::string, GPUimageitsImages
 
std::map< std::string, GPUimageitsImages2
 
GPUimageitsLastDrawnImage = nullptr
 
int itsLastDrawnTextLine = -1
 
bool itsUsingScaledImage = false
 
float itsScaledImageFacX = 1.0F
 
float itsScaledImageFacY = 1.0F
 
std::chrono::time_point< std::chrono::steady_clock > itsLastEventTime
 
bool itsIdle
 Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI. More...
 
bool itsEndFrameCalled = true
 
std::mutex itsErrorMtx
 
std::list< ErrorDataitsErrors
 
std::set< std::string > itsOpenModals
 
bool itsConsLock
 
ImGuiBackendMALI itsBackend
 
std::string itsWindowTitle
 
ImGuiImage itsIcon
 
ImGuiImage itsHeadless
 
std::string itsModName
 
std::string itsModDesc
 
std::string itsModAuth
 
std::string itsModLang
 
std::vector< std::string > itsModDoc
 
gui::GuiStyle itsCurrentStyle = gui::GuiStyle::Dark
 
bool itsShowStyleEditor = false
 
bool itsShowAppMetrics = false
 
bool itsShowImGuiDemo = false
 
bool itsSerLogEnabled = true
 
bool itsSerOutEnabled = false
 
std::shared_ptr< GUIeditoritsCfgEditor
 
std::shared_ptr< GUIeditoritsCodeEditor
 
std::future< std::string > itsDnnGetFut
 
bool itsRefreshVideoMappings = false
 
int itsVideoMappingListType = 0
 

Related Functions

(Note that these are not member functions.)

 JEVOIS_DECLARE_PARAMETER (fullscreen, bool, "Use a fullscreen display when true, only has effect on host. " "Platform always is fullscreen as the MALI OpenGL driver do not support windowing.", false, ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (winsize, cv::Size, "Initial window size to use on host. On platform, size is determined " "by hardware and the value of this parameter will be overwritten on init. The " "parameter can still be used to query display size.", cv::Size(0, 0), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (hidesecs, float, "Number of seconds of inactivity from keyboard/mouse/joystick/etc after " "which we hide the GUI, or 0.0 to never hide it. Note: The GUI starts hidden until the " "first input event from a keyboard, mouse, etc.", 30.0F, ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (scale, float, "Scale factor applied to the GUI", 2.0f, { 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f }, ParamCateg)
 Parameter. More...
 
 JEVOIS_DEFINE_ENUM_CLASS (GuiStyle,(Light)(Dark)(Classic))
 Enum for Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (style, GuiStyle, "Color style for the JeVois GUI", GuiStyle::Light, GuiStyle_Values, ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (rounding, int, "Window and widget corner rounding for the JeVois GUI. " "Note than changing GUI scale will update this parameter as well.", 4, jevois::Range< int >(0, 24), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (overlaycolor, ImColor, "Default color to use for overlay text", ImColor(255, 255, 255, 255), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (linethick, float, "Line thickness for overlay drawings", 5.0F, jevois::Range< float >(0.1F, 20.0F), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (fillalpha, float, "Alpha multiplier for overlay fills", 0.25F, jevois::Range< float >(0.0F, 1.0F), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (allowquit, bool, "Quit application on ESC key (platform) or window close (host)", false, ParamCateg)
 Parameter. More...
 

Constructor & Destructor Documentation

◆ GUIhelper()

jevois::GUIhelper::GUIhelper ( std::string const &  instance,
bool  conslock = false 
)

◆ ~GUIhelper()

jevois::GUIhelper::~GUIhelper ( )
virtual

Destructor.

Definition at line 108 of file GUIhelper.C.

References JEVOIS_WAIT_GET_FUTURE.

Member Function Documentation

◆ applyFillAlpha()

ImU32 jevois::GUIhelper::applyFillAlpha ( ImU32  col) const
protected

Definition at line 522 of file GUIhelper.C.

References jevois::imu::get().

◆ clearErrors()

void jevois::GUIhelper::clearErrors ( )

Clear all errors currently displayed in the JeVois-Pro GUI.

In the JevoisPro GUI, errors reported via reportError() remain displayed for a few seconds, but sometimes we want to clear them right away, e.g., after DNN pipeline threw, if the user selects another one, we want the previous error to disappear immediately since it is not applicable anymore.

Definition at line 2073 of file GUIhelper.C.

◆ d2i() [1/2]

ImVec2 jevois::GUIhelper::d2i ( float  x,
float  y,
char const *  name = nullptr 
)

Convert coordinates of a point from on-screen to within a rendered image.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 621 of file GUIhelper.C.

◆ d2i() [2/2]

ImVec2 jevois::GUIhelper::d2i ( ImVec2  p,
char const *  name = nullptr 
)

Convert coordinates of a point from on-screen to within a rendered image.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 588 of file GUIhelper.C.

References jevois::GPUimage::d2i().

◆ d2is() [1/2]

ImVec2 jevois::GUIhelper::d2is ( float  x,
float  y,
char const *  name = nullptr 
)

Convert a 2D size from on-screen to within a rendered image.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 658 of file GUIhelper.C.

◆ d2is() [2/2]

ImVec2 jevois::GUIhelper::d2is ( ImVec2  p,
char const *  name = nullptr 
)

Convert a 2D size from on-screen to within a rendered image.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 625 of file GUIhelper.C.

References jevois::GPUimage::d2is().

◆ drawCamCtrls()

void jevois::GUIhelper::drawCamCtrls ( )
protected

Definition at line 1392 of file GUIhelper.C.

◆ drawCircle()

void jevois::GUIhelper::drawCircle ( float  x,
float  y,
float  r,
ImU32  col = IM_COL32(128,255,128,255),
bool  filled = true 
)

Draw circle over an image.

Coordinates used should be image coordinates, as this function internally calls i2d().

Definition at line 497 of file GUIhelper.C.

References jevois::imu::get().

Referenced by jevois::dnn::Pipeline::process(), and jevois::dnn::PostProcessorYuNet::report().

◆ drawConsole()

◆ drawErrorPopup()

void jevois::GUIhelper::drawErrorPopup ( )
protected

Definition at line 2112 of file GUIhelper.C.

◆ drawImage() [1/2]

void jevois::GUIhelper::drawImage ( char const *  name,
cv::Mat const &  img,
bool  rgb,
int &  x,
int &  y,
unsigned short &  w,
unsigned short &  h,
bool  noalias = false,
bool  isoverlay = false 
)

Draw an OpenCV image, copying pixel data to an OpenGL texture.

Name should be a unique name, and should typically remain constant across successive video frames. This name is used as an index to OpenGL textures, shaders, and programs created to render the images. Note that OpenGL will slow down and eventually run out of resources if you create too many textures, thus Module writers should try to minimize the number of different names that are used. If image has three or four 8-bit channels, interpret as RGB[A] if rgb is true, otherwise BGR[A]. If two 8-bit channels, interpret as YUYV. If one, interpret as GRAY. If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if noalias is true, that rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. If isoverlay is true, then the image is assumed to be a semi-transparent overlay to be drawn on top of a previously drawn image, and we preserve the drawing parameters of that previous image.

Definition at line 298 of file GUIhelper.C.

References h.

◆ drawImage() [2/2]

void jevois::GUIhelper::drawImage ( char const *  name,
jevois::RawImage const &  img,
int &  x,
int &  y,
unsigned short &  w,
unsigned short &  h,
bool  noalias = false,
bool  isoverlay = false 
)

Draw a RawImage, copying pixel data to an OpenGL texture.

Name should be a unique name, and should typically remain constant across successive video frames. This name is used as an index to OpenGL textures, shaders, and programs created to render the images. Note that OpenGL will slow down and eventually run out of resources if you create too many textures, thus Module writers should try to minimize the number of different names that are used. Note that we will add a suffix to the name, corresponding to the bufindex of the RawImage. If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without changing the aspect ratio, and the actually used x,y,w,h will be returned. Otherwise, x,y,w,h are not modified. If noalias is specified, the scaling factor will be rounded down to the nearest integer to prevent aliasing in the display. This may reduce the displayed image size. For example, with a 1920x1080 window, a 640x480 image would be letterboxed to 1440x1080 when noalias is false. But that is a scaling factor of 2.25 which may create rendering aliasing. When noalias is true, the letterboxed image size will be 1280x960 (scale factor of 2.0). If isoverlay is true, then the image is assumed to be a semi-transparent overlay to be drawn on top of a previously drawn image, and we preserve the drawing parameters of that previous image.

Definition at line 273 of file GUIhelper.C.

References jevois::RawImage::bufindex, h, and jevois::to_string().

Referenced by jevois::dnn::PostProcessorSegment::report().

◆ drawInfo()

void jevois::GUIhelper::drawInfo ( )
protected

◆ drawInputFrame()

void jevois::GUIhelper::drawInputFrame ( char const *  name,
jevois::InputFrame const &  frame,
int &  x,
int &  y,
unsigned short &  w,
unsigned short &  h,
bool  noalias = false,
bool  casync = false 
)

Draw the input video frame from the camera using zero-copy.

If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if noalias is true, that rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified.

Definition at line 320 of file GUIhelper.C.

References jevois::RawImage::bufindex, jevois::InputFrame::get(), jevois::InputFrame::get2(), h, jevois::InputFrame::hasScaledImage(), jevois::RawImage::height, jevois::to_string(), and jevois::RawImage::width.

◆ drawInputFrame2()

void jevois::GUIhelper::drawInputFrame2 ( char const *  name,
jevois::InputFrame const &  frame,
int &  x,
int &  y,
unsigned short &  w,
unsigned short &  h,
bool  noalias = false,
bool  casync = false 
)

Draw the second (scaled) input video frame from the camera using zero-copy.

If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if noalias is true, that rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. Throws unless we are JeVois-Pro Platform and the camera is set to CropScale mode.

Definition at line 350 of file GUIhelper.C.

References jevois::RawImage::bufindex, jevois::InputFrame::get2(), h, and jevois::to_string().

◆ drawJeVoisGUI()

void jevois::GUIhelper::drawJeVoisGUI ( )
protected

Definition at line 677 of file GUIhelper.C.

◆ drawLine()

void jevois::GUIhelper::drawLine ( float  x1,
float  y1,
float  x2,
float  y2,
ImU32  col = IM_COL32(128,255,128,255) 
)

Draw line over an image.

Coordinates used should be image coordinates, as this function internally calls i2d().

Definition at line 442 of file GUIhelper.C.

References jevois::imu::get().

Referenced by jevois::dnn::PostProcessorYuNet::report().

◆ drawMenuBar()

void jevois::GUIhelper::drawMenuBar ( )
protected

Definition at line 758 of file GUIhelper.C.

◆ drawModuleSelect()

void jevois::GUIhelper::drawModuleSelect ( )
protected

Definition at line 814 of file GUIhelper.C.

References JEVOISPRO_FMT_GUI, and LFATAL.

◆ drawNewModuleForm()

void jevois::GUIhelper::drawNewModuleForm ( )
protected

◆ drawParameters()

◆ drawPoly() [1/2]

void jevois::GUIhelper::drawPoly ( std::vector< cv::Point > const &  pts,
ImU32  col = IM_COL32(128,255,128,255),
bool  filled = true 
)

Draw polygon over an image.

Coordinates used should be image coordinates, as this function internally calls i2d().

Definition at line 475 of file GUIhelper.C.

◆ drawPoly() [2/2]

void jevois::GUIhelper::drawPoly ( std::vector< cv::Point2f > const &  pts,
ImU32  col = IM_COL32(128,255,128,255),
bool  filled = true 
)

Draw polygon over an image.

Coordinates used should be image coordinates, as this function internally calls i2d().

Definition at line 486 of file GUIhelper.C.

◆ drawPolyInternal()

void jevois::GUIhelper::drawPolyInternal ( ImVec2 const *  pts,
size_t  npts,
ImU32  col,
bool  filled 
)
protected

Definition at line 460 of file GUIhelper.C.

References jevois::imu::get().

◆ drawRect()

void jevois::GUIhelper::drawRect ( float  x1,
float  y1,
float  x2,
float  y2,
ImU32  col = IM_COL32(128,255,128,255),
bool  filled = true 
)

Draw rectangular box over an image.

Coordinates used should be image coordinates, as this function internally calls i2d().

Definition at line 448 of file GUIhelper.C.

References jevois::imu::get().

Referenced by jevois::dnn::PostProcessorDetect::report(), and jevois::dnn::PostProcessorYuNet::report().

◆ drawSystem()

◆ drawText() [1/2]

void jevois::GUIhelper::drawText ( float  x,
float  y,
char const *  txt,
ImU32  col = IM_COL32(128,255,128,255) 
)

Draw text over an image.

Coordinates used should be image coordinates, as this function internally calls i2d().

Definition at line 510 of file GUIhelper.C.

Referenced by jevois::dnn::PostProcessorDetect::report(), and jevois::dnn::PostProcessorYuNet::report().

◆ drawText() [2/2]

void jevois::GUIhelper::drawText ( float  x,
float  y,
std::string const &  txt,
ImU32  col = IM_COL32(128,255,128,255) 
)

Draw text over an image.

Coordinates used should be image coordinates, as this function internally calls i2d().

Definition at line 516 of file GUIhelper.C.

◆ drawTweaks()

void jevois::GUIhelper::drawTweaks ( )
protected

Definition at line 1980 of file GUIhelper.C.

References FX().

◆ endFrame()

void jevois::GUIhelper::endFrame ( )

Finish current frame and render it.

This should be called once for every call to startFrame().

Definition at line 662 of file GUIhelper.C.

◆ frameStarted()

bool jevois::GUIhelper::frameStarted ( ) const

Helper to indicate that startFrame() was called, and thus endFrame() should be called.

Mostly useful during exception handling inside Engine.

Definition at line 269 of file GUIhelper.C.

◆ headlessDisplay()

void jevois::GUIhelper::headlessDisplay ( )

Show a message that we are running headless.

Definition at line 2190 of file GUIhelper.C.

References jevois::warnAndIgnoreException().

◆ helpMarker()

void jevois::GUIhelper::helpMarker ( char const *  msg,
char const *  msg2 = nullptr,
char const *  msg3 = nullptr 
)

Display a (?) label and show tooltip when it is hovered.

If 2 or more messages are provided, they will be separated by a separator.

Definition at line 2154 of file GUIhelper.C.

◆ i2d() [1/2]

ImVec2 jevois::GUIhelper::i2d ( float  x,
float  y,
char const *  name = nullptr 
)

Convert coordinates of a point from within a rendered image to on-screen.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 404 of file GUIhelper.C.

◆ i2d() [2/2]

ImVec2 jevois::GUIhelper::i2d ( ImVec2  p,
char const *  name = nullptr 
)

Convert coordinates of a point from within a rendered image to on-screen.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 374 of file GUIhelper.C.

References jevois::GPUimage::i2d().

Referenced by jevois::dnn::PostProcessorSegment::report(), and jevois::dnn::PreProcessor::sendreport().

◆ i2ds() [1/2]

ImVec2 jevois::GUIhelper::i2ds ( float  x,
float  y,
char const *  name = nullptr 
)

Convert a 2D size from within a rendered image to on-screen.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 438 of file GUIhelper.C.

◆ i2ds() [2/2]

ImVec2 jevois::GUIhelper::i2ds ( ImVec2  p,
char const *  name = nullptr 
)

Convert a 2D size from within a rendered image to on-screen.

If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from second to first frame.

Definition at line 408 of file GUIhelper.C.

References jevois::GPUimage::i2ds().

◆ iinfo()

void jevois::GUIhelper::iinfo ( jevois::InputFrame const &  inframe,
std::string const &  fpscpu,
unsigned short  winw = 0,
unsigned short  winh = 0 
)

Display processing and video info at bottom of screen.

This helper is to be used by modules to provide a consistent info display at the bottom of the screen. fpscpu should be the string returned by Timer::stop(). If winw and winh are not given, will query from display backend, which will cost a few CPU cycles; so pass it on if you already have it, e.g, from running startFrame() previously.

Definition at line 553 of file GUIhelper.C.

References jevois::fccstr(), jevois::RawImage::fmt, jevois::InputFrame::get(), jevois::imu::get(), jevois::InputFrame::get2(), jevois::InputFrame::hasScaledImage(), jevois::RawImage::height, jevois::sformat(), and jevois::RawImage::width.

◆ iline()

ImVec2 jevois::GUIhelper::iline ( int  line = -1,
char const *  name = nullptr 
)

Get coordinates of the start of a given line of text to be drawn as overlay on top of an image.

Use this to draw overlay text on top of a previously drawn image, it will scale by font size for you. If line is -1, we will increment over the last time this function was called (use with caution). Line number is reset to 0 when drawImage() or drawInputFrame(), etc are called.

Definition at line 530 of file GUIhelper.C.

◆ itext() [1/2]

void jevois::GUIhelper::itext ( char const *  txt,
ImU32 const &  col = IM_COL32_BLACK_TRANS,
int  line = -1 
)

Draw some overlay text on top of an image.

Definition at line 540 of file GUIhelper.C.

References jevois::imu::get().

Referenced by jevois::dnn::Pipeline::process(), and jevois::dnn::PostProcessorClassify::report().

◆ itext() [2/2]

void jevois::GUIhelper::itext ( std::string const &  txt,
ImU32 const &  col = IM_COL32_BLACK_TRANS,
int  line = -1 
)

Draw some overlay text on top of an image.

Definition at line 547 of file GUIhelper.C.

◆ modal()

int jevois::GUIhelper::modal ( std::string const &  title,
char const *  text,
int *  default_val = nullptr,
char const *  b1txt = "Ok",
char const *  b2txt = "Cancel" 
)

Helper to draw a modal with 2 choices.

Returns 1 if the first button was clicked, 2 if the second was, or some other value if no button was clicked (caller should just wait and try again at the next frame if not 1 or 2, passing again that returned value). By default, the first button is in focus. If default_val is not nullptr, add a "don't ask again" checkbox. If default_val is 1 or 2, just return that without even showing the modal.

Definition at line 1398 of file GUIhelper.C.

◆ newModEntry()

void jevois::GUIhelper::newModEntry ( char const *  wname,
std::string &  str,
char const *  desc,
char const *  hint,
char const *  hlp 
)
protected

Definition at line 1447 of file GUIhelper.C.

◆ onParamChange() [1/3]

void jevois::GUIhelper::onParamChange ( gui::rounding const &  param,
int const &  newval 
)
overrideprotected

◆ onParamChange() [2/3]

void jevois::GUIhelper::onParamChange ( gui::scale const &  param,
float const &  newval 
)
overrideprotected

◆ onParamChange() [3/3]

void jevois::GUIhelper::onParamChange ( gui::style const &  param,
gui::GuiStyle const &  newval 
)
overrideprotected

◆ releaseImage()

void jevois::GUIhelper::releaseImage ( char const *  name)

Release an image.

Call this if you plan on re-using the same image name later for an image of different size or format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is not found, i.e., has not been drawn before.

Definition at line 574 of file GUIhelper.C.

Referenced by jevois::dnn::PostProcessorSegment::~PostProcessorSegment().

◆ releaseImage2()

void jevois::GUIhelper::releaseImage2 ( char const *  name)

Release an image, second video stream.

Call this if you plan on re-using the same image name later for an image of different size or format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is not found, i.e., has not been drawn before.

Definition at line 581 of file GUIhelper.C.

◆ reportAndIgnoreException()

void jevois::GUIhelper::reportAndIgnoreException ( std::string const &  prefix = "")

Report current exception in a modal dialog, then ignore it.

Definition at line 2080 of file GUIhelper.C.

References jevois::getPythonExceptionString().

Referenced by jevois::dnn::Pipeline::process().

◆ reportAndRethrowException()

void jevois::GUIhelper::reportAndRethrowException ( std::string const &  prefix = "")

Report current exception in a modal dialog, then re-throw it.

Definition at line 2105 of file GUIhelper.C.

◆ reportError()

void jevois::GUIhelper::reportError ( std::string const &  err)

Report an error in an overlay window.

Definition at line 2053 of file GUIhelper.C.

References LERROR.

◆ reset()

void jevois::GUIhelper::reset ( bool  modulechanged = true)

Reset to default state, typically called on Module or video format change.

Free images, reset matrices, etc.

Definition at line 115 of file GUIhelper.C.

References jevois::imu::get(), h, and LFATAL.

◆ serlogEnabled()

bool jevois::GUIhelper::serlogEnabled ( ) const

Tell whether user enabled serlog messages to GUI console.

Definition at line 1384 of file GUIhelper.C.

◆ seroutEnabled()

bool jevois::GUIhelper::seroutEnabled ( ) const

Tell whether user enabled serout messages to GUI console.

Definition at line 1388 of file GUIhelper.C.

◆ setparstr()

void jevois::GUIhelper::setparstr ( std::string const &  descriptor,
std::string const &  val 
)
protected

Definition at line 1054 of file GUIhelper.C.

References jevois::warnAndIgnoreException().

◆ setparval()

template<class T >
void jevois::GUIhelper::setparval ( std::string const &  descriptor,
T const &  val 
)
protected

◆ startFrame()

bool jevois::GUIhelper::startFrame ( unsigned short &  w,
unsigned short &  h 
)

Start a new rendering frame.

This should be called on every new video frame to be rendered. Will initialize OpenGL and open the window or screen if needed. Sets the current window size into w and h, returns true if idle (no keyboard/mouse/etc events received in more than hidesecs seconds).

Definition at line 163 of file GUIhelper.C.

References jevois::imu::get(), h, LFATAL, and LINFO.

◆ toggleButton()

bool jevois::GUIhelper::toggleButton ( char const *  name,
bool *  val 
)

Helper to draw a toggle button.

Definition at line 2171 of file GUIhelper.C.

Friends And Related Function Documentation

◆ JEVOIS_DECLARE_PARAMETER() [1/7]

JEVOIS_DECLARE_PARAMETER ( allowquit  ,
bool  ,
"Quit application on ESC key (platform) or window close (host)"  ,
false  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [2/7]

JEVOIS_DECLARE_PARAMETER ( fillalpha  ,
float  ,
"Alpha multiplier for overlay fills"  ,
0.  25F,
jevois::Range< float >  0.0F, 1.0F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [3/7]

JEVOIS_DECLARE_PARAMETER ( fullscreen  ,
bool  ,
"Use a fullscreen display when  true,
only has effect on host. " "Platform always is fullscreen as the MALI OpenGL driver do not support windowing."  ,
false  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [4/7]

JEVOIS_DECLARE_PARAMETER ( hidesecs  ,
float  ,
"Number of seconds of inactivity from keyboard/mouse/joystick/etc after " "which we hide the  GUI,
or 0.0 to never hide it. Note:The GUI starts hidden until the " "first input event from a  keyboard,
mouse  ,
etc."  ,
30.  0F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [5/7]

JEVOIS_DECLARE_PARAMETER ( linethick  ,
float  ,
"Line thickness for overlay drawings"  ,
5.  0F,
jevois::Range< float >  0.1F, 20.0F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [6/7]

JEVOIS_DECLARE_PARAMETER ( overlaycolor  ,
ImColor  ,
"Default color to use for overlay text"  ,
ImColor(255, 255, 255, 255)  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [7/7]

JEVOIS_DECLARE_PARAMETER ( winsize  ,
cv::Size  ,
"Initial window size to use on host. On  platform,
size is determined " "by hardware and the value of this parameter will be overwritten on init. The " "parameter can still be used to query display size."  ,
cv::Size(0, 0)  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() [1/3]

JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK ( rounding  ,
int  ,
"Window and widget corner rounding for the JeVois GUI. " "Note than changing GUI scale will update this parameter as well."  ,
,
jevois::Range< int >  0, 24,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() [2/3]

JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK ( scale  ,
float  ,
"Scale factor applied to the GUI"  ,
2.  0f,
{ 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f }  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() [3/3]

JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK ( style  ,
GuiStyle  ,
"Color style for the JeVois GUI"  ,
GuiStyle::Light  ,
GuiStyle_Values  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DEFINE_ENUM_CLASS()

JEVOIS_DEFINE_ENUM_CLASS ( GuiStyle  ,
(Light)(Dark)(Classic)   
)
related

Enum for Parameter.

Member Data Documentation

◆ itsBackend

ImGuiBackendMALI jevois::GUIhelper::itsBackend
protected

Definition at line 398 of file GUIhelper.H.

◆ itsCfgEditor

std::shared_ptr<GUIeditor> jevois::GUIhelper::itsCfgEditor
protected

Definition at line 443 of file GUIhelper.H.

Referenced by GUIhelper().

◆ itsCodeEditor

std::shared_ptr<GUIeditor> jevois::GUIhelper::itsCodeEditor
protected

Definition at line 446 of file GUIhelper.H.

Referenced by GUIhelper().

◆ itsConsLock

bool jevois::GUIhelper::itsConsLock
protected

Definition at line 396 of file GUIhelper.H.

◆ itsCurrentStyle

gui::GuiStyle jevois::GUIhelper::itsCurrentStyle = gui::GuiStyle::Dark
protected

Definition at line 410 of file GUIhelper.H.

◆ itsDnnGetFut

std::future<std::string> jevois::GUIhelper::itsDnnGetFut
protected

Definition at line 449 of file GUIhelper.H.

◆ itsEndFrameCalled

bool jevois::GUIhelper::itsEndFrameCalled = true
protected

Definition at line 380 of file GUIhelper.H.

◆ itsErrorMtx

std::mutex jevois::GUIhelper::itsErrorMtx
mutableprotected

Definition at line 382 of file GUIhelper.H.

◆ itsErrors

std::list<ErrorData> jevois::GUIhelper::itsErrors
protected

Definition at line 389 of file GUIhelper.H.

◆ itsHeadless

ImGuiImage jevois::GUIhelper::itsHeadless
protected

Definition at line 404 of file GUIhelper.H.

◆ itsIcon

ImGuiImage jevois::GUIhelper::itsIcon
protected

Definition at line 403 of file GUIhelper.H.

◆ itsIdle

bool jevois::GUIhelper::itsIdle
protected

Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI.

Definition at line 379 of file GUIhelper.H.

◆ itsImages

std::map<std::string , GPUimage> jevois::GUIhelper::itsImages
protected

Definition at line 372 of file GUIhelper.H.

◆ itsImages2

std::map<std::string , GPUimage> jevois::GUIhelper::itsImages2
protected

Definition at line 372 of file GUIhelper.H.

◆ itsLastDrawnImage

GPUimage* jevois::GUIhelper::itsLastDrawnImage = nullptr
protected

Definition at line 373 of file GUIhelper.H.

◆ itsLastDrawnTextLine

int jevois::GUIhelper::itsLastDrawnTextLine = -1
protected

Definition at line 374 of file GUIhelper.H.

◆ itsLastEventTime

std::chrono::time_point<std::chrono::steady_clock> jevois::GUIhelper::itsLastEventTime
protected

Definition at line 378 of file GUIhelper.H.

◆ itsModAuth

std::string jevois::GUIhelper::itsModAuth
protected

Definition at line 407 of file GUIhelper.H.

◆ itsModDesc

std::string jevois::GUIhelper::itsModDesc
protected

Definition at line 406 of file GUIhelper.H.

◆ itsModDoc

std::vector<std::string> jevois::GUIhelper::itsModDoc
protected

Definition at line 409 of file GUIhelper.H.

◆ itsModLang

std::string jevois::GUIhelper::itsModLang
protected

Definition at line 408 of file GUIhelper.H.

◆ itsModName

std::string jevois::GUIhelper::itsModName
protected

Definition at line 405 of file GUIhelper.H.

◆ itsOpenModals

std::set<std::string> jevois::GUIhelper::itsOpenModals
protected

Definition at line 391 of file GUIhelper.H.

◆ itsRefreshVideoMappings

bool jevois::GUIhelper::itsRefreshVideoMappings = false
protected

Definition at line 452 of file GUIhelper.H.

◆ itsScaledImageFacX

float jevois::GUIhelper::itsScaledImageFacX = 1.0F
protected

Definition at line 376 of file GUIhelper.H.

◆ itsScaledImageFacY

float jevois::GUIhelper::itsScaledImageFacY = 1.0F
protected

Definition at line 376 of file GUIhelper.H.

◆ itsSerLogEnabled

bool jevois::GUIhelper::itsSerLogEnabled = true
protected

Definition at line 414 of file GUIhelper.H.

◆ itsSerOutEnabled

bool jevois::GUIhelper::itsSerOutEnabled = false
protected

Definition at line 415 of file GUIhelper.H.

◆ itsShowAppMetrics

bool jevois::GUIhelper::itsShowAppMetrics = false
protected

Definition at line 412 of file GUIhelper.H.

◆ itsShowImGuiDemo

bool jevois::GUIhelper::itsShowImGuiDemo = false
protected

Definition at line 413 of file GUIhelper.H.

◆ itsShowStyleEditor

bool jevois::GUIhelper::itsShowStyleEditor = false
protected

Definition at line 411 of file GUIhelper.H.

◆ itsUsingScaledImage

bool jevois::GUIhelper::itsUsingScaledImage = false
protected

Definition at line 375 of file GUIhelper.H.

◆ itsVideoMappingListType

int jevois::GUIhelper::itsVideoMappingListType = 0
protected

Definition at line 453 of file GUIhelper.H.

◆ itsWindowTitle

std::string jevois::GUIhelper::itsWindowTitle
protected

Definition at line 402 of file GUIhelper.H.

Referenced by GUIhelper().

◆ pixel_perfect_z

const float jevois::GUIhelper::pixel_perfect_z

Z distance from camera to image plane to achieve pixel-perfect rendering.

Definition at line 308 of file GUIhelper.H.

◆ proj

glm::mat4 jevois::GUIhelper::proj

Our projection matrix.

Definition at line 311 of file GUIhelper.H.

◆ view

glm::mat4 jevois::GUIhelper::view

Our view matrix.

On the first call to startFrame(), the whole OpenGL engine is initialized and the view matrix is set so that the pixel perfect image plane is vertical and centered on the origin, while the camera is translated in negative Z to achieve pixel perfect rendering.

Definition at line 317 of file GUIhelper.H.


The documentation for this class was generated from the following files: