00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CDisplayWindowPlots_H 00029 #define CDisplayWindowPlots_H 00030 00031 #include <mrpt/gui/CBaseGUIWindow.h> 00032 #include <mrpt/math/CMatrixTemplateNumeric.h> 00033 #include <mrpt/math/lightweight_geom_data.h> 00034 #include <mrpt/utils/CImage.h> 00035 00036 /*--------------------------------------------------------------- 00037 Class 00038 ---------------------------------------------------------------*/ 00039 namespace mrpt 00040 { 00041 namespace gui 00042 { 00043 using namespace mrpt::utils; 00044 using namespace mrpt::math; 00045 00046 class CWindowDialogPlots; 00047 00048 DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE(CDisplayWindowPlots, mrpt::gui::CBaseGUIWindow, GUI_IMPEXP) 00049 00050 /** Create a GUI window and display plots with MATLAB-like interfaces and commands. 00051 * 00052 * For a list of supported events with the observer/observable pattern, see the discussion in mrpt::gui::CBaseGUIWindow. 00053 * 00054 * See CDisplayWindowPlots::plot 00055 */ 00056 class GUI_IMPEXP CDisplayWindowPlots : public mrpt::gui::CBaseGUIWindow 00057 { 00058 // This must be added to any CObject derived class: 00059 DEFINE_MRPT_OBJECT( CDisplayWindowPlots ) 00060 00061 public: 00062 typedef void (* TCallbackMenu) (int menuID,float cursor_x, float cursor_y, void* userParam); //!< Type for the callback function used in setMenuCallback 00063 00064 protected: 00065 friend class CWindowDialogPlots; 00066 00067 bool m_holdon; //!< Whether hold_on is enabled 00068 bool m_holdon_just_disabled; 00069 uint32_t m_holdon_cnt; //!< Counter for hold_on 00070 TCallbackMenu m_callback; 00071 void *m_callback_param; 00072 00073 public: 00074 00075 /** Constructor 00076 */ 00077 CDisplayWindowPlots( 00078 const std::string &windowCaption = std::string(), 00079 unsigned int initialWidth = 350, 00080 unsigned int initialHeight = 300 ); 00081 00082 /** Class factory returning a smart pointer */ 00083 static CDisplayWindowPlotsPtr Create( 00084 const std::string &windowCaption = std::string(), 00085 unsigned int initialWindowWidth = 400, 00086 unsigned int initialWindowHeight = 300 ) 00087 { 00088 return CDisplayWindowPlotsPtr(new CDisplayWindowPlots(windowCaption,initialWindowWidth,initialWindowHeight)); 00089 } 00090 00091 /** Destructor 00092 */ 00093 virtual ~CDisplayWindowPlots(); 00094 00095 /** Resizes the window, stretching the image to fit into the display area. 00096 */ 00097 void resize( unsigned int width, unsigned int height ); 00098 00099 /** Changes the position of the window on the screen. 00100 */ 00101 void setPos( int x, int y ); 00102 00103 /** Changes the window title text. 00104 */ 00105 void setWindowTitle( const std::string &str ); 00106 00107 /** Enable/disable the feature of pan/zoom with the mouse (default=enabled) 00108 */ 00109 void enableMousePanZoom( bool enabled ); 00110 00111 /** Adds a new layer with a 2D plot based on two vectors of X and Y points, using a MATLAB-like syntax. 00112 * 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). 00113 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00114 * 00115 * The lineFormat string is a combination of the following characters: 00116 * - Line styles: 00117 * - '.': One point for each data point 00118 * - '-': A continuous line 00119 * - ':': A dashed line 00120 * - Colors: 00121 * - k: black 00122 * - r: red 00123 * - g: green 00124 * - b: blue 00125 * - m: magenta 00126 * - c: cyan 00127 * - Line width: 00128 * - '1' to '9': The line width (default=1) 00129 * 00130 * Examples: 00131 * - 'r.' -> red points. 00132 * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels. 00133 * \note The vectors x & y can be of types: float or double. 00134 * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off 00135 */ 00136 template <typename T> 00137 void GUI_IMPEXP plot( 00138 const std::vector<T> &x, 00139 const std::vector<T> &y, 00140 const std::string &lineFormat = std::string("b-"), 00141 const std::string &plotName = std::string("plotXY") ); 00142 00143 /** Adds a new layer with a 2D plot based on the vector Y, using a MATLAB-like syntax. 00144 * 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). 00145 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00146 * 00147 * The lineFormat string is a combination of the following characters: 00148 * - Line styles: 00149 * - '.': One point for each data point 00150 * - '-': A continuous line 00151 * - ':': A dashed line 00152 * - Colors: 00153 * - k: black 00154 * - r: red 00155 * - g: green 00156 * - b: blue 00157 * - m: magenta 00158 * - c: cyan 00159 * - Line width: 00160 * - '1' to '9': The line width (default=1) 00161 * 00162 * Examples: 00163 * - 'r.' -> red points. 00164 * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels. 00165 * \note The method can be called with vectors of types: float, double. 00166 * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off 00167 */ 00168 template <typename T> 00169 void GUI_IMPEXP plot( 00170 const std::vector<T> &y, 00171 const std::string &lineFormat = std::string("b-"), 00172 const std::string &plotName = std::string("plotXY") ); 00173 00174 /** Set the view area according to the passed coordinated. 00175 */ 00176 void axis( float x_min, float x_max, float y_min, float y_max, bool aspectRatioFix = false ); 00177 00178 /** Enable/disable the fixed X/Y aspect ratio fix feature (default=disabled). 00179 */ 00180 void axis_equal(bool enable=true); 00181 00182 /** Fix automatically the view area according to existing graphs. 00183 */ 00184 void axis_fit(bool aspectRatioFix=false); 00185 00186 /** Plots a 2D ellipse given its mean, covariance matrix, and 00187 * 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). 00188 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00189 * 00190 * For a description of lineFormat see CDisplayWindowPlots::plot. 00191 * The "quantiles" value determines the confidence interval for the ellipse: 00192 * - 1 : 68.27% confidence interval 00193 * - 2 : 95.45% 00194 * - 3 : 99.73% 00195 * - 4 : 99.994% 00196 * \note This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double. 00197 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00198 */ 00199 template <typename T> 00200 void GUI_IMPEXP plotEllipse( 00201 const T mean_x, 00202 const T mean_y, 00203 const CMatrixTemplateNumeric<T> &cov22, 00204 const float quantiles, 00205 const std::string &lineFormat = std::string("b-"), 00206 const std::string &plotName = std::string("plotEllipse"), 00207 bool showName = false); 00208 00209 /** Plots a 2D ellipse given its mean, covariance matrix, and 00210 * 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). 00211 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00212 * 00213 * For a description of lineFormat see CDisplayWindowPlots::plot. 00214 * The "quantiles" value determines the confidence interval for the ellipse: 00215 * - 1 : 68.27% confidence interval 00216 * - 2 : 95.45% 00217 * - 3 : 99.73% 00218 * - 4 : 99.994% 00219 * \note This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double. 00220 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00221 */ 00222 template <typename T> 00223 void GUI_IMPEXP plotEllipse( 00224 const T mean_x, 00225 const T mean_y, 00226 const CMatrixFixedNumeric<T,2,2> &cov22, 00227 const float quantiles, 00228 const std::string &lineFormat = std::string("b-"), 00229 const std::string &plotName = std::string("plotEllipse"), 00230 bool showName = false); 00231 00232 /** Adds a bitmap image layer. 00233 * 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). 00234 * 00235 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00236 */ 00237 void image( 00238 const utils::CImage &img, 00239 const float &x_left, 00240 const float &y_bottom, 00241 const float &x_width, 00242 const float &y_height, 00243 const std::string &plotName = std::string("image") ); 00244 00245 00246 /** Remove all plot objects in the display. 00247 * \sa plot 00248 */ 00249 void clear(); 00250 00251 /** Remove all plot objects in the display (clear and clf do exactly the same). 00252 * \sa plot, hold_on, hold_off 00253 */ 00254 inline void clf() { 00255 clear(); 00256 } 00257 00258 /** Enables keeping all the graphs, instead of overwritting them. 00259 * \sa hold_off, plot 00260 */ 00261 void hold_on(); 00262 00263 /** Disables keeping all the graphs (this is the default behavior). 00264 * \sa hold_on, plot 00265 */ 00266 void hold_off(); 00267 00268 /** Disables keeping all the graphs (this is the default behavior). 00269 * \param label The text that appears in the new popup menu item. 00270 * \param menuID Any positive number (0,1,..). Used to tell which menu was selected in the user callback. 00271 * \sa setMenuCallback 00272 */ 00273 void addPopupMenuEntry( const std::string &label, int menuID ); 00274 00275 00276 /** Must be called to have a callback when the user selects one of the user-defined entries in the popup menu. 00277 * \sa addPopupMenuEntry 00278 */ 00279 void setMenuCallback(TCallbackMenu userFunction, void* userParam = NULL ); 00280 00281 00282 }; // End of class def. 00283 } 00284 00285 } // End of namespace 00286 00287 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
