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



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018