MRPT  1.9.9
CDisplayWindow.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <mrpt/img/CImage.h>
14 #include <mrpt/system/os.h>
15 #include <vector>
16 
17 namespace mrpt
18 {
19 /** Classes for creating GUI windows for 2D and 3D visualization. \ingroup
20  * mrpt_gui_grp */
21 namespace gui
22 {
23 /** This class creates a window as a graphical user interface (GUI) for
24  * displaying images to the user.
25  *
26  * For a list of supported events with the observer/observable pattern, see the
27  * discussion in mrpt::gui::CBaseGUIWindow.
28  * \ingroup mrpt_gui_grp
29  */
31 {
32  public:
35 
36  protected:
37  /** Enables or disables the visualization of cursor coordinates on the
38  * window caption.
39  */
41 
42  public:
43  /** Constructor
44  */
46  const std::string& windowCaption = std::string(),
47  unsigned int initWidth = 400, unsigned int initHeight = 400);
48 
49  /** Class factory returning a smart pointer */
51  const std::string& windowCaption, unsigned int initWidth = 400,
52  unsigned int initHeight = 400);
53 
54  /** Destructor
55  */
56  ~CDisplayWindow() override;
57 
58  /** Gets the last x,y pixel coordinates of the mouse. \return False if the
59  * window is closed. */
60  bool getLastMousePosition(int& x, int& y) const override;
61 
62  /** Set cursor style to default (cursorIsCross=false) or to a cross
63  * (cursorIsCross=true) */
64  void setCursorCross(bool cursorIsCross) override;
65 
66  /** Show a given color or grayscale image on the window and print a set of
67  * points on it.
68  * It adapts the size of the window to that of the image.
69  */
70  void showImageAndPoints(
74  const bool& showNumbers = false);
75  /** \overload */
76  void showImageAndPoints(
77  const mrpt::img::CImage& img, const std::vector<float>& x,
78  const std::vector<float>& y,
80  const bool& showNumbers = false);
81 
82  /** Show a given color or grayscale image on the window and print a set of
83  * points on it.
84  * It adapts the size of the window to that of the image.
85  * The class of FEATURELIST can be: mrpt::vision::CFeatureList or any STL
86  * container of entities having "x","y" and "ID" fields.
87  */
88  template <class FEATURELIST>
90  const mrpt::img::CImage& img, const FEATURELIST& list,
92  const bool& showIDs = false)
93  {
95  mrpt::img::CImage imgColor = img.colorImage();
96  imgColor.drawFeatures(list, color, showIDs);
97  showImage(imgColor);
98  MRPT_END
99  }
100 
101  /** Show a given color or grayscale image on the window and print a set of
102  * points on it and a set of lines splitting the image in tiles.
103  * It adapts the size of the window to that of the image.
104  * The class of FEATURELIST can be: mrpt::vision::CFeatureList
105  */
106  template <class FEATURELIST>
108  const mrpt::img::CImage& img, const FEATURELIST& list,
110  {
111  MRPT_START
112  using mrpt::img::TColor;
113  mrpt::img::CImage imgColor = img.colorImage();
114 
115  // Print the 4 tile lines
116  unsigned int w = imgColor.getWidth();
117  unsigned int h = imgColor.getHeight();
118  imgColor.line(0, h / 2, w - 1, h / 2, TColor::green());
119  imgColor.line(w / 4, 0, w / 4, h, TColor::green());
120  imgColor.line(w / 2, 0, w / 2, h, TColor::green());
121  imgColor.line(3 * w / 4, 0, 3 * w / 4, h, TColor::green());
122 
123  showImageAndPoints(imgColor, list, color);
124 
125  MRPT_END
126  }
127 
128  /** Show a pair of given color or grayscale images (put together) on the
129  * window and print a set of matches on them.
130  * It adapts the size of the window to that of the image.
131  * MATCHEDLIST can be of the class: mrpt::vision::CMatchedFeatureList, or
132  * any STL container of pairs of anything having ".x" and ".y" (e.g.
133  * mrpt::math::TPoint2D)
134  */
135  template <class MATCHEDLIST>
137  const mrpt::img::CImage& img1, const mrpt::img::CImage& img2,
138  const MATCHEDLIST& mList,
140  bool showNumbers = false)
141  {
142  MRPT_START
143 
144  mrpt::img::CImage imgColor;
145 
146  // img1.colorImage( imgColor ); // Create a colorimage
147  imgColor.joinImagesHorz(img1, img2);
148 
149  unsigned int w = img1.getWidth();
150  unsigned int nf = 0;
151 
152  for (typename MATCHEDLIST::const_iterator i = mList.begin();
153  i != mList.end(); ++i, ++nf)
154  {
155  const auto x1 = round(i->first.keypoint.pt.x);
156  const auto y1 = round(i->first.keypoint.pt.y);
157  const auto x2 = round(i->second.keypoint.pt.x);
158  const auto y2 = round(i->second.keypoint.pt.y);
159 
160  imgColor.drawCircle(x1, y1, 4, color);
161  imgColor.drawCircle(x2 + w, y2, 4, color);
162 
163  if (showNumbers)
164  {
165  char buf[15];
167  buf, 15, "%d[%u]", nf, (unsigned int)i->first.keypoint.ID);
168  imgColor.textOut(x1 - 10, y1, buf, color);
170  buf, 15, "%d[%u]", nf, (unsigned int)i->second.keypoint.ID);
171  imgColor.textOut(x2 + w + 10, y2, buf, color);
172  }
173  }
174  showImage(imgColor);
175 
176  MRPT_END
177  }
178 
179  /** Show a pair of given color or grayscale images (put together) on the
180  * window and print a set of matches on them.
181  * It adapts the size of the window to that of the image.
182  * FEATURELIST can be of the class: mrpt::vision::CFeatureList
183  */
184  template <class FEATURELIST>
186  const mrpt::img::CImage& img1, const mrpt::img::CImage& img2,
187  const FEATURELIST& leftList, const FEATURELIST& rightList,
189  {
190  MRPT_START
191 
192  mrpt::img::CImage imgColor;
193 
194  // img1.colorImage( imgColor ); // Create a colorimage
195  ASSERT_(leftList.size() == rightList.size());
196  imgColor.joinImagesHorz(img1, img2);
197 
198  unsigned int w = img1.getWidth();
199 
200  for (typename FEATURELIST::const_iterator iL = leftList.begin(),
201  iR = rightList.begin();
202  iL != leftList.end(); ++iL, ++iR)
203  {
204  imgColor.drawCircle(round((*iL)->x), round((*iL)->y), 4, color);
205  imgColor.drawCircle(round((*iR)->x + w), round((*iR)->y), 4, color);
206  imgColor.line(
207  round((*iL)->x), round((*iL)->y), round((*iR)->x + w),
208  round((*iR)->y), color);
209  }
210  showImage(imgColor);
211 
212  MRPT_END
213  }
214 
215  /** Show a given color or grayscale image on the window.
216  * It adapts the size of the window to that of the image.
217  */
218  void showImage(const mrpt::img::CImage& img);
219 
220  /** Plots a graph in MATLAB-like style.
221  */
222  void plot(
224 
225  /** Plots a graph in MATLAB-like style.
226  */
227  void plot(const mrpt::math::CVectorFloat& y);
228 
229  /** Resizes the window, stretching the image to fit into the display area.
230  */
231  void resize(unsigned int width, unsigned int height) override;
232 
233  /** Changes the position of the window on the screen.
234  */
235  void setPos(int x, int y) override;
236 
237  /** Enables or disables the visualization of cursor coordinates on the
238  * window caption (default = enabled).
239  */
240  inline void enableCursorCoordinatesVisualization(bool enable)
241  {
242  m_enableCursorCoordinates = enable;
243  }
244 
245  /** Changes the window title text.
246  */
247  void setWindowTitle(const std::string& str) override;
248 
249 }; // End of class def.
250 
251 } // namespace gui
252 
253 } // namespace mrpt
void showImageAndPoints(const mrpt::img::CImage &img, const FEATURELIST &list, const mrpt::img::TColor &color=mrpt::img::TColor::red(), const bool &showIDs=false)
Show a given color or grayscale image on the window and print a set of points on it.
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.
Definition: CImage.cpp:1143
#define MRPT_START
Definition: exceptions.h:241
bool m_enableCursorCoordinates
Enables or disables the visualization of cursor coordinates on the window caption.
Template for column vectors of dynamic size, compatible with Eigen.
void setCursorCross(bool cursorIsCross) override
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) ...
void showImagesAndMatchedPoints(const mrpt::img::CImage &img1, const mrpt::img::CImage &img2, const MATCHEDLIST &mList, const mrpt::img::TColor &color=mrpt::img::TColor::red(), bool showNumbers=false)
Show a pair of given color or grayscale images (put together) on the window and print a set of matche...
~CDisplayWindow() override
Destructor.
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:877
void enableCursorCoordinatesVisualization(bool enable)
Enables or disables the visualization of cursor coordinates on the window caption (default = enabled)...
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
Definition: CImage.cpp:1839
GLenum GLsizei width
Definition: glext.h:3535
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4199
void setWindowTitle(const std::string &str) override
Changes the window title text.
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y)
Plots a graph in MATLAB-like style.
CImage colorImage() const
Returns a color (RGB) version of the grayscale image, or a shallow copy of itself if it is already a ...
Definition: CImage.cpp:1813
GLuint color
Definition: glext.h:8459
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:846
GLint GLvoid * img
Definition: glext.h:3769
bool getLastMousePosition(int &x, int &y) const override
Gets the last x,y pixel coordinates of the mouse.
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
GLsizei const GLchar ** string
Definition: glext.h:4116
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
void showImagesAndMatchedPoints(const mrpt::img::CImage &img1, const mrpt::img::CImage &img2, const FEATURELIST &leftList, const FEATURELIST &rightList, const mrpt::img::TColor &color=mrpt::img::TColor::red())
Show a pair of given color or grayscale images (put together) on the window and print a set of matche...
void setPos(int x, int y) override
Changes the position of the window on the screen.
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:60
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void drawFeatures(const FEATURELIST &list, const TColor &color=TColor::red(), const bool showIDs=false, const bool showResponse=false, const bool showScale=false, const char marker='+')
Draws a set of marks (or scaled circles for features with scale) onto the image, given a generic cont...
Definition: CCanvas.h:280
GLclampf green
Definition: glext.h:3529
void showImageAndPoints(const mrpt::img::CImage &img, const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const mrpt::img::TColor &color=mrpt::img::TColor::red(), const bool &showNumbers=false)
Show a given color or grayscale image on the window and print a set of points on it.
#define MRPT_END
Definition: exceptions.h:245
void showImage(const mrpt::img::CImage &img)
Show a given color or grayscale image on the window.
GLenum GLint GLint y
Definition: glext.h:3542
CDisplayWindow(const std::string &windowCaption=std::string(), unsigned int initWidth=400, unsigned int initHeight=400)
Constructor.
static CDisplayWindow::Ptr Create(const std::string &windowCaption, unsigned int initWidth=400, unsigned int initHeight=400)
Class factory returning a smart pointer.
A RGB color - 8bit.
Definition: TColor.h:20
GLenum GLint x
Definition: glext.h:3542
GLenum GLsizei GLsizei height
Definition: glext.h:3558
The base class for GUI window classes.
void showTiledImageAndPoints(const mrpt::img::CImage &img, const FEATURELIST &list, const mrpt::img::TColor &color=mrpt::img::TColor::red())
Show a given color or grayscale image on the window and print a set of points on it and a set of line...
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:191
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:147
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: ce1a28c9f Fri Aug 23 08:02:09 2019 +0200 at vie ago 23 08:10:11 CEST 2019