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