Main MRPT website > C++ reference
MRPT logo
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-2014, 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/utils/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 mrpt_gui_grp */
20  namespace gui
21  {
22  using namespace mrpt::utils;
23 
25 
26  /** This class creates a window as a graphical user interface (GUI) for displaying images to the user.
27  *
28  * For a list of supported events with the observer/observable pattern, see the discussion in mrpt::gui::CBaseGUIWindow.
29  * \ingroup mrpt_gui_grp
30  */
32  {
33  // This must be added to any CSerializable derived class:
35 
36  protected:
37 
38  /** Enables or disables the visualization of cursor coordinates on the window caption.
39  */
40  bool m_enableCursorCoordinates;
41 
42  public:
43  /** Constructor
44  */
45  CDisplayWindow( const std::string &windowCaption = std::string(), unsigned int initWidth = 400, unsigned int initHeight = 400 );
46 
47  /** Class factory returning a smart pointer */
48  static CDisplayWindowPtr Create(
49  const std::string &windowCaption,
50  unsigned int initWidth = 400,
51  unsigned int initHeight = 400 );
52 
53  /** Destructor
54  */
55  virtual ~CDisplayWindow();
56 
57  /** Gets the last x,y pixel coordinates of the mouse. \return False if the window is closed. */
58  virtual bool getLastMousePosition(int &x, int &y) const;
59 
60  /** Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) */
61  virtual void setCursorCross(bool cursorIsCross);
62 
63  /** Show a given color or grayscale image on the window and print a set of points on it.
64  * It adapts the size of the window to that of the image.
65  */
66  void showImageAndPoints( const CImage &img, const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const TColor &color = TColor::red, const bool &showNumbers = false );
67  /** \overload */
68  void showImageAndPoints( const CImage &img, const std::vector<float> &x, const std::vector<float> &y, const TColor &color = TColor::red, const bool &showNumbers = false );
69 
70  /** Show a given color or grayscale image on the window and print a set of points on it.
71  * It adapts the size of the window to that of the image.
72  * The class of FEATURELIST can be: mrpt::vision::CFeatureList or any STL container of entities having "x","y" and "ID" fields.
73  */
74  template <class FEATURELIST>
75  void showImageAndPoints( const CImage &img, const FEATURELIST &list, const TColor &color = TColor::red, const bool &showIDs = false )
76  {
78  CImage imgColor(1,1,CH_RGB);
79  img.colorImage( imgColor ); // Create a colorimage
80  imgColor.drawFeatures(list,color,showIDs);
81  showImage(imgColor);
82  MRPT_END
83  }
84 
85  /** Show a given color or grayscale image on the window and print a set of points on it and a set of lines splitting the image in tiles.
86  * It adapts the size of the window to that of the image.
87  * The class of FEATURELIST can be: mrpt::vision::CFeatureList
88  */
89  template <class FEATURELIST>
90  void showTiledImageAndPoints( const CImage &img, const FEATURELIST &list, const TColor &color = TColor::red )
91  {
93 
94  CImage imgColor(1,1,3);
95  img.colorImage( imgColor ); // Create a colorimage
96 
97  // Print the 4 tile lines
98  unsigned int w = imgColor.getWidth();
99  unsigned int h = imgColor.getHeight();
100  imgColor.line( 0, h/2, w-1, h/2, TColor::green );
101  imgColor.line( w/4, 0, w/4, h, TColor::green );
102  imgColor.line( w/2, 0, w/2, h, TColor::green );
103  imgColor.line( 3*w/4, 0, 3*w/4, h, TColor::green );
104 
105  showImageAndPoints( imgColor, list, color );
106 
107  MRPT_END
108  }
109 
110  /** Show a pair of given color or grayscale images (put together) on the window and print a set of matches on them.
111  * It adapts the size of the window to that of the image.
112  * MATCHEDLIST can be of the class: mrpt::vision::CMatchedFeatureList, or any STL container of pairs of anything having ".x" and ".y" (e.g. mrpt::math::TPoint2D)
113  */
114  template <class MATCHEDLIST>
115  void showImagesAndMatchedPoints( const CImage &img1, const CImage &img2, const MATCHEDLIST &mList, const TColor &color = TColor::red, bool showNumbers = false )
116  {
117  MRPT_START
118 
119  CImage imgColor;
120 
121  //img1.colorImage( imgColor ); // Create a colorimage
122  imgColor.joinImagesHorz( img1, img2 );
123 
124  unsigned int w = img1.getWidth();
125  unsigned int nf = 0;
126 
127  for( typename MATCHEDLIST::const_iterator i = mList.begin(); i != mList.end(); ++i, ++nf )
128  {
129  imgColor.drawCircle( round( i->first->x ), round( i->first->y ), 4, color );
130  imgColor.drawCircle( round( i->second->x + w ), round( i->second->y ), 4, color );
131  //imgColor.line( round( i->first->x ), round( i->first->y ), round( i->second->x + w ), round( i->second->y ), color );
132  if( showNumbers )
133  {
134  char buf[15];
135  mrpt::system::os::sprintf( buf, 15, "%d[%u]", nf, (unsigned int)i->first->ID );
136  imgColor.textOut( round( i->first->x ) - 10, round( i->first->y ), buf, color );
137  mrpt::system::os::sprintf( buf, 15, "%d[%u]", nf, (unsigned int)i->second->ID );
138  imgColor.textOut( round( i->second->x + w ) + 10, round( i->second->y ), buf, color );
139  }
140  }
141  showImage(imgColor);
142 
143  MRPT_END
144  }
145 
146  /** Show a pair of given color or grayscale images (put together) on the window and print a set of matches on them.
147  * It adapts the size of the window to that of the image.
148  * FEATURELIST can be of the class: mrpt::vision::CFeatureList
149  */
150  template <class FEATURELIST>
151  void showImagesAndMatchedPoints( const CImage &img1, const CImage &img2, const FEATURELIST &leftList, const FEATURELIST &rightList, const TColor &color = TColor::red )
152  {
153  MRPT_START
154 
155  CImage imgColor;
156 
157  //img1.colorImage( imgColor ); // Create a colorimage
158  ASSERT_( leftList.size() == rightList.size() );
159  imgColor.joinImagesHorz( img1, img2 );
160 
161  unsigned int w = img1.getWidth();
162 
163  for( typename FEATURELIST::const_iterator iL = leftList.begin(), iR = rightList.begin(); iL != leftList.end(); ++iL, ++iR )
164  {
165  imgColor.drawCircle( round( (*iL)->x ), round( (*iL)->y ), 4, color );
166  imgColor.drawCircle( round( (*iR)->x + w ), round( (*iR)->y ), 4, color );
167  imgColor.line( round( (*iL)->x ), round( (*iL)->y ), round( (*iR)->x + w ), round( (*iR)->y ), color );
168  }
169  showImage(imgColor);
170 
171  MRPT_END
172  }
173 
174  /** Show a given color or grayscale image on the window.
175  * It adapts the size of the window to that of the image.
176  */
177  void showImage( const CImage &img );
178 
179  /** Plots a graph in MATLAB-like style.
180  */
181  void plot( const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y );
182 
183  /** Plots a graph in MATLAB-like style.
184  */
185  void plot( const mrpt::math::CVectorFloat &y );
186 
187  /** Resizes the window, stretching the image to fit into the display area.
188  */
189  void resize( unsigned int width, unsigned int height );
190 
191  /** Changes the position of the window on the screen.
192  */
193  void setPos( int x, int y );
194 
195  /** Enables or disables the visualization of cursor coordinates on the window caption (default = enabled).
196  */
197  inline void enableCursorCoordinatesVisualization(bool enable)
198  {
199  m_enableCursorCoordinates = enable;
200  }
201 
202  /** Changes the window title text.
203  */
204  void setWindowTitle( const std::string &str );
205 
206  }; // End of class def.
208 
209  } // End of namespace
210 
211 } // End of namespace
212 
213 #endif
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:22
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:97
void showImagesAndMatchedPoints(const CImage &img1, const CImage &img2, const MATCHEDLIST &mList, const TColor &color=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...
void enableCursorCoordinatesVisualization(bool enable)
Enables or disables the visualization of cursor coordinates on the window caption (default = enabled)...
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
dynamic_vector< float > CVectorFloat
Column vector, like Eigen::MatrixXf, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:51
size_t getWidth() const
Returns the width of the image in pixels.
void showImagesAndMatchedPoints(const CImage &img1, const CImage &img2, const FEATURELIST &leftList, const FEATURELIST &rightList, const TColor &color=TColor::red)
Show a pair of given color or grayscale images (put together) on the window and print a set of matche...
#define MRPT_END
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
#define CH_RGB
Definition: CImage.h:39
#define DEFINE_MRPT_OBJECT(class_name)
This declaration must be inserted in all CObject classes definition, within the class declaration...
Definition: CObject.h:167
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
#define DEFINE_MRPT_OBJECT_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition: CObject.h:172
A RGB color - 8bit.
Definition: TColor.h:25
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
void colorImage(CImage &ret) const
Returns a RGB version of the grayscale image, or itself if it is already a RGB image.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:51
#define DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition: CObject.h:171
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define ASSERT_(f)
void showTiledImageAndPoints(const CImage &img, const FEATURELIST &list, const TColor &color=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...
The base class for GUI window classes.



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014