JeVois  1.22
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 Color order is IMCOL_32(R,G,B,A). */
231 void drawLine(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255));
232
233 //! Draw rectangular box over an image
234 /*! Coordinates used should be image coordinates, as this function internally calls i2d().
235 Color order is IMCOL_32(R,G,B,A). */
236 void drawRect(float x1, float y1, float x2, float y2, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
237
238 //! Draw polygon over an image
239 /*! Coordinates used should be image coordinates, as this function internally calls i2d().
240 Color order is IMCOL_32(R,G,B,A). */
241 void drawPoly(std::vector<cv::Point> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
242
243 //! Draw polygon over an image
244 /*! Coordinates used should be image coordinates, as this function internally calls i2d().
245 Color order is IMCOL_32(R,G,B,A). */
246 void drawPoly(std::vector<cv::Point2f> const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
247
248 //! Draw polygon over an image
249 /*! 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
250 x,y,x,y,x,y...; or CV_32FC2 and 1xN or Nx1. If N < 2, nothing is drawn. Other shapes are illegal.
251 Color order is IMCOL_32(R,G,B,A). */
252 void drawPoly(cv::Mat const & pts, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
253
254 //! Draw circle over an image
255 /*! Coordinates used should be image coordinates, as this function internally calls i2d().
256 Color order is IMCOL_32(R,G,B,A). */
257 void drawCircle(float x, float y, float r, ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
258
259 //! Draw ellipse over an image
260 /*! Coordinates used should be image coordinates, as this function internally calls i2d(). */
261 void drawEllipse(float x, float y, float rx, float ry, float rot = 0.0F,
262 ImU32 col = IM_COL32(128,255,128,255), bool filled = true);
263
264 //! Draw text over an image
265 /*! Coordinates used should be image coordinates, as this function internally calls i2d().
266 Color order is IMCOL_32(R,G,B,A). */
267 void drawText(float x, float y, char const * txt, ImU32 col = IM_COL32(128,255,128,255));
268
269 //! Draw text over an image
270 /*! Coordinates used should be image coordinates, as this function internally calls i2d().
271 Color order is IMCOL_32(R,G,B,A). */
272 void drawText(float x, float y, std::string const & txt, ImU32 col = IM_COL32(128,255,128,255));
273
274 //! Get coordinates of the start of a given line of text to be drawn as overlay on top of an image
275 /*! Use this to draw overlay text on top of a previously drawn image, it will scale by font size for you. If line
276 is -1, we will increment over the last time this function was called (use with caution). Line number is reset
277 to 0 when drawImage() or drawInputFrame(), etc are called. */
278 ImVec2 iline(int line = -1, char const * name = nullptr);
279
280 //! Draw some overlay text on top of an image
281 /* If line is -1, we will increment over the last time this function was called (use with caution). Line number is
282 reset to 0 when drawImage() or drawInputFrame(), etc are called. If col is not given, use overlaycolor. Color
283 order is IMCOL_32(R,G,B,A). */
284 void itext(char const * txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
285
286 //! Draw some overlay text on top of an image
287 /* If line is -1, we will increment over the last time this function was called (use with caution). Line number is
288 reset to 0 when drawImage() or drawInputFrame(), etc are called. If col is not given, use overlaycolor. Color
289 order is IMCOL_32(R,G,B,A). */
290 void itext(std::string const & txt, ImU32 const & col = IM_COL32_BLACK_TRANS, int line = -1);
291
292 //! Display processing and video info at bottom of screen
293 /*! This helper is to be used by modules to provide a consistent info display at the bottom of the screen.
294 fpscpu should be the string returned by Timer::stop(). If winw and winh are not given, will query from display
295 backend, which will cost a few CPU cycles; so pass it on if you already have it, e.g, from running
296 startFrame() previously. */
297 void iinfo(jevois::InputFrame const & inframe, std::string const & fpscpu,
298 unsigned short winw = 0, unsigned short winh = 0);
299
300 //! Release an image
301 /*! Call this if you plan on re-using the same image name later for an image of different size or
302 format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the
303 same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is
304 not found, i.e., has not been drawn before. */
305 void releaseImage(char const * name);
306
307 //! Release an image, second video stream
308 /*! Call this if you plan on re-using the same image name later for an image of different size or
309 format. Otherwise, once an image has been used once, its OpenGL texture (including its dims) will remain the
310 same and only the pixel values will be updated when the image is drawn again. Silently ignores if the image is
311 not found, i.e., has not been drawn before. */
312 void releaseImage2(char const * name);
313
314 //! Finish current frame and render it
315 /*! This should be called once for every call to startFrame(). */
316 void endFrame();
317
318 //! Reset to default state, typically called on Module or video format change
319 /*! Free images, reset matrices, etc. */
320 void resetstate(bool modulechanged = true);
321
322 //! Report an error in an overlay window
323 void reportError(std::string const & err);
324
325 //! Report current exception in a modal dialog, then ignore it
326 void reportAndIgnoreException(std::string const & prefix = "");
327
328 //! Report current exception in a modal dialog, then re-throw it
329 void reportAndRethrowException(std::string const & prefix = "");
330
331 //! Clear all errors currently displayed in the JeVois-Pro GUI
332 /*! In the JevoisPro GUI, errors reported via reportError() remain displayed for a few seconds, but sometimes we
333 want to clear them right away, e.g., after DNN pipeline threw, if the user selects another one, we want the
334 previous error to disappear immediately since it is not applicable anymore. */
335 void clearErrors();
336
337 //! Z distance from camera to image plane to achieve pixel-perfect rendering
338 float const pixel_perfect_z = 0.0F;
339
340 //! Our projection matrix
341 glm::mat4 proj;
342
343 //! Our view matrix
344 /*! On the first call to startFrame(), the whole OpenGL engine is initialized and the view matrix is set so that
345 the pixel perfect image plane is vertical and centered on the origin, while the camera is translated in
346 negative Z to achieve pixel perfect rendering. */
347 glm::mat4 view;
348
349 //! Display a (?) label and show tooltip when it is hovered
350 /*! If 2 or more messages are provided, they will be separated by a separator. */
351 void helpMarker(char const * msg, char const * msg2 = nullptr, char const * msg3 = nullptr);
352
353 //! Helper to draw a toggle button
354 bool toggleButton(char const * name, bool * val);
355
356 //! Helper to draw a modal with 2 choices
357 /*! Returns 1 if the first button was clicked, 2 if the second was, or some other value if no button was clicked
358 (caller should just wait and try again at the next frame if not 1 or 2, passing again that returned value). By
359 default, the first button is in focus. If default_val is not nullptr, add a "don't ask again" checkbox. If
360 *default_val is 1 or 2, just return that without even showing the modal. */
361 int modal(std::string const & title, char const * text, int * default_val = nullptr,
362 char const * b1txt = "Ok", char const * b2txt = "Cancel");
363
364 //! Helper to draw a combobox from a vector of strings
365 /*! Note that selected_index is read-write: the passed value is used to display the current item in the combobox,
366 and, when a new item is selected, its index is returned in selected_index and true is returned. */
367 bool combo(std::string const & name, std::vector<std::string> const & items, int & selected_index);
368
369 //! Show a message that we are running headless
370 void headlessDisplay();
371
372 //! Tell whether user enabled serlog messages to GUI console
373 bool serlogEnabled() const;
374
375 //! Tell whether user enabled serout messages to GUI console
376 bool seroutEnabled() const;
377
378 //! Convert coordinates of a point from on-screen to within a rendered image
379 /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
380 drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
381 full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
382 second to first frame. */
383 ImVec2 d2i(ImVec2 p, char const * name = nullptr);
384
385 //! Convert coordinates of a point from on-screen to within a rendered image
386 /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
387 drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
388 full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
389 second to first frame. */
390 ImVec2 d2i(float x, float y, char const * name = nullptr);
391
392 //! Convert a 2D size from on-screen to within a rendered image
393 /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
394 drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
395 full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
396 second to first frame. */
397 ImVec2 d2is(ImVec2 p, char const * name = nullptr);
398
399 //! Convert a 2D size from on-screen to within a rendered image
400 /*! If name is nullptr, the last image used by drawImage() or drawInputFrame() is used. In such case, if
401 drawInputFrame() was called on a frame that also had a second, scaled image, assume that we have displayed the
402 full-resolution input frame but sent the scaled image to processing, and that hence we also need to scale from
403 second to first frame. */
404 ImVec2 d2is(float x, float y, char const * name = nullptr);
405
406 //! Compile a newly created module
407 /*! This is mainly for internal use. Called by the code editor when saving C++ code to let us know to start the
408 compilation process again. itsNewMapping should contain the new module's data. */
409 void startCompilation();
410
411 //! Like ImGui::Textunformatted but in a highlight color (typically, red)
412 void highlightText(std::string const & str);
413
414 //! Display some text in a big banner, used by demo mode
415 /*! Any non-empty banner remains on screen until demoBanner() called again with empty title (default args). */
416 void demoBanner(std::string const & title = "", std::string const & msg = "");
417
418 protected:
419 std::map<std::string /* name */, GPUimage> itsImages, itsImages2;
424
425 std::chrono::time_point<std::chrono::steady_clock> itsLastEventTime;
426 bool itsIdle = true; //!< Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI
427 bool itsIdleBlocked = false; //!< While creating/compiling new modules, prevent idle
428 bool itsEndFrameCalled = true; // try to avoid violent assert() crash from ImGui if user forgets to endFrame()
429
430 mutable std::mutex itsErrorMtx;
432 {
433 std::string err;
434 std::chrono::time_point<std::chrono::steady_clock> firsttime;
435 std::chrono::time_point<std::chrono::steady_clock> lasttime;
436 };
437 std::list<ErrorData> itsErrors;
438
439 std::set<std::string> itsOpenModals;
440
441 void drawPolyInternal(ImVec2 const * pts, size_t npts, ImU32 col, bool filled);
442 ImU32 applyFillAlpha(ImU32 col) const;
443
445#ifdef JEVOIS_PLATFORM_PRO
447#else
448 ImGuiBackendSDL itsBackend;
449#endif
450 std::string itsWindowTitle;
453 std::string itsModName;
454 std::string itsModDesc;
455 std::string itsModAuth;
456 std::string itsModLang;
457 std::vector<std::string> itsModDoc;
458 gui::GuiStyle itsCurrentStyle = gui::GuiStyle::Dark;
459 bool itsShowStyleEditor = false;
460 bool itsShowAppMetrics = false;
461 bool itsShowImGuiDemo = false;
462 bool itsSerLogEnabled = true;
463 bool itsSerOutEnabled = false;
466
467 void drawJeVoisGUI();
468 void drawInfo();
469 void drawParameters();
470 void drawConsole();
471 void drawCamCtrls();
472 void drawTweaks();
473 void drawSystem();
474 void drawMenuBar();
475 void drawModuleSelect();
476 void drawErrorPopup();
477 void drawNewModuleForm();
478 void compileModule();
479
480 void newModEntry(char const * wname, std::string & str, char const * desc, char const * hint, char const * hlp);
481
482 // Set a parameter by string, catch any exception and report it in popup modal
483 void setparstr(std::string const & descriptor, std::string const & val);
484
485 // Set a parameter by value, catch any exception and report it in popup modal
486 template <class T>
487 void setparval(std::string const & descriptor, T const & val);
488
489 void onParamChange(gui::scale const & param, float const & newval) override;
490 void onParamChange(gui::rounding const & param, int const & newval) override;
491 void onParamChange(gui::style const & param, gui::GuiStyle const & newval) override;
492 void onParamChange(gui::twirl const & param, float const & newval) override;
493
494 // Config files:
495 std::shared_ptr<GUIeditor> itsCfgEditor;
496
497 // Code editing:
498 std::shared_ptr<GUIeditor> itsCodeEditor;
499
500 // dnnget helpers
501 std::future<std::string> itsDnnGetFut;
502
503 // Flag to refresh video mappings when we save the file or add a new one by creating a new module:
506
507 // Flag to indicate whether we have a USB serial gadget
508 bool itsUSBserial = false;
509
510 // Compilation progress
514 std::future<std::string> itsCompileFut;
515 bool compileCommand(std::string const & cmd, std::string & msg); // true on success, false in progress, throws
516 std::array<std::string, 4> itsCompileMessages; // messages for the compilation steps
517 void runNewModule(); // install and load up the module defined in itsNewMapping
518
519 // Banner stuff:
521 float itsGlobalAlpha = 1.0F;
522 };
523
524} // namespace jevois
525
526// Include inlined implementation details that are of no interest to the end user
527#include <jevois/GPU/details/GUIhelperImpl.H>
528
529#endif // JEVOIS_PRO
int h
Definition GUIhelper.C:2520
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:341
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:437
std::map< std::string, GPUimage > itsImages2
Definition GUIhelper.H:419
std::string itsBannerMsg
Definition GUIhelper.H:520
std::string itsBannerTitle
Definition GUIhelper.H:520
void endFrame()
Finish current frame and render it.
Definition GUIhelper.C:776
bool seroutEnabled() const
Tell whether user enabled serout messages to GUI console.
Definition GUIhelper.C:1647
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:1710
void resetstate(bool modulechanged=true)
Reset to default state, typically called on Module or video format change.
Definition GUIhelper.C:114
VideoMapping itsNewMapping
Definition GUIhelper.H:513
std::shared_ptr< GUIeditor > itsCfgEditor
Definition GUIhelper.H:495
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:644
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:2638
bool itsIdleBlocked
While creating/compiling new modules, prevent idle.
Definition GUIhelper.H:427
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:334
bool startFrame(unsigned short &w, unsigned short &h)
Start a new rendering frame.
Definition GUIhelper.C:169
GPUimage * itsLastDrawnImage
Definition GUIhelper.H:420
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:436
bool itsShowHardSerialWin
Definition GUIhelper.H:464
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:624
std::mutex itsErrorMtx
Definition GUIhelper.H:430
void drawEllipse(float x, float y, float rx, float ry, float rot=0.0F, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw ellipse over an image.
Definition GUIhelper.C:611
std::set< std::string > itsOpenModals
Definition GUIhelper.H:439
virtual ~GUIhelper()
Destructor.
Definition GUIhelper.C:107
std::string itsModName
Definition GUIhelper.H:453
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:478
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:283
void startCompilation()
Compile a newly created module.
Definition GUIhelper.C:2784
ImGuiImage itsHeadless
Definition GUIhelper.H:452
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:364
std::shared_ptr< GUIeditor > itsCodeEditor
Definition GUIhelper.H:498
void drawNewModuleForm()
Definition GUIhelper.C:2060
void clearErrors()
Clear all errors currently displayed in the JeVois-Pro GUI.
Definition GUIhelper.C:2631
std::string itsModAuth
Definition GUIhelper.H:455
void newModEntry(char const *wname, std::string &str, char const *desc, char const *hint, char const *hlp)
Definition GUIhelper.C:1724
void releaseImage(char const *name)
Release an image.
Definition GUIhelper.C:688
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:667
glm::mat4 view
Our view matrix.
Definition GUIhelper.H:347
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:2712
void demoBanner(std::string const &title="", std::string const &msg="")
Display some text in a big banner, used by demo mode.
Definition GUIhelper.C:2776
void highlightText(std::string const &str)
Like ImGui::Textunformatted but in a highlight color (typically, red)
Definition GUIhelper.C:2768
void reportError(std::string const &err)
Report an error in an overlay window.
Definition GUIhelper.C:2605
void headlessDisplay()
Show a message that we are running headless.
Definition GUIhelper.C:2748
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
Definition GUIhelper.C:400
float const pixel_perfect_z
Z distance from camera to image plane to achieve pixel-perfect rendering.
Definition GUIhelper.H:338
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
Definition GUIhelper.C:2663
void drawModuleSelect()
Definition GUIhelper.C:1020
CompilationState itsCompileState
Definition GUIhelper.H:512
bool idle() const
Check for idle in case startFrame() was called elsewhere.
Definition GUIhelper.C:227
ImVec2 d2is(ImVec2 p, char const *name=nullptr)
Convert a 2D size from on-screen to within a rendered image.
Definition GUIhelper.C:739
ImGuiImage itsIcon
Definition GUIhelper.H:451
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:472
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:654
void releaseImage2(char const *name)
Release an image, second video stream.
Definition GUIhelper.C:695
float itsScaledImageFacY
Definition GUIhelper.H:423
ImU32 applyFillAlpha(ImU32 col) const
Definition GUIhelper.C:636
std::chrono::time_point< std::chrono::steady_clock > itsLastEventTime
Definition GUIhelper.H:425
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:1657
std::array< std::string, 4 > itsCompileMessages
Definition GUIhelper.H:516
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:504
std::future< std::string > itsDnnGetFut
Definition GUIhelper.H:501
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:1274
gui::GuiStyle itsCurrentStyle
Definition GUIhelper.H:458
std::string itsWindowTitle
Definition GUIhelper.H:450
std::string itsModDesc
Definition GUIhelper.H:454
int itsVideoMappingListType
Definition GUIhelper.H:505
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:514
JEVOIS_DECLARE_PARAMETER(allowquit, bool, "Quit application on ESC key (platform) or window close (host)", false, ParamCateg)
Parameter.
ImGuiBackendMALI itsBackend
Definition GUIhelper.H:446
bool compileCommand(std::string const &cmd, std::string &msg)
Definition GUIhelper.C:3002
std::vector< std::string > itsModDoc
Definition GUIhelper.H:457
std::map< std::string, GPUimage > itsImages
Definition GUIhelper.H:419
bool itsIdle
Idle state, updated by startFrame(), used by endFrame() to decide whether to draw GUI.
Definition GUIhelper.H:426
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:702
float itsScaledImageFacX
Definition GUIhelper.H:423
bool toggleButton(char const *name, bool *val)
Helper to draw a toggle button.
Definition GUIhelper.C:2729
std::string itsModLang
Definition GUIhelper.H:456
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:287
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:1643
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:434
std::chrono::time_point< std::chrono::steady_clock > lasttime
Definition GUIhelper.H:435
A category to which multiple ParameterDef definitions can belong.
Simple struct to hold video mapping definitions for the processing Engine.