Main MRPT website > C++ reference for MRPT 1.9.9
CDisplayWindow.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 #ifndef CDisplayWindow_H
10 #define CDisplayWindow_H
11 
13 #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:
33  using Ptr = std::shared_ptr<CDisplayWindow>;
34  using ConstPtr = std::shared_ptr<const CDisplayWindow>;
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  virtual ~CDisplayWindow();
57 
58  /** Gets the last x,y pixel coordinates of the mouse. \return False if the
59  * window is closed. */
60  virtual 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  virtual 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(1, 1, CH_RGB);
96  img.colorImage(imgColor); // Create a colorimage
97  imgColor.drawFeatures(list, color, showIDs);
98  showImage(imgColor);
99  MRPT_END
100  }
101 
102  /** Show a given color or grayscale image on the window and print a set of
103  * points on it and a set of lines splitting the image in tiles.
104  * It adapts the size of the window to that of the image.
105  * The class of FEATURELIST can be: mrpt::vision::CFeatureList
106  */
107  template <class FEATURELIST>
109  const mrpt::img::CImage& img, const FEATURELIST& list,
111  {
112  MRPT_START
113  using mrpt::img::TColor;
114  mrpt::img::CImage imgColor(1, 1, 3);
115  img.colorImage(imgColor); // Create a colorimage
116 
117  // Print the 4 tile lines
118  unsigned int w = imgColor.getWidth();
119  unsigned int h = imgColor.getHeight();
120  imgColor.line(0, h / 2, w - 1, h / 2, TColor::green());
121  imgColor.line(w / 4, 0, w / 4, h, TColor::green());
122  imgColor.line(w / 2, 0, w / 2, h, TColor::green());
123  imgColor.line(3 * w / 4, 0, 3 * w / 4, h, TColor::green());
124 
125  showImageAndPoints(imgColor, list, color);
126 
127  MRPT_END
128  }
129 
130  /** Show a pair of given color or grayscale images (put together) on the
131  * window and print a set of matches on them.
132  * It adapts the size of the window to that of the image.
133  * MATCHEDLIST can be of the class: mrpt::vision::CMatchedFeatureList, or
134  * any STL container of pairs of anything having ".x" and ".y" (e.g.
135  * mrpt::math::TPoint2D)
136  */
137  template <class MATCHEDLIST>
139  const mrpt::img::CImage& img1, const mrpt::img::CImage& img2,
140  const MATCHEDLIST& mList,
142  bool showNumbers = false)
143  {
144  MRPT_START
145 
146  mrpt::img::CImage imgColor;
147 
148  // img1.colorImage( imgColor ); // Create a colorimage
149  imgColor.joinImagesHorz(img1, img2);
150 
151  unsigned int w = img1.getWidth();
152  unsigned int nf = 0;
153 
154  for (typename MATCHEDLIST::const_iterator i = mList.begin();
155  i != mList.end(); ++i, ++nf)
156  {
157  imgColor.drawCircle(
158  round(i->first->x), round(i->first->y), 4, color);
159  imgColor.drawCircle(
160  round(i->second->x + w), round(i->second->y), 4, color);
161  // imgColor.line( round( i->first->x ), round( i->first->y ), round(
162  // i->second->x + w ), round( i->second->y ), color );
163  if (showNumbers)
164  {
165  char buf[15];
167  buf, 15, "%d[%u]", nf, (unsigned int)i->first->ID);
168  imgColor.textOut(
169  round(i->first->x) - 10, round(i->first->y), buf, color);
171  buf, 15, "%d[%u]", nf, (unsigned int)i->second->ID);
172  imgColor.textOut(
173  round(i->second->x + w) + 10, round(i->second->y), buf,
174  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,
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 } // End of namespace
255 
256 } // End of namespace
257 
258 #endif
os.h
mrpt::img::CImage::getWidth
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:864
mrpt::gui::CDisplayWindow::showTiledImageAndPoints
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...
Definition: CDisplayWindow.h:108
mrpt::img::TColor::red
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:62
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::gui::CDisplayWindow::resize
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
Definition: CDisplayWindow.cpp:594
mrpt::gui::CDisplayWindow::ConstPtr
std::shared_ptr< const CDisplayWindow > ConstPtr
Definition: CDisplayWindow.h:34
green
GLclampf green
Definition: glext.h:3525
mrpt::math::dynamic_vector
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
Definition: eigen_frwds.h:44
mrpt::gui::CDisplayWindow::~CDisplayWindow
virtual ~CDisplayWindow()
Destructor.
Definition: CDisplayWindow.cpp:381
mrpt::gui::CDisplayWindow::showImageAndPoints
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.
Definition: CDisplayWindow.h:89
CH_RGB
#define CH_RGB
Definition: img/CImage.h:45
mrpt::gui::CDisplayWindow::setPos
void setPos(int x, int y) override
Changes the position of the window on the screen.
Definition: CDisplayWindow.cpp:621
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::gui::CDisplayWindow::setCursorCross
virtual void setCursorCross(bool cursorIsCross) override
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true)
Definition: CDisplayWindow.cpp:384
mrpt::gui::CDisplayWindow::Create
static CDisplayWindow::Ptr Create(const std::string &windowCaption, unsigned int initWidth=400, unsigned int initHeight=400)
Class factory returning a smart pointer.
Definition: CDisplayWindow.cpp:359
mrpt::gui::CDisplayWindow::showImage
void showImage(const mrpt::img::CImage &img)
Show a given color or grayscale image on the window.
Definition: CDisplayWindow.cpp:417
mrpt::gui::CDisplayWindow::plot
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y)
Plots a graph in MATLAB-like style.
Definition: CDisplayWindow.cpp:488
mrpt::gui::CDisplayWindow::showImagesAndMatchedPoints
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...
Definition: CDisplayWindow.h:138
mrpt::system::os::sprintf
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:189
mrpt::gui::CDisplayWindow::Ptr
std::shared_ptr< CDisplayWindow > Ptr
Definition: CDisplayWindow.h:33
mrpt::gui::CBaseGUIWindow
The base class for GUI window classes.
Definition: CBaseGUIWindow.h:42
mrpt::round
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:23
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::gui::CDisplayWindow::m_enableCursorCoordinates
bool m_enableCursorCoordinates
Enables or disables the visualization of cursor coordinates on the window caption.
Definition: CDisplayWindow.h:40
mrpt::img::CImage::line
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:1296
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
color
GLuint color
Definition: glext.h:8300
mrpt::img::CImage::joinImagesHorz
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
Definition: CImage.cpp:2437
mrpt::gui::CDisplayWindow
This class creates a window as a graphical user interface (GUI) for displaying images to the user.
Definition: CDisplayWindow.h:30
mrpt::gui::CDisplayWindow::showImageAndPoints
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.
Definition: CDisplayWindow.cpp:443
height
GLenum GLsizei GLsizei height
Definition: glext.h:3554
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
mrpt::img::CImage::getHeight
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:892
img
GLint GLvoid * img
Definition: glext.h:3763
mrpt::gui::CDisplayWindow::showImagesAndMatchedPoints
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...
Definition: CDisplayWindow.h:188
width
GLenum GLsizei width
Definition: glext.h:3531
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
CBaseGUIWindow.h
mrpt::gui::CDisplayWindow::setWindowTitle
void setWindowTitle(const std::string &str) override
Changes the window title text.
Definition: CDisplayWindow.cpp:648
string
GLsizei const GLchar ** string
Definition: glext.h:4101
CImage.h
mrpt::gui::CDisplayWindow::enableCursorCoordinatesVisualization
void enableCursorCoordinatesVisualization(bool enable)
Enables or disables the visualization of cursor coordinates on the window caption (default = enabled)...
Definition: CDisplayWindow.h:243
mrpt::gui::CDisplayWindow::getLastMousePosition
virtual bool getLastMousePosition(int &x, int &y) const override
Gets the last x,y pixel coordinates of the mouse.
Definition: CDisplayWindow.cpp:399
mrpt::gui::CDisplayWindow::CDisplayWindow
CDisplayWindow(const std::string &windowCaption=std::string(), unsigned int initWidth=400, unsigned int initHeight=400)
Constructor.
Definition: CDisplayWindow.cpp:369
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST