class mrpt::gui::CDisplayWindowPlots
Create a GUI window and display plots with MATLAB-like interfaces and commands.
For a list of supported events with the observer/observable pattern, see the discussion in mrpt::gui::CBaseGUIWindow.
#include <mrpt/gui/CDisplayWindowPlots.h> class CDisplayWindowPlots: public mrpt::gui::CBaseGUIWindow { public: // typedefs typedef std::shared_ptr<CDisplayWindowPlots> Ptr; typedef void(*)(int menuID, float cursor_x, float cursor_y, void*userParam) TCallbackMenu; // construction CDisplayWindowPlots( const std::string& windowCaption = std::string(), unsigned int initialWidth = 350, unsigned int initialHeight = 300 ); // methods virtual bool getLastMousePosition(int& x, int& y) const; virtual void setCursorCross(bool cursorIsCross); virtual void resize(unsigned int width, unsigned int height); virtual void setPos(int x, int y); virtual void setWindowTitle(const std::string& str); void enableMousePanZoom(bool enabled); template <typename VEC1, typename VEC2, typename = typename VEC2::Scalar> void plot( const VEC1& x, const VEC2& y, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotXY") ); template <typename T> void plot( const std::vector<T>& x, const std::vector<T>& y, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotXY") ); template <typename VEC> void plot( const VEC& y, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotXY") ); void axis( float x_min, float x_max, float y_min, float y_max, bool aspectRatioFix = false ); void axis_equal(bool enable = true); void axis_fit(bool aspectRatioFix = false); template <typename T> void plotEllipse( const T mean_x, const T mean_y, const mrpt::math::CMatrixDynamic<T>& cov22, const float quantiles, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotEllipse"), bool showName = false ); template <typename T> void plotEllipse( const T mean_x, const T mean_y, const mrpt::math::CMatrixFixed<T, 2, 2>& cov22, const float quantiles, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotEllipse"), bool showName = false ); void image( const mrpt::img::CImage& img, float x_left, float y_bottom, float x_width, float y_height, const std::string& plotName = std::string("image") ); void clear(); void clf(); void hold_on(); void hold_off(); void addPopupMenuEntry(const std::string& label, int menuID); void setMenuCallback(TCallbackMenu userFunction, void* userParam = nullptr); template <typename T> void plotEllipse( ] const T mean_x, ] const T mean_y, ] const CMatrixDynamic<T>& cov22, ] const float quantiles, ] const std::string& lineFormat, ] const std::string& plotName, ] bool showName ); template <typename T> void plotEllipse( ] const T mean_x, ] const T mean_y, ] const CMatrixFixed<T, 2, 2>& cov22, ] const float quantiles, ] const std::string& lineFormat, ] const std::string& plotName, ] bool showName ); static CDisplayWindowPlots::Ptr Create( const std::string& windowCaption, unsigned int initialWindowWidth = 400, unsigned int initialWindowHeight = 300 ); };
Inherited Members
public: // methods void* getWxObject(); void notifyChildWindowDestruction(); void notifySemThreadReady(); bool isOpen(); virtual void resize(unsigned int width, unsigned int height) = 0; virtual void setPos(int x, int y) = 0; virtual void setWindowTitle(const std::string& str) = 0; virtual bool getLastMousePosition(int& x, int& y) const = 0; virtual void setCursorCross(bool cursorIsCross) = 0; int waitForKey(bool ignoreControlKeys = true, mrptKeyModifier* out_pushModifier = nullptr); bool keyHit() const; void clearKeyHitFlag(); int getPushedKey(mrptKeyModifier* out_pushModifier = nullptr);
Typedefs
typedef void(*)(int menuID, float cursor_x, float cursor_y, void*userParam) TCallbackMenu
Type for the callback function used in setMenuCallback.
Construction
CDisplayWindowPlots( const std::string& windowCaption = std::string(), unsigned int initialWidth = 350, unsigned int initialHeight = 300 )
Constructor.
Methods
virtual bool getLastMousePosition(int& x, int& y) const
Gets the last x,y pixel coordinates of the mouse.
Returns:
False if the window is closed.
virtual void setCursorCross(bool cursorIsCross)
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true)
virtual void resize(unsigned int width, unsigned int height)
Resizes the window, stretching the image to fit into the display area.
virtual void setPos(int x, int y)
Changes the position of the window on the screen.
virtual void setWindowTitle(const std::string& str)
Changes the window title text.
void enableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
template <typename VEC1, typename VEC2, typename = typename VEC2::Scalar> void plot( const VEC1& x, const VEC2& y, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotXY") )
Adds a new layer with a 2D plot based on two vectors of X and Y points, using a MATLAB-like syntax.
Each call to this function creates a new plot, unless the plot name coincides with an already existing plot: in this case the X & Y points are used to update this existing layer (this also applies to using the default plot name). If “hold_on” is enabled, then every call will always create a new plot, even if no “plotName” is provided.
The lineFormat string is a combination of the following characters:
Line styles:
‘.’: One point for each data point
‘-’: A continuous line
‘:’: A dashed line
Colors:
k: black
r: red
g: green
b: blue
m: magenta
c: cyan
Line width:
‘1’ to ‘9’: The line width (default=1)
Examples:
‘r.’ -> red points.
‘k3’ or ‘k-3’ -> A black line with a line width of 3 pixels. The vectors x & y can be of types: float or double.
Parameters:
VECTOR |
Can be std::vector<float/double> or mrpt::dynamicsize_vector<float/double> or a column/row Eigen::Matrix<> |
See also:
axis, axis_equal, axis_fit, clear, hold_on, hold_off
template <typename VEC> void plot( const VEC& y, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotXY") )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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 axis_equal(bool enable = true)
Enable/disable the fixed X/Y aspect ratio fix feature (default=disabled).
void axis_fit(bool aspectRatioFix = false)
Fix automatically the view area according to existing graphs.
template <typename T> void plotEllipse( const T mean_x, const T mean_y, const mrpt::math::CMatrixDynamic<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 plot, unless the plot name coincides with an already existing plot: in this case the new values are used to update this existing layer (this also applies to using the default plot name).
If “hold_on” is enabled, then every call will always create a new plot, even if no “plotName” is provided.
For a description of lineFormat see CDisplayWindowPlots::plot. The “quantiles” value determines the confidence interval for the ellipse:
1 : 68.27% confidence interval
2 : 95.45%
3 : 99.73%
4 : 99.994% This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double.
See also:
axis, axis_equal, axis_fit, hold_on, hold_off
template <typename T> void plotEllipse( const T mean_x, const T mean_y, const mrpt::math::CMatrixFixed<T, 2, 2>& cov22, const float quantiles, const std::string& lineFormat = std::string("b-"), const std::string& plotName = std::string("plotEllipse"), bool showName = false )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void image( const mrpt::img::CImage& img, float x_left, float y_bottom, float x_width, float y_height, const std::string& plotName = std::string("image") )
Adds a bitmap image layer.
Each call to this function creates a new layer, unless the plot name coincides with an already existing plot: in this case the new values are used to update this existing layer (this also applies to using the default plot name).
See also:
axis, axis_equal, axis_fit, hold_on, hold_off
void clear()
Remove all plot objects in the display.
See also:
void clf()
Remove all plot objects in the display (clear and clf do exactly the same).
See also:
void hold_on()
Enables keeping all the graphs, instead of overwriting them.
See also:
void hold_off()
Disables keeping all the graphs (this is the default behavior).
See also:
void addPopupMenuEntry(const std::string& label, int menuID)
Disables keeping all the graphs (this is the default behavior).
Parameters:
label |
The text that appears in the new popup menu item. |
menuID |
Any positive number (0,1,..). Used to tell which menu was selected in the user callback. |
See also:
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 menu.
See also:
static CDisplayWindowPlots::Ptr Create( const std::string& windowCaption, unsigned int initialWindowWidth = 400, unsigned int initialWindowHeight = 300 )
Class factory returning a smart pointer, equivalent to std::make_shared<>(...)