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