MRPT  2.0.4
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-2020, 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  *
29  * ![mrpt::gui::CDisplayWindow screenshot](preview_CDisplayWindow.jpg)
30  *
31  * \ingroup mrpt_gui_grp
32  */
34 {
35  public:
38 
39  protected:
40  /** Enables or disables the visualization of cursor coordinates on the
41  * window caption.
42  */
44 
45  public:
46  /** Constructor
47  */
49  const std::string& windowCaption = std::string(),
50  unsigned int initWidth = 400, unsigned int initHeight = 400);
51 
52  /** Class factory returning a smart pointer */
54  const std::string& windowCaption, unsigned int initWidth = 400,
55  unsigned int initHeight = 400);
56 
57  /** Destructor
58  */
59  ~CDisplayWindow() override;
60 
61  /** Gets the last x,y pixel coordinates of the mouse. \return False if the
62  * window is closed. */
63  bool getLastMousePosition(int& x, int& y) const override;
64 
65  /** Set cursor style to default (cursorIsCross=false) or to a cross
66  * (cursorIsCross=true) */
67  void setCursorCross(bool cursorIsCross) override;
68 
69  /** Show a given color or grayscale image on the window and print a set of
70  * points on it.
71  * It adapts the size of the window to that of the image.
72  */
73  void showImageAndPoints(
74  const mrpt::img::CImage& img, const mrpt::math::CVectorFloat& x,
75  const mrpt::math::CVectorFloat& y,
77  bool showNumbers = false);
78  /** \overload */
79  void showImageAndPoints(
80  const mrpt::img::CImage& img, const std::vector<float>& x,
81  const std::vector<float>& y,
83  bool showNumbers = false);
84 
85  /** Show a given color or grayscale image on the window and print a set of
86  * points on it.
87  * It adapts the size of the window to that of the image.
88  * The class of FEATURELIST can be: mrpt::vision::CFeatureList or any STL
89  * container of entities having "x","y" and "ID" fields.
90  */
91  template <class FEATURELIST>
93  const mrpt::img::CImage& img, const FEATURELIST& list,
95  bool showIDs = false)
96  {
98  mrpt::img::CImage imgColor = img.colorImage();
99  imgColor.drawFeatures(list, color, showIDs);
100  showImage(imgColor);
101  MRPT_END
102  }
103 
104  /** Show a given color or grayscale image on the window and print a set of
105  * points on it and a set of lines splitting the image in tiles.
106  * It adapts the size of the window to that of the image.
107  * The class of FEATURELIST can be: mrpt::vision::CFeatureList
108  */
109  template <class FEATURELIST>
111  const mrpt::img::CImage& img, const FEATURELIST& list,
112  const mrpt::img::TColor& color = mrpt::img::TColor::red())
113  {
114  MRPT_START
115  using mrpt::img::TColor;
116  mrpt::img::CImage imgColor = img.colorImage();
117 
118  // Print the 4 tile lines
119  unsigned int w = imgColor.getWidth();
120  unsigned int h = imgColor.getHeight();
121  imgColor.line(0, h / 2, w - 1, h / 2, TColor::green());
122  imgColor.line(w / 4, 0, w / 4, h, TColor::green());
123  imgColor.line(w / 2, 0, w / 2, h, TColor::green());
124  imgColor.line(3 * w / 4, 0, 3 * w / 4, h, TColor::green());
125 
126  showImageAndPoints(imgColor, list, color);
127 
128  MRPT_END
129  }
130 
131  /** Show a pair of given color or grayscale images (put together) on the
132  * window and print a set of matches on them.
133  * It adapts the size of the window to that of the image.
134  * MATCHEDLIST can be of the class: mrpt::vision::CMatchedFeatureList, or
135  * any STL container of pairs of anything having ".x" and ".y" (e.g.
136  * mrpt::math::TPoint2D)
137  */
138  template <class MATCHEDLIST>
140  const mrpt::img::CImage& img1, const mrpt::img::CImage& img2,
141  const MATCHEDLIST& mList,
142  const mrpt::img::TColor& color = mrpt::img::TColor::red(),
143  bool showNumbers = false)
144  {
145  MRPT_START
146 
147  mrpt::img::CImage imgColor;
148 
149  // img1.colorImage( imgColor ); // Create a colorimage
150  imgColor.joinImagesHorz(img1, img2);
151 
152  unsigned int w = img1.getWidth();
153  unsigned int nf = 0;
154 
155  for (typename MATCHEDLIST::const_iterator i = mList.begin();
156  i != mList.end(); ++i, ++nf)
157  {
158  const auto x1 = round(i->first.keypoint.pt.x);
159  const auto y1 = round(i->first.keypoint.pt.y);
160  const auto x2 = round(i->second.keypoint.pt.x);
161  const auto y2 = round(i->second.keypoint.pt.y);
162 
163  imgColor.drawCircle(x1, y1, 4, color);
164  imgColor.drawCircle(x2 + w, y2, 4, color);
165 
166  if (showNumbers)
167  {
168  char buf[15];
170  buf, 15, "%d[%u]", nf, (unsigned int)i->first.keypoint.ID);
171  imgColor.textOut(x1 - 10, y1, buf, color);
173  buf, 15, "%d[%u]", nf, (unsigned int)i->second.keypoint.ID);
174  imgColor.textOut(x2 + w + 10, y2, buf, color);
175  }
176  }
177  showImage(imgColor);
178 
179  MRPT_END
180  }
181 
182  /** Show a pair of given color or grayscale images (put together) on the
183  * window and print a set of matches on them.
184  * It adapts the size of the window to that of the image.
185  * FEATURELIST can be of the class: mrpt::vision::CFeatureList
186  */
187  template <class FEATURELIST>
189  const mrpt::img::CImage& img1, const mrpt::img::CImage& img2,
190  const FEATURELIST& leftList, const FEATURELIST& rightList,
191  const mrpt::img::TColor& color = mrpt::img::TColor::red())
192  {
193  MRPT_START
194 
195  mrpt::img::CImage imgColor;
196 
197  // img1.colorImage( imgColor ); // Create a colorimage
198  ASSERT_(leftList.size() == rightList.size());
199  imgColor.joinImagesHorz(img1, img2);
200 
201  unsigned int w = img1.getWidth();
202 
203  for (typename FEATURELIST::const_iterator iL = leftList.begin(),
204  iR = rightList.begin();
205  iL != leftList.end(); ++iL, ++iR)
206  {
207  imgColor.drawCircle(round((*iL)->x), round((*iL)->y), 4, color);
208  imgColor.drawCircle(round((*iR)->x + w), round((*iR)->y), 4, color);
209  imgColor.line(
210  round((*iL)->x), round((*iL)->y), round((*iR)->x + w),
211  round((*iR)->y), color);
212  }
213  showImage(imgColor);
214 
215  MRPT_END
216  }
217 
218  /** Show a given color or grayscale image on the window.
219  * It adapts the size of the window to that of the image.
220  */
221  void showImage(const mrpt::img::CImage& img);
222 
223  /** Plots a graph in MATLAB-like style.
224  */
225  void plot(
227 
228  /** Plots a graph in MATLAB-like style.
229  */
230  void plot(const mrpt::math::CVectorFloat& y);
231 
232  /** Resizes the window, stretching the image to fit into the display area.
233  */
234  void resize(unsigned int width, unsigned int height) override;
235 
236  /** Changes the position of the window on the screen.
237  */
238  void setPos(int x, int y) override;
239 
240  /** Enables or disables the visualization of cursor coordinates on the
241  * window caption (default = enabled).
242  */
243  inline void enableCursorCoordinatesVisualization(bool enable)
244  {
245  m_enableCursorCoordinates = enable;
246  }
247 
248  /** Changes the window title text.
249  */
250  void setWindowTitle(const std::string& str) override;
251 
252 }; // End of class def.
253 
254 } // namespace gui
255 
256 } // namespace mrpt
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:1123
#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:855
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:1893
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:1867
#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:818
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(), bool showNumbers=false)
Show a given color or grayscale image on the window and print a set of points on it.
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...
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.
void showImageAndPoints(const mrpt::img::CImage &img, const FEATURELIST &list, const mrpt::img::TColor &color=mrpt::img::TColor::red(), bool showIDs=false)
Show a given color or grayscale image on the window and print a set of points on it.
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:66
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
#define MRPT_END
Definition: exceptions.h:245
void showImage(const mrpt::img::CImage &img)
Show a given color or grayscale image on the window.
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:25
The base class for GUI window classes based on wxWidgets.
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...
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:24



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020