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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019