JeVois  1.20
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 
46 namespace jevois
47 {
48  class GPUimage;
49  class GUIeditor;
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 #ifdef JEVOIS_PLATFORM
65  // Use 0 x 0 default on platform which will trigger a query for framebuffer size in
66  // VideoDisplayBackEndMali:
67  cv::Size(0, 0),
68 #else
69  // On host, provide a default size since by default we run in a window:
70  cv::Size(1920, 1080),
71 #endif
72  ParamCateg);
73 
74  //! Parameter \relates jevois::GUIhelper
75  JEVOIS_DECLARE_PARAMETER(hidesecs, float, "Number of seconds of inactivity from keyboard/mouse/joystick/etc after "
76  "which we hide the GUI, or 0.0 to never hide it. Note: The GUI starts hidden until the "
77  "first input event from a keyboard, mouse, etc.",
78  30.0F, ParamCateg);
79 
80  //! Parameter \relates jevois::GUIhelper
81  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(scale, float, "Scale factor applied to the GUI",
82  2.0f, { 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f,
83  2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f },
84  ParamCateg);
85 
86  //! Enum for Parameter \relates jevois::GUIhelper
87  JEVOIS_DEFINE_ENUM_CLASS(GuiStyle, (Light) (Dark) (Classic) );
88 
89  //! Parameter \relates jevois::GUIhelper
90  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(style, GuiStyle, "Color style for the JeVois GUI",
91  GuiStyle::Light, GuiStyle_Values, ParamCateg);
92 
93  //! Parameter \relates jevois::GUIhelper
94  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(rounding, int, "Window and widget corner rounding for the JeVois GUI. "
95  "Note than changing GUI scale will update this parameter as well.",
96  4, jevois::Range<int>(0, 24), ParamCateg);
97 
98  //! Parameter \relates jevois::GUIhelper
99  JEVOIS_DECLARE_PARAMETER(overlaycolor, ImColor, "Default color to use for overlay text",
100  ImColor(255, 255, 255, 255), ParamCateg);
101 
102  //! Parameter \relates jevois::GUIhelper
103  JEVOIS_DECLARE_PARAMETER(linethick, float, "Line thickness for overlay drawings",
104  5.0F, jevois::Range<float>(0.1F, 20.0F), ParamCateg);
105 
106  //! Parameter \relates jevois::GUIhelper
107  JEVOIS_DECLARE_PARAMETER(fillalpha, float, "Alpha multiplier for overlay fills",
108  0.25F, jevois::Range<float>(0.0F, 1.0F), ParamCateg);
109 
110  //! Parameter \relates jevois::GUIhelper
111  JEVOIS_DECLARE_PARAMETER(allowquit, bool, "Quit application on ESC key (platform) or window close (host)",
112  false, ParamCateg);
113 
114  //! Parameter \relates jevois::GUIhelper
115  JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(twirl, float, "Apply twirl effect to displayed video and images, useful "
116  "mainly for demo mode",
117  0.0F, jevois::Range<float>(-15.0F, 15.0F), ParamCateg);
118  } // namespace gui
119 
120  /*! \defgroup gui JeVois-Pro Graphical Interface
121 
122  Classes and utilities to provide a graphical interface using Dear ImGui. Supported on JeVois-Pro only.
123 
124  \ingroup core */
125 
126  //! Helper class to assist modules in creating graphical and GUI elements
127  /*! This class only works on JeVois-Pro. \ingroup gui */
128  class GUIhelper : public Component,
129  public Parameter<gui::fullscreen, gui::winsize, gui::hidesecs, gui::scale,
130  gui::style, gui::rounding, gui::overlaycolor, gui::linethick,
131  gui::fillalpha, gui::allowquit, gui::twirl>
132  {
133  public:
134  //! Constructor
135  GUIhelper(std::string const & instance, bool conslock = false);
136 
137  //! Destructor
138  virtual ~GUIhelper();
139 
140  //! Start a new rendering frame
141  /*! This should be called on every new video frame to be rendered. Will initialize OpenGL and open the window or
142  screen if needed. Sets the current window size into w and h, returns true if idle (no keyboard/mouse/etc
143  events received in more than hidesecs seconds). */
144  bool startFrame(unsigned short & w, unsigned short & h);
145 
146  //! Check for idle in case startFrame() was called elsewhere
147  bool idle() const;
148 
149  //! Helper to indicate that startFrame() was called, and thus endFrame() should be called
150  /*! Mostly useful during exception handling inside Engine. */
151  bool frameStarted() const;
152 
153  //! Draw a RawImage, copying pixel data to an OpenGL texture
154  /*! Name should be a unique name, and should typically remain constant across successive video frames. This name
155  is used as an index to OpenGL textures, shaders, and programs created to render the images. Note that OpenGL
156  will slow down and eventually run out of resources if you create too many textures, thus Module writers should
157  try to minimize the number of different names that are used. Note that we will add a suffix to the name,
158  corresponding to the bufindex of the RawImage. If you pass w=0 or h=0 then the image will be rescaled to fill
159  the display as much as possible without changing the aspect ratio, and the actually used x,y,w,h will be
160  returned. Otherwise, x,y,w,h are not modified. If noalias is specified, the scaling factor will be rounded
161  down to the nearest integer to prevent aliasing in the display. This may reduce the displayed image size. For
162  example, with a 1920x1080 window, a 640x480 image would be letterboxed to 1440x1080 when noalias is false. But
163  that is a scaling factor of 2.25 which may create rendering aliasing. When noalias is true, the letterboxed
164  image size will be 1280x960 (scale factor of 2.0). If isoverlay is true, then the image is assumed to be a
165  semi-transparent overlay to be drawn on top of a previously drawn image, and we preserve the drawing
166  parameters of that previous image. */
167  void drawImage(char const * name, RawImage const & img, int & x, int & y, unsigned short & w, unsigned short & h,
168  bool noalias = false, bool isoverlay = false);
169 
170  //! Draw an OpenCV image, copying pixel data to an OpenGL texture
171  /*! Name should be a unique name, and should typically remain constant across successive video frames. This name
172  is used as an index to OpenGL textures, shaders, and programs created to render the images. Note that OpenGL
173  will slow down and eventually run out of resources if you create too many textures, thus Module writers should
174  try to minimize the number of different names that are used. If image has three or four 8-bit channels,
175  interpret as RGB[A] if rgb is true, otherwise BGR[A]. If two 8-bit channels, interpret as YUYV. If one,
176  interpret as GRAY. If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as
177  possible without changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if
178  noalias is true, that rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. If
179  isoverlay is true, then the image is assumed to be a semi-transparent overlay to be drawn on top of a
180  previously drawn image, and we preserve the drawing parameters of that previous image. */
181  void drawImage(char const * name, cv::Mat const & img, bool rgb, int & x, int & y, unsigned short & w,
182  unsigned short & h, bool noalias = false, bool isoverlay = false);
183 
184  //! Draw the input video frame from the camera using zero-copy
185  /*! If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without
186  changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if noalias is true, that
187  rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. */
188  void drawInputFrame(char const * name, InputFrame const & frame, int & x, int & y,
189  unsigned short & w, unsigned short & h, bool noalias = false, bool casync = false);
190 
191  //! Draw the second (scaled) input video frame from the camera using zero-copy
192  /*! If you pass w=0 or h=0 then the image will be rescaled to fill the display as much as possible without
193  changing the aspect ratio, and the actually used x,y,w,h will be returned. Further, if noalias is true, that
194  rescaling will ensure an integer scaling factor. Otherwise, x,y,w,h are not modified. Throws unless we are
195  JeVois-Pro Platform and the camera is set to CropScale mode. */
196  void drawInputFrame2(char const * name, InputFrame const & frame, int & x, int & y,
197  unsigned short & w, unsigned short & h, bool noalias = false, bool casync = false);
198 
199  //! Convert coordinates of a point from within a rendered image to on-screen
200  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
201  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
202  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
203  second to first frame. */
204  ImVec2 i2d(ImVec2 p, char const * name = nullptr);
205 
206  //! Convert coordinates of a point from within a rendered image to on-screen
207  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
208  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
209  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
210  second to first frame. */
211  ImVec2 i2d(float x, float y, char const * name = nullptr);
212 
213  //! Convert a 2D size from within a rendered image to on-screen
214  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
215  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
216  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
217  second to first frame. */
218  ImVec2 i2ds(ImVec2 p, char const * name = nullptr);
219 
220  //! Convert a 2D size from within a rendered image to on-screen
221  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
222  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
223  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
224  second to first frame. */
225  ImVec2 i2ds(float x, float y, char const * name = nullptr);
226 
227  //! Draw line over an image
228  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
229  void drawLine(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255));
230 
231  //! Draw rectangular box over an image
232  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
233  void drawRect(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
234 
235  //! Draw polygon over an image
236  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
237  void drawPoly(std::vector<cv::Point> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
238 
239  //! Draw polygon over an image
240  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
241  void drawPoly(std::vector<cv::Point2f> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
242 
243  //! Draw circle over an image
244  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
245  void drawCircle(float x, float y, float r, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
246 
247  //! Draw text over an image
248  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
249  void drawText(float x, float y, char const * txt, ImU32 col = IM_COL32(128,255,128,255));
250 
251  //! Draw text over an image
252  /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
253  void drawText(float x, float y, std::string const & txt, ImU32 col = IM_COL32(128,255,128,255));
254 
255  //! Get coordinates of the start of a given line of text to be drawn as overlay on top of an image
256  /*! Use this to draw overlay text on top of a previously drawn image, it will scale by font size for you. If line
257  is -1, we will increment over the last time this function was called (use with caution). Line number is reset
258  to 0 when drawImage() or drawInputFrame(), etc are called. */
259  ImVec2 iline(int line = -1, char const * name = nullptr);
260 
261  //! Draw some overlay text on top of an image
262  /* If line is -1, we will increment over the last time this function was called (use with caution). Line number is
263  reset to 0 when drawImage() or drawInputFrame(), etc are called. If col is not given, use overlaycolor. */
264  void itext(char const * txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
265 
266  //! Draw some overlay text on top of an image
267  /* If line is -1, we will increment over the last time this function was called (use with caution). Line number is
268  reset to 0 when drawImage() or drawInputFrame(), etc are called. If col is not given, use overlaycolor. */
269  void itext(std::string const & txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
270 
271  //! Display processing and video info at bottom of screen
272  /*! This helper is to be used by modules to provide a consistent info display at the bottom of the screen.
273  fpscpu should be the string returned by Timer::stop(). If winw and winh are not given, will query from display
274  backend, which will cost a few CPU cycles; so pass it on if you already have it, e.g, from running
275  startFrame() previously. */
276  void iinfo(jevois::InputFrame const & inframe, std::string const & fpscpu,
277  unsigned short winw = 0, unsigned short winh = 0);
278 
279  //! Release an image
280  /*! Call this if you plan on re-using the same image name later for an image of different size or
281  format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the
282  same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is
283  not found, i.e., has not been drawn before. */
284  void releaseImage(char const * name);
285 
286  //! Release an image, second video stream
287  /*! Call this if you plan on re-using the same image name later for an image of different size or
288  format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the
289  same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is
290  not found, i.e., has not been drawn before. */
291  void releaseImage2(char const * name);
292 
293  //! Finish current frame and render it
294  /*! This should be called once for every call to startFrame(). */
295  void endFrame();
296 
297  //! Reset to default state, typically called on Module or video format change
298  /*! Free images, reset matrices, etc. */
299  void reset(bool modulechanged = true);
300 
301  //! Report an error in an overlay window
302  void reportError(std::string const & err);
303 
304  //! Report current exception in a modal dialog, then ignore it
305  void reportAndIgnoreException(std::string const & prefix = "");
306 
307  //! Report current exception in a modal dialog, then re-throw it
308  void reportAndRethrowException(std::string const & prefix = "");
309 
310  //! Clear all errors currently displayed in the JeVois-Pro GUI
311  /*! In the JevoisPro GUI, errors reported via reportError() remain displayed for a few seconds, but sometimes we
312  want to clear them right away, e.g., after DNN pipeline threw, if the user selects another one, we want the
313  previous error to disappear immediately since it is not applicable anymore. */
314  void clearErrors();
315 
316  //! Z distance from camera to image plane to achieve pixel-perfect rendering
317  float const pixel_perfect_z = 0.0F;
318 
319  //! Our projection matrix
320  glm::mat4 proj;
321 
322  //! Our view matrix
323  /*! On the first call to startFrame(), the whole OpenGL engine is initialized and the view matrix is set so that
324  the pixel perfect image plane is vertical and centered on the origin, while the camera is translated in
325  negative Z to achieve pixel perfect rendering. */
326  glm::mat4 view;
327 
328  //! Display a (?) label and show tooltip when it is hovered
329  /*! If 2 or more messages are provided, they will be separated by a separator. */
330  void helpMarker(char const * msg, char const * msg2 = nullptr, char const * msg3 = nullptr);
331 
332  //! Helper to draw a toggle button
333  bool toggleButton(char const * name, bool * val);
334 
335  //! Helper to draw a modal with 2 choices
336  /*! Returns 1 if the first button was clicked, 2 if the second was, or some other value if no button was clicked
337  (caller should just wait and try again at the next frame if not 1 or 2, passing again that returned value). By
338  default, the first button is in focus. If default_val is not nullptr, add a "don't ask again" checkbox. If
339  *default_val is 1 or 2, just return that without even showing the modal. */
340  int modal(std::string const & title, char const * text, int * default_val = nullptr,
341  char const * b1txt = "Ok", char const * b2txt = "Cancel");
342 
343  //! Show a message that we are running headless
344  void headlessDisplay();
345 
346  //! Tell whether user enabled serlog messages to GUI console
347  bool serlogEnabled() const;
348 
349  //! Tell whether user enabled serout messages to GUI console
350  bool seroutEnabled() const;
351 
352  //! Convert coordinates of a point from on-screen to within a rendered image
353  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
354  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
355  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
356  second to first frame. */
357  ImVec2 d2i(ImVec2 p, char const * name = nullptr);
358 
359  //! Convert coordinates of a point from on-screen to within a rendered image
360  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
361  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
362  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
363  second to first frame. */
364  ImVec2 d2i(float x, float y, char const * name = nullptr);
365 
366  //! Convert a 2D size from on-screen to within a rendered image
367  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
368  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
369  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
370  second to first frame. */
371  ImVec2 d2is(ImVec2 p, char const * name = nullptr);
372 
373  //! Convert a 2D size from on-screen to within a rendered image
374  /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
375  drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
376  full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
377  second to first frame. */
378  ImVec2 d2is(float x, float y, char const * name = nullptr);
379 
380  //! Compile a newly created module
381  /*! This is mainly for internal use. Called by the code editor when saving C++ code to let us know to start the
382  compilation process again. itsNewMapping should contain the new module's data. */
383  void startCompilation();
384 
385  //! Like ImGui::Textunformatted but in a highlight color (typically, red)
386  void highlightText(std::string const & str);
387 
388  //! Display some text in a big banner, used by demo mode
389  /*! Any non-empty banner remains on screen until demoBanner() called again with empty title (default args). */
390  void demoBanner(std::string const & title = "", std::string const & msg = "");
391 
392  protected:
393  std::map<std::string /* name */, GPUimage> itsImages, itsImages2;
396  bool itsUsingScaledImage = false;
398 
399  std::chrono::time_point<std::chrono::steady_clock> itsLastEventTime;
400  bool itsIdle = true; //!< Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI
401  bool itsIdleBlocked = false; //!< While creating/compiling new modules, prevent idle
402  bool itsEndFrameCalled = true; // try to avoid violent assert() crash from ImGui if user forgets to endFrame()
403 
404  mutable std::mutex itsErrorMtx;
405  struct ErrorData
406  {
407  std::string err;
408  std::chrono::time_point<std::chrono::steady_clock> firsttime;
409  std::chrono::time_point<std::chrono::steady_clock> lasttime;
410  };
411  std::list<ErrorData> itsErrors;
412 
413  std::set<std::string> itsOpenModals;
414 
415  void drawPolyInternal(ImVec2 const * pts, size_t npts, ImU32 col, bool filled);
416  ImU32 applyFillAlpha(ImU32 col) const;
417 
419 #ifdef JEVOIS_PLATFORM_PRO
421 #else
422  ImGuiBackendSDL itsBackend;
423 #endif
424  std::string itsWindowTitle;
427  std::string itsModName;
428  std::string itsModDesc;
429  std::string itsModAuth;
430  std::string itsModLang;
431  std::vector<std::string> itsModDoc;
432  gui::GuiStyle itsCurrentStyle = gui::GuiStyle::Dark;
433  bool itsShowStyleEditor = false;
434  bool itsShowAppMetrics = false;
435  bool itsShowImGuiDemo = false;
436  bool itsSerLogEnabled = true;
437  bool itsSerOutEnabled = false;
438 
439  void drawJeVoisGUI();
440  void drawInfo();
441  void drawParameters();
442  void drawConsole();
443  void drawCamCtrls();
444  void drawTweaks();
445  void drawSystem();
446  void drawMenuBar();
447  void drawModuleSelect();
448  void drawErrorPopup();
449  void drawNewModuleForm();
450  void compileModule();
451 
452  void newModEntry(char const * wname, std::string & str, char const * desc, char const * hint, char const * hlp);
453 
454  // Set a parameter by string, catch any exception and report it in popup modal
455  void setparstr(std::string const & descriptor, std::string const & val);
456 
457  // Set a parameter by value, catch any exception and report it in popup modal
458  template <class T>
459  void setparval(std::string const & descriptor, T const & val);
460 
461  void onParamChange(gui::scale const & param, float const & newval) override;
462  void onParamChange(gui::rounding const & param, int const & newval) override;
463  void onParamChange(gui::style const & param, gui::GuiStyle const & newval) override;
464  void onParamChange(gui::twirl const & param, float const & newval) override;
465 
466  // Config files:
467  std::shared_ptr<GUIeditor> itsCfgEditor;
468 
469  // Code editing:
470  std::shared_ptr<GUIeditor> itsCodeEditor;
471 
472  // dnnget helpers
473  std::future<std::string> itsDnnGetFut;
474 
475  // Flag to refresh video mappings when we save the file or add a new one by creating a new module:
478 
479  // Flag to indicate whether we have a USB serial gadget
480  bool itsUSBserial = false;
481 
482  // Compilation progress
484  CompilationState itsCompileState = CompilationState::Idle;
485  VideoMapping itsNewMapping = { };
486  std::future<std::string> itsCompileFut;
487  bool compileCommand(std::string const & cmd, std::string & msg); // true on success, false in progress, throws
488  std::array<std::string, 4> itsCompileMessages; // messages for the compilation steps
489  void runNewModule(); // install and load up the module defined in itsNewMapping
490 
491  // Banner stuff:
493  float itsGlobalAlpha = 1.0F;
494  };
495 
496 } // namespace jevois
497 
498 // Include inlined implementation details that are of no interest to the end user
499 #include <jevois/GPU/details/GUIhelperImpl.H>
500 
501 #endif // JEVOIS_PRO
jevois::GUIhelper::ErrorData
Definition: GUIhelper.H:405
jevois::Component::descriptor
std::string descriptor() const
Get our full descriptor (including all parents) as [Instancename]:[...]:[...].
Definition: Component.C:276
jevois::GUIhelper::itsCodeEditor
std::shared_ptr< GUIeditor > itsCodeEditor
Definition: GUIhelper.H:470
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:288
jevois::GUIhelper::highlightText
void highlightText(std::string const &str)
Like ImGui::Textunformatted but in a highlight color (typically, red)
Definition: GUIhelper.C:2621
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:365
jevois::GUIhelper::drawNewModuleForm
void drawNewModuleForm()
Definition: GUIhelper.C:1913
jevois::GUIhelper::idle
bool idle() const
Check for idle in case startFrame() was called elsewhere.
Definition: GUIhelper.C:227
jevois::GUIhelper::reportAndIgnoreException
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
Definition: GUIhelper.C:2491
jevois::GUIhelper::itsSerLogEnabled
bool itsSerLogEnabled
Definition: GUIhelper.H:436
jevois::Range
A generic range class.
Definition: Range.H:80
jevois::GUIhelper::drawMenuBar
void drawMenuBar()
Definition: GUIhelper.C:839
jevois::GUIhelper::demoBanner
void demoBanner(std::string const &title="", std::string const &msg="")
Display some text in a big banner, used by demo mode.
Definition: GUIhelper.C:2629
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:528
jevois::GUIhelper::itsModLang
std::string itsModLang
Definition: GUIhelper.H:430
jevois::GUIhelper::itsImages2
std::map< std::string, GPUimage > itsImages2
Definition: GUIhelper.H:393
jevois::GUIhelper::startFrame
bool startFrame(unsigned short &w, unsigned short &h)
Start a new rendering frame.
Definition: GUIhelper.C:169
jevois::GUIhelper::modal
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.
Definition: GUIhelper.C:1530
jevois::GUIhelper::compileCommand
bool compileCommand(std::string const &cmd, std::string &msg)
Definition: GUIhelper.C:2802
jevois::GUIhelper::runNewModule
void runNewModule()
Definition: GUIhelper.C:2351
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:571
jevois::GUIhelper::onParamChange
void onParamChange(gui::scale const &param, float const &newval) override
jevois::GUIhelper::drawInfo
void drawInfo()
Definition: GUIhelper.C:975
JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(thresh1, double, "First threshold for hysteresis", 50.0, ParamCateg)
jevois::GUIhelper::itsSerOutEnabled
bool itsSerOutEnabled
Definition: GUIhelper.H:437
jevois::GUIhelper::setparstr
void setparstr(std::string const &descriptor, std::string const &val)
Definition: GUIhelper.C:1149
jevois::GPUimage
Class to hold a GPUtexture, GPUprogram, and other data associated with rendering an image in OpenGL.
Definition: GPUimage.H:38
jevois::GUIhelper::headlessDisplay
void headlessDisplay()
Show a message that we are running headless.
Definition: GUIhelper.C:2601
jevois::GUIhelper::drawPolyInternal
void drawPolyInternal(ImVec2 const *pts, size_t npts, ImU32 col, bool filled)
Definition: GUIhelper.C:491
jevois::GUIhelper::endFrame
void endFrame()
Finish current frame and render it.
Definition: GUIhelper.C:693
jevois::Component
A component of a model hierarchy.
Definition: Component.H:181
jevois::GUIhelper::itsOpenModals
std::set< std::string > itsOpenModals
Definition: GUIhelper.H:413
jevois::GUIhelper::reportAndRethrowException
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
Definition: GUIhelper.C:2516
jevois::GUIhelper::releaseImage
void releaseImage(char const *name)
Release an image.
Definition: GUIhelper.C:605
jevois::GUIhelper::itsIdle
bool itsIdle
Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI.
Definition: GUIhelper.H:400
jevois::GUIhelper::itsErrors
std::list< ErrorData > itsErrors
Definition: GUIhelper.H:411
jevois::GUIhelper::drawTweaks
void drawTweaks()
Definition: GUIhelper.C:2385
jevois::GUIhelper::newModEntry
void newModEntry(char const *wname, std::string &str, char const *desc, char const *hint, char const *hlp)
Definition: GUIhelper.C:1583
jevois::ImGuiImage
Wrapper for an image that can be rendered into ImGui.
Definition: ImGuiImage.H:30
jevois::GUIhelper::itsUsingScaledImage
bool itsUsingScaledImage
Definition: GUIhelper.H:396
jevois::GUIhelper::clearErrors
void clearErrors()
Clear all errors currently displayed in the JeVois-Pro GUI.
Definition: GUIhelper.C:2484
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::d2i
ImVec2 d2i(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from on-screen to within a rendered image.
Definition: GUIhelper.C:619
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:2565
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:401
jevois::GUIhelper::itsRefreshVideoMappings
bool itsRefreshVideoMappings
Definition: GUIhelper.H:476
jevois::GUIhelper::drawErrorPopup
void drawErrorPopup()
Definition: GUIhelper.C:2523
jevois::GUIhelper::drawModuleSelect
void drawModuleSelect()
Definition: GUIhelper.C:895
jevois::ParameterCategory
A category to which multiple ParameterDef definitions can belong.
Definition: ParameterDef.H:33
jevois::GUIhelper::drawParameters
void drawParameters()
Definition: GUIhelper.C:1157
jevois::GUIhelper::itsModName
std::string itsModName
Definition: GUIhelper.H:427
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:479
jevois::GUIhelper::drawCamCtrls
void drawCamCtrls()
Definition: GUIhelper.C:1524
jevois::GUIhelper::itsDnnGetFut
std::future< std::string > itsDnnGetFut
Definition: GUIhelper.H:473
jevois::GUIhelper::itsCurrentStyle
gui::GuiStyle itsCurrentStyle
Definition: GUIhelper.H:432
jevois::GUIhelper::itsScaledImageFacX
float itsScaledImageFacX
Definition: GUIhelper.H:397
jevois::GUIhelper
Helper class to assist modules in creating graphical and GUI elements.
Definition: GUIhelper.H:128
jevois::GUIhelper::itsLastDrawnImage
GPUimage * itsLastDrawnImage
Definition: GUIhelper.H:394
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:473
jevois::GUIhelper::seroutEnabled
bool seroutEnabled() const
Tell whether user enabled serout messages to GUI console.
Definition: GUIhelper.C:1520
jevois::GUIhelper::itsShowStyleEditor
bool itsShowStyleEditor
Definition: GUIhelper.H:433
jevois::GUIhelper::itsLastEventTime
std::chrono::time_point< std::chrono::steady_clock > itsLastEventTime
Definition: GUIhelper.H:399
jevois::GUIhelper::itsImages
std::map< std::string, GPUimage > itsImages
Definition: GUIhelper.H:393
jevois::GUIhelper::Make
@ Make
Definition: GUIhelper.H:483
jevois::GUIhelper::proj
glm::mat4 proj
Our projection matrix.
Definition: GUIhelper.H:320
jevois::GUIhelper::reportError
void reportError(std::string const &err)
Report an error in an overlay window.
Definition: GUIhelper.C:2458
jevois
Definition: Concepts.dox:1
jevois::GUIhelper::itsUSBserial
bool itsUSBserial
Definition: GUIhelper.H:480
jevois::GUIhelper::ErrorData::lasttime
std::chrono::time_point< std::chrono::steady_clock > lasttime
Definition: GUIhelper.H:409
jevois::GUIhelper::itsModDesc
std::string itsModDesc
Definition: GUIhelper.H:428
F
float F
Definition: GUIhelper.C:2373
Component.H
jevois::GUIhelper::Install
@ Install
Definition: GUIhelper.H:483
jevois::GUIhelper::itsBackend
ImGuiBackendMALI itsBackend
Definition: GUIhelper.H:420
Engine.H
jevois::GUIhelper::Idle
@ Idle
Definition: GUIhelper.H:483
jevois::GUIhelper::itsConsLock
bool itsConsLock
Definition: GUIhelper.H:418
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:506
jevois::GUIhelper::Success
@ Success
Definition: GUIhelper.H:483
ImGuiBackendSDL.H
jevois::GUIhelper::Error
@ Error
Definition: GUIhelper.H:483
jevois::GUIhelper::Start
@ Start
Definition: GUIhelper.H:483
jevois::GUIhelper::itsNewMapping
VideoMapping itsNewMapping
Definition: GUIhelper.H:485
jevois::GUIhelper::toggleButton
bool toggleButton(char const *name, bool *val)
Helper to draw a toggle button.
Definition: GUIhelper.C:2582
jevois::GUIhelper::reset
void reset(bool modulechanged=true)
Reset to default state, typically called on Module or video format change.
Definition: GUIhelper.C:114
jevois::GUIhelper::frameStarted
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
Definition: GUIhelper.C:284
jevois::GUIhelper::Cmake
@ Cmake
Definition: GUIhelper.H:483
jevois::GUIhelper::itsIdleBlocked
bool itsIdleBlocked
While creating/compiling new modules, prevent idle.
Definition: GUIhelper.H:401
jevois::GUIhelper::drawJeVoisGUI
void drawJeVoisGUI()
Definition: GUIhelper.C:758
jevois::GUIhelper::itsHeadless
ImGuiImage itsHeadless
Definition: GUIhelper.H:426
jevois::GUIhelper::itsShowImGuiDemo
bool itsShowImGuiDemo
Definition: GUIhelper.H:435
jevois::GUIhelper::serlogEnabled
bool serlogEnabled() const
Tell whether user enabled serlog messages to GUI console.
Definition: GUIhelper.C:1516
jevois::GUIhelper::releaseImage2
void releaseImage2(char const *name)
Release an image, second video stream.
Definition: GUIhelper.C:612
jevois::GUIhelper::itsModDoc
std::vector< std::string > itsModDoc
Definition: GUIhelper.H:431
jevois::GUIhelper::drawSystem
void drawSystem()
Definition: GUIhelper.C:1598
jevois::GUIhelper::itsEndFrameCalled
bool itsEndFrameCalled
Definition: GUIhelper.H:402
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:541
jevois::GUIhelper::itsCompileFut
std::future< std::string > itsCompileFut
Definition: GUIhelper.H:486
jevois::GUIhelper::ErrorData::err
std::string err
Definition: GUIhelper.H:407
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:326
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:335
jevois::GUIhelper::itsBannerMsg
std::string itsBannerMsg
Definition: GUIhelper.H:492
jevois::GUIhelper::drawConsole
void drawConsole()
Definition: GUIhelper.C:1396
jevois::GUIhelper::compileModule
void compileModule()
Definition: GUIhelper.C:2646
jevois::GUIhelper::itsCompileMessages
std::array< std::string, 4 > itsCompileMessages
Definition: GUIhelper.H:488
jevois::GUIhelper::itsErrorMtx
std::mutex itsErrorMtx
Definition: GUIhelper.H:404
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:584
jevois::ImGuiBackendMALI
BackendMALI for ImGui on JeVois-Pro.
Definition: ImGuiBackendMALI.H:86
jevois::GUIhelper::CompilationState
CompilationState
Definition: GUIhelper.H:483
jevois::GUIhelper::itsWindowTitle
std::string itsWindowTitle
Definition: GUIhelper.H:424
jevois::InputFrame
Exception-safe wrapper around a raw camera input frame.
Definition: InputFrame.H:50
jevois::GUIhelper::d2is
ImVec2 d2is(ImVec2 p, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
Definition: GUIhelper.C:656
jevois::GUIhelper::itsLastDrawnTextLine
int itsLastDrawnTextLine
Definition: GUIhelper.H:395
jevois::GUIhelper::itsCfgEditor
std::shared_ptr< GUIeditor > itsCfgEditor
Definition: GUIhelper.H:467
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:437
jevois::GUIhelper::itsScaledImageFacY
float itsScaledImageFacY
Definition: GUIhelper.H:397
jevois::GUIhelper::itsCompileState
CompilationState itsCompileState
Definition: GUIhelper.H:484
jevois::GUIhelper::itsModAuth
std::string itsModAuth
Definition: GUIhelper.H:429
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:561
h
int h
Definition: GUIhelper.C:2373
ImGuiImage.H
jevois::GUIhelper::itsShowAppMetrics
bool itsShowAppMetrics
Definition: GUIhelper.H:434
jevois::GUIhelper::itsVideoMappingListType
int itsVideoMappingListType
Definition: GUIhelper.H:477
jevois::JEVOIS_DEFINE_ENUM_CLASS
JEVOIS_DEFINE_ENUM_CLASS(CameraSensor,(any)(imx290)(os08a10)(ar0234))
Enum for different sensor models.
jevois::GUIhelper::startCompilation
void startCompilation()
Compile a newly created module.
Definition: GUIhelper.C:2637
jevois::GUIhelper::itsGlobalAlpha
float itsGlobalAlpha
Definition: GUIhelper.H:493
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:317
jevois::GUIhelper::itsBannerTitle
std::string itsBannerTitle
Definition: GUIhelper.H:492
jevois::GUIhelper::applyFillAlpha
ImU32 applyFillAlpha(ImU32 col) const
Definition: GUIhelper.C:553
ImGuiBackendMALI.H
jevois::GUIhelper::itsIcon
ImGuiImage itsIcon
Definition: GUIhelper.H:425
jevois::GUIhelper::~GUIhelper
virtual ~GUIhelper()
Destructor.
Definition: GUIhelper.C:107
jevois::GUIhelper::setparval
void setparval(std::string const &descriptor, T const &val)
jevois::GUIhelper::ErrorData::firsttime
std::chrono::time_point< std::chrono::steady_clock > firsttime
Definition: GUIhelper.H:408
jevois::GUIhelper::CPack
@ CPack
Definition: GUIhelper.H:483
Enum.H