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_SERIALIZABLE_PRE(CDisplayWindowPlots) 00049 00050 /** Create a GUI window and display plots with MATLAB-like interfaces and commands. 00051 * See CDisplayWindowPlots::plot 00052 */ 00053 class MRPTDLLIMPEXP CDisplayWindowPlots : public mrpt::utils::CSerializable, public mrpt::gui::CBaseGUIWindow 00054 { 00055 // This must be added to any CSerializable derived class: 00056 DEFINE_SERIALIZABLE( CDisplayWindowPlots ) 00057 00058 public: 00059 typedef void (* TCallbackMenu) (int menuID,float cursor_x, float cursor_y, void* userParam); //!< Type for the callback function used in setMenuCallback 00060 00061 protected: 00062 friend class CWindowDialogPlots; 00063 00064 bool m_holdon; //!< Whether hold_on is enabled 00065 bool m_holdon_just_disabled; 00066 uint32_t m_holdon_cnt; //!< Counter for hold_on 00067 TCallbackMenu m_callback; 00068 void *m_callback_param; 00069 00070 public: 00071 00072 /** Constructor 00073 */ 00074 CDisplayWindowPlots( 00075 const std::string &windowCaption = std::string(), 00076 unsigned int initialWidth = 350, 00077 unsigned int initialHeight = 300 ); 00078 00079 /** Class factory returning a smart pointer */ 00080 static CDisplayWindowPlotsPtr Create( 00081 const std::string &windowCaption = std::string(), 00082 unsigned int initialWindowWidth = 400, 00083 unsigned int initialWindowHeight = 300 ) 00084 { 00085 return CDisplayWindowPlotsPtr(new CDisplayWindowPlots(windowCaption,initialWindowWidth,initialWindowHeight)); 00086 } 00087 00088 /** Destructor 00089 */ 00090 virtual ~CDisplayWindowPlots(); 00091 00092 /** Resizes the window, stretching the image to fit into the display area. 00093 */ 00094 void resize( unsigned int width, unsigned int height ); 00095 00096 /** Changes the position of the window on the screen. 00097 */ 00098 void setPos( int x, int y ); 00099 00100 /** Changes the window title text. 00101 */ 00102 void setWindowTitle( const std::string &str ); 00103 00104 /** Enable/disable the feature of pan/zoom with the mouse (default=enabled) 00105 */ 00106 void enableMousePanZoom( bool enabled ); 00107 00108 /** Adds a new layer with a 2D plot based on two vectors of X and Y points, using a MATLAB-like syntax. 00109 * 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). 00110 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00111 * 00112 * The lineFormat string is a combination of the following characters: 00113 * - Line styles: 00114 * - '.': One point for each data point 00115 * - '-': A continuous line 00116 * - ':': A dashed line 00117 * - Colors: 00118 * - k: black 00119 * - r: red 00120 * - g: green 00121 * - b: blue 00122 * - m: magenta 00123 * - c: cyan 00124 * - Line width: 00125 * - '1' to '9': The line width (default=1) 00126 * 00127 * Examples: 00128 * - 'r.' -> red points. 00129 * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels. 00130 * \note The vectors x & y can be of types: float or double. 00131 * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off 00132 */ 00133 template <typename T> 00134 void MRPTDLLIMPEXP plot( 00135 const std::vector<T> &x, 00136 const std::vector<T> &y, 00137 const std::string &lineFormat = std::string("b-"), 00138 const std::string &plotName = std::string("plotXY") ); 00139 00140 /** Adds a new layer with a 2D plot based on the vector Y, using a MATLAB-like syntax. 00141 * 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). 00142 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00143 * 00144 * The lineFormat string is a combination of the following characters: 00145 * - Line styles: 00146 * - '.': One point for each data point 00147 * - '-': A continuous line 00148 * - ':': A dashed line 00149 * - Colors: 00150 * - k: black 00151 * - r: red 00152 * - g: green 00153 * - b: blue 00154 * - m: magenta 00155 * - c: cyan 00156 * - Line width: 00157 * - '1' to '9': The line width (default=1) 00158 * 00159 * Examples: 00160 * - 'r.' -> red points. 00161 * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels. 00162 * \note The method can be called with vectors of types: float, double. 00163 * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off 00164 */ 00165 template <typename T> 00166 void MRPTDLLIMPEXP plot( 00167 const std::vector<T> &y, 00168 const std::string &lineFormat = std::string("b-"), 00169 const std::string &plotName = std::string("plotXY") ); 00170 00171 /** Set the view area according to the passed coordinated. 00172 */ 00173 void axis( float x_min, float x_max, float y_min, float y_max, bool aspectRatioFix = false ); 00174 00175 /** Enable/disable the fixed X/Y aspect ratio fix feature (default=disabled). 00176 */ 00177 void axis_equal(bool enable=true); 00178 00179 /** Fix automatically the view area according to existing graphs. 00180 */ 00181 void axis_fit(bool aspectRatioFix=false); 00182 00183 /** Plots a 2D ellipse given its mean, covariance matrix, and 00184 * 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). 00185 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00186 * 00187 * For a description of lineFormat see CDisplayWindowPlots::plot. 00188 * The "quantiles" value determines the confidence interval for the ellipse: 00189 * - 1 : 68.27% confidence interval 00190 * - 2 : 95.45% 00191 * - 3 : 99.73% 00192 * - 4 : 99.994% 00193 * \note This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double. 00194 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00195 */ 00196 template <typename T> 00197 void MRPTDLLIMPEXP plotEllipse( 00198 const T mean_x, 00199 const T mean_y, 00200 const CMatrixTemplateNumeric<T> &cov22, 00201 const float quantiles, 00202 const std::string &lineFormat = std::string("b-"), 00203 const std::string &plotName = std::string("plotEllipse"), 00204 bool showName = false); 00205 00206 /** Plots a 2D ellipse given its mean, covariance matrix, and 00207 * 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). 00208 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00209 * 00210 * For a description of lineFormat see CDisplayWindowPlots::plot. 00211 * The "quantiles" value determines the confidence interval for the ellipse: 00212 * - 1 : 68.27% confidence interval 00213 * - 2 : 95.45% 00214 * - 3 : 99.73% 00215 * - 4 : 99.994% 00216 * \note This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double. 00217 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00218 */ 00219 template <typename T> 00220 void MRPTDLLIMPEXP plotEllipse( 00221 const T mean_x, 00222 const T mean_y, 00223 const CMatrixFixedNumeric<T,2,2> &cov22, 00224 const float quantiles, 00225 const std::string &lineFormat = std::string("b-"), 00226 const std::string &plotName = std::string("plotEllipse"), 00227 bool showName = false); 00228 00229 /** Adds a bitmap image layer. 00230 * 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). 00231 * 00232 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00233 */ 00234 void image( 00235 const utils::CImage &img, 00236 const float &x_left, 00237 const float &y_bottom, 00238 const float &x_width, 00239 const float &y_height, 00240 const std::string &plotName = std::string("image") ); 00241 00242 00243 /** Remove all plot objects in the display. 00244 * \sa plot 00245 */ 00246 void clear(); 00247 00248 /** Remove all plot objects in the display (clear and clf do exactly the same). 00249 * \sa plot, hold_on, hold_off 00250 */ 00251 inline void clf() { 00252 clear(); 00253 } 00254 00255 /** Enables keeping all the graphs, instead of overwritting them. 00256 * \sa hold_off, plot 00257 */ 00258 void hold_on(); 00259 00260 /** Disables keeping all the graphs (this is the default behavior). 00261 * \sa hold_on, plot 00262 */ 00263 void hold_off(); 00264 00265 /** Disables keeping all the graphs (this is the default behavior). 00266 * \param label The text that appears in the new popup menu item. 00267 * \param menuID Any positive number (0,1,..). Used to tell which menu was selected in the user callback. 00268 * \sa setMenuCallback 00269 */ 00270 void addPopupMenuEntry( const std::string &label, int menuID ); 00271 00272 00273 /** Must be called to have a callback when the user selects one of the user-defined entries in the popup menu. 00274 * \sa addPopupMenuEntry 00275 */ 00276 void setMenuCallback(TCallbackMenu userFunction, void* userParam = NULL ); 00277 00278 00279 }; // End of class def. 00280 } 00281 00282 } // End of namespace 00283 00284 #endif
| Page generated by Doxygen 1.6.2 for MRPT 0.8.1 SVN:exported at Mon Feb 15 22:01:07 UTC 2010 |
