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