Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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  virtual ~CEnhancedMetaFile( );
50 
51  /** Changes the value of the pixel (x,y).
52  * Pixel coordinates starts at the left-top corner of the image, and start in (0,0).
53  * The meaning of the parameter "color" depends on the implementation: it will usually
54  * be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray level.
55  * This method must support (x,y) values OUT of the actual image size without neither
56  * raising exceptions, nor leading to memory access errors.
57  */
58  void setPixel( int x, int y, size_t color) MRPT_OVERRIDE;
59 
60  /** Returns the width of the image in pixels (this currently has no applicability for a EMF file...) */
61  size_t getWidth() const MRPT_OVERRIDE { return 640; }
62 
63  /** Returns the height of the image in pixels (this currently has no applicability for a EMF file...) */
64  size_t getHeight() const MRPT_OVERRIDE {return 480;}
65 
66  /** Draws an image as a bitmap at a given position.
67  * \param x0 The top-left corner x coordinates on this canvas where the image is to be drawn
68  * \param y0 The top-left corner y coordinates on this canvas where the image is to be drawn
69  * \param img The image to be drawn in this canvas
70  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
71  */
72  void drawImage(int x, int y, const utils::CImage &img ) MRPT_OVERRIDE;
73 
74  /** Draws a line.
75  * \param x0 The starting point x coordinate
76  * \param y0 The starting point y coordinate
77  * \param x1 The end point x coordinate
78  * \param y1 The end point y coordinate
79  * \param color The color of the line
80  * \param width The desired width of the line (this is IGNORED in this virtual class)
81  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
82  */
83  void line(
84  int x0, int y0,
85  int x1, int y1,
86  const mrpt::utils::TColor color,
87  unsigned int width = 1,
88  TPenStyle penStyle = psSolid) MRPT_OVERRIDE;
89 
90  /** Places a text label.
91  * \param x0 The x coordinates
92  * \param y0 The y coordinates
93  * \param str The string to put
94  * \param color The text color
95  * \param fontSize The font size, in "points"
96  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
97  * \sa rectangle
98  */
99  void textOut(
100  int x0, int y0,
101  const std::string &str,
102  const mrpt::utils::TColor color
103  ) MRPT_OVERRIDE;
104 
105  /** Select the current font used when drawing text.
106  * \param fontName The face name of a font (e.g. "Arial","System",...)
107  * \param fontSize The size of the font in pts.
108  * \param bold Whether the font is bold
109  * \param italic Whether the font is italic
110  * \sa textOut, CCanvas::selectTextFont
111  */
112  virtual void selectVectorTextFont(
113  const std::string &fontName,
114  int fontSize,
115  bool bold = false,
116  bool italic = false );
117 
118  /** Draws an image as a bitmap at a given position, with some custom scale and rotation changes.
119  * \param x0 The top-left corner x coordinates on this canvas where the image is to be drawn
120  * \param y0 The top-left corner y coordinates on this canvas where the image is to be drawn
121  * \param rotation The rotation in radians, positive values being anti-clockwise direction, 0 is the normal position.
122  * \param scale The scale factor, e.g. 2 means twice the original size.
123  * \param img The image to be drawn in this canvas
124  * This method may be redefined in some classes implementing this interface in a more appropiate manner.
125  */
126  void drawImage(
127  int x, int y,
128  const utils::CImage &img,
129  float rotation,
130  float scale ) MRPT_OVERRIDE
131  {
132  CCanvas::drawImage(x,y,img,rotation,scale);
133  }
134 
135  /** Draws a rectangle (an empty rectangle, without filling)
136  * \param x0 The top-left x coordinate
137  * \param y0 The top-left y coordinate
138  * \param x1 The right-bottom x coordinate
139  * \param y1 The right-bottom y coordinate
140  * \param color The color of the line
141  * \param width The desired width of the line.
142  * \sa filledRectangle
143  */
144  virtual void rectangle(
145  int x0,
146  int y0,
147  int x1,
148  int y1,
149  const mrpt::utils::TColor color,
150  unsigned int width = 1 );
151 
152  /** Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution.
153  * \param mean_x The x coordinate of the center point of the ellipse.
154  * \param mean_y The y coordinate of the center point of the ellipse.
155  * \param cov2D A 2x2 covariance matrix.
156  * \param confIntervalStds How many "sigmas" for the confidence level (i.e. 2->95%, 3=99.97%,...)
157  * \param color The color of the ellipse
158  * \param width The desired width of the line (this is IGNORED in this virtual class)
159  * \param nEllipsePoints The number of points to generate to approximate the ellipse shape.
160  * \exception std::exception On an invalid matrix.
161  */
162  template <class T>
165  T mean_x,
166  T mean_y,
167  float confIntervalStds = 2,
168  const mrpt::utils::TColor &color = mrpt::utils::TColor(255,255,255),
169  unsigned int width = 1,
170  int nEllipsePoints = 20
171  )
172  {
173  MRPT_START
174  int x1=0,y1=0,x2=0,y2=0;
175  double ang;
176  math::CMatrixTemplateNumeric<T> eigVal,eigVec;
177  int i;
178 
179  // Compute the eigen-vectors & values:
180  cov2D->eigenVectors(eigVec,eigVal);
181 
182  eigVal.Sqrt();
183  math::CMatrixTemplateNumeric<T> M( eigVal * (~eigVec) );
184 
185  // Compute the points of the 2D ellipse:
186  for (i=0,ang=0;i<nEllipsePoints;i++,ang+= (M_2PI/(nEllipsePoints-1)))
187  {
188  float ccos = cos(ang);
189  float ssin = sin(ang);
190 
191  x2 = round( mean_x + confIntervalStds * (ccos * M(0,0) + ssin * M(1,0)) );
192  y2 = round( mean_y + confIntervalStds * (ccos * M(0,1) + ssin * M(1,1)) );
193 
194  if (i>0)
195  line( x1, y1,x2, y2,color,width );
196 
197  x1 = x2;
198  y1 = y2;
199  } // end for points on ellipse
200 
202  std::cout << "Covariance matrix leading to error is:" << std::endl << *cov2D << std::endl; \
203  );
204  }
205  }; // End of class def.
206  } // End of namespace
207 } // end of namespace
208 #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
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels (this currently has no applicability for a EMF file...
#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.
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
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels (this currently has no applicability for a EMF file...
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
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.14 for MRPT 1.4.0 SVN: at Mon Mar 5 22:51:34 UTC 2018