Main MRPT website > C++ reference for MRPT 1.3.2
CEnhancedMetaFile.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2015, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CEnhancedMetaFile_H
10 #define CEnhancedMetaFile_H
11 
12 #include <mrpt/utils/utils_defs.h>
13 #include <mrpt/utils/CCanvas.h>
15 
16 /*---------------------------------------------------------------
17  Class
18  ---------------------------------------------------------------*/
19 namespace mrpt
20 {
21 namespace utils
22 {
23  /** This class represents a Windows Enhanced Meta File (EMF) for generating and saving graphics.
24  * If used under Linux, a ".png", non-vectorial, file will be generated instead.
25  * \ingroup mrpt_base_grp
26  */
28  {
29  private:
31  int m_scale;
33  std::string m_targetFile;
34 
35  public:
36  static int LINUX_IMG_WIDTH; //!< In Linux, the size of the bitmap image that emulates the EMF (Default:800)
37  static int LINUX_IMG_HEIGHT; //!< In Linux, the size of the bitmap image that emulates the EMF (Default:600)
38 
39 
40  /** Constructor
41  * \param targetFileName This file will be created and the EMF saved there.
42  * \param scaleFactor All coordinates in draw commands will be internally multiplied by this scale, to provide a way of obtaining "subpixel" drawing.
43  */
45  const std::string &targetFileName,
46  int scaleFactor = 1);
47 
48  /** Destructor
49  */
50  virtual ~CEnhancedMetaFile( );
51 
52  /** Changes the value of the pixel (x,y).
53  * Pixel coordinates starts at the left-top corner of the image, and start in (0,0).
54  * The meaning of the parameter "color" depends on the implementation: it will usually
55  * be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray level.
56  * This method must support (x,y) values OUT of the actual image size without neither
57  * raising exceptions, nor leading to memory access errors.
58  */
59  virtual void setPixel( int x, int y, size_t color);
60 
61  /** Returns the width of the image in pixels (this currently has no applicability for a EMF file...)
62  */
63  virtual size_t getWidth() const { return 640; }
64 
65  /** Returns the height of the image in pixels (this currently has no applicability for a EMF file...)
66  */
67  virtual size_t getHeight() const {return 480;}
68 
69  /** Draws an image as a bitmap at a given position.
70  * \param x0 The top-left corner x coordinates on this canvas where the image is to be drawn
71  * \param y0 The top-left corner y coordinates on this canvas where the image is to be drawn
72  * \param img The image to be drawn in this canvas
73  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
74  */
75  virtual void drawImage(
76  int x,
77  int y,
78  const utils::CImage &img );
79 
80  /** Draws a line.
81  * \param x0 The starting point x coordinate
82  * \param y0 The starting point y coordinate
83  * \param x1 The end point x coordinate
84  * \param y1 The end point y coordinate
85  * \param color The color of the line
86  * \param width The desired width of the line (this is IGNORED in this virtual class)
87  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
88  */
89  virtual void line(
90  int x0,
91  int y0,
92  int x1,
93  int y1,
94  const mrpt::utils::TColor color,
95  unsigned int width = 1,
96  TPenStyle penStyle = psSolid);
97 
98  /** Places a text label.
99  * \param x0 The x coordinates
100  * \param y0 The y coordinates
101  * \param str The string to put
102  * \param color The text color
103  * \param fontSize The font size, in "points"
104  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
105  * \sa rectangle
106  */
107  virtual void textOut(
108  int x0,
109  int y0,
110  const std::string &str,
111  const mrpt::utils::TColor color
112  );
113 
114  /** Select the current font used when drawing text.
115  * \param fontName The face name of a font (e.g. "Arial","System",...)
116  * \param fontSize The size of the font in pts.
117  * \param bold Whether the font is bold
118  * \param italic Whether the font is italic
119  * \sa textOut, CCanvas::selectTextFont
120  */
121  virtual void selectVectorTextFont(
122  const std::string &fontName,
123  int fontSize,
124  bool bold = false,
125  bool italic = false );
126 
127  /** Draws an image as a bitmap at a given position, with some custom scale and rotation changes.
128  * \param x0 The top-left corner x coordinates on this canvas where the image is to be drawn
129  * \param y0 The top-left corner y coordinates on this canvas where the image is to be drawn
130  * \param rotation The rotation in radians, positive values being anti-clockwise direction, 0 is the normal position.
131  * \param scale The scale factor, e.g. 2 means twice the original size.
132  * \param img The image to be drawn in this canvas
133  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
134  */
135  virtual void drawImage(
136  int x,
137  int y,
138  const utils::CImage &img,
139  float rotation,
140  float scale )
141  {
142  CCanvas::drawImage(x,y,img,rotation,scale);
143  }
144 
145 
146  /** Draws a rectangle (an empty rectangle, without filling)
147  * \param x0 The top-left x coordinate
148  * \param y0 The top-left y coordinate
149  * \param x1 The right-bottom x coordinate
150  * \param y1 The right-bottom y coordinate
151  * \param color The color of the line
152  * \param width The desired width of the line.
153  * \sa filledRectangle
154  */
155  virtual void rectangle(
156  int x0,
157  int y0,
158  int x1,
159  int y1,
160  const mrpt::utils::TColor color,
161  unsigned int width = 1 );
162 
163  /** Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution.
164  * \param mean_x The x coordinate of the center point of the ellipse.
165  * \param mean_y The y coordinate of the center point of the ellipse.
166  * \param cov2D A 2x2 covariance matrix.
167  * \param confIntervalStds How many "sigmas" for the confidence level (i.e. 2->95%, 3=99.97%,...)
168  * \param color The color of the ellipse
169  * \param width The desired width of the line (this is IGNORED in this virtual class)
170  * \param nEllipsePoints The number of points to generate to approximate the ellipse shape.
171  * \exception std::exception On an invalid matrix.
172  */
173  template <class T>
176  T mean_x,
177  T mean_y,
178  float confIntervalStds = 2,
179  const mrpt::utils::TColor &color = mrpt::utils::TColor(255,255,255),
180  unsigned int width = 1,
181  int nEllipsePoints = 20
182  )
183  {
184  MRPT_START
185  int x1=0,y1=0,x2=0,y2=0;
186  double ang;
187  math::CMatrixTemplateNumeric<T> eigVal,eigVec;
188  int i;
189 
190  // Compute the eigen-vectors & values:
191  cov2D->eigenVectors(eigVec,eigVal);
192 
193  eigVal.Sqrt();
194  math::CMatrixTemplateNumeric<T> M( eigVal * (~eigVec) );
195 
196  // Compute the points of the 2D ellipse:
197  for (i=0,ang=0;i<nEllipsePoints;i++,ang+= (M_2PI/(nEllipsePoints-1)))
198  {
199  float ccos = cos(ang);
200  float ssin = sin(ang);
201 
202  x2 = round( mean_x + confIntervalStds * (ccos * M(0,0) + ssin * M(1,0)) );
203  y2 = round( mean_y + confIntervalStds * (ccos * M(0,1) + ssin * M(1,1)) );
204 
205  if (i>0)
206  line( x1, y1,x2, y2,color,width );
207 
208  x1 = x2;
209  y1 = y2;
210  } // end for points on ellipse
211 
213  std::cout << "Covariance matrix leading to error is:" << std::endl << *cov2D << std::endl; \
214  );
215  }
216 
217 
218 
219  }; // End of class def.
220 
221  } // End of namespace
222 } // end of namespace
223 #endif
#define MRPT_END_WITH_CLEAN_UP(stuff)
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:101
virtual void drawImage(int x, int y, const utils::CImage &img, float rotation, float scale)
Draws an image as a bitmap at a given position, with some custom scale and rotation changes...
#define M_2PI
Definition: mrpt_macros.h:363
virtual void drawImage(int x, int y, const utils::CImage &img)
Draws an image as a bitmap at a given position.
virtual size_t getHeight() const
Returns the height of the image in pixels (this currently has no applicability for a EMF file...
virtual size_t getWidth() const
Returns the width of the image in pixels (this currently has no applicability for a EMF file...
void ellipseGaussian(math::CMatrixTemplateNumeric< T > *cov2D, T mean_x, T mean_y, float confIntervalStds=2, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1, int nEllipsePoints=20)
Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution.
A RGB color - 8bit.
Definition: TColor.h:25
#define MRPT_START
This class represents a Windows Enhanced Meta File (EMF) for generating and saving graphics...
static int LINUX_IMG_HEIGHT
In Linux, the size of the bitmap image that emulates the EMF (Default:600)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:26
This virtual class defines the interface of any object accepting drawing primitives on it...
Definition: CCanvas.h:40
TPenStyle
Definition of pen styles.
Definition: CCanvas.h:53
static int LINUX_IMG_WIDTH
In Linux, the size of the bitmap image that emulates the EMF (Default:800)



Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN: at Mon May 9 06:50:38 UTC 2016