00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 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 CEnhancedMetaFile_H 00029 #define CEnhancedMetaFile_H 00030 00031 #include <mrpt/utils/utils_defs.h> 00032 #include <mrpt/utils/CCanvas.h> 00033 #include <mrpt/utils/safe_pointers.h> 00034 00035 /*--------------------------------------------------------------- 00036 Class 00037 ---------------------------------------------------------------*/ 00038 namespace mrpt 00039 { 00040 namespace utils 00041 { 00042 /** This class represents a Windows Enhanced Meta File (EMF) for generating and saving graphics. 00043 * If used under Linux, a ".png", non-vectorial, file will be generated instead. 00044 * \ingroup mrpt_base_grp 00045 */ 00046 class BASE_IMPEXP CEnhancedMetaFile : public CCanvas 00047 { 00048 private: 00049 void_ptr_noncopy m_hdc; 00050 int m_scale; 00051 void_ptr_noncopy m_hFont; 00052 std::string m_targetFile; 00053 00054 public: 00055 static int LINUX_IMG_WIDTH; //!< In Linux, the size of the bitmap image that emulates the EMF (Default:800) 00056 static int LINUX_IMG_HEIGHT; //!< In Linux, the size of the bitmap image that emulates the EMF (Default:600) 00057 00058 00059 /** Constructor 00060 * \param targetFileName This file will be created and the EMF saved there. 00061 * \param scaleFactor All coordinates in draw commands will be internally multiplied by this scale, to provide a way of obtaining "subpixel" drawing. 00062 */ 00063 CEnhancedMetaFile( 00064 const std::string &targetFileName, 00065 int scaleFactor = 1); 00066 00067 /** Destructor 00068 */ 00069 virtual ~CEnhancedMetaFile( ); 00070 00071 /** Changes the value of the pixel (x,y). 00072 * Pixel coordinates starts at the left-top corner of the image, and start in (0,0). 00073 * The meaning of the parameter "color" depends on the implementation: it will usually 00074 * be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray level. 00075 * This method must support (x,y) values OUT of the actual image size without neither 00076 * raising exceptions, nor leading to memory access errors. 00077 */ 00078 virtual void setPixel( int x, int y, size_t color); 00079 00080 /** Returns the width of the image in pixels (this currently has no applicability for a EMF file...) 00081 */ 00082 virtual size_t getWidth() const { return 640; } 00083 00084 /** Returns the height of the image in pixels (this currently has no applicability for a EMF file...) 00085 */ 00086 virtual size_t getHeight() const {return 480;} 00087 00088 /** Draws an image as a bitmap at a given position. 00089 * \param x0 The top-left corner x coordinates on this canvas where the image is to be drawn 00090 * \param y0 The top-left corner y coordinates on this canvas where the image is to be drawn 00091 * \param img The image to be drawn in this canvas 00092 * This method may be redefined in some classes implementing this interface in a more appropiate manner. 00093 */ 00094 virtual void drawImage( 00095 int x, 00096 int y, 00097 const utils::CImage &img ); 00098 00099 /** Draws a line. 00100 * \param x0 The starting point x coordinate 00101 * \param y0 The starting point y coordinate 00102 * \param x1 The end point x coordinate 00103 * \param y1 The end point y coordinate 00104 * \param color The color of the line 00105 * \param width The desired width of the line (this is IGNORED in this virtual class) 00106 * This method may be redefined in some classes implementing this interface in a more appropiate manner. 00107 */ 00108 virtual void line( 00109 int x0, 00110 int y0, 00111 int x1, 00112 int y1, 00113 const mrpt::utils::TColor color, 00114 unsigned int width = 1, 00115 TPenStyle penStyle = psSolid); 00116 00117 /** Places a text label. 00118 * \param x0 The x coordinates 00119 * \param y0 The y coordinates 00120 * \param str The string to put 00121 * \param color The text color 00122 * \param fontSize The font size, in "points" 00123 * This method may be redefined in some classes implementing this interface in a more appropiate manner. 00124 * \sa rectangle 00125 */ 00126 virtual void textOut( 00127 int x0, 00128 int y0, 00129 const std::string &str, 00130 const mrpt::utils::TColor color 00131 ); 00132 00133 /** Select the current font used when drawing text. 00134 * \param fontName The face name of a font (e.g. "Arial","System",...) 00135 * \param fontSize The size of the font in pts. 00136 * \param bold Whether the font is bold 00137 * \param italic Whether the font is italic 00138 * \sa textOut 00139 */ 00140 virtual void selectTextFont( 00141 const std::string &fontName, 00142 int fontSize, 00143 bool bold = false, 00144 bool italic = false ); 00145 00146 /** Draws an image as a bitmap at a given position, with some custom scale and rotation changes. 00147 * \param x0 The top-left corner x coordinates on this canvas where the image is to be drawn 00148 * \param y0 The top-left corner y coordinates on this canvas where the image is to be drawn 00149 * \param rotation The rotation in radians, positive values being anti-clockwise direction, 0 is the normal position. 00150 * \param scale The scale factor, e.g. 2 means twice the original size. 00151 * \param img The image to be drawn in this canvas 00152 * This method may be redefined in some classes implementing this interface in a more appropiate manner. 00153 */ 00154 virtual void drawImage( 00155 int x, 00156 int y, 00157 const utils::CImage &img, 00158 float rotation, 00159 float scale ) 00160 { 00161 CCanvas::drawImage(x,y,img,rotation,scale); 00162 } 00163 00164 00165 /** Draws a rectangle (an empty rectangle, without filling) 00166 * \param x0 The top-left x coordinate 00167 * \param y0 The top-left y coordinate 00168 * \param x1 The right-bottom x coordinate 00169 * \param y1 The right-bottom y coordinate 00170 * \param color The color of the line 00171 * \param width The desired width of the line. 00172 * \sa filledRectangle 00173 */ 00174 virtual void rectangle( 00175 int x0, 00176 int y0, 00177 int x1, 00178 int y1, 00179 const mrpt::utils::TColor color, 00180 unsigned int width = 1 ); 00181 00182 /** Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution. 00183 * \param mean_x The x coordinate of the center point of the ellipse. 00184 * \param mean_y The y coordinate of the center point of the ellipse. 00185 * \param cov2D A 2x2 covariance matrix. 00186 * \param confIntervalStds How many "sigmas" for the confidence level (i.e. 2->95%, 3=99.97%,...) 00187 * \param color The color of the ellipse 00188 * \param width The desired width of the line (this is IGNORED in this virtual class) 00189 * \param nEllipsePoints The number of points to generate to approximate the ellipse shape. 00190 * \exception std::exception On an invalid matrix. 00191 */ 00192 template <class T> 00193 void ellipseGaussian( 00194 math::CMatrixTemplateNumeric<T> *cov2D, 00195 T mean_x, 00196 T mean_y, 00197 float confIntervalStds = 2, 00198 const mrpt::utils::TColor color = mrpt::utils::TColor(255,255,255), 00199 unsigned int width = 1, 00200 int nEllipsePoints = 20 00201 ) 00202 { 00203 MRPT_START 00204 int x1=0,y1=0,x2=0,y2=0; 00205 double ang; 00206 math::CMatrixTemplateNumeric<T> eigVal,eigVec; 00207 int i; 00208 00209 // Compute the eigen-vectors & values: 00210 cov2D->eigenVectors(eigVec,eigVal); 00211 00212 eigVal.Sqrt(); 00213 math::CMatrixTemplateNumeric<T> M( eigVal * (~eigVec) ); 00214 00215 // Compute the points of the 2D ellipse: 00216 for (i=0,ang=0;i<nEllipsePoints;i++,ang+= (M_2PI/(nEllipsePoints-1))) 00217 { 00218 float ccos = cos(ang); 00219 float ssin = sin(ang); 00220 00221 x2 = round( mean_x + confIntervalStds * (ccos * M(0,0) + ssin * M(1,0)) ); 00222 y2 = round( mean_y + confIntervalStds * (ccos * M(0,1) + ssin * M(1,1)) ); 00223 00224 if (i>0) 00225 line( x1, y1,x2, y2,color,width ); 00226 00227 x1 = x2; 00228 y1 = y2; 00229 } // end for points on ellipse 00230 00231 MRPT_END_WITH_CLEAN_UP( \ 00232 std::cout << "Covariance matrix leading to error is:" << std::endl << *cov2D << std::endl; \ 00233 ); 00234 } 00235 00236 00237 00238 }; // End of class def. 00239 00240 } // End of namespace 00241 } // end of namespace 00242 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |