JeVois  1.16
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
GUIhelper.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2020 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 // To minimize the amount of ifdef junk in user code, define type alias OptGUIhelper here as either GUIhelper or void
21 namespace jevois
22 {
23 #ifdef JEVOIS_PRO
24  class GUIhelper;
26 #else
27  using OptGUIhelper = void;
28 #endif
29 }
30 
31 // This is only available on JeVoisPro
32 #ifdef JEVOIS_PRO
33 
35 #include <jevois/Core/Engine.H>
36 #include <jevois/Core/InputFrame.H>
39 #include <jevois/GPU/ImGuiImage.H>
40 #include <jevois/Types/Enum.H>
41 #include <chrono>
42 #include <imgui.h>
43 #include <glm/glm.hpp>
44 #include <opencv2/core/core.hpp>
45 #include <ImGuiColorTextEdit/TextEditor.h>
46 
47 namespace jevois
48 {
49  class GPUimage;
50 
51  namespace gui
52  {
53  static jevois::ParameterCategory const ParamCateg("Graphical Interface Options");
54 
55  //! Parameter \relates jevois::GUIhelper
56  JEVOIS_DECLARE_PARAMETER(fullscreen, bool, "Use a fullscreen display when true, only has effect on host. "
57  "Platform always is fullscreen as the MALI OpenGL driver do not support windowing.",
58  false, ParamCateg);
59 
60  //! Parameter \relates jevois::GUIhelper
61  JEVOIS_DECLARE_PARAMETER(winsize, cv::Size, "Initial window size to use on host. On platform, size is determined "
62  "by hardware and the value of this parameter will be overwritten on init. The "
63  "parameter can still be used to query display size.",
64  cv::Size(1920, 1080), ParamCateg);
65 
66  //! Parameter \relates jevois::GUIhelper
67  JEVOIS_DECLARE_PARAMETER(hidesecs, float, "Number of seconds of inactivity from keyboard/mouse/joystick/etc after "
68  "which we hide the GUI, or 0.0 to never hide it. Note: The GUI starts hidden until the "
69  "first input event from a keyboard, mouse, etc.",
70  30.0F, ParamCateg);
71 
72  //! Parameter \relates jevois::GUIhelper
73  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(scale, float, "Scale factor applied to the GUI",
74  2.0f, { 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f,
75  2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f },
76  ParamCateg);
77 
78  //! Enum for Parameter \relates jevois::GUIhelper
79  JEVOIS_DEFINE_ENUM_CLASS(GuiStyle, (Light) (Dark) (Classic) );
80 
81  //! Parameter \relates jevois::GUIhelper
82  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(style, GuiStyle, "Color style for the JeVois GUI",
83  GuiStyle::Light, GuiStyle_Values, ParamCateg);
84 
85  //! Parameter \relates jevois::GUIhelper
86  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(rounding, int, "Window and widget corner rounding for the JeVois GUI. "
87  "Note than changing GUI scale will update this parameter as well.",
88  4, jevois::Range<int>(0, 24), ParamCateg);
89  //! Parameter \relates jevois::GUIhelper
90  JEVOIS_DECLARE_PARAMETER(overlaycolor, ImColor, "Default color to use for overlay text",
91  ImColor(255, 255, 255, 255), ParamCateg);
92 
93  //! Parameter \relates jevois::GUIhelper
94  JEVOIS_DECLARE_PARAMETER(linethick, float, "Line thickness for overlay drawings",
95  5.0F, jevois::Range<float>(0.1F, 20.0F), ParamCateg);
96 
97  //! Parameter \relates jevois::GUIhelper
98  JEVOIS_DECLARE_PARAMETER(fillalpha, float, "Alpha multiplier for overlay fills",
99  0.25F, jevois::Range<float>(0.0F, 1.0F), ParamCateg);
100 
101  //! Parameter \relates jevois::GUIhelper
102  JEVOIS_DECLARE_PARAMETER(allowquit, bool, "Quit application on ESC key (platform) or window close (host)",
103  false, ParamCateg);
104  } // namespace gui
105 
106  //! Helper class to assist modules in creating graphical and GUI elements
107  /*! This class only works on JeVois-Pro. All functions except constructor and destructor throw on other platforms. */
108  class GUIhelper : public Component,
109  public Parameter<gui::fullscreen, gui::winsize, gui::hidesecs, gui::scale,
110  gui::style, gui::rounding, gui::overlaycolor, gui::linethick,
111  gui::fillalpha, gui::allowquit>
112  {
113  public:
114  //! Constructor
115  GUIhelper(std::string const & instance, bool conslock = false);
116 
117  //! Destructor
118  virtual ~GUIhelper();
119 
120  //! Start a new rendering frame
121  /*! This should be called on every new video frame to be rendered. Will initialize OpenGL and open the window or
122  screen if needed. Sets the current window size into w and h, returns true if idle (no keyboard/mouse/etc
123  events received in more than hidesecs seconds). */
124  bool startFrame(unsigned short & w, unsigned short & h);
125 
126  //! Helper to indicate that startFrame() was called, and thus endFrame() should be called
127  /*! Mostly useful during exception handling inside Engine. */
128  bool frameStarted() const;
129 
130  //! Draw a RawImage, copying pixel data to an OpenGL texture
131  /*! Name should be a unique name, and should typically remain constant across successive video frames. This name
132  is used as an index to OpenGL textures, shaders, and programs created to render the images. Note that OpenGL
133  will slow down and eventually run out of resources if you create too many textures, thus Module writers should
134  try to minimize the number of different names that are used. Note that we will add a suffix to the name,
135  corresponding to the bufindex of the RawImage. If you pass w=0 or h=0 then the image will be rescaled to fill
136  the display as much as possible without changing the aspect ratio, and the actually used x,y,w,h will be
137  returned. Otherwise, x,y,w,h are not modified. If noalias is specified, the scaling factor will be rounded
138  down to the nearest integer to prevent aliasing in the display. This may reduce the displayed image size. For
139  example, with a 1920x1080 window, a 640x480 image would be letterboxed to 1440x1080 when noalias is false. But
140  that is a scaling factor of 2.25 which may create rendering aliasing. When noalias is true, the letterboxed
141  image size will be 1280x960 (scale factor of 2.0). If isoverlay is true, then the image is assumed to be a
142  semi-transparent overlay to be drawn on top of a previously drawn image, and we preserve the drawing
143  parameters of that previous image. */
144  void drawImage(char const * name, RawImage const & img, int & x, int & y, unsigned short & w, unsigned short & h,
145  bool noalias = false, bool isoverlay = false);
146 
147  //! Draw an OpenCV image, copying pixel data to an OpenGL texture
148  /*! Name should be a unique name, and should typically remain constant across successive video frames. This name
149  is used as an index to OpenGL textures, shaders, and programs created to render the images. Note that OpenGL
150  will slow down and eventually run out of resources if you create too many textures, thus Module writers should
151  try to minimize the number of different names that are used. If image has three or four 8-bit channels,
152  interpret as RGB[A] if rgb is true, otherwise BGR[A]. If two 8-bit channels, interpret as YUYV. If one,
153  interpret as GRAY. If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as
154  possible without changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if
155  noalias is true, that rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. If
156  isoverlay is true, then the image is assumed to be a semi-transparent overlay to be drawn on top of a
157  previously drawn image, and we preserve the drawing parameters of that previous image. */
158  void drawImage(char const * name, cv::Mat const & img, bool rgb, int & x, int & y, unsigned short & w,
159  unsigned short & h, bool noalias = false, bool isoverlay = false);
160 
161  //! Draw the input video frame from the camera using zero-copy
162  /*! If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without
163  changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if noalias is true, that
164  rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. */
165  void drawInputFrame(char const * name, InputFrame const & frame, int & x, int & y,
166  unsigned short & w, unsigned short & h, bool noalias = false, bool casync = false);
167 
168  //! Draw the second (scaled) input video frame from the camera using zero-copy
169  /*! If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without
170  changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if noalias is true, that
171  rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. Throws unless we are
172  JeVois-Pro Platform and the camera is set to CropScale mode. */
173  void drawInputFrame2(char const * name, InputFrame const & frame, int & x, int & y,
174  unsigned short & w, unsigned short & h, bool noalias = false, bool casync = false);
175 
176  //! Convert coordinates of a point from within a rendered image to on-screen
177  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
178  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
179  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
180  second to first frame. */
181  ImVec2 i2d(ImVec2 p, char const * name = nullptr);
182 
183  //! Convert coordinates of a point from within a rendered image to on-screen
184  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
185  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
186  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
187  second to first frame. */
188  ImVec2 i2d(float x, float y, char const * name = nullptr);
189 
190  //! Convert a 2D size from within a rendered image to on-screen
191  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
192  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
193  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
194  second to first frame. */
195  ImVec2 i2ds(ImVec2 p, char const * name = nullptr);
196 
197  //! Convert a 2D size from within a rendered image to on-screen
198  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
199  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
200  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
201  second to first frame. */
202  ImVec2 i2ds(float x, float y, char const * name = nullptr);
203 
204  //! Draw line over an image
205  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
206  void drawLine(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255));
207 
208  //! Draw rectangular box over an image
209  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
210  void drawRect(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
211 
212  //! Draw polygon over an image
213  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
214  void drawPoly(std::vector<cv::Point> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
215 
216  //! Draw polygon over an image
217  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
218  void drawPoly(std::vector<cv::Point2f> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
219 
220  //! Draw circle over an image
221  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
222  void drawCircle(float x, float y, float r, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
223 
224  //! Draw text over an image
225  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
226  void drawText(float x, float y, char const * txt, ImU32 col = IM_COL32(128,255,128,255));
227 
228  //! Draw text over an image
229  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
230  void drawText(float x, float y, std::string const & txt, ImU32 col = IM_COL32(128,255,128,255));
231 
232  //! Get coordinates of the start of a given line of text to be drawn as overlay on top of an image
233  /*! Use this to draw overlay text on top of a previously drawn image, it will scale by font size for you. If line
234  is -1, we will increment over the last time this function was called (use with caution). Line number is reset
235  to 0 when drawImage() or drawInputFrame(), etc are called. */
236  ImVec2 iline(int line = -1, char const * name = nullptr);
237 
238  //! Draw some overlay text on top of an image
239  /* If line is -1, we will increment over the last time this function was called (use with caution). Line number is
240  reset to 0 when drawImage() or drawInputFrame(), etc are called. If col is not given, use overlaycolor. */
241  void itext(char const * txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
242 
243  //! Draw some overlay text on top of an image
244  /* If line is -1, we will increment over the last time this function was called (use with caution). Line number is
245  reset to 0 when drawImage() or drawInputFrame(), etc are called. If col is not given, use overlaycolor. */
246  void itext(std::string const & txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
247 
248  //! Display processing and video info at bottom of screen
249  /*! This helper is to be used by modules to provide a consistent info display at the bottom of the screen.
250  fpscpu should be the string returned by Timer::stop(). If winw and winh are not given, will query from display
251  backend, which will cost a few CPU cycles; so pass it on if you already have it, e.g, from running
252  startFrame() previously. */
253  void iinfo(jevois::InputFrame const & inframe, std::string const & fpscpu,
254  unsigned short winw = 0, unsigned short winh = 0);
255 
256  //! Release an image
257  /*! Call this if you plan on re-using the same image name later for an image of different size or
258  format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the
259  same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is
260  not found, i.e., has not been drawn before. */
261  void releaseImage(char const * name);
262 
263  //! Release an image, second video stream
264  /*! Call this if you plan on re-using the same image name later for an image of different size or
265  format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the
266  same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is
267  not found, i.e., has not been drawn before. */
268  void releaseImage2(char const * name);
269 
270  //! Finish current frame and render it
271  /*! This should be called once for every call to startFrame(). */
272  void endFrame();
273 
274  //! Reset to default state, typically called on Module or video format change
275  /*! Free images, reset matrices, etc. */
276  void reset(bool modulechanged = true);
277 
278  //! Report an error in an overlay window
279  void reportError(std::string const & err);
280 
281  //! Report current exception in a modal dialog, then ignore it
282  void reportAndIgnoreException(std::string const & prefix = "");
283 
284  //! Report current exception in a modal dialog, then re-throw it
285  void reportAndRethrowException(std::string const & prefix = "");
286 
287  //! Z distance from camera to image plane to achieve pixel-perfect rendering
288  float const pixel_perfect_z;
289 
290  //! Our projection matrix
291  glm::mat4 proj;
292 
293  //! Our view matrix
294  /*! On the first call to startFrame(), the whole OpenGL engine is initialized and the view matrix is set so that
295  the pixel perfect image plane is vertical and centered on the origin, while the camera is translated in
296  negative Z to achieve pixel perfect rendering. */
297  glm::mat4 view;
298 
299  //! Display a (?) label and show tooltip when it is hovered
300  /*! If 2 or more messages are provided, they will be separated by a separator. */
301  void helpMarker(char const * msg, char const * msg2 = nullptr, char const * msg3 = nullptr);
302 
303  //! Helper to draw a toggle button
304  bool toggleButton(char const * name, bool * val);
305 
306  //! Helper to draw a modal with 2 choices
307  /*! Returns 0 if no button was clicked, 1 if the first button was, 2 if the second was. By default, the first
308  button is in focus. */
309  int modal(std::string const & title, char const * text, bool & dont_ask_me_next_time,
310  char const * b1txt = "Ok", char const * b2txt = "Cancel");
311 
312  //! Show a message that we are running headless
313  void headlessDisplay();
314 
315  //! Tell whether user enabled serlog messages to GUI console
316  bool serlogEnabled() const;
317 
318  //! Tell whether user enabled serout messages to GUI console
319  bool seroutEnabled() const;
320 
321  protected:
322  std::map<std::string /* name */, GPUimage> itsImages, itsImages2;
325  bool itsUsingScaledImage = false;
327 
328  std::chrono::time_point<std::chrono::steady_clock> itsLastEventTime;
329  bool itsIdle; //!< Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI
330  bool itsEndFrameCalled = true; // try to avoid violent assert() crash from ImGui if user forgets to endFrame()
331 
332  mutable std::mutex itsErrorMtx;
333  struct ErrorData
334  {
335  std::string err;
336  std::chrono::time_point<std::chrono::steady_clock> firsttime;
337  std::chrono::time_point<std::chrono::steady_clock> lasttime;
338  };
339  std::list<ErrorData> itsErrors;
340 
341  std::set<std::string> itsOpenModals;
342 
343  void drawPolyInternal(ImVec2 const * pts, size_t npts, ImU32 col, bool filled);
344  ImU32 applyFillAlpha(ImU32 col) const;
345 
347 #ifdef JEVOIS_PLATFORM_PRO
348  ImGuiBackendMALI itsBackend;
349 #else
350  ImGuiBackendSDL itsBackend;
351 #endif
352  std::string itsWindowTitle;
355  std::string itsModName;
356  std::string itsModDesc;
357  std::string itsModAuth;
358  std::string itsModLang;
359  std::vector<std::string> itsModDoc;
360  gui::GuiStyle itsCurrentStyle = gui::GuiStyle::Dark;
361  bool itsShowStyleEditor = false;
362  bool itsShowAppMetrics = false;
363  bool itsShowImGuiDemo = false;
364  bool itsSerLogEnabled = true;
365  bool itsSerOutEnabled = true;
366 
367  void drawJeVoisGUI();
368  void drawInfo();
369  void drawParameters();
370  void drawConsole();
371  void drawEditorMenu(TextEditor & e);
372  void drawEditor(TextEditor & e);
373  void drawCamCtrls();
374  void drawCfgEditor();
375  void drawCodeEditor();
376  void drawTweaks();
377  void drawSystem();
378  void drawMenuBar();
379  void drawModuleSelect();
380  void drawErrorPopup();
381  void drawNewModuleForm();
382 
383  void newModEntry(char const * wname, std::string & str, char const * desc, char const * hint, char const * hlp);
384 
385  // Set a parameter by string, catch any exception and report it in popup modal
386  void setparstr(std::string const & descriptor, std::string const & val);
387 
388  // Set a parameter by value, catch any exception and report it in popup modal
389  template <class T>
390  void setparval(std::string const & descriptor, T const & val);
391 
392  void onParamChange(gui::scale const & param, float const & newval) override;
393  void onParamChange(gui::rounding const & param, int const & newval) override;
394  void onParamChange(gui::style const & param, gui::GuiStyle const & newval) override;
395 
396  // Config files:
397  TextEditor itsCfgEditor;
398  std::string itsCfgFileName;
399  void loadEditorFile(TextEditor & e, std::string const & fn, std::string const & failtxt, bool failro);
400  void saveEditorFile(TextEditor & e, std::string const & fn);
401 
402  // Helper enum for actions to execute after saving a config file
404 
405  // Helper class to represent config file in a pull-down menu:
406  struct CfgItem {
407  std::string filename;
408  std::string displayname;
409  std::string defaulttext;
411  };
412  std::vector<CfgItem> itsCfgItems;
414  bool itsRefreshCfgList = true;
417  bool itsCfgWantLoad = true;
418  bool itsCfgWantAction = false;
419  bool itsCfgOkToLoad = false;
420  int itsCfgNewItem = 0;
421 
422  // Code editing:
423  TextEditor itsCodeEditor;
424  std::string itsCodeFileName;
425 
426  // dnnget helpers
427  std::future<std::string> itsDnnGetFut;
428 
429  // Flag to refresh video mappings when we save the file or add a new one by creating a new module:
432  };
433 
434 } // namespace jevois
435 
436 // Include inlined implementation details that are of no interest to the end user
437 #include <jevois/GPU/details/GUIhelperImpl.H>
438 
439 #endif // JEVOIS_PRO
jevois::GUIhelper::ErrorData
Definition: GUIhelper.H:333
jevois::GUIhelper::CfgSaveAction::Reload
@ Reload
jevois::Component::descriptor
std::string descriptor() const
Get our full descriptor (including all parents) as [Instancename]:[...]:[...].
Definition: Component.C:276
jevois::GUIhelper::drawImage
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.
Definition: GUIhelper.C:242
jevois::GUIhelper::drawInputFrame2
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.
Definition: GUIhelper.C:319
jevois::GUIhelper::drawNewModuleForm
void drawNewModuleForm()
Definition: GUIhelper.C:1826
jevois::GUIhelper::reportAndIgnoreException
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
Definition: GUIhelper.C:2252
jevois::GUIhelper::itsSerLogEnabled
bool itsSerLogEnabled
Definition: GUIhelper.H:364
jevois::GUIhelper::CfgSaveAction::RefreshMappings
@ RefreshMappings
jevois::Range
A generic range class.
Definition: Range.H:80
jevois::GUIhelper::drawMenuBar
void drawMenuBar()
Definition: GUIhelper.C:660
jevois::GUIhelper::drawCircle
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw circle over an image.
Definition: GUIhelper.C:466
jevois::GUIhelper::itsModLang
std::string itsModLang
Definition: GUIhelper.H:358
jevois::GUIhelper::itsBackend
ImGuiBackendSDL itsBackend
Definition: GUIhelper.H:350
jevois::GUIhelper::itsImages2
std::map< std::string, GPUimage > itsImages2
Definition: GUIhelper.H:322
jevois::GUIhelper::startFrame
bool startFrame(unsigned short &w, unsigned short &h)
Start a new rendering frame.
Definition: GUIhelper.C:139
jevois::GUIhelper::itext
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
Definition: GUIhelper.C:509
jevois::GUIhelper::onParamChange
void onParamChange(gui::scale const &param, float const &newval) override
jevois::GUIhelper::drawInfo
void drawInfo()
Definition: GUIhelper.C:796
jevois::GUIhelper::CfgItem
Definition: GUIhelper.H:406
JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(thresh1, double, "First threshold for hysteresis", 50.0, ParamCateg)
jevois::GUIhelper::itsSerOutEnabled
bool itsSerOutEnabled
Definition: GUIhelper.H:365
jevois::GUIhelper::setparstr
void setparstr(std::string const &descriptor, std::string const &val)
Definition: GUIhelper.C:956
jevois::GPUimage
Class to hold a GPUtexture, GPUprogram, and other data associated with rendering an image in OpenGL.
Definition: GPUimage.H:38
jevois::GUIhelper::itsRefreshCfgList
bool itsRefreshCfgList
Definition: GUIhelper.H:414
jevois::GUIhelper::headlessDisplay
void headlessDisplay()
Show a message that we are running headless.
Definition: GUIhelper.C:2354
jevois::JEVOIS_DEFINE_ENUM_CLASS
JEVOIS_DEFINE_ENUM_CLASS(CameraSensor,(any)(ov9650)(ov2640)(ov7725)(ar0135)(imx290))
Enum for different sensor models.
jevois::GUIhelper::drawPolyInternal
void drawPolyInternal(ImVec2 const *pts, size_t npts, ImU32 col, bool filled)
Definition: GUIhelper.C:429
jevois::GUIhelper::itsCfgWantAction
bool itsCfgWantAction
Definition: GUIhelper.H:418
jevois::GUIhelper::endFrame
void endFrame()
Finish current frame and render it.
Definition: GUIhelper.C:557
jevois::Component
A component of a model hierarchy.
Definition: Component.H:180
jevois::GUIhelper::itsOpenModals
std::set< std::string > itsOpenModals
Definition: GUIhelper.H:341
jevois::GUIhelper::reportAndRethrowException
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
Definition: GUIhelper.C:2269
jevois::GUIhelper::itsCfgEditor
TextEditor itsCfgEditor
Definition: GUIhelper.H:397
jevois::GUIhelper::releaseImage
void releaseImage(char const *name)
Release an image.
Definition: GUIhelper.C:543
jevois::GUIhelper::itsIdle
bool itsIdle
Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI.
Definition: GUIhelper.H:329
jevois::GUIhelper::itsErrors
std::list< ErrorData > itsErrors
Definition: GUIhelper.H:339
jevois::GUIhelper::drawTweaks
void drawTweaks()
Definition: GUIhelper.C:2162
jevois::GUIhelper::newModEntry
void newModEntry(char const *wname, std::string &str, char const *desc, char const *hint, char const *hlp)
Definition: GUIhelper.C:1637
jevois::ImGuiImage
Wrapper for an image that can be rendered into ImGui.
Definition: ImGuiImage.H:30
jevois::GUIhelper::itsUsingScaledImage
bool itsUsingScaledImage
Definition: GUIhelper.H:325
jevois::GUIhelper::itsNumFixedCfgItems
size_t itsNumFixedCfgItems
Definition: GUIhelper.H:413
jevois::RawImage
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
jevois::GUIhelper::itsCfgItems
std::vector< CfgItem > itsCfgItems
Definition: GUIhelper.H:412
jevois::GUIhelper::CfgSaveAction::Reboot
@ Reboot
jevois::GUIhelper::helpMarker
void helpMarker(char const *msg, char const *msg2=nullptr, char const *msg3=nullptr)
Display a (?) label and show tooltip when it is hovered.
Definition: GUIhelper.C:2318
jevois::GUIhelper::loadEditorFile
void loadEditorFile(TextEditor &e, std::string const &fn, std::string const &failtxt, bool failro)
Definition: GUIhelper.C:1339
jevois::GUIhelper::i2d
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
Definition: GUIhelper.C:343
jevois::GUIhelper::itsRefreshVideoMappings
bool itsRefreshVideoMappings
Definition: GUIhelper.H:430
jevois::GUIhelper::drawErrorPopup
void drawErrorPopup()
Definition: GUIhelper.C:2276
jevois::GUIhelper::drawModuleSelect
void drawModuleSelect()
Definition: GUIhelper.C:716
jevois::GUIhelper::drawEditorMenu
void drawEditorMenu(TextEditor &e)
Definition: GUIhelper.C:1372
jevois::ParameterCategory
A category to which multiple ParameterDef definitions can belong.
Definition: ParameterDef.H:33
jevois::GUIhelper::drawParameters
void drawParameters()
Definition: GUIhelper.C:964
jevois::GUIhelper::itsModName
std::string itsModName
Definition: GUIhelper.H:355
jevois::GUIhelper::drawRect
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.
Definition: GUIhelper.C:417
jevois::GUIhelper::drawCamCtrls
void drawCamCtrls()
Definition: GUIhelper.C:1294
jevois::GUIhelper::itsDnnGetFut
std::future< std::string > itsDnnGetFut
Definition: GUIhelper.H:427
jevois::GUIhelper::itsCurrentStyle
gui::GuiStyle itsCurrentStyle
Definition: GUIhelper.H:360
jevois::GUIhelper::itsScaledImageFacX
float itsScaledImageFacX
Definition: GUIhelper.H:326
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:108
jevois::GUIhelper::itsLastDrawnImage
GPUimage * itsLastDrawnImage
Definition: GUIhelper.H:323
jevois::GUIhelper::drawLine
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
Definition: GUIhelper.C:411
jevois::GUIhelper::seroutEnabled
bool seroutEnabled() const
Tell whether user enabled serout messages to GUI console.
Definition: GUIhelper.C:1290
jevois::GUIhelper::itsShowStyleEditor
bool itsShowStyleEditor
Definition: GUIhelper.H:361
jevois::GUIhelper::itsLastEventTime
std::chrono::time_point< std::chrono::steady_clock > itsLastEventTime
Definition: GUIhelper.H:328
jevois::GUIhelper::itsImages
std::map< std::string, GPUimage > itsImages
Definition: GUIhelper.H:322
jevois::GUIhelper::proj
glm::mat4 proj
Our projection matrix.
Definition: GUIhelper.H:291
jevois::GUIhelper::reportError
void reportError(std::string const &err)
Report an error in an overlay window.
Definition: GUIhelper.C:2235
jevois
Definition: Concepts.dox:1
jevois::GUIhelper::ErrorData::lasttime
std::chrono::time_point< std::chrono::steady_clock > lasttime
Definition: GUIhelper.H:337
jevois::GUIhelper::itsModDesc
std::string itsModDesc
Definition: GUIhelper.H:356
F
float F
Definition: GUIhelper.C:2150
Component.H
Engine.H
jevois::GUIhelper::itsConsLock
bool itsConsLock
Definition: GUIhelper.H:346
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(l2grad, bool, "Use more accurate L2 gradient norm if true, L1 if false", false, ParamCateg)
jevois::GUIhelper::drawPoly
void drawPoly(std::vector< cv::Point > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
Definition: GUIhelper.C:444
ImGuiBackendSDL.H
jevois::GUIhelper::CfgItem::displayname
std::string displayname
Definition: GUIhelper.H:408
jevois::GUIhelper::itsCfgCurrentAction
CfgSaveAction itsCfgCurrentAction
Definition: GUIhelper.H:416
jevois::GUIhelper::drawCodeEditor
void drawCodeEditor()
Definition: GUIhelper.C:1580
jevois::GUIhelper::saveEditorFile
void saveEditorFile(TextEditor &e, std::string const &fn)
Definition: GUIhelper.C:1358
jevois::GUIhelper::toggleButton
bool toggleButton(char const *name, bool *val)
Helper to draw a toggle button.
Definition: GUIhelper.C:2335
jevois::GUIhelper::reset
void reset(bool modulechanged=true)
Reset to default state, typically called on Module or video format change.
Definition: GUIhelper.C:95
jevois::GUIhelper::frameStarted
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
Definition: GUIhelper.C:238
jevois::GUIhelper::drawEditor
void drawEditor(TextEditor &e)
Definition: GUIhelper.C:1406
jevois::GUIhelper::drawJeVoisGUI
void drawJeVoisGUI()
Definition: GUIhelper.C:572
jevois::GUIhelper::itsHeadless
ImGuiImage itsHeadless
Definition: GUIhelper.H:354
jevois::GUIhelper::itsShowImGuiDemo
bool itsShowImGuiDemo
Definition: GUIhelper.H:363
jevois::GUIhelper::serlogEnabled
bool serlogEnabled() const
Tell whether user enabled serlog messages to GUI console.
Definition: GUIhelper.C:1286
jevois::GUIhelper::releaseImage2
void releaseImage2(char const *name)
Release an image, second video stream.
Definition: GUIhelper.C:550
jevois::GUIhelper::itsModDoc
std::vector< std::string > itsModDoc
Definition: GUIhelper.H:359
jevois::GUIhelper::drawSystem
void drawSystem()
Definition: GUIhelper.C:1652
jevois::GUIhelper::itsEndFrameCalled
bool itsEndFrameCalled
Definition: GUIhelper.H:330
jevois::GUIhelper::drawText
void drawText(float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw text over an image.
Definition: GUIhelper.C:479
jevois::GUIhelper::ErrorData::err
std::string err
Definition: GUIhelper.H:335
jevois::GUIhelper::GUIhelper
GUIhelper(std::string const &instance, bool conslock=false)
Constructor.
Definition: GUIhelper.C:43
jevois::GUIhelper::view
glm::mat4 view
Our view matrix.
Definition: GUIhelper.H:297
jevois::GUIhelper::drawInputFrame
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.
Definition: GUIhelper.C:289
jevois::GUIhelper::drawConsole
void drawConsole()
Definition: GUIhelper.C:1197
jevois::GUIhelper::itsErrorMtx
std::mutex itsErrorMtx
Definition: GUIhelper.H:332
jevois::GUIhelper::itsCfgWantLoad
bool itsCfgWantLoad
Definition: GUIhelper.H:417
InputFrame.H
jevois::GUIhelper::iinfo
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.
Definition: GUIhelper.C:522
jevois::GUIhelper::itsWindowTitle
std::string itsWindowTitle
Definition: GUIhelper.H:352
jevois::InputFrame
Exception-safe wrapper around a raw camera input frame.
Definition: InputFrame.H:50
jevois::GUIhelper::CfgItem::filename
std::string filename
Definition: GUIhelper.H:407
jevois::GUIhelper::itsLastDrawnTextLine
int itsLastDrawnTextLine
Definition: GUIhelper.H:324
jevois::GUIhelper::i2ds
ImVec2 i2ds(ImVec2 p, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
Definition: GUIhelper.C:377
jevois::GUIhelper::itsScaledImageFacY
float itsScaledImageFacY
Definition: GUIhelper.H:326
jevois::GUIhelper::itsCfgFileName
std::string itsCfgFileName
Definition: GUIhelper.H:398
jevois::GUIhelper::itsModAuth
std::string itsModAuth
Definition: GUIhelper.H:357
jevois::GUIhelper::itsCfgNewItem
int itsCfgNewItem
Definition: GUIhelper.H:420
jevois::GUIhelper::CfgItem::action
CfgSaveAction action
Definition: GUIhelper.H:410
jevois::GUIhelper::modal
int modal(std::string const &title, char const *text, bool &dont_ask_me_next_time, char const *b1txt="Ok", char const *b2txt="Cancel")
Helper to draw a modal with 2 choices.
Definition: GUIhelper.C:1300
jevois::GUIhelper::iline
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.
Definition: GUIhelper.C:499
h
int h
Definition: GUIhelper.C:2150
ImGuiImage.H
jevois::GUIhelper::itsShowAppMetrics
bool itsShowAppMetrics
Definition: GUIhelper.H:362
jevois::GUIhelper::CfgItem::defaulttext
std::string defaulttext
Definition: GUIhelper.H:409
jevois::GUIhelper::itsVideoMappingListType
int itsVideoMappingListType
Definition: GUIhelper.H:431
jevois::GUIhelper::itsCfgCurrentItem
int itsCfgCurrentItem
Definition: GUIhelper.H:415
jevois::GUIhelper::pixel_perfect_z
const float pixel_perfect_z
Z distance from camera to image plane to achieve pixel-perfect rendering.
Definition: GUIhelper.H:288
jevois::GUIhelper::applyFillAlpha
ImU32 applyFillAlpha(ImU32 col) const
Definition: GUIhelper.C:491
jevois::GUIhelper::itsCodeFileName
std::string itsCodeFileName
Definition: GUIhelper.H:424
jevois::GUIhelper::CfgSaveAction
CfgSaveAction
Definition: GUIhelper.H:403
jevois::GUIhelper::drawCfgEditor
void drawCfgEditor()
Definition: GUIhelper.C:1419
ImGuiBackendMALI.H
jevois::GUIhelper::itsIcon
ImGuiImage itsIcon
Definition: GUIhelper.H:353
jevois::GUIhelper::CfgSaveAction::None
@ None
jevois::GUIhelper::~GUIhelper
virtual ~GUIhelper()
Destructor.
Definition: GUIhelper.C:88
jevois::GUIhelper::setparval
void setparval(std::string const &descriptor, T const &val)
jevois::GUIhelper::itsCfgOkToLoad
bool itsCfgOkToLoad
Definition: GUIhelper.H:419
jevois::GUIhelper::itsCodeEditor
TextEditor itsCodeEditor
Definition: GUIhelper.H:423
jevois::GUIhelper::ErrorData::firsttime
std::chrono::time_point< std::chrono::steady_clock > firsttime
Definition: GUIhelper.H:336
Enum.H