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