27 #if MRPT_HAS_WXWIDGETS 39 wxWindow* parent, wxWindowID winID,
int x,
int y,
int width,
int height)
42 this->Create(parent, winID, wxPoint(
x,
y), wxSize(
width,
height));
46 wxPaintEventHandler(CWindowDialog::wxMRPTImageControl::OnPaint));
49 wxMouseEventHandler(CWindowDialog::wxMRPTImageControl::OnMouseMove));
51 wxID_ANY, wxEVT_LEFT_DOWN,
52 wxMouseEventHandler(CWindowDialog::wxMRPTImageControl::OnMouseClick));
56 (wxObjectEventFunction)&CWindowDialog::wxMRPTImageControl::OnChar);
59 (wxObjectEventFunction)&CWindowDialog::wxMRPTImageControl::OnChar);
65 CWindowDialog::wxMRPTImageControl::~wxMRPTImageControl()
67 std::lock_guard<std::mutex> lock(m_img_cs);
75 void CWindowDialog::wxMRPTImageControl::OnMouseMove(wxMouseEvent& ev)
78 m_last_mouse_point = ev.GetPosition();
81 void CWindowDialog::wxMRPTImageControl::OnMouseClick(wxMouseEvent& ev)
84 m_last_mouse_click = ev.GetPosition();
87 void CWindowDialog::wxMRPTImageControl::OnChar(wxKeyEvent& ev) {}
88 void CWindowDialog::wxMRPTImageControl::AssignImage(wxBitmap*
img)
90 std::lock_guard<std::mutex> lock(m_img_cs);
100 void CWindowDialog::wxMRPTImageControl::OnPaint(wxPaintEvent& ev)
104 std::lock_guard<std::mutex> lock(m_img_cs);
111 dc.DrawBitmap(*m_img, 0, 0);
114 void CWindowDialog::wxMRPTImageControl::GetBitmap(wxBitmap& bmp)
116 std::lock_guard<std::mutex> lock(m_img_cs);
121 CWindowDialog::CWindowDialog(
124 : m_win2D(win2D), m_mainFrame(parent)
127 parent,
id, caption.c_str(), wxDefaultPosition, initialSize,
128 wxDEFAULT_FRAME_STYLE, _T(
"id"));
129 SetClientSize(initialSize);
140 SetWindowStyle(GetWindowStyle() | wxCLIP_CHILDREN);
143 auto* MenuBar1 =
new wxMenuBar();
145 auto* Menu1 =
new wxMenu();
146 wxMenuItem* MenuItem3 =
new wxMenuItem(
147 Menu1,
ID_MENUITEM3, _(
"Save to file..."), _(
""), wxITEM_NORMAL);
148 Menu1->Append(MenuItem3);
149 wxMenuItem* MenuItem1 =
150 new wxMenuItem(Menu1,
ID_MENUITEM1, _(
"Close"), _(
""), wxITEM_NORMAL);
151 Menu1->Append(MenuItem1);
152 MenuBar1->Append(Menu1, _(
"&File"));
154 auto* Menu2 =
new wxMenu();
155 wxMenuItem* MenuItem2 =
new wxMenuItem(
156 Menu2,
ID_MENUITEM2, _(
"About..."), _(
""), wxITEM_NORMAL);
157 Menu2->Append(MenuItem2);
158 MenuBar1->Append(Menu2, _(
"&Help"));
160 SetMenuBar(MenuBar1);
164 wxID_ANY, wxEVT_CLOSE_WINDOW,
178 wxID_ANY, wxEVT_KEY_DOWN,
213 bool allow_close =
true;
223 if (!allow_close)
return;
245 const int code =
event.GetKeyCode();
272 m_win2D, event.GetSize().GetWidth(),
273 event.GetSize().GetHeight()));
291 event.LeftDown(),
event.RightDown()));
309 event.LeftDown(),
event.RightDown()));
324 _(
"Image viewer\n Class gui::CDisplayWindow\n MRPT C++ library"),
332 this, wxT(
"Save image as..."), wxT(
"."), wxT(
"image.png"),
333 wxT(
"PNG image files (*.png)|*.png"),
334 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
336 if (wxID_OK == dialog.ShowModal())
342 bmp.SaveFile(dialog.GetPath(), wxBITMAP_TYPE_PNG);
353 const std::string& windowCaption,
unsigned int initWidth,
354 unsigned int initHeight)
356 return std::make_shared<CDisplayWindow>(
357 windowCaption, initWidth, initHeight);
363 const std::string& windowCaption,
unsigned int initWidth,
364 unsigned int initHeight)
379 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 382 win->m_image->SetCursor(
383 *(cursorIsCross ? wxCROSS_CURSOR : wxSTANDARD_CURSOR));
394 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 396 if (!
win)
return false;
397 x =
win->m_image->m_last_mouse_point.x;
398 y =
win->m_image->m_last_mouse_point.y;
412 #if MRPT_HAS_WXWIDGETS 423 REQ->voidPtr2 = (
void*)newImg;
439 std::vector<float>
x(x_.
size()),
y(y_.
size());
440 for (
size_t i = 0; i <
x.size(); i++)
x[i] = x_[i];
441 for (
size_t i = 0; i <
y.size(); i++)
y[i] = y_[i];
446 const CImage&
img,
const std::vector<float>&
x,
const std::vector<float>&
y,
449 #if MRPT_HAS_WXWIDGETS 454 for (
size_t i = 0; i <
x.size(); i++)
492 imgColor.
line(40, 40, 560, 40, TColor::black(), 3);
493 imgColor.
line(40, 40, 40, 440, TColor::black(), 3);
494 imgColor.
line(560, 40, 555, 45, TColor::black(), 3);
495 imgColor.
line(560, 40, 555, 35, TColor::black(), 3);
496 imgColor.
line(40, 440, 35, 435, TColor::black(), 3);
497 imgColor.
line(40, 440, 45, 435, TColor::black(), 3);
504 itymx = std::max_element(
y.begin(),
y.end());
505 itymn = std::min_element(
y.begin(),
y.end());
506 float px = (
x[
x.size() - 1] -
x[0]) / 520;
507 float py = (*itymx - *itymn) / 400;
509 float tpxA = 0, tpyA = 0;
511 for (itx =
x.begin(), ity =
y.begin(); itx !=
x.end(); ++itx, ++ity)
513 float tpx = (*itx -
x[0]) / px + ox;
514 float tpy = (*ity - *itymn) / py + oy;
516 if (itx !=
x.begin())
517 imgColor.
line(tpxA, tpyA, tpx, tpy,
TColor(0, 0, 255), 3);
543 imgColor.
line(40, 40, 560, 40, TColor::black(), 3);
544 imgColor.
line(40, 40, 40, 440, TColor::black(), 3);
545 imgColor.
line(560, 40, 555, 45, TColor::black(), 3);
546 imgColor.
line(560, 40, 555, 35, TColor::black(), 3);
547 imgColor.
line(40, 440, 35, 435, TColor::black(), 3);
548 imgColor.
line(40, 440, 45, 435, TColor::black(), 3);
550 imgColor.
textOut(550, 25,
"x", TColor::black());
551 imgColor.
textOut(25, 430,
"y", TColor::black());
555 itymx = std::max_element(
y.begin(),
y.end());
556 itymn = std::min_element(
y.begin(),
y.end());
557 float px =
y.size() / 520.0f;
558 float py = (*itymx - *itymn) / 400.0f;
559 float tpxA = 0, tpyA = 0;
563 for (k = 0, ity =
y.begin(); ity !=
y.end(); ++k, ++ity)
565 float tpx = k / px + ox;
566 float tpy = (*ity - *itymn) / py + oy;
583 #if MRPT_HAS_WXWIDGETS 586 cerr <<
"[CDisplayWindow::resize] Window closed!: " <<
m_caption 609 #if MRPT_HAS_WXWIDGETS 612 cerr <<
"[CDisplayWindow::setPos] Window closed!: " <<
m_caption 635 #if MRPT_HAS_WXWIDGETS 638 cerr <<
"[CDisplayWindow::setWindowTitle] Window closed!: " <<
m_caption 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.
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
void OnMenuSave(wxCommandEvent &event)
void OnResize(wxSizeEvent &event)
The data structure for each inter-thread request:
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.
void GetBitmap(wxBitmap &bmp)
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
static wxBitmap getMRPTDefaultIcon()
wxImage * MRPTImage2wxImage(const mrpt::img::CImage &img)
Create a wxImage from a MRPT image.
An event sent by a window upon when it'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
CImage colorImage() const
Returns a color (RGB) version of the grayscale image, or a shallow copy of itself if it is already a ...
void OnKeyDown(wxKeyEvent &event)
void OnMouseDown(wxMouseEvent &event)
#define ASSERT_(f)
Defines an assertion mechanism.
void OnMenuClose(wxCommandEvent &event)
This base provides a set of functions for maths stuff.
A custom control to display the bitmap and avoid flicker.
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
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.
The main frame of the wxWidgets application.
A pair (x,y) of pixel coordinates (integer resolution).
The wx dialog for gui::CDisplayWindow.
typename vec_t::const_iterator const_iterator
An event sent by a window upon a char pressed by the user.
void OnMouseMove(wxMouseEvent &event)
mrpt::gui::CDisplayWindow3D::Ptr win
GLsizei const GLchar ** string
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.
void setPos(int x, int y) override
Changes the position of the window on the screen.
void OnChar(wxKeyEvent &event)
volatile mrptKeyModifier m_keyPushedModifier
void drawMark(int x0, int y0, const mrpt::img::TColor color, char type, int size=5, unsigned int width=1)
Draw a mark.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void OnClose(wxCloseEvent &event)
void OnMenuAbout(wxCommandEvent &event)
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(), const bool &showNumbers=false)
Show a given color or grayscale image on the window and print a set of points on it.
volatile bool m_keyPushed
bool hasSubscribers() const
Can be called by a derived class before preparing an event for publishing with publishEvent to determ...
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...
static const long ID_IMAGE_BITMAP
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.
CDisplayWindow(const std::string &windowCaption=std::string(), unsigned int initWidth=400, unsigned int initHeight=400)
Constructor.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
Classes for creating GUI windows for 2D and 3D visualization.
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.
volatile int m_keyPushedCode
mrpt::gui::CDisplayWindow * source2D
Only one of source* can be non-nullptr, indicating the class that generated the request.
GLenum GLsizei GLsizei height
~CWindowDialog() override
std::promise< void > m_windowDestroyed
This semaphore will be signaled when the wx window is destroyed.
The base class for GUI window classes.
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.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
int round(const T value)
Returns the closer integer (int) to x.