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);
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...
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
The data structure for each inter-thread request:
Create a GUI window and display plots with MATLAB-like interfaces and commands.
mrpt::void_ptr_noncopy m_hwnd
The window handle.
void enableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
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.
void OnMenuClose(wxCommandEvent &event)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
The wx dialog for gui::CDisplayWindowPlots.
void setPos(int x, int y) override
Changes the position of the window on the screen.
static wxBitmap getMRPTDefaultIcon()
bool m_holdon
Whether hold_on is enabled.
void axis(float x_min, float x_max, float y_min, float y_max, bool aspectRatioFix=false)
Set the view area according to the passed coordinated.
void internal_plot(mrpt::math::CVectorFloat &x, mrpt::math::CVectorFloat &y, const std::string &lineFormat, const std::string &plotName)
void hold_off()
Disables keeping all the graphs (this is the default behavior).
wxImage * MRPTImage2wxImage(const mrpt::img::CImage &img)
Create a wxImage from a MRPT image.
int OPCODE
Valid codes are: For CDisplayWindow:
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.
GLubyte GLubyte GLubyte GLubyte w
void axis_equal(bool enable=true)
Enable/disable the fixed X/Y aspect ratio fix feature (default=disabled).
CDisplayWindowPlots(const std::string &windowCaption=std::string(), unsigned int initialWidth=350, unsigned int initialHeight=300)
Constructor.
#define ASSERT_(f)
Defines an assertion mechanism.
void OnMenuSelected(wxCommandEvent &ev)
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
uint32_t m_holdon_cnt
Counter for hold_on.
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
bool isOpen()
Returns false if the user has already closed the window.
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const std::string &lineFormat, const std::string &plotName)
Redirected from CDisplayWindowPlots::plot.
mrpt::math::CVectorFloat vector_y
virtual bool getLastMousePosition(int &x, int &y) const override
Gets the last x,y pixel coordinates of the mouse.
A pair (x,y) of pixel coordinates (integer resolution).
void(*)(int menuID, float cursor_x, float cursor_y, void *userParam) TCallbackMenu
Type for the callback function used in setMenuCallback.
An event sent by a window upon a char pressed by the user.
void addPopupMenuEntry(const std::string &label, int menuID)
Disables keeping all the graphs (this is the default behavior).
mrpt::gui::CDisplayWindow3D::Ptr win
GLsizei const GLchar ** string
mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent &ev)
Extracts the key modifiers from a wxKeyEvent.
void image(void *theWxImage, const float &x0, const float &y0, const float &w, const float &h, const std::string &plotName)
Redirected from CDisplayWindowPlots::image.
void OnMouseMove(wxMouseEvent &event)
virtual ~CWindowDialogPlots()
virtual ~CDisplayWindowPlots()
Destructor.
void clear()
Remove all plot objects in the display.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void axis_fit(bool aspectRatioFix=false)
Fix automatically the view area according to existing graphs.
std::shared_ptr< CDisplayWindowPlots > Ptr
void OnResize(wxSizeEvent &event)
This class implements the GUI thread required for the wxWidgets-based GUI.
void hold_on()
Enables keeping all the graphs, instead of overwritting them.
void clf()
Remove all plot objects in the display (clear and clf do exactly the same).
void image(const mrpt::img::CImage &img, const float &x_left, const float &y_bottom, const float &x_width, const float &y_height, const std::string &plotName=std::string("image"))
Adds a bitmap image layer.
void setWindowTitle(const std::string &str) override
Changes the window title text.
void plotEllipse(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const std::string &lineFormat, const std::string &plotName, bool showName=false)
Redirected from CDisplayWindowPlots::plotEllipse.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
static CDisplayWindowPlots::Ptr Create(const std::string &windowCaption, unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300)
Class factory returning a smart pointer.
void OnMouseDown(wxMouseEvent &event)
A matrix of dynamic size.
mrpt::gui::CDisplayWindowPlots * sourcePlots
Only one of source* can be non-nullptr, indicating the class that generated the request.
void destroyWxWindow()
Must be called by child classes in their destructors.
virtual void setCursorCross(bool cursorIsCross) override
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) ...
void OnClose(wxCloseEvent &event)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
Classes for creating GUI windows for 2D and 3D visualization.
void OnMenuPrint(wxCommandEvent &event)
void createWxWindow(unsigned int initialWidth, unsigned int initialHeight)
Must be called by child classes just within the constructor.
mrpt::math::CVectorFloat vector_x
void OnMenuAbout(wxCommandEvent &event)
GLenum GLsizei GLsizei height
void OnChar(wxKeyEvent &event)
std::string str
Parameters, depending on OPCODE.
GLsizei GLsizei GLenum GLenum const GLvoid * data
const Scalar * const_iterator
bool m_holdon_just_disabled
The base class for GUI window classes.
void setMenuCallback(TCallbackMenu userFunction, void *userParam=nullptr)
Must be called to have a callback when the user selects one of the user-defined entries in the popup ...
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
static int notifyWindowDestruction()
Atomically decrements the number of windows created with the main frame as parent.
void plotEllipse(const T mean_x, const T mean_y, const mrpt::math::CMatrixTemplateNumeric< T > &cov22, const float quantiles, const std::string &lineFormat=std::string("b-"), const std::string &plotName=std::string("plotEllipse"), bool showName=false)
Plots a 2D ellipse given its mean, covariance matrix, and Each call to this function creates a new pl...
A class for storing images as grayscale or RGB bitmaps.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.