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



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019