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));
44 Bind(wxEVT_PAINT, &CWindowDialog::wxMRPTImageControl::OnPaint,
this);
45 Bind(wxEVT_MOTION, &CWindowDialog::wxMRPTImageControl::OnMouseMove,
this);
47 wxEVT_LEFT_DOWN, &CWindowDialog::wxMRPTImageControl::OnMouseClick,
50 wxEVT_CHAR, &CWindowDialog::wxMRPTImageControl::OnChar,
this, wxID_ANY);
51 Bind(wxEVT_CHAR, &CWindowDialog::wxMRPTImageControl::OnChar,
this);
54 CWindowDialog::wxMRPTImageControl::~wxMRPTImageControl()
56 std::lock_guard<std::mutex> lock(m_img_cs);
57 if (m_img) m_img.reset();
60 void CWindowDialog::wxMRPTImageControl::OnMouseMove(wxMouseEvent& ev)
63 m_last_mouse_point = ev.GetPosition();
66 void CWindowDialog::wxMRPTImageControl::OnMouseClick(wxMouseEvent& ev)
69 m_last_mouse_click = ev.GetPosition();
72 void CWindowDialog::wxMRPTImageControl::OnChar(wxKeyEvent& ev) {}
73 void CWindowDialog::wxMRPTImageControl::AssignImage(wxBitmap* img)
75 std::lock_guard<std::mutex> lock(m_img_cs);
79 void CWindowDialog::wxMRPTImageControl::OnPaint(wxPaintEvent& ev)
83 std::lock_guard<std::mutex> lock(m_img_cs);
90 dc.DrawBitmap(*m_img, 0, 0);
93 void CWindowDialog::wxMRPTImageControl::GetBitmap(wxBitmap& bmp)
95 std::lock_guard<std::mutex> lock(m_img_cs);
100 CWindowDialog::CWindowDialog(
102 const std::string& caption, wxSize initialSize)
103 : m_win2D(win2D), m_mainFrame(parent)
106 parent,
id, caption.c_str(), wxDefaultPosition, initialSize,
107 wxDEFAULT_FRAME_STYLE, _T(
"id"));
108 SetClientSize(initialSize);
119 SetWindowStyle(GetWindowStyle() | wxCLIP_CHILDREN);
122 auto* MenuBar1 =
new wxMenuBar();
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"));
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"));
139 SetMenuBar(MenuBar1);
170 bool allow_close =
true;
180 if (!allow_close)
return;
202 const int code =
event.GetKeyCode();
229 m_win2D, event.GetSize().GetWidth(),
230 event.GetSize().GetHeight()));
248 event.LeftDown(), event.RightDown()));
266 event.LeftDown(), event.RightDown()));
281 _(
"Image viewer\n Class gui::CDisplayWindow\n MRPT C++ library"),
289 this, wxT(
"Save image as..."), wxT(
"."), wxT(
"image.png"),
290 wxT(
"PNG image files (*.png)|*.png"),
291 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
293 if (wxID_OK == dialog.ShowModal())
299 bmp.SaveFile(dialog.GetPath(), wxBITMAP_TYPE_PNG);
310 const std::string& windowCaption,
unsigned int initWidth,
311 unsigned int initHeight)
313 return std::make_shared<CDisplayWindow>(
314 windowCaption, initWidth, initHeight);
320 const std::string& windowCaption,
unsigned int initWidth,
321 unsigned int initHeight)
322 :
CBaseGUIWindow(static_cast<void*>(this), 200, 299, windowCaption)
336 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
339 win->m_image->SetCursor(
340 *(cursorIsCross ? wxCROSS_CURSOR : wxSTANDARD_CURSOR));
348 [[maybe_unused]]
int& x, [[maybe_unused]]
int& y)
const
350 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
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;
366 #if MRPT_HAS_WXWIDGETS
377 REQ->voidPtr2 = (
void*)newImg;
389 const TColor& color,
bool showNumbers)
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];
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)
403 #if MRPT_HAS_WXWIDGETS
408 for (
size_t i = 0; i < x.size(); i++)
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);
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;
457 float tpxA = 0, tpyA = 0;
459 for (itx = x.
begin(), ity = y.
begin(); itx != x.
end(); ++itx, ++ity)
461 float tpx = (*itx - x[0]) / px + ox;
462 float tpy = (*ity - *itymn) / py + oy;
464 if (itx != x.
begin())
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);
500 imgColor.
textOut(550, 25,
"x", TColor::black());
501 imgColor.
textOut(25, 430,
"y", TColor::black());
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;
513 for (k = 0, ity = y.
begin(); ity != y.
end(); ++k, ++ity)
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);
532 [[maybe_unused]]
unsigned int width, [[maybe_unused]]
unsigned int height)
534 #if MRPT_HAS_WXWIDGETS
537 cerr <<
"[CDisplayWindow::resize] Window closed!: " <<
m_caption
557 #if MRPT_HAS_WXWIDGETS
560 cerr <<
"[CDisplayWindow::setPos] Window closed!: " <<
m_caption
580 #if MRPT_HAS_WXWIDGETS
583 cerr <<
"[CDisplayWindow::setWindowTitle] Window closed!: " <<
m_caption