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,
_U(caption.c_str()), wxDefaultPosition, initialSize,
128 wxDEFAULT_FRAME_STYLE, _T(
"id"));
129 SetClientSize(initialSize);
140 SetWindowStyle(GetWindowStyle() | wxCLIP_CHILDREN);
143 wxMenuBar* MenuBar1 =
new wxMenuBar();
145 wxMenu* 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 wxMenu* 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();
273 m_win2D, event.GetSize().GetWidth(),
274 event.GetSize().GetHeight()));
293 event.LeftDown(), event.RightDown()));
312 event.LeftDown(), event.RightDown()));
327 _(
"Image viewer\n Class gui::CDisplayWindow\n MRPT C++ library"),
335 this, wxT(
"Save image as..."), wxT(
"."), wxT(
"image.png"),
336 wxT(
"PNG image files (*.png)|*.png"),
337 #
if wxCHECK_VERSION(2, 8, 0)
338 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
340 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
343 if (wxID_OK == dialog.ShowModal())
349 bmp.SaveFile(dialog.GetPath(), wxBITMAP_TYPE_PNG);
360 const std::string& windowCaption,
unsigned int initWidth,
361 unsigned int initHeight)
370 const std::string& windowCaption,
unsigned int initWidth,
371 unsigned int initHeight)
373 m_enableCursorCoordinates(true)
386 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
389 win->m_image->SetCursor(
390 *(cursorIsCross ? wxCROSS_CURSOR : wxSTANDARD_CURSOR));
401 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
403 if (!
win)
return false;
404 x =
win->m_image->m_last_mouse_point.x;
405 y =
win->m_image->m_last_mouse_point.y;
419 #if MRPT_HAS_WXWIDGETS
447 std::vector<float>
x(x_.size()),
y(y_.size());
448 for (
size_t i = 0; i <
x.size(); i++)
x[i] = x_[i];
449 for (
size_t i = 0; i <
y.size(); i++)
y[i] = y_[i];
454 const CImage&
img,
const std::vector<float>&
x,
const std::vector<float>&
y,
457 #if MRPT_HAS_WXWIDGETS
462 img.colorImage(imgColor);
463 for (
size_t i = 0; i <
x.size(); i++)
500 imgColor.
resize(640, 480, 3, 0);
503 imgColor.
line(40, 40, 560, 40, TColor::black(), 3);
504 imgColor.
line(40, 40, 40, 440, TColor::black(), 3);
505 imgColor.
line(560, 40, 555, 45, TColor::black(), 3);
506 imgColor.
line(560, 40, 555, 35, TColor::black(), 3);
507 imgColor.
line(40, 440, 35, 435, TColor::black(), 3);
508 imgColor.
line(40, 440, 45, 435, TColor::black(), 3);
515 itymx = std::max_element(
y.begin(),
y.end());
516 itymn = std::min_element(
y.begin(),
y.end());
517 float px = (
x[
x.size() - 1] -
x[0]) / 520;
518 float py = (*itymx - *itymn) / 400;
520 float tpxA = 0, tpyA = 0;
522 for (itx =
x.begin(), ity =
y.begin(); itx !=
x.end(); ++itx, ++ity)
524 float tpx = (*itx -
x[0]) / px + ox;
525 float tpy = (*ity - *itymn) / py + oy;
527 if (itx !=
x.begin())
528 imgColor.
line(tpxA, tpyA, tpx, tpy,
TColor(0, 0, 255), 3);
553 imgColor.
resize(640, 480, 3, 0);
556 imgColor.
line(40, 40, 560, 40, TColor::black(), 3);
557 imgColor.
line(40, 40, 40, 440, TColor::black(), 3);
558 imgColor.
line(560, 40, 555, 45, TColor::black(), 3);
559 imgColor.
line(560, 40, 555, 35, TColor::black(), 3);
560 imgColor.
line(40, 440, 35, 435, TColor::black(), 3);
561 imgColor.
line(40, 440, 45, 435, TColor::black(), 3);
563 imgColor.
textOut(550, 25,
"x", TColor::black());
564 imgColor.
textOut(25, 430,
"y", TColor::black());
568 itymx = std::max_element(
y.begin(),
y.end());
569 itymn = std::min_element(
y.begin(),
y.end());
570 float px =
y.size() / 520.0f;
571 float py = (*itymx - *itymn) / 400.0f;
572 float tpxA = 0, tpyA = 0;
576 for (k = 0, ity =
y.begin(); ity !=
y.end(); ++k, ++ity)
578 float tpx = k / px + ox;
579 float tpy = (*ity - *itymn) / py + oy;
596 #if MRPT_HAS_WXWIDGETS
599 cerr <<
"[CDisplayWindow::resize] Window closed!: " <<
m_caption
623 #if MRPT_HAS_WXWIDGETS
626 cerr <<
"[CDisplayWindow::setPos] Window closed!: " <<
m_caption
650 #if MRPT_HAS_WXWIDGETS
653 cerr <<
"[CDisplayWindow::setWindowTitle] Window closed!: " <<
m_caption
The base class for GUI window classes.
std::string m_caption
The caption of the window.
void notifyChildWindowDestruction()
Called by wx main thread to set m_hwnd to NULL.
bool isOpen()
Returns false if the user has already closed the window.
std::promise< void > m_windowDestroyed
This semaphore will be signaled when the wx window is destroyed.
void createWxWindow(unsigned int initialWidth, unsigned int initialHeight)
Must be called by child classes just within the constructor.
void destroyWxWindow()
Must be called by child classes in their destructors.
mrpt::void_ptr_noncopy m_hwnd
The window handle.
volatile int m_keyPushedCode
volatile mrptKeyModifier m_keyPushedModifier
volatile bool m_keyPushed
This class creates a window as a graphical user interface (GUI) for displaying images to the user.
virtual void setCursorCross(bool cursorIsCross) override
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true)
void showImage(const mrpt::img::CImage &img)
Show a given color or grayscale image on the window.
virtual bool getLastMousePosition(int &x, int &y) const override
Gets the last x,y pixel coordinates of the mouse.
void setWindowTitle(const std::string &str) override
Changes the window title text.
void setPos(int x, int y) override
Changes the position of the window on the screen.
std::shared_ptr< CDisplayWindow > Ptr
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y)
Plots a graph in MATLAB-like style.
CDisplayWindow(const std::string &windowCaption=std::string(), unsigned int initWidth=400, unsigned int initHeight=400)
Constructor.
virtual ~CDisplayWindow()
Destructor.
static CDisplayWindow::Ptr Create(const std::string &windowCaption, unsigned int initWidth=400, unsigned int initHeight=400)
Class factory returning a smart pointer.
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.
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
A custom control to display the bitmap and avoid flicker.
void GetBitmap(wxBitmap &bmp)
The wx dialog for gui::CDisplayWindow.
void OnResize(wxSizeEvent &event)
void OnKeyDown(wxKeyEvent &event)
void OnChar(wxKeyEvent &event)
void OnMenuClose(wxCommandEvent &event)
void OnMenuAbout(wxCommandEvent &event)
void OnMouseMove(wxMouseEvent &event)
void OnMouseDown(wxMouseEvent &event)
wxMRPTImageControl * m_image
static const long ID_IMAGE_BITMAP
void OnMenuSave(wxCommandEvent &event)
void OnClose(wxCloseEvent &event)
The main frame of the wxWidgets application.
static int notifyWindowCreation()
Atomically increments the number of windows created with the main frame as parent.
static int notifyWindowDestruction()
Atomically decrements the number of windows created with the main frame as parent.
static void pushPendingWxRequest(TRequestToWxMainThread *data)
Thread-safe method to insert a new pending request (The memory must be dinamically allocated with "ne...
static wxBitmap getMRPTDefaultIcon()
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates.
An event sent by a window when the mouse is moved over it.
An event sent by a window upon a char pressed by the user.
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 upon resize.
void cross(int x0, int y0, const mrpt::img::TColor color, char type, unsigned int size=5, unsigned int width=1)
Draw a cross.
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
virtual void textOut(int x0, int y0, const std::string &str, const mrpt::img::TColor color)
Renders 2D text using bitmap fonts.
A class for storing images as grayscale or RGB bitmaps.
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.
void resize(unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
Changes the size of the image, erasing previous contents (does NOT scale its current content,...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
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...
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
const Scalar * const_iterator
#define ASSERT_(f)
Defines an assertion mechanism.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLenum GLsizei GLsizei height
GLsizei const GLchar ** string
wxImage * MRPTImage2wxImage(const mrpt::img::CImage &img)
Create a wxImage from a MRPT image.
mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent &ev)
Extracts the key modifiers from a wxKeyEvent.
int round(const T value)
Returns the closer integer (int) to x.
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...
Classes for creating GUI windows for 2D and 3D visualization.
This base provides a set of functions for maths stuff.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
The data structure for each inter-thread request:
int OPCODE
Valid codes are: For CDisplayWindow:
void * voidPtr
Parameters, depending on OPCODE.
mrpt::gui::CDisplayWindow * source2D
Only one of source* can be non-nullptr, indicating the class that generated the request.
std::string str
Parameters, depending on OPCODE.
A pair (x,y) of pixel coordinates (integer resolution).
mrpt::gui::CDisplayWindow3D::Ptr win