Main MRPT website > C++ reference for MRPT 1.9.9
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-2017, 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 namespace mrpt
19 {
20 namespace gui
21 {
22 /** Create a GUI window and display plots with MATLAB-like interfaces and
23  * commands.
24  *
25  * For a list of supported events with the observer/observable pattern, see the
26  * discussion in mrpt::gui::CBaseGUIWindow.
27  *
28  * See CDisplayWindowPlots::plot
29  * \ingroup mrpt_gui_grp
30  */
32 {
33  public:
34  using Ptr = std::shared_ptr<CDisplayWindowPlots>;
35 
36  /** Type for the callback function used in setMenuCallback */
37  typedef void (*TCallbackMenu)(
38  int menuID, float cursor_x, float cursor_y, void* userParam);
39 
40  protected:
41  friend class CWindowDialogPlots;
42 
43  /** Whether hold_on is enabled */
44  bool m_holdon;
46  /** Counter for hold_on */
50 
51  void internal_plot(
53  const std::string& lineFormat, const std::string& plotName);
54  template <typename VECTOR1, typename VECTOR2>
56  const VECTOR1& x, const VECTOR2& y, const std::string& lineFormat,
57  const std::string& plotName)
58  {
59  mrpt::math::CVectorFloat x1(x.size()), y1(y.size());
60  const size_t N1 = size_t(x.size());
61  for (size_t i = 0; i < N1; i++) x1[i] = x[i];
62  const size_t N2 = size_t(y.size());
63  for (size_t i = 0; i < N2; i++) y1[i] = y[i];
64  this->internal_plot(x1, y1, lineFormat, plotName);
65  }
66  template <typename VECTOR1>
68  const VECTOR1& y, const std::string& lineFormat,
69  const std::string& plotName)
70  {
71  const size_t N = size_t(y.size());
72  mrpt::math::CVectorFloat x1(N), y1(N);
73  for (size_t i = 0; i < N; i++)
74  {
75  x1[i] = i;
76  y1[i] = y[i];
77  }
78  this->internal_plot(x1, y1, lineFormat, plotName);
79  }
80 
81  public:
82  /** Constructor
83  */
85  const std::string& windowCaption = std::string(),
86  unsigned int initialWidth = 350, unsigned int initialHeight = 300);
87 
88  /** Class factory returning a smart pointer */
90  const std::string& windowCaption, unsigned int initialWindowWidth = 400,
91  unsigned int initialWindowHeight = 300);
92 
93  /** Destructor
94  */
95  virtual ~CDisplayWindowPlots();
96 
97  /** Gets the last x,y pixel coordinates of the mouse. \return False if the
98  * window is closed. */
99  virtual bool getLastMousePosition(int& x, int& y) const override;
100 
101  /** Set cursor style to default (cursorIsCross=false) or to a cross
102  * (cursorIsCross=true) */
103  virtual void setCursorCross(bool cursorIsCross) override;
104 
105  /** Resizes the window, stretching the image to fit into the display area.
106  */
107  void resize(unsigned int width, unsigned int height) override;
108 
109  /** Changes the position of the window on the screen.
110  */
111  void setPos(int x, int y) override;
112 
113  /** Changes the window title text.
114  */
115  void setWindowTitle(const std::string& str) override;
116 
117  /** Enable/disable the feature of pan/zoom with the mouse (default=enabled)
118  */
119  void enableMousePanZoom(bool enabled);
120 
121  /** Adds a new layer with a 2D plot based on two vectors of X and Y points,
122  *using a MATLAB-like syntax.
123  * Each call to this function creates a new plot, unless the plot name
124  *coincides with an already existing plot: in this case the X & Y points
125  *are used to update this existing layer (this also applies to using the
126  *default plot name).
127  * If "hold_on" is enabled, then every call will always create a new plot,
128  *even if no "plotName" is provided.
129  *
130  * The lineFormat string is a combination of the following characters:
131  * - Line styles:
132  * - '.': One point for each data point
133  * - '-': A continuous line
134  * - ':': A dashed line
135  * - Colors:
136  * - k: black
137  * - r: red
138  * - g: green
139  * - b: blue
140  * - m: magenta
141  * - c: cyan
142  * - Line width:
143  * - '1' to '9': The line width (default=1)
144  *
145  * Examples:
146  * - 'r.' -> red points.
147  * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels.
148  * \note The vectors x & y can be of types: float or double.
149  * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off
150  * \tparam VECTOR Can be std::vector<float/double> or
151  *mrpt::dynamicsize_vector<float/double> or a column/row Eigen::Matrix<>
152  */
153  template <typename T1, typename T2>
154  inline void plot(
155  const std::vector<T1>& x, const std::vector<T2>& y,
156  const std::string& lineFormat = std::string("b-"),
157  const std::string& plotName = std::string("plotXY"))
158  {
159  this->internal_plot_interface(x, y, lineFormat, plotName);
160  }
161  //! \overload
162  template <typename T1, typename Derived2>
163  inline void plot(
164  const std::vector<T1>& x, const Eigen::MatrixBase<Derived2>& y,
165  const std::string& lineFormat = std::string("b-"),
166  const std::string& plotName = std::string("plotXY"))
167  {
168  this->internal_plot_interface(x, y, lineFormat, plotName);
169  }
170  //! \overload
171  template <typename Derived1, typename T2>
172  inline void plot(
173  const Eigen::MatrixBase<Derived1>& x, const std::vector<T2>& y,
174  const std::string& lineFormat = std::string("b-"),
175  const std::string& plotName = std::string("plotXY"))
176  {
177  this->internal_plot_interface(x, y, lineFormat, plotName);
178  }
179  //! \overload
180  template <typename Derived1, typename Derived2>
181  inline void plot(
182  const Eigen::MatrixBase<Derived1>& x,
183  const Eigen::MatrixBase<Derived2>& y,
184  const std::string& lineFormat = std::string("b-"),
185  const std::string& plotName = std::string("plotXY"))
186  {
187  this->internal_plot_interface(x, y, lineFormat, plotName);
188  }
189 
190  //! \overload
191  template <typename T>
192  void plot(
193  const std::vector<T>& y,
194  const std::string& lineFormat = std::string("b-"),
195  const std::string& plotName = std::string("plotXY"))
196  {
197  this->internal_plot_interface(y, lineFormat, plotName);
198  }
199  //! \overload
200  template <typename Derived>
201  void plot(
202  const Eigen::MatrixBase<Derived>& y,
203  const std::string& lineFormat = std::string("b-"),
204  const std::string& plotName = std::string("plotXY"))
205  {
206  this->internal_plot_interface(y, lineFormat, plotName);
207  }
208 
209  /** Set the view area according to the passed coordinated. */
210  void axis(
211  float x_min, float x_max, float y_min, float y_max,
212  bool aspectRatioFix = false);
213 
214  /** Enable/disable the fixed X/Y aspect ratio fix feature
215  * (default=disabled). */
216  void axis_equal(bool enable = true);
217 
218  /** Fix automatically the view area according to existing graphs. */
219  void axis_fit(bool aspectRatioFix = false);
220 
221  /** Plots a 2D ellipse given its mean, covariance matrix, and
222  * Each call to this function creates a new plot, unless the plot name
223  * coincides with an already existing plot: in this case the new values are
224  * used to update this existing layer (this also applies to using the
225  * default plot name).
226  * If "hold_on" is enabled, then every call will always create a new plot,
227  * even if no "plotName" is provided.
228  *
229  * For a description of lineFormat see CDisplayWindowPlots::plot.
230  * The "quantiles" value determines the confidence interval for the
231  * ellipse:
232  * - 1 : 68.27% confidence interval
233  * - 2 : 95.45%
234  * - 3 : 99.73%
235  * - 4 : 99.994%
236  * \note This method can be called with 2x2 fixed-sized or dynamic-size
237  * matrices of types: float or double.
238  * \sa axis, axis_equal, axis_fit, hold_on, hold_off
239  */
240  template <typename T>
241  void plotEllipse(
242  const T mean_x, const T mean_y,
244  const float quantiles,
245  const std::string& lineFormat = std::string("b-"),
246  const std::string& plotName = std::string("plotEllipse"),
247  bool showName = false);
248 
249  //! \overload
250  template <typename T>
251  void plotEllipse(
252  const T mean_x, const T mean_y,
254  const float quantiles,
255  const std::string& lineFormat = std::string("b-"),
256  const std::string& plotName = std::string("plotEllipse"),
257  bool showName = false);
258 
259  /** Adds a bitmap image layer.
260  * Each call to this function creates a new layer, unless the plot name
261  * coincides with an already existing plot: in this case the new values are
262  * used to update this existing layer (this also applies to using the
263  * default plot name).
264  *
265  * \sa axis, axis_equal, axis_fit, hold_on, hold_off
266  */
267  void image(
268  const utils::CImage& img, const float& x_left, const float& y_bottom,
269  const float& x_width, const float& y_height,
270  const std::string& plotName = std::string("image"));
271 
272  /** Remove all plot objects in the display.
273  * \sa plot
274  */
275  void clear();
276 
277  /** Remove all plot objects in the display (clear and clf do exactly the
278  * same).
279  * \sa plot, hold_on, hold_off
280  */
281  inline void clf() { clear(); }
282  /** Enables keeping all the graphs, instead of overwritting them.
283  * \sa hold_off, plot
284  */
285  void hold_on();
286 
287  /** Disables keeping all the graphs (this is the default behavior).
288  * \sa hold_on, plot
289  */
290  void hold_off();
291 
292  /** Disables keeping all the graphs (this is the default behavior).
293  * \param label The text that appears in the new popup menu item.
294  * \param menuID Any positive number (0,1,..). Used to tell which menu was
295  * selected in the user callback.
296  * \sa setMenuCallback
297  */
298  void addPopupMenuEntry(const std::string& label, int menuID);
299 
300  /** Must be called to have a callback when the user selects one of the
301  * user-defined entries in the popup menu.
302  * \sa addPopupMenuEntry
303  */
304  void setMenuCallback(TCallbackMenu userFunction, void* userParam = nullptr);
305 
306 }; // End of class def.
307 }
308 
309 } // End of namespace
310 
311 #endif
Create a GUI window and display plots with MATLAB-like interfaces and commands.
void enableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
The wx dialog for gui::CDisplayWindowPlots.
Definition: WxSubsystem.h:441
void setPos(int x, int y) override
Changes the position of the window on the screen.
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).
void internal_plot_interface(const VECTOR1 &y, const std::string &lineFormat, const std::string &plotName)
GLenum GLsizei width
Definition: glext.h:3531
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 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 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"))
A numeric matrix of compile-time fixed size.
uint32_t m_holdon_cnt
Counter for hold_on.
GLint GLvoid * img
Definition: glext.h:3763
virtual bool getLastMousePosition(int &x, int &y) const override
Gets the last x,y pixel coordinates of the mouse.
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"))
void plot(const std::vector< T > &y, const std::string &lineFormat=std::string("b-"), const std::string &plotName=std::string("plotXY"))
void addPopupMenuEntry(const std::string &label, int menuID)
Disables keeping all the graphs (this is the default behavior).
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...
GLsizei const GLchar ** string
Definition: glext.h:4101
void internal_plot_interface(const VECTOR1 &x, const VECTOR2 &y, const std::string &lineFormat, const std::string &plotName)
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 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 setWindowTitle(const std::string &str) override
Changes the window title text.
static CDisplayWindowPlots::Ptr Create(const std::string &windowCaption, unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300)
Class factory returning a smart pointer.
GLenum GLint GLint y
Definition: glext.h:3538
virtual void setCursorCross(bool cursorIsCross) override
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) ...
void plot(const Eigen::MatrixBase< Derived > &y, const std::string &lineFormat=std::string("b-"), const std::string &plotName=std::string("plotXY"))
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLenum GLint x
Definition: glext.h:3538
GLenum GLsizei GLsizei height
Definition: glext.h:3554
unsigned __int32 uint32_t
Definition: rptypes.h:47
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"))
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(* TCallbackMenu)(int menuID, float cursor_x, float cursor_y, void *userParam)
Type for the callback function used in setMenuCallback.
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
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...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019