Main MRPT website > C++ reference for MRPT 1.4.0
CDisplayWindowPlots.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6 | See: http://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See details in http://www.mrpt.org/License |
8 +---------------------------------------------------------------------------+ */
9#ifndef CDisplayWindowPlots_H
10#define CDisplayWindowPlots_H
11
15#include <mrpt/utils/CImage.h>
16#include <mrpt/gui/gui_frwds.h>
17
18/*---------------------------------------------------------------
19 Class
20 ---------------------------------------------------------------*/
21namespace mrpt
22{
23 namespace gui
24 {
26
27 /** Create a GUI window and display plots with MATLAB-like interfaces and commands.
28 *
29 * For a list of supported events with the observer/observable pattern, see the discussion in mrpt::gui::CBaseGUIWindow.
30 *
31 * See CDisplayWindowPlots::plot
32 * \ingroup mrpt_gui_grp
33 */
35 {
36 // This must be added to any CObject derived class:
38
39 public:
40 typedef void (* TCallbackMenu) (int menuID,float cursor_x, float cursor_y, void* userParam); //!< Type for the callback function used in setMenuCallback
41
42 protected:
43 friend class CWindowDialogPlots;
44
45 bool m_holdon; //!< Whether hold_on is enabled
47 uint32_t m_holdon_cnt; //!< Counter for hold_on
48 TCallbackMenu m_callback;
50
51 void internal_plot(mrpt::math::CVectorFloat &x,mrpt::math::CVectorFloat &y,const std::string &lineFormat,const std::string &plotName);
52 template <typename VECTOR1,typename VECTOR2>
53 void internal_plot_interface(const VECTOR1 &x,const VECTOR2 &y,const std::string &lineFormat,const std::string &plotName)
54 {
55 mrpt::math::CVectorFloat x1(x.size()), y1(y.size());
56 const size_t N1=size_t(x.size());
57 for (size_t i=0;i<N1;i++) x1[i]=x[i];
58 const size_t N2=size_t(y.size());
59 for (size_t i=0;i<N2;i++) y1[i]=y[i];
60 this->internal_plot(x1,y1,lineFormat,plotName);
61 }
62 template <typename VECTOR1>
63 void internal_plot_interface(const VECTOR1 &y,const std::string &lineFormat,const std::string &plotName)
64 {
65 const size_t N=size_t(y.size());
66 mrpt::math::CVectorFloat x1(N),y1(N);
67 for (size_t i=0;i<N;i++) { x1[i]=i; y1[i]=y[i]; }
68 this->internal_plot(x1,y1,lineFormat,plotName);
69 }
70
71 public:
72
73 /** Constructor
74 */
76 const std::string &windowCaption = std::string(),
77 unsigned int initialWidth = 350,
78 unsigned int initialHeight = 300 );
79
80 /** Class factory returning a smart pointer */
82 const std::string &windowCaption,
83 unsigned int initialWindowWidth = 400,
84 unsigned int initialWindowHeight = 300 );
85
86 /** Destructor
87 */
89
90 /** Gets the last x,y pixel coordinates of the mouse. \return False if the window is closed. */
91 virtual bool getLastMousePosition(int &x, int &y) const MRPT_OVERRIDE;
92
93 /** Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) */
94 virtual void setCursorCross(bool cursorIsCross) MRPT_OVERRIDE;
95
96 /** Resizes the window, stretching the image to fit into the display area.
97 */
98 void resize( unsigned int width, unsigned int height ) MRPT_OVERRIDE;
99
100 /** Changes the position of the window on the screen.
101 */
102 void setPos( int x, int y ) MRPT_OVERRIDE;
103
104 /** Changes the window title text.
105 */
106 void setWindowTitle( const std::string &str ) MRPT_OVERRIDE;
107
108 /** Enable/disable the feature of pan/zoom with the mouse (default=enabled)
109 */
110 void enableMousePanZoom( bool enabled );
111
112 /** Adds a new layer with a 2D plot based on two vectors of X and Y points, using a MATLAB-like syntax.
113 * 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).
114 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided.
115 *
116 * The lineFormat string is a combination of the following characters:
117 * - Line styles:
118 * - '.': One point for each data point
119 * - '-': A continuous line
120 * - ':': A dashed line
121 * - Colors:
122 * - k: black
123 * - r: red
124 * - g: green
125 * - b: blue
126 * - m: magenta
127 * - c: cyan
128 * - Line width:
129 * - '1' to '9': The line width (default=1)
130 *
131 * Examples:
132 * - 'r.' -> red points.
133 * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels.
134 * \note The vectors x & y can be of types: float or double.
135 * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off
136 * \tparam VECTOR Can be std::vector<float/double> or mrpt::dynamicsize_vector<float/double> or a column/row Eigen::Matrix<>
137 */
138 template <typename T1,typename T2> inline void plot(const std::vector<T1> &x,const std::vector<T2> &y,const std::string &lineFormat = std::string("b-"),const std::string &plotName = std::string("plotXY") ) { this->internal_plot_interface(x,y,lineFormat,plotName); }
139 //! \overload
140 template <typename T1,typename Derived2> inline void plot(const std::vector<T1> &x,const Eigen::MatrixBase<Derived2> &y,const std::string &lineFormat = std::string("b-"),const std::string &plotName = std::string("plotXY") ) { this->internal_plot_interface(x,y,lineFormat,plotName); }
141 //! \overload
142 template <typename Derived1,typename T2> inline void plot(const Eigen::MatrixBase<Derived1> &x,const std::vector<T2> &y,const std::string &lineFormat = std::string("b-"),const std::string &plotName = std::string("plotXY") ) { this->internal_plot_interface(x,y,lineFormat,plotName); }
143 //! \overload
144 template <typename Derived1,typename Derived2> inline void plot(const Eigen::MatrixBase<Derived1> &x,const Eigen::MatrixBase<Derived2> &y,const std::string &lineFormat = std::string("b-"),const std::string &plotName = std::string("plotXY") ) { this->internal_plot_interface(x,y,lineFormat,plotName); }
145
146 //! \overload
147 template <typename T> void plot(const std::vector<T> &y,const std::string &lineFormat = std::string("b-"),const std::string &plotName = std::string("plotXY") ) { this->internal_plot_interface(y,lineFormat,plotName); }
148 //! \overload
149 template <typename Derived> void plot(const Eigen::MatrixBase<Derived> &y,const std::string &lineFormat = std::string("b-"),const std::string &plotName = std::string("plotXY") ) { this->internal_plot_interface(y,lineFormat,plotName); }
150
151 /** Set the view area according to the passed coordinated. */
152 void axis( float x_min, float x_max, float y_min, float y_max, bool aspectRatioFix = false );
153
154 /** Enable/disable the fixed X/Y aspect ratio fix feature (default=disabled). */
155 void axis_equal(bool enable=true);
156
157 /** Fix automatically the view area according to existing graphs. */
158 void axis_fit(bool aspectRatioFix=false);
159
160 /** Plots a 2D ellipse given its mean, covariance matrix, and
161 * 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).
162 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided.
163 *
164 * For a description of lineFormat see CDisplayWindowPlots::plot.
165 * The "quantiles" value determines the confidence interval for the ellipse:
166 * - 1 : 68.27% confidence interval
167 * - 2 : 95.45%
168 * - 3 : 99.73%
169 * - 4 : 99.994%
170 * \note This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double.
171 * \sa axis, axis_equal, axis_fit, hold_on, hold_off
172 */
173 template <typename T>
175 const T mean_x,
176 const T mean_y,
178 const float quantiles,
179 const std::string &lineFormat = std::string("b-"),
180 const std::string &plotName = std::string("plotEllipse"),
181 bool showName = false);
182
183 //! \overload
184 template <typename T>
186 const T mean_x,
187 const T mean_y,
189 const float quantiles,
190 const std::string &lineFormat = std::string("b-"),
191 const std::string &plotName = std::string("plotEllipse"),
192 bool showName = false);
193
194 /** Adds a bitmap image layer.
195 * 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).
196 *
197 * \sa axis, axis_equal, axis_fit, hold_on, hold_off
198 */
199 void image(
200 const utils::CImage &img,
201 const float &x_left,
202 const float &y_bottom,
203 const float &x_width,
204 const float &y_height,
205 const std::string &plotName = std::string("image") );
206
207
208 /** Remove all plot objects in the display.
209 * \sa plot
210 */
211 void clear();
212
213 /** Remove all plot objects in the display (clear and clf do exactly the same).
214 * \sa plot, hold_on, hold_off
215 */
216 inline void clf() {
217 clear();
218 }
219
220 /** Enables keeping all the graphs, instead of overwritting them.
221 * \sa hold_off, plot
222 */
223 void hold_on();
224
225 /** Disables keeping all the graphs (this is the default behavior).
226 * \sa hold_on, plot
227 */
228 void hold_off();
229
230 /** Disables keeping all the graphs (this is the default behavior).
231 * \param label The text that appears in the new popup menu item.
232 * \param menuID Any positive number (0,1,..). Used to tell which menu was selected in the user callback.
233 * \sa setMenuCallback
234 */
235 void addPopupMenuEntry( const std::string &label, int menuID );
236
237
238 /** Must be called to have a callback when the user selects one of the user-defined entries in the popup menu.
239 * \sa addPopupMenuEntry
240 */
241 void setMenuCallback(TCallbackMenu userFunction, void* userParam = NULL );
242
243
244 }; // End of class def.
246 }
247
248} // End of namespace
249
250#endif
#define DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition CObject.h:171
#define DEFINE_MRPT_OBJECT_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition CObject.h:172
#define DEFINE_MRPT_OBJECT(class_name)
This declaration must be inserted in all CObject classes definition, within the class declaration.
Definition CObject.h:167
The base class for GUI window classes.
Create a GUI window and display plots with MATLAB-like interfaces and commands.
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.
void enableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
void setPos(int x, int y) MRPT_OVERRIDE
Changes the position of the window on the screen.
void clear()
Remove all plot objects in the display.
bool m_holdon
Whether hold_on is enabled.
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 ...
void internal_plot(mrpt::math::CVectorFloat &x, mrpt::math::CVectorFloat &y, const std::string &lineFormat, const std::string &plotName)
static CDisplayWindowPlotsPtr Create(const std::string &windowCaption, unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300)
Class factory returning a smart pointer.
void hold_off()
Disables keeping all the graphs (this is the default behavior).
void clf()
Remove all plot objects in the display (clear and clf do exactly the same).
void hold_on()
Enables keeping all the graphs, instead of overwritting them.
void plot(const std::vector< T1 > &x, const std::vector< T2 > &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.
CDisplayWindowPlots(const std::string &windowCaption=std::string(), unsigned int initialWidth=350, unsigned int initialHeight=300)
Constructor.
void axis_equal(bool enable=true)
Enable/disable the fixed X/Y aspect ratio fix feature (default=disabled).
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 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...
void internal_plot_interface(const VECTOR1 &y, const std::string &lineFormat, const std::string &plotName)
void plot(const std::vector< T1 > &x, const Eigen::MatrixBase< Derived2 > &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 o...
void addPopupMenuEntry(const std::string &label, int menuID)
Disables keeping all the graphs (this is the default behavior).
void plot(const Eigen::MatrixBase< Derived1 > &x, const Eigen::MatrixBase< Derived2 > &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 o...
virtual bool getLastMousePosition(int &x, int &y) const MRPT_OVERRIDE
Gets the last x,y pixel coordinates of the mouse.
virtual ~CDisplayWindowPlots()
Destructor.
uint32_t m_holdon_cnt
Counter for hold_on.
void axis_fit(bool aspectRatioFix=false)
Fix automatically the view area according to existing graphs.
void internal_plot_interface(const VECTOR1 &x, const VECTOR2 &y, const std::string &lineFormat, const std::string &plotName)
void plot(const Eigen::MatrixBase< Derived > &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 o...
void GUI_IMPEXP plotEllipse(const T mean_x, const T mean_y, const mrpt::math::CMatrixFixedNumeric< 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 o...
void resize(unsigned int width, unsigned int height) MRPT_OVERRIDE
Resizes the window, stretching the image to fit into the display area.
void plot(const std::vector< T > &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 o...
void setWindowTitle(const std::string &str) MRPT_OVERRIDE
Changes the window title text.
virtual void setCursorCross(bool cursorIsCross) MRPT_OVERRIDE
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true)
void plot(const Eigen::MatrixBase< Derived1 > &x, const std::vector< T2 > &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 o...
A numeric matrix of compile-time fixed size.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
Definition types_math.h:65
A class for storing images as grayscale or RGB bitmaps.
Definition CImage.h:102
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition mrpt_macros.h:28
struct GUI_IMPEXP CDisplayWindowPlotsPtr
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned long uint32_t
Definition pstdint.h:216



Page generated by Doxygen 1.9.7 for MRPT 1.4.0 SVN: at Tue Jun 27 15:23:24 UTC 2023