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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019