MRPT  2.0.4
CDisplayWindow.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "gui-precomp.h" // Precompiled headers
11 
12 #include <mrpt/core/round.h>
14 #include <mrpt/img/CImage.h>
15 #include <mrpt/system/os.h>
16 
17 #include <mrpt/gui/WxSubsystem.h>
18 #include <mrpt/gui/WxUtils.h>
19 
20 using namespace mrpt;
21 using namespace mrpt::math;
22 using namespace mrpt::gui;
23 using namespace mrpt::system;
24 using namespace std;
25 using namespace mrpt::img;
26 
27 #if MRPT_HAS_WXWIDGETS
28 
29 BEGIN_EVENT_TABLE(CWindowDialog, wxFrame)
30 
31 END_EVENT_TABLE()
32 
33 const long CWindowDialog::ID_IMAGE_BITMAP = wxNewId();
34 const long ID_MENUITEM1 = wxNewId();
35 const long ID_MENUITEM2 = wxNewId();
36 const long ID_MENUITEM3 = wxNewId();
37 
39  wxWindow* parent, wxWindowID winID, int x, int y, int width, int height)
40  : m_img(nullptr)
41 {
42  this->Create(parent, winID, wxPoint(x, y), wxSize(width, height));
43 
44  Bind(wxEVT_PAINT, &CWindowDialog::wxMRPTImageControl::OnPaint, this);
45  Bind(wxEVT_MOTION, &CWindowDialog::wxMRPTImageControl::OnMouseMove, this);
46  Bind(
47  wxEVT_LEFT_DOWN, &CWindowDialog::wxMRPTImageControl::OnMouseClick,
48  this);
49  Bind(
50  wxEVT_CHAR, &CWindowDialog::wxMRPTImageControl::OnChar, this, wxID_ANY);
51  Bind(wxEVT_CHAR, &CWindowDialog::wxMRPTImageControl::OnChar, this);
52 }
53 
54 CWindowDialog::wxMRPTImageControl::~wxMRPTImageControl()
55 {
56  std::lock_guard<std::mutex> lock(m_img_cs);
57  if (m_img) m_img.reset();
58 }
59 
60 void CWindowDialog::wxMRPTImageControl::OnMouseMove(wxMouseEvent& ev)
61 {
62  // std::lock_guard<std::mutex> lock( m_mouse_cs);
63  m_last_mouse_point = ev.GetPosition();
64 }
65 
66 void CWindowDialog::wxMRPTImageControl::OnMouseClick(wxMouseEvent& ev)
67 {
68  // std::lock_guard<std::mutex> lock( m_mouse_cs);
69  m_last_mouse_click = ev.GetPosition();
70 }
71 
72 void CWindowDialog::wxMRPTImageControl::OnChar(wxKeyEvent& ev) {}
73 void CWindowDialog::wxMRPTImageControl::AssignImage(wxBitmap* img)
74 {
75  std::lock_guard<std::mutex> lock(m_img_cs);
76  m_img.reset(img);
77 }
78 
79 void CWindowDialog::wxMRPTImageControl::OnPaint(wxPaintEvent& ev)
80 {
81  wxPaintDC dc(this);
82 
83  std::lock_guard<std::mutex> lock(m_img_cs);
84  if (!m_img)
85  {
86  // Erase background:
87  return;
88  }
89 
90  dc.DrawBitmap(*m_img, 0, 0);
91 }
92 
93 void CWindowDialog::wxMRPTImageControl::GetBitmap(wxBitmap& bmp)
94 {
95  std::lock_guard<std::mutex> lock(m_img_cs);
96  if (!m_img) return;
97  bmp = *m_img;
98 }
99 
100 CWindowDialog::CWindowDialog(
101  CDisplayWindow* win2D, WxSubsystem::CWXMainFrame* parent, wxWindowID id,
102  const std::string& caption, wxSize initialSize)
103  : m_win2D(win2D), m_mainFrame(parent)
104 {
105  Create(
106  parent, id, caption.c_str(), wxDefaultPosition, initialSize,
107  wxDEFAULT_FRAME_STYLE, _T("id"));
108  SetClientSize(initialSize);
109 
110  wxIcon FrameIcon;
111  FrameIcon.CopyFromBitmap(mrpt::gui::WxSubsystem::getMRPTDefaultIcon());
112  SetIcon(FrameIcon);
113 
114  // Create the image object:
116  this, ID_IMAGE_BITMAP, 0, 0, 10, 10);
117 
118  // wxCLIP_CHILDREN seems to avoid flicker
119  SetWindowStyle(GetWindowStyle() | wxCLIP_CHILDREN);
120 
121  // Menu:
122  auto* MenuBar1 = new wxMenuBar();
123 
124  auto* Menu1 = new wxMenu();
125  wxMenuItem* MenuItem3 = new wxMenuItem(
126  Menu1, ID_MENUITEM3, _("Save to file..."), _(""), wxITEM_NORMAL);
127  Menu1->Append(MenuItem3);
128  wxMenuItem* MenuItem1 =
129  new wxMenuItem(Menu1, ID_MENUITEM1, _("Close"), _(""), wxITEM_NORMAL);
130  Menu1->Append(MenuItem1);
131  MenuBar1->Append(Menu1, _("&File"));
132 
133  auto* Menu2 = new wxMenu();
134  wxMenuItem* MenuItem2 = new wxMenuItem(
135  Menu2, ID_MENUITEM2, _("About..."), _(""), wxITEM_NORMAL);
136  Menu2->Append(MenuItem2);
137  MenuBar1->Append(Menu2, _("&Help"));
138 
139  SetMenuBar(MenuBar1);
140 
141  // Events:
142  Bind(wxEVT_CLOSE_WINDOW, &CWindowDialog::OnClose, this, wxID_ANY);
143  Bind(wxEVT_MENU, &CWindowDialog::OnMenuClose, this, ID_MENUITEM1);
144  Bind(wxEVT_MENU, &CWindowDialog::OnMenuAbout, this, ID_MENUITEM2);
145  Bind(wxEVT_MENU, &CWindowDialog::OnMenuSave, this, ID_MENUITEM3);
146 
147  Bind(wxEVT_KEY_DOWN, &CWindowDialog::OnChar, this, wxID_ANY);
148  Bind(wxEVT_CHAR, &CWindowDialog::OnChar, this, wxID_ANY);
149 
150  m_image->Bind(wxEVT_KEY_DOWN, &CWindowDialog::OnChar, this);
151  m_image->Bind(wxEVT_SIZE, &CWindowDialog::OnResize, this);
152 
153  m_image->Bind(wxEVT_LEFT_DOWN, &CWindowDialog::OnMouseDown, this);
154  m_image->Bind(wxEVT_RIGHT_DOWN, &CWindowDialog::OnMouseDown, this);
155  m_image->Bind(wxEVT_MOTION, &CWindowDialog::OnMouseMove, this);
156 
157  // Increment number of windows:
158  // int winCount =
160 
161  // this->Iconize(false);
162 }
163 
164 // Destructor
166 // OnClose event:
167 void CWindowDialog::OnClose(wxCloseEvent& event)
168 {
169  // Send the event:
170  bool allow_close = true;
171  try
172  {
173  mrptEventWindowClosed ev(m_win2D, true /* allow close */);
174  m_win2D->publishEvent(ev);
175  allow_close = ev.allow_close;
176  }
177  catch (...)
178  {
179  }
180  if (!allow_close) return; // Don't process this close event.
181 
182  // Set the m_hwnd=nullptr in our parent object.
184 
185  // Decrement number of windows:
187 
188  m_win2D->m_windowDestroyed.set_value();
189 
190  event.Skip(); // keep processing by parent classes.
191 }
192 
193 void CWindowDialog::OnKeyDown(wxKeyEvent& event)
194 {
195  event.Skip(); // So OnChar event is produced.
196 }
197 
198 void CWindowDialog::OnChar(wxKeyEvent& event)
199 {
200  if (m_win2D)
201  {
202  const int code = event.GetKeyCode();
204 
205  m_win2D->m_keyPushedCode = code;
207  m_win2D->m_keyPushed = true;
208 
209  // Send the event:
210  try
211  {
213  }
214  catch (...)
215  {
216  }
217  }
218  event.Skip();
219 }
220 
221 void CWindowDialog::OnResize(wxSizeEvent& event)
222 {
223  // Send the event:
224  if (m_win2D && m_win2D->hasSubscribers())
225  {
226  try
227  {
229  m_win2D, event.GetSize().GetWidth(),
230  event.GetSize().GetHeight()));
231  }
232  catch (...)
233  {
234  }
235  }
236  event.Skip(); // so it's processed by the wx system!
237 }
238 
239 void CWindowDialog::OnMouseDown(wxMouseEvent& event)
240 {
241  // Send the event:
242  if (m_win2D && m_win2D->hasSubscribers())
243  {
244  try
245  {
247  m_win2D, TPixelCoord(event.GetX(), event.GetY()),
248  event.LeftDown(), event.RightDown()));
249  }
250  catch (...)
251  {
252  }
253  }
254  event.Skip(); // so it's processed by the wx system!
255 }
256 
257 void CWindowDialog::OnMouseMove(wxMouseEvent& event)
258 {
259  // Send the event:
260  if (m_win2D && m_win2D->hasSubscribers())
261  {
262  try
263  {
265  m_win2D, TPixelCoord(event.GetX(), event.GetY()),
266  event.LeftDown(), event.RightDown()));
267  }
268  catch (...)
269  {
270  }
271  }
272  event.Skip(); // so it's processed by the wx system!
273 }
274 
275 // Menu: Close
276 void CWindowDialog::OnMenuClose(wxCommandEvent& event) { Close(); }
277 // Menu: About
278 void CWindowDialog::OnMenuAbout(wxCommandEvent& event)
279 {
280  ::wxMessageBox(
281  _("Image viewer\n Class gui::CDisplayWindow\n MRPT C++ library"),
282  _("About..."));
283 }
284 
285 // Menu: Save to file
286 void CWindowDialog::OnMenuSave(wxCommandEvent& event)
287 {
288  wxFileDialog dialog(
289  this, wxT("Save image as..."), wxT("."), wxT("image.png"),
290  wxT("PNG image files (*.png)|*.png"),
291  wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
292 
293  if (wxID_OK == dialog.ShowModal())
294  {
295  try
296  {
297  wxBitmap bmp;
298  m_image->GetBitmap(bmp);
299  bmp.SaveFile(dialog.GetPath(), wxBITMAP_TYPE_PNG);
300  }
301  catch (...)
302  {
303  }
304  }
305 }
306 
307 #endif
308 
310  const std::string& windowCaption, unsigned int initWidth,
311  unsigned int initHeight)
312 {
313  return std::make_shared<CDisplayWindow>(
314  windowCaption, initWidth, initHeight);
315 }
316 /*---------------------------------------------------------------
317  Constructor
318  ---------------------------------------------------------------*/
320  const std::string& windowCaption, unsigned int initWidth,
321  unsigned int initHeight)
322  : CBaseGUIWindow(static_cast<void*>(this), 200, 299, windowCaption)
323 
324 {
325  CBaseGUIWindow::createWxWindow(initWidth, initHeight);
326 }
327 
328 /*---------------------------------------------------------------
329  Destructor
330  ---------------------------------------------------------------*/
332 /** Set cursor style to default (cursorIsCross=false) or to a cross
333  * (cursorIsCross=true) */
334 void CDisplayWindow::setCursorCross([[maybe_unused]] bool cursorIsCross)
335 {
336 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
337  const auto* win = (const CWindowDialog*)m_hwnd.get();
338  if (!win) return;
339  win->m_image->SetCursor(
340  *(cursorIsCross ? wxCROSS_CURSOR : wxSTANDARD_CURSOR));
341 #endif
342 }
343 
344 /*---------------------------------------------------------------
345  getLastMousePosition
346  ---------------------------------------------------------------*/
348  [[maybe_unused]] int& x, [[maybe_unused]] int& y) const
349 {
350 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
351  const auto* win = (const CWindowDialog*)m_hwnd.get();
352  if (!win) return false;
353  x = win->m_image->m_last_mouse_point.x;
354  y = win->m_image->m_last_mouse_point.y;
355  return true;
356 #else
357  return false;
358 #endif
359 }
360 
361 /*---------------------------------------------------------------
362  showImage
363  ---------------------------------------------------------------*/
364 void CDisplayWindow::showImage([[maybe_unused]] const CImage& img)
365 {
366 #if MRPT_HAS_WXWIDGETS
367  MRPT_START
368 
369  // Send message of new image:
370  wxImage* newImg = mrpt::gui::MRPTImage2wxImage(img);
371 
372  // Send a request to destroy this object:
373  auto* REQ = new WxSubsystem::TRequestToWxMainThread[1];
374  REQ->source2D = this;
375  REQ->OPCODE = 201;
376  REQ->voidPtr = m_hwnd.get();
377  REQ->voidPtr2 = (void*)newImg;
379 
380  MRPT_END
381 #endif
382 }
383 
384 /*---------------------------------------------------------------
385  showImageAndPoints
386  ---------------------------------------------------------------*/
388  const CImage& img, const CVectorFloat& x_, const CVectorFloat& y_,
389  const TColor& color, bool showNumbers)
390 {
391  std::vector<float> x(x_.size()), y(y_.size());
392  for (size_t i = 0; i < x.size(); i++) x[i] = x_[i];
393  for (size_t i = 0; i < y.size(); i++) y[i] = y_[i];
394  showImageAndPoints(img, x, y, color, showNumbers);
395 }
396 
398  [[maybe_unused]] const CImage& img,
399  [[maybe_unused]] const std::vector<float>& x,
400  [[maybe_unused]] const std::vector<float>& y,
401  [[maybe_unused]] const TColor& color, [[maybe_unused]] bool showNumbers)
402 {
403 #if MRPT_HAS_WXWIDGETS
404  MRPT_START
405  ASSERT_(x.size() == y.size());
406 
407  CImage imgColor = img.colorImage(); // Create a colorimage
408  for (size_t i = 0; i < x.size(); i++)
409  {
410  imgColor.drawMark(round(x[i]), round(y[i]), color, '+');
411 
412  if (showNumbers)
413  {
414  char buf[15];
415  mrpt::system::os::sprintf(buf, 15, "%d", int(i));
416  imgColor.textOut(round(x[i]) - 10, round(y[i]), buf, color);
417  }
418  } // end-for
419  showImage(imgColor);
420  MRPT_END
421 #endif
422 }
423 
424 /*---------------------------------------------------------------
425  plot
426  ---------------------------------------------------------------*/
428 {
429  MRPT_START
430 
431  ASSERT_(x.size() == y.size());
432 
433  const int ox = 40;
434  const int oy = 40;
435 
436  // Suboptimal but...
437  CImage imgColor(640, 480, mrpt::img::CH_RGB);
438  // Draw axis:
439  imgColor.filledRectangle(0, 0, 640, 480, TColor(255, 255, 255));
440  imgColor.line(40, 40, 560, 40, TColor::black(), 3);
441  imgColor.line(40, 40, 40, 440, TColor::black(), 3);
442  imgColor.line(560, 40, 555, 45, TColor::black(), 3);
443  imgColor.line(560, 40, 555, 35, TColor::black(), 3);
444  imgColor.line(40, 440, 35, 435, TColor::black(), 3);
445  imgColor.line(40, 440, 45, 435, TColor::black(), 3);
446 
447  // imgColor.textOut( 550, 25, "x", TColor::black );
448  // imgColor.textOut( 25, 430, "y", TColor::black );
449 
451  CVectorFloat::const_iterator itymx, itymn;
452  itymx = std::max_element(y.begin(), y.end());
453  itymn = std::min_element(y.begin(), y.end());
454  float px = (x[x.size() - 1] - x[0]) / 520;
455  float py = (*itymx - *itymn) / 400;
456 
457  float tpxA = 0, tpyA = 0;
458 
459  for (itx = x.begin(), ity = y.begin(); itx != x.end(); ++itx, ++ity)
460  {
461  float tpx = (*itx - x[0]) / px + ox;
462  float tpy = (*ity - *itymn) / py + oy;
463  imgColor.drawMark(round(tpx), round(tpy), TColor(255, 0, 0), 'x');
464  if (itx != x.begin())
465  imgColor.line(
466  round(tpxA), round(tpyA), round(tpx), round(tpy),
467  TColor(0, 0, 255), 3);
468  tpxA = tpx;
469  tpyA = tpy;
470  } // end for
471 
472  showImage(imgColor);
473 
474  MRPT_END
475 }
476 
477 /*---------------------------------------------------------------
478  plot
479  ---------------------------------------------------------------*/
481 {
482  MRPT_START
483 
484  ASSERT_(y.size() >= 0);
485 
486  const int ox = 40;
487  const int oy = 40;
488 
489  // Suboptimal but...
490  CImage imgColor(640, 480, mrpt::img::CH_RGB);
491  // Draw axis:
492  imgColor.filledRectangle(0, 0, 640, 480, TColor::white());
493  imgColor.line(40, 40, 560, 40, TColor::black(), 3);
494  imgColor.line(40, 40, 40, 440, TColor::black(), 3);
495  imgColor.line(560, 40, 555, 45, TColor::black(), 3);
496  imgColor.line(560, 40, 555, 35, TColor::black(), 3);
497  imgColor.line(40, 440, 35, 435, TColor::black(), 3);
498  imgColor.line(40, 440, 45, 435, TColor::black(), 3);
499 
500  imgColor.textOut(550, 25, "x", TColor::black());
501  imgColor.textOut(25, 430, "y", TColor::black());
502 
504  CVectorFloat::const_iterator itymx, itymn;
505  itymx = std::max_element(y.begin(), y.end());
506  itymn = std::min_element(y.begin(), y.end());
507  float px = y.size() / 520.0f;
508  float py = (*itymx - *itymn) / 400.0f;
509  int tpxA = 0, tpyA = 0;
510 
511  unsigned int k = 0;
512 
513  for (k = 0, ity = y.begin(); ity != y.end(); ++k, ++ity)
514  {
515  auto tpx = round(k / px + ox);
516  auto tpy = round((*ity - *itymn) / py + oy);
517  imgColor.drawMark(tpx, tpy, TColor::red(), 'x');
518  if (k > 0) imgColor.line(tpxA, tpyA, tpx, tpy, TColor::blue(), 3);
519  tpxA = tpx;
520  tpyA = tpy;
521  } // end for
522 
523  showImage(imgColor);
524 
525  MRPT_END
526 }
527 
528 /*---------------------------------------------------------------
529  resize
530  ---------------------------------------------------------------*/
532  [[maybe_unused]] unsigned int width, [[maybe_unused]] unsigned int height)
533 {
534 #if MRPT_HAS_WXWIDGETS
535  if (!isOpen())
536  {
537  cerr << "[CDisplayWindow::resize] Window closed!: " << m_caption
538  << endl;
539  return;
540  }
541 
542  // Send a request to destroy this object:
543  auto* REQ = new WxSubsystem::TRequestToWxMainThread[1];
544  REQ->source2D = this;
545  REQ->OPCODE = 203;
546  REQ->x = width;
547  REQ->y = height;
549 #endif
550 }
551 
552 /*---------------------------------------------------------------
553  setPos
554  ---------------------------------------------------------------*/
555 void CDisplayWindow::setPos([[maybe_unused]] int x, [[maybe_unused]] int y)
556 {
557 #if MRPT_HAS_WXWIDGETS
558  if (!isOpen())
559  {
560  cerr << "[CDisplayWindow::setPos] Window closed!: " << m_caption
561  << endl;
562  return;
563  }
564 
565  // Send a request to destroy this object:
566  auto* REQ = new WxSubsystem::TRequestToWxMainThread[1];
567  REQ->source2D = this;
568  REQ->OPCODE = 202;
569  REQ->x = x;
570  REQ->y = y;
572 #endif
573 }
574 
575 /*---------------------------------------------------------------
576  setWindowTitle
577  ---------------------------------------------------------------*/
578 void CDisplayWindow::setWindowTitle([[maybe_unused]] const std::string& str)
579 {
580 #if MRPT_HAS_WXWIDGETS
581  if (!isOpen())
582  {
583  cerr << "[CDisplayWindow::setWindowTitle] Window closed!: " << m_caption
584  << endl;
585  return;
586  }
587 
588  // Send a request to destroy this object:
589  auto* REQ = new WxSubsystem::TRequestToWxMainThread[1];
590  REQ->source2D = this;
591  REQ->OPCODE = 204;
592  REQ->str = str;
594 #endif
595 }
An event sent by a window upon resize.
static void pushPendingWxRequest(TRequestToWxMainThread *data)
Thread-safe method to insert a new pending request (The memory must be dinamically allocated with "ne...
void line(int x0, int y0, int x1, int y1, const mrpt::img::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid) override
Draws a line.
Definition: CImage.cpp:1123
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
std::atomic_int m_keyPushedCode
#define MRPT_START
Definition: exceptions.h:241
void OnMenuSave(wxCommandEvent &event)
void OnResize(wxSizeEvent &event)
The data structure for each inter-thread request:
Definition: WxSubsystem.h:189
Template for column vectors of dynamic size, compatible with Eigen.
mrpt::void_ptr_noncopy m_hwnd
The window handle.
void setCursorCross(bool cursorIsCross) override
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) ...
std::string m_caption
The caption of the window.
static int notifyWindowCreation()
Atomically increments the number of windows created with the main frame as parent.
~CDisplayWindow() override
Destructor.
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
mrptKeyModifier
Definition: keycodes.h:156
static wxBitmap getMRPTDefaultIcon()
STL namespace.
wxImage * MRPTImage2wxImage(const mrpt::img::CImage &img)
Create a wxImage from a MRPT image.
Definition: WxUtils.cpp:24
const long ID_MENUITEM3
An event sent by a window upon when it&#39;s about to be closed, either manually by the user or programma...
An event sent by a window when the mouse is moved over it.
void setWindowTitle(const std::string &str) override
Changes the window title text.
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y)
Plots a graph in MATLAB-like style.
void notifyChildWindowDestruction()
Called by wx main thread to set m_hwnd to NULL.
wxMRPTImageControl * m_image
Definition: WxSubsystem.h:363
CImage colorImage() const
Returns a color (RGB) version of the grayscale image, or a shallow copy of itself if it is already a ...
Definition: CImage.cpp:1867
void OnKeyDown(wxKeyEvent &event)
void OnMouseDown(wxMouseEvent &event)
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
void OnMenuClose(wxCommandEvent &event)
const long ID_MENUITEM1
This base provides a set of functions for maths stuff.
A custom control to display the bitmap and avoid flicker.
Definition: WxSubsystem.h:320
void showImageAndPoints(const mrpt::img::CImage &img, const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const mrpt::img::TColor &color=mrpt::img::TColor::red(), bool showNumbers=false)
Show a given color or grayscale image on the window and print a set of points on it.
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
Definition: CCanvas.cpp:205
bool getLastMousePosition(int &x, int &y) const override
Gets the last x,y pixel coordinates of the mouse.
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
bool isOpen()
Returns false if the user has already closed the window.
std::atomic< mrptKeyModifier > m_keyPushedModifier
The main frame of the wxWidgets application.
Definition: WxSubsystem.h:132
A pair (x,y) of pixel coordinates (integer resolution).
Definition: TPixelCoord.h:40
CDisplayWindow * m_win2D
Definition: WxSubsystem.h:359
The wx dialog for gui::CDisplayWindow.
Definition: WxSubsystem.h:315
typename vec_t::const_iterator const_iterator
An event sent by a window upon a char pressed by the user.
const long ID_MENUITEM2
void OnMouseMove(wxMouseEvent &event)
mrpt::gui::CDisplayWindow3D::Ptr win
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent &ev)
Extracts the key modifiers from a wxKeyEvent.
Definition: WxUtils.cpp:939
void setPos(int x, int y) override
Changes the position of the window on the screen.
void OnChar(wxKeyEvent &event)
void drawMark(int x0, int y0, const mrpt::img::TColor color, char type, int size=5, unsigned int width=1)
Draw a mark.
Definition: CCanvas.cpp:304
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void OnClose(wxCloseEvent &event)
void OnMenuAbout(wxCommandEvent &event)
std::atomic_bool m_keyPushed
#define MRPT_END
Definition: exceptions.h:245
bool hasSubscribers() const
Can be called by a derived class before preparing an event for publishing with publishEvent to determ...
Definition: CObservable.h:53
void publishEvent(const mrptEvent &e) const
Called when you want this object to emit an event to all the observers currently subscribed to this o...
Definition: CObservable.cpp:57
static const long ID_IMAGE_BITMAP
Definition: WxSubsystem.h:365
void showImage(const mrpt::img::CImage &img)
Show a given color or grayscale image on the window.
void destroyWxWindow()
Must be called by child classes in their destructors.
virtual void textOut(int x0, int y0, const std::string &str, const mrpt::img::TColor color)
Renders 2D text using bitmap fonts.
Definition: CCanvas.cpp:374
CDisplayWindow(const std::string &windowCaption=std::string(), unsigned int initWidth=400, unsigned int initHeight=400)
Constructor.
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
void createWxWindow(unsigned int initialWidth, unsigned int initialHeight)
Must be called by child classes just within the constructor.
static CDisplayWindow::Ptr Create(const std::string &windowCaption, unsigned int initWidth=400, unsigned int initHeight=400)
Class factory returning a smart pointer.
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::gui::CDisplayWindow * source2D
Only one of source* can be non-nullptr, indicating the class that generated the request.
Definition: WxSubsystem.h:195
std::promise< void > m_windowDestroyed
This semaphore will be signaled when the wx window is destroyed.
The base class for GUI window classes based on wxWidgets.
static int notifyWindowDestruction()
Atomically decrements the number of windows created with the main frame as parent.
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:24



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020