00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 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 /** Destructor 00080 */ 00081 virtual ~CDisplayWindowPlots(); 00082 00083 /** Resizes the window, stretching the image to fit into the display area. 00084 */ 00085 void resize( unsigned int width, unsigned int height ); 00086 00087 /** Changes the position of the window on the screen. 00088 */ 00089 void setPos( int x, int y ); 00090 00091 /** Changes the window title text. 00092 */ 00093 void setWindowTitle( const std::string &str ); 00094 00095 /** Enable/disable the feature of pan/zoom with the mouse (default=enabled) 00096 */ 00097 void enableMousePanZoom( bool enabled ); 00098 00099 /** Adds a new layer with a 2D plot based on two vectors of X and Y points, using a MATLAB-like syntax. 00100 * 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). 00101 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00102 * 00103 * The lineFormat string is a combination of the following characters: 00104 * - Line styles: 00105 * - '.': One point for each data point 00106 * - '-': A continuous line 00107 * - ':': A dashed line 00108 * - Colors: 00109 * - k: black 00110 * - r: red 00111 * - g: green 00112 * - b: blue 00113 * - m: magenta 00114 * - c: cyan 00115 * - Line width: 00116 * - '1' to '9': The line width (default=1) 00117 * 00118 * Examples: 00119 * - 'r.' -> red points. 00120 * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels. 00121 * \note The vectors x & y can be of types: float or double. 00122 * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off 00123 */ 00124 template <typename T> 00125 void MRPTDLLIMPEXP plot( 00126 const std::vector<T> &x, 00127 const std::vector<T> &y, 00128 const std::string &lineFormat = std::string("b-"), 00129 const std::string &plotName = std::string("plotXY") ); 00130 00131 /** Adds a new layer with a 2D plot based on the vector Y, using a MATLAB-like syntax. 00132 * 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). 00133 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00134 * 00135 * The lineFormat string is a combination of the following characters: 00136 * - Line styles: 00137 * - '.': One point for each data point 00138 * - '-': A continuous line 00139 * - ':': A dashed line 00140 * - Colors: 00141 * - k: black 00142 * - r: red 00143 * - g: green 00144 * - b: blue 00145 * - m: magenta 00146 * - c: cyan 00147 * - Line width: 00148 * - '1' to '9': The line width (default=1) 00149 * 00150 * Examples: 00151 * - 'r.' -> red points. 00152 * - 'k3' or 'k-3' -> A black line with a line width of 3 pixels. 00153 * \note The method can be called with vectors of types: float, double. 00154 * \sa axis, axis_equal, axis_fit, clear, hold_on, hold_off 00155 */ 00156 template <typename T> 00157 void MRPTDLLIMPEXP plot( 00158 const std::vector<T> &y, 00159 const std::string &lineFormat = std::string("b-"), 00160 const std::string &plotName = std::string("plotXY") ); 00161 00162 /** Set the view area according to the passed coordinated. 00163 */ 00164 void axis( float x_min, float x_max, float y_min, float y_max, bool aspectRatioFix = false ); 00165 00166 /** Enable/disable the fixed X/Y aspect ratio fix feature (default=disabled). 00167 */ 00168 void axis_equal(bool enable=true); 00169 00170 /** Fix automatically the view area according to existing graphs. 00171 */ 00172 void axis_fit(bool aspectRatioFix=false); 00173 00174 /** Plots a 2D ellipse given its mean, covariance matrix, and 00175 * 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). 00176 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00177 * 00178 * For a description of lineFormat see CDisplayWindowPlots::plot. 00179 * The "quantiles" value determines the confidence interval for the ellipse: 00180 * - 1 : 68.27% confidence interval 00181 * - 2 : 95.45% 00182 * - 3 : 99.73% 00183 * - 4 : 99.994% 00184 * \note This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double. 00185 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00186 */ 00187 template <typename T> 00188 void MRPTDLLIMPEXP plotEllipse( 00189 const T mean_x, 00190 const T mean_y, 00191 const CMatrixTemplateNumeric<T> &cov22, 00192 const float quantiles, 00193 const std::string &lineFormat = std::string("b-"), 00194 const std::string &plotName = std::string("plotEllipse"), 00195 bool showName = false); 00196 00197 /** Plots a 2D ellipse given its mean, covariance matrix, and 00198 * 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). 00199 * If "hold_on" is enabled, then every call will always create a new plot, even if no "plotName" is provided. 00200 * 00201 * For a description of lineFormat see CDisplayWindowPlots::plot. 00202 * The "quantiles" value determines the confidence interval for the ellipse: 00203 * - 1 : 68.27% confidence interval 00204 * - 2 : 95.45% 00205 * - 3 : 99.73% 00206 * - 4 : 99.994% 00207 * \note This method can be called with 2x2 fixed-sized or dynamic-size matrices of types: float or double. 00208 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00209 */ 00210 template <typename T> 00211 void MRPTDLLIMPEXP plotEllipse( 00212 const T mean_x, 00213 const T mean_y, 00214 const CMatrixFixedNumeric<T,2,2> &cov22, 00215 const float quantiles, 00216 const std::string &lineFormat = std::string("b-"), 00217 const std::string &plotName = std::string("plotEllipse"), 00218 bool showName = false); 00219 00220 /** Adds a bitmap image layer. 00221 * 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). 00222 * 00223 * \sa axis, axis_equal, axis_fit, hold_on, hold_off 00224 */ 00225 void image( 00226 const utils::CImage &img, 00227 const float &x_left, 00228 const float &y_bottom, 00229 const float &x_width, 00230 const float &y_height, 00231 const std::string &plotName = std::string("image") ); 00232 00233 00234 /** Remove all plot objects in the display. 00235 * \sa plot 00236 */ 00237 void clear(); 00238 00239 /** Remove all plot objects in the display (clear and clf do exactly the same). 00240 * \sa plot, hold_on, hold_off 00241 */ 00242 inline void clf() { 00243 clear(); 00244 } 00245 00246 /** Enables keeping all the graphs, instead of overwritting them. 00247 * \sa hold_off, plot 00248 */ 00249 void hold_on(); 00250 00251 /** Disables keeping all the graphs (this is the default behavior). 00252 * \sa hold_on, plot 00253 */ 00254 void hold_off(); 00255 00256 /** Disables keeping all the graphs (this is the default behavior). 00257 * \param label The text that appears in the new popup menu item. 00258 * \param menuID Any positive number (0,1,..). Used to tell which menu was selected in the user callback. 00259 * \sa setMenuCallback 00260 */ 00261 void addPopupMenuEntry( const std::string &label, int menuID ); 00262 00263 00264 /** Must be called to have a callback when the user selects one of the user-defined entries in the popup menu. 00265 * \sa addPopupMenuEntry 00266 */ 00267 void setMenuCallback(TCallbackMenu userFunction, void* userParam = NULL ); 00268 00269 00270 }; // End of class def. 00271 } 00272 00273 } // End of namespace 00274 00275 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:32:05 EDT 2009 |