12 #include <mrpt/config.h> 32 #if MRPT_HAS_WXWIDGETS 49 const
std::
string &caption,
52 m_winPlots( winPlots ),
62 wxDEFAULT_FRAME_STYLE,
65 SetClientSize(initialSize);
73 m_plot =
new mpWindow(
this, ID_PLOT );
74 m_plot->AddLayer(
new mpScaleX() );
75 m_plot->AddLayer(
new mpScaleY() );
76 m_plot->LockAspect(
false );
77 m_plot->EnableDoubleBuffer(
true);
79 m_plot->Fit( -10,10,-10,10 );
82 wxMenuBar *MenuBar1 =
new wxMenuBar();
84 wxMenu *Menu1 =
new wxMenu();
85 wxMenuItem *MenuItem1 =
new wxMenuItem(Menu1,
ID_MENUITEM1, _(
"Close"), _(
""), wxITEM_NORMAL);
86 Menu1->Append(MenuItem1);
88 wxMenuItem *MenuItemPrint =
new wxMenuItem(Menu1, ID_MENU_PRINT, _(
"Print..."), _(
""), wxITEM_NORMAL);
89 Menu1->Append(MenuItemPrint);
91 MenuBar1->Append(Menu1, _(
"&File"));
93 wxMenu *Menu2 =
new wxMenu();
94 wxMenuItem *MenuItem2 =
new wxMenuItem(Menu2,
ID_MENUITEM2, _(
"About..."), _(
""), wxITEM_NORMAL);
95 Menu2->Append(MenuItem2);
96 MenuBar1->Append(Menu2, _(
"&Help"));
133 XYPlot *plot =
new XYPlot();
135 XYSimpleDataset *dataset =
new XYSimpleDataset();
137 dataset->AddSerie((
double *)
data, WXSIZEOF(
data));
139 dataset->SetRenderer(
new XYLineRenderer());
141 plot->AddDataset(dataset);
143 NumberAxis *leftAxis =
new NumberAxis(AXIS_LEFT);
144 NumberAxis *bottomAxis =
new NumberAxis(AXIS_BOTTOM);
146 leftAxis->SetTitle(wxT(
"X"));
147 bottomAxis->SetTitle(wxT(
"Y"));
149 plot->AddAxis(leftAxis);
150 plot->AddAxis(bottomAxis);
152 plot->LinkDataVerticalAxis(0, 0);
153 plot->LinkDataHorizontalAxis(0, 0);
155 Chart* chart =
new Chart(plot, wxT(
"my title"));
156 wxChartPanel *m_chartPanel =
new wxChartPanel(
this );
157 m_chartPanel->SetChart( chart );
170 bool allow_close=
true;
173 m_winPlots->publishEvent(ev);
176 if (!allow_close)
return;
179 m_winPlots->notifyChildWindowDestruction();
185 m_winPlots->m_semWindowDestroyed.release();
194 const int code =
event.GetKeyCode();
197 m_winPlots->m_keyPushedCode =
code;
198 m_winPlots->m_keyPushedModifier = mod;
199 m_winPlots->m_keyPushed =
true;
214 m_winPlots->publishEvent(
mrptEventWindowResize(m_winPlots,event.GetSize().GetWidth(),
event.GetSize().GetHeight()));
242 m_plot->ShowPrintDialog();
247 ::wxMessageBox(_(
"Plot viewer\n Class gui::CDisplayWindowPlots\n MRPT C++ & wxMathPlot library"),_(
"About..."));
253 if (it!=m_ID2ID.end())
255 if (m_winPlots && m_winPlots->m_callback)
256 m_winPlots->m_callback(it->second,m_curCursorPos.x,m_curCursorPos.y, m_winPlots->m_callback_param);
263 event.GetPosition(&X,&Y);
264 m_curCursorPos.x = m_plot->p2x(X);
265 m_curCursorPos.y = m_plot->p2y(Y);
266 m_last_mouse_point.x = X;
267 m_last_mouse_point.y = Y;
270 if (m_winPlots && m_winPlots->hasSubscribers())
288 mpFXYVector *theLayer;
290 wxString lyName =
_U(plotName.c_str());
291 bool updateAtTheEnd =
false;
294 mpLayer* existingLy = m_plot->GetLayerByName( lyName );
299 mpFXYVector *lyPlot2D =
static_cast<mpFXYVector*
> ( existingLy );
303 cerr <<
"[CWindowDialogPlots::plot] Plot name '" << plotName <<
"' is not of expected class mpFXYVector!."<< endl;
309 updateAtTheEnd =
true;
314 theLayer =
new mpFXYVector( lyName );
315 m_plot->AddLayer( theLayer );
320 std::vector<float> x_(
x.size()),y_(
x.size());
321 ::memcpy(&x_[0],&
x[0],
sizeof(
x[0])*x_.size());
322 ::memcpy(&y_[0],&
y[0],
sizeof(
y[0])*y_.size());
323 theLayer->SetData( x_,y_ );
328 bool isContinuous=
true;
329 int lineColor[] = {0,0,255};
331 int lineStyle = wxSOLID;
334 if ( string::npos != lineFormat.find(
".") ) { isContinuous=
false; }
335 if ( string::npos != lineFormat.find(
"-") ) { isContinuous=
true; lineStyle = wxSOLID; }
336 if ( string::npos != lineFormat.find(
":") ) { isContinuous=
true; lineStyle = wxLONG_DASH; }
338 if ( string::npos != lineFormat.find(
"r") ) { lineColor[0]=0xFF; lineColor[1]=0x00; lineColor[2]=0x00; }
339 if ( string::npos != lineFormat.find(
"g") ) { lineColor[0]=0x00; lineColor[1]=0xFF; lineColor[2]=0x00; }
340 if ( string::npos != lineFormat.find(
"b") ) { lineColor[0]=0x00; lineColor[1]=0x00; lineColor[2]=0xFF; }
341 if ( string::npos != lineFormat.find(
"k") ) { lineColor[0]=0x00; lineColor[1]=0x00; lineColor[2]=0x00; }
342 if ( string::npos != lineFormat.find(
"m") ) { lineColor[0]=192; lineColor[1]=0; lineColor[2]=192; }
343 if ( string::npos != lineFormat.find(
"c") ) { lineColor[0]=0; lineColor[1]=192; lineColor[2]=192; }
345 if ( string::npos != lineFormat.find(
"1") ) { lineWidth=1; }
346 if ( string::npos != lineFormat.find(
"2") ) { lineWidth=2; }
347 if ( string::npos != lineFormat.find(
"3") ) { lineWidth=3; }
348 if ( string::npos != lineFormat.find(
"4") ) { lineWidth=4; }
349 if ( string::npos != lineFormat.find(
"5") ) { lineWidth=5; }
350 if ( string::npos != lineFormat.find(
"6") ) { lineWidth=6; }
351 if ( string::npos != lineFormat.find(
"7") ) { lineWidth=7; }
352 if ( string::npos != lineFormat.find(
"8") ) { lineWidth=8; }
353 if ( string::npos != lineFormat.find(
"9") ) { lineWidth=9; }
355 theLayer->SetContinuity(isContinuous);
357 wxPen pen( wxColour(lineColor[0],lineColor[1],lineColor[2]), lineWidth, lineStyle );
358 theLayer->SetPen(pen);
360 theLayer->ShowName(
false);
363 m_plot->Refresh(
false);
377 mpCovarianceEllipse *theLayer;
379 if (
x.size()!=3 ||
y.size()!=3)
381 cerr <<
"[CWindowDialogPlots::plotEllipse] vectors do not have expected size!!" << endl;
385 wxString lyName =
_U(plotName.c_str());
386 bool updateAtTheEnd =
false;
389 mpLayer* existingLy = m_plot->GetLayerByName( lyName );
394 mpCovarianceEllipse *lyPlotEllipse =
static_cast<mpCovarianceEllipse*
> ( existingLy );
398 cerr <<
"[CWindowDialogPlots::plotEllipse] Plot name '" << plotName <<
"' is not of expected class mpCovarianceEllipse!."<< endl;
403 theLayer = lyPlotEllipse;
404 updateAtTheEnd =
true;
409 theLayer =
new mpCovarianceEllipse( 1,1,0,2,32, lyName );
410 m_plot->AddLayer( theLayer );
414 theLayer->SetCovarianceMatrix(
y[0],
y[2],
y[1]);
415 theLayer->SetCoordinateBase(
x[0],
x[1]);
416 theLayer->SetQuantiles(
x[2]);
417 theLayer->ShowName(showName);
421 bool isContinuous=
true;
422 int lineColor[] = {0,0,255};
424 int lineStyle = wxSOLID;
427 if ( string::npos != lineFormat.find(
".") ) { isContinuous=
false; }
428 if ( string::npos != lineFormat.find(
"-") ) { isContinuous=
true; lineStyle = wxSOLID; }
429 if ( string::npos != lineFormat.find(
":") ) { isContinuous=
true; lineStyle = wxLONG_DASH; }
431 if ( string::npos != lineFormat.find(
"r") ) { lineColor[0]=0xFF; lineColor[1]=0x00; lineColor[2]=0x00; }
432 if ( string::npos != lineFormat.find(
"g") ) { lineColor[0]=0x00; lineColor[1]=0xFF; lineColor[2]=0x00; }
433 if ( string::npos != lineFormat.find(
"b") ) { lineColor[0]=0x00; lineColor[1]=0x00; lineColor[2]=0xFF; }
434 if ( string::npos != lineFormat.find(
"k") ) { lineColor[0]=0x00; lineColor[1]=0x00; lineColor[2]=0x00; }
435 if ( string::npos != lineFormat.find(
"m") ) { lineColor[0]=192; lineColor[1]=0; lineColor[2]=192; }
436 if ( string::npos != lineFormat.find(
"c") ) { lineColor[0]=0; lineColor[1]=192; lineColor[2]=192; }
438 if ( string::npos != lineFormat.find(
"1") ) { lineWidth=1; }
439 if ( string::npos != lineFormat.find(
"2") ) { lineWidth=2; }
440 if ( string::npos != lineFormat.find(
"3") ) { lineWidth=3; }
441 if ( string::npos != lineFormat.find(
"4") ) { lineWidth=4; }
442 if ( string::npos != lineFormat.find(
"5") ) { lineWidth=5; }
443 if ( string::npos != lineFormat.find(
"6") ) { lineWidth=6; }
444 if ( string::npos != lineFormat.find(
"7") ) { lineWidth=7; }
445 if ( string::npos != lineFormat.find(
"8") ) { lineWidth=8; }
446 if ( string::npos != lineFormat.find(
"9") ) { lineWidth=9; }
448 theLayer->SetContinuity(isContinuous);
450 wxPen pen( wxColour(lineColor[0],lineColor[1],lineColor[2]), lineWidth, lineStyle );
451 theLayer->SetPen(pen);
454 m_plot->Refresh(
false);
466 mpBitmapLayer *theLayer;
468 wxString lyName =
_U(plotName.c_str());
469 bool updateAtTheEnd =
false;
472 mpLayer* existingLy = m_plot->GetLayerByName( lyName );
477 mpBitmapLayer *ly =
static_cast<mpBitmapLayer*
> ( existingLy );
481 cerr <<
"[CWindowDialogPlots::image] Plot name '" << plotName <<
"' is not of expected class mpBitmapLayer!."<< endl;
487 updateAtTheEnd =
true;
492 theLayer =
new mpBitmapLayer();
493 m_plot->AddLayer( theLayer );
497 wxImage *ii =
static_cast<wxImage *
>(theWxImage);
498 theLayer->SetBitmap( *ii, x0,y0,
w,h );
500 delete ii;theWxImage=NULL;
502 if (updateAtTheEnd) m_plot->Refresh();
509 unsigned int initialWindowWidth,
510 unsigned int initialWindowHeight )
512 return CDisplayWindowPlotsPtr(
new CDisplayWindowPlots(windowCaption,initialWindowWidth,initialWindowHeight));
519 unsigned int initialWidth,
520 unsigned int initialHeight ) :
523 m_holdon_just_disabled(false),
526 m_callback_param (NULL)
542 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 545 win->
m_plot->SetCursor( *(cursorIsCross ? wxCROSS_CURSOR : wxSTANDARD_CURSOR) );
556 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 558 if (!win)
return false;
576 #if MRPT_HAS_WXWIDGETS 579 cerr <<
"[CDisplayWindowPlots::resize] Window closed!: " <<
m_caption << endl;
600 #if MRPT_HAS_WXWIDGETS 603 cerr <<
"[CDisplayWindowPlots::setPos] Window closed!: " <<
m_caption << endl;
624 #if MRPT_HAS_WXWIDGETS 627 cerr <<
"[CDisplayWindowPlots::setWindowTitle] Window closed!: " <<
m_caption << endl;
647 #if MRPT_HAS_WXWIDGETS 666 #if MRPT_HAS_WXWIDGETS 685 #if MRPT_HAS_WXWIDGETS 711 #if MRPT_HAS_WXWIDGETS 730 template <
typename T>
735 const float quantiles,
740 #if MRPT_HAS_WXWIDGETS 745 ASSERT_(cov22.getColCount()==2 && cov22.getRowCount()==2);
748 ASSERT_(cov22(0,1) == cov22(1,0) );
764 REQ->
str = lineFormat;
765 REQ->
plotName = plotName+holdon_post;
797 const float quantiles,
805 const float quantiles,
813 template <
typename T>
818 const float quantiles,
823 #if MRPT_HAS_WXWIDGETS 830 ASSERT_(cov22(0,1) == cov22(1,0) );
846 REQ->
str = lineFormat;
847 REQ->
plotName = plotName+holdon_post;
880 const float quantiles,
889 const float quantiles,
901 const float &y_bottom,
902 const float &x_width,
903 const float &y_height,
906 #if MRPT_HAS_WXWIDGETS 926 REQ->
plotName = plotName+holdon_post;
957 #if MRPT_HAS_WXWIDGETS 970 if (x.empty())
return;
980 REQ->
str = lineFormat;
981 REQ->
plotName = plotName + holdon_post;
1003 #if MRPT_HAS_WXWIDGETS 1049 #if MRPT_HAS_WXWIDGETS #define ASSERT_EQUAL_(__A, __B)
An event sent by a window upon resize.
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
static void pushPendingWxRequest(TRequestToWxMainThread *data)
Thread-safe method to insert a new pending request (The memory must be dinamically allocated with "ne...
void setMenuCallback(TCallbackMenu userFunction, void *userParam=NULL)
Must be called to have a callback when the user selects one of the user-defined entries in the popup ...
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
The data structure for each inter-thread request:
void setPos(int x, int y) MRPT_OVERRIDE
Changes the position of the window on the screen.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Create a GUI window and display plots with MATLAB-like interfaces and commands.
#define IMPLEMENTS_MRPT_OBJECT(class_name, base, NameSpace)
This must be inserted in all CObject classes implementation files.
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.
A class for storing images as grayscale or RGB bitmaps.
static int notifyWindowCreation()
Atomically increments the number of windows created with the main frame as parent.
A pair (x,y) of pixel coordinates (integer resolution).
void OnMenuClose(wxCommandEvent &event)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
The wx dialog for gui::CDisplayWindowPlots.
wxPoint m_last_mouse_point
In pixels.
static wxBitmap getMRPTDefaultIcon()
bool m_holdon
Whether hold_on is enabled.
const Scalar * const_iterator
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).
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 programat...
An event sent by a window when the mouse is moved over it.
void image(const utils::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.
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.
void OnMenuSelected(wxCommandEvent &ev)
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
uint32_t m_holdon_cnt
Counter for hold_on.
void GUI_IMPEXP 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...
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
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
virtual void setCursorCross(bool cursorIsCross) MRPT_OVERRIDE
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) ...
wxImage GUI_IMPEXP * MRPTImage2wxImage(const mrpt::utils::CImage &img)
Create a wxImage from a MRPT image.
An event sent by a window upon a char pressed by the user.
static CDisplayWindowPlotsPtr Create()
void addPopupMenuEntry(const std::string &label, int menuID)
Disables keeping all the graphs (this is the default behavior).
GLsizei const GLchar ** string
mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent &ev)
Extracts the key modifiers from a wxKeyEvent.
void resize(unsigned int width, unsigned int height) MRPT_OVERRIDE
Resizes the window, stretching the image to fit into the display area.
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.
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 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.
void OnMouseDown(wxMouseEvent &event)
virtual bool getLastMousePosition(int &x, int &y) const MRPT_OVERRIDE
Gets the last x,y pixel coordinates of the mouse.
A matrix of dynamic size.
mrpt::gui::CDisplayWindowPlots * sourcePlots
Only one of source* can be non-NULL, indicating the class that generated the request.
void destroyWxWindow()
Must be called by child classes in their destructors. The code cannot be put into this class' destruc...
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
mrpt::utils::void_ptr_noncopy m_hwnd
The window handle.
bool m_holdon_just_disabled
The base class for GUI window classes.
void setWindowTitle(const std::string &str) MRPT_OVERRIDE
Changes the window title text.
static int notifyWindowDestruction()
Atomically decrements the number of windows created with the main frame as parent.