12 #include <mrpt/config.h>
28 #if MRPT_HAS_WXWIDGETS
41 wxWindowID
id, const std::
string& caption, wxSize initialSize)
42 : m_winPlots(winPlots), m_mainFrame(parent), m_firstSubmenu(true)
45 parent,
id,
_U(caption.c_str()), wxDefaultPosition, initialSize,
46 wxDEFAULT_FRAME_STYLE, _T(
"id"));
48 SetClientSize(initialSize);
55 m_plot =
new mpWindow(
this, ID_PLOT);
56 m_plot->AddLayer(
new mpScaleX());
57 m_plot->AddLayer(
new mpScaleY());
58 m_plot->LockAspect(
false);
59 m_plot->EnableDoubleBuffer(
true);
61 m_plot->Fit(-10, 10, -10, 10);
64 wxMenuBar* MenuBar1 =
new wxMenuBar();
66 wxMenu* Menu1 =
new wxMenu();
67 wxMenuItem* MenuItem1 =
68 new wxMenuItem(Menu1,
ID_MENUITEM1, _(
"Close"), _(
""), wxITEM_NORMAL);
69 Menu1->Append(MenuItem1);
71 wxMenuItem* MenuItemPrint =
new wxMenuItem(
72 Menu1, ID_MENU_PRINT, _(
"Print..."), _(
""), wxITEM_NORMAL);
73 Menu1->Append(MenuItemPrint);
75 MenuBar1->Append(Menu1, _(
"&File"));
77 wxMenu* Menu2 =
new wxMenu();
78 wxMenuItem* MenuItem2 =
new wxMenuItem(
79 Menu2,
ID_MENUITEM2, _(
"About..."), _(
""), wxITEM_NORMAL);
80 Menu2->Append(MenuItem2);
81 MenuBar1->Append(Menu2, _(
"&Help"));
87 wxID_ANY, wxEVT_CLOSE_WINDOW,
93 ID_MENU_PRINT, wxEVT_COMMAND_MENU_SELECTED,
100 wxID_ANY, wxEVT_SIZE,
104 wxID_ANY, wxEVT_CHAR,
138 XYPlot *plot =
new XYPlot();
140 XYSimpleDataset *dataset =
new XYSimpleDataset();
142 dataset->AddSerie((
double *)
data, WXSIZEOF(
data));
144 dataset->SetRenderer(
new XYLineRenderer());
146 plot->AddDataset(dataset);
148 NumberAxis *leftAxis =
new NumberAxis(AXIS_LEFT);
149 NumberAxis *bottomAxis =
new NumberAxis(AXIS_BOTTOM);
151 leftAxis->SetTitle(wxT(
"X"));
152 bottomAxis->SetTitle(wxT(
"Y"));
154 plot->AddAxis(leftAxis);
155 plot->AddAxis(bottomAxis);
157 plot->LinkDataVerticalAxis(0, 0);
158 plot->LinkDataHorizontalAxis(0, 0);
160 Chart* chart =
new Chart(plot, wxT(
"my title"));
161 wxChartPanel *m_chartPanel =
new wxChartPanel(
this );
162 m_chartPanel->SetChart( chart );
172 bool allow_close =
true;
176 m_winPlots->publishEvent(ev);
182 if (!allow_close)
return;
185 m_winPlots->notifyChildWindowDestruction();
191 m_winPlots->m_windowDestroyed.set_value();
200 const int code =
event.GetKeyCode();
203 m_winPlots->m_keyPushedCode =
code;
204 m_winPlots->m_keyPushedModifier = mod;
205 m_winPlots->m_keyPushed =
true;
209 m_winPlots->publishEvent(
226 m_winPlots->publishEvent(
228 m_winPlots, event.GetSize().GetWidth(),
229 event.GetSize().GetHeight()));
245 m_winPlots->publishEvent(
247 m_winPlots,
TPixelCoord(event.GetX(), event.GetY()),
248 event.LeftDown(), event.RightDown()));
262 m_plot->ShowPrintDialog();
268 _(
"Plot viewer\n Class gui::CDisplayWindowPlots\n MRPT C++ & "
269 "wxMathPlot library"),
276 if (it != m_ID2ID.end())
278 if (m_winPlots && m_winPlots->m_callback)
279 m_winPlots->m_callback(
280 it->second, m_curCursorPos.x, m_curCursorPos.y,
281 m_winPlots->m_callback_param);
288 event.GetPosition(&X, &Y);
289 m_curCursorPos.x = m_plot->p2x(X);
290 m_curCursorPos.y = m_plot->p2y(Y);
291 m_last_mouse_point.x = X;
292 m_last_mouse_point.y = Y;
295 if (m_winPlots && m_winPlots->hasSubscribers())
299 m_winPlots->publishEvent(
303 event.LeftDown(), event.RightDown()));
317 mpFXYVector* theLayer;
319 wxString lyName =
_U(plotName.c_str());
320 bool updateAtTheEnd =
false;
324 mpLayer* existingLy = m_plot->GetLayerByName(lyName);
329 mpFXYVector* lyPlot2D =
static_cast<mpFXYVector*
>(existingLy);
333 cerr <<
"[CWindowDialogPlots::plot] Plot name '" << plotName
334 <<
"' is not of expected class mpFXYVector!." << endl;
340 updateAtTheEnd =
true;
345 theLayer =
new mpFXYVector(lyName);
346 m_plot->AddLayer(theLayer);
351 std::vector<float> x_(
x.size()), y_(
x.size());
352 ::memcpy(&x_[0], &
x[0],
sizeof(
x[0]) * x_.size());
353 ::memcpy(&y_[0], &
y[0],
sizeof(
y[0]) * y_.size());
354 theLayer->SetData(x_, y_);
359 bool isContinuous =
true;
360 int lineColor[] = {0, 0, 255};
362 int lineStyle = wxSOLID;
365 if (string::npos != lineFormat.find(
"."))
367 isContinuous =
false;
369 if (string::npos != lineFormat.find(
"-"))
374 if (string::npos != lineFormat.find(
":"))
377 lineStyle = wxLONG_DASH;
380 if (string::npos != lineFormat.find(
"r"))
386 if (string::npos != lineFormat.find(
"g"))
392 if (string::npos != lineFormat.find(
"b"))
398 if (string::npos != lineFormat.find(
"k"))
404 if (string::npos != lineFormat.find(
"m"))
410 if (string::npos != lineFormat.find(
"c"))
417 if (string::npos != lineFormat.find(
"1"))
421 if (string::npos != lineFormat.find(
"2"))
425 if (string::npos != lineFormat.find(
"3"))
429 if (string::npos != lineFormat.find(
"4"))
433 if (string::npos != lineFormat.find(
"5"))
437 if (string::npos != lineFormat.find(
"6"))
441 if (string::npos != lineFormat.find(
"7"))
445 if (string::npos != lineFormat.find(
"8"))
449 if (string::npos != lineFormat.find(
"9"))
454 theLayer->SetContinuity(isContinuous);
457 wxColour(lineColor[0], lineColor[1], lineColor[2]), lineWidth,
459 theLayer->SetPen(pen);
461 theLayer->ShowName(
false);
463 if (updateAtTheEnd) m_plot->Refresh(
false);
473 mpCovarianceEllipse* theLayer;
475 if (
x.size() != 3 ||
y.size() != 3)
477 cerr <<
"[CWindowDialogPlots::plotEllipse] vectors do not have "
483 wxString lyName =
_U(plotName.c_str());
484 bool updateAtTheEnd =
false;
488 mpLayer* existingLy = m_plot->GetLayerByName(lyName);
493 mpCovarianceEllipse* lyPlotEllipse =
494 static_cast<mpCovarianceEllipse*
>(existingLy);
498 cerr <<
"[CWindowDialogPlots::plotEllipse] Plot name '" << plotName
499 <<
"' is not of expected class mpCovarianceEllipse!." << endl;
504 theLayer = lyPlotEllipse;
505 updateAtTheEnd =
true;
510 theLayer =
new mpCovarianceEllipse(1, 1, 0, 2, 32, lyName);
511 m_plot->AddLayer(theLayer);
515 theLayer->SetCovarianceMatrix(
y[0],
y[2],
y[1]);
516 theLayer->SetCoordinateBase(
x[0],
x[1]);
517 theLayer->SetQuantiles(
x[2]);
518 theLayer->ShowName(showName);
522 bool isContinuous =
true;
523 int lineColor[] = {0, 0, 255};
525 int lineStyle = wxSOLID;
528 if (string::npos != lineFormat.find(
"."))
530 isContinuous =
false;
532 if (string::npos != lineFormat.find(
"-"))
537 if (string::npos != lineFormat.find(
":"))
540 lineStyle = wxLONG_DASH;
543 if (string::npos != lineFormat.find(
"r"))
549 if (string::npos != lineFormat.find(
"g"))
555 if (string::npos != lineFormat.find(
"b"))
561 if (string::npos != lineFormat.find(
"k"))
567 if (string::npos != lineFormat.find(
"m"))
573 if (string::npos != lineFormat.find(
"c"))
580 if (string::npos != lineFormat.find(
"1"))
584 if (string::npos != lineFormat.find(
"2"))
588 if (string::npos != lineFormat.find(
"3"))
592 if (string::npos != lineFormat.find(
"4"))
596 if (string::npos != lineFormat.find(
"5"))
600 if (string::npos != lineFormat.find(
"6"))
604 if (string::npos != lineFormat.find(
"7"))
608 if (string::npos != lineFormat.find(
"8"))
612 if (string::npos != lineFormat.find(
"9"))
617 theLayer->SetContinuity(isContinuous);
620 wxColour(lineColor[0], lineColor[1], lineColor[2]), lineWidth,
622 theLayer->SetPen(pen);
624 if (updateAtTheEnd) m_plot->Refresh(
false);
628 void* theWxImage,
const float& x0,
const float& y0,
const float&
w,
631 mpBitmapLayer* theLayer;
633 wxString lyName =
_U(plotName.c_str());
634 bool updateAtTheEnd =
false;
638 mpLayer* existingLy = m_plot->GetLayerByName(lyName);
643 mpBitmapLayer* ly =
static_cast<mpBitmapLayer*
>(existingLy);
647 cerr <<
"[CWindowDialogPlots::image] Plot name '" << plotName
648 <<
"' is not of expected class mpBitmapLayer!." << endl;
654 updateAtTheEnd =
true;
659 theLayer =
new mpBitmapLayer();
660 m_plot->AddLayer(theLayer);
664 wxImage* ii =
static_cast<wxImage*
>(theWxImage);
665 theLayer->SetBitmap(*ii, x0, y0,
w, h);
668 theWxImage =
nullptr;
670 if (updateAtTheEnd) m_plot->Refresh();
676 const std::string& windowCaption,
unsigned int initialWindowWidth,
677 unsigned int initialWindowHeight)
681 windowCaption, initialWindowWidth, initialWindowHeight));
687 const std::string& windowCaption,
unsigned int initialWidth,
688 unsigned int initialHeight)
691 m_holdon_just_disabled(false),
694 m_callback_param(nullptr)
711 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
714 win->m_plot->SetCursor(
715 *(cursorIsCross ? wxCROSS_CURSOR : wxSTANDARD_CURSOR));
726 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT
728 if (!
win)
return false;
729 x =
win->m_last_mouse_point.x;
730 y =
win->m_last_mouse_point.y;
744 #if MRPT_HAS_WXWIDGETS
747 cerr <<
"[CDisplayWindowPlots::resize] Window closed!: " <<
m_caption
771 #if MRPT_HAS_WXWIDGETS
774 cerr <<
"[CDisplayWindowPlots::setPos] Window closed!: " <<
m_caption
798 #if MRPT_HAS_WXWIDGETS
801 cerr <<
"[CDisplayWindowPlots::setWindowTitle] Window closed!: "
823 #if MRPT_HAS_WXWIDGETS
843 #if MRPT_HAS_WXWIDGETS
862 float x_min,
float x_max,
float y_min,
float y_max,
bool aspectRatioFix)
864 #if MRPT_HAS_WXWIDGETS
894 #if MRPT_HAS_WXWIDGETS
912 template <
typename T>
915 const float quantiles,
const std::string& lineFormat,
918 #if MRPT_HAS_WXWIDGETS
922 ASSERT_(cov22.cols() == 2 && cov22.rows() == 2);
925 ASSERT_(cov22(0, 1) == cov22(1, 0));
945 REQ->
str = lineFormat;
946 REQ->
plotName = plotName + holdon_post;
975 const float mean_x,
const float mean_y,
979 const double mean_x,
const double mean_y,
986 template <
typename T>
989 const float quantiles,
const std::string& lineFormat,
992 #if MRPT_HAS_WXWIDGETS
998 ASSERT_(cov22(0, 1) == cov22(1, 0));
1018 REQ->
str = lineFormat;
1019 REQ->
plotName = plotName + holdon_post;
1048 const float mean_x,
const float mean_y,
1052 const double mean_x,
const double mean_y,
1061 const float& x_width,
const float& y_height,
const std::string& plotName)
1063 #if MRPT_HAS_WXWIDGETS
1086 REQ->
plotName = plotName + holdon_post;
1115 #if MRPT_HAS_WXWIDGETS
1127 if (x.empty())
return;
1139 REQ->
str = lineFormat;
1140 REQ->
plotName = plotName + holdon_post;
1160 #if MRPT_HAS_WXWIDGETS
1198 #if MRPT_HAS_WXWIDGETS
1224 ASSERT_(userFunction !=
nullptr);