Main MRPT website > C++ reference
MRPT logo
CDisplayWindow.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CDisplayWindow_H
29 #define CDisplayWindow_H
30 
32 #include <mrpt/utils/CImage.h>
33 
34 namespace mrpt
35 {
36  /** Classes for creating GUI windows for 2D and 3D visualization. \ingroup mrpt_gui_grp */
37  namespace gui
38  {
39  using namespace mrpt::utils;
40 
42 
43  /** This class creates a window as a graphical user interface (GUI) for displaying images to the user.
44  *
45  * For a list of supported events with the observer/observable pattern, see the discussion in mrpt::gui::CBaseGUIWindow.
46  * \ingroup mrpt_gui_grp
47  */
48  class GUI_IMPEXP CDisplayWindow : public mrpt::gui::CBaseGUIWindow
49  {
50  // This must be added to any CSerializable derived class:
52 
53  protected:
54 
55  /** Enables or disables the visualization of cursor coordinates on the window caption.
56  */
57  bool m_enableCursorCoordinates;
58 
59  public:
60  /** Constructor
61  */
62  CDisplayWindow( const std::string &windowCaption = std::string(), unsigned int initWidth = 400, unsigned int initHeight = 400 );
63 
64  /** Class factory returning a smart pointer */
65  static CDisplayWindowPtr Create(
66  const std::string &windowCaption = std::string(),
67  unsigned int initWidth = 400,
68  unsigned int initHeight = 400 )
69  {
70  return CDisplayWindowPtr(new CDisplayWindow(windowCaption,initWidth,initHeight));
71  }
72 
73  /** Destructor
74  */
75  virtual ~CDisplayWindow();
76 
77  /** Gets the last x,y pixel coordinates of the mouse. \return False if the window is closed. */
78  virtual bool getLastMousePosition(int &x, int &y) const;
79 
80  /** Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) */
81  virtual void setCursorCross(bool cursorIsCross);
82 
83  /** Show a given color or grayscale image on the window and print a set of points on it.
84  * It adapts the size of the window to that of the image.
85  */
86  void showImageAndPoints( const CImage &img, const vector_float &x, const vector_float &y, const TColor &color = TColor::red, const bool &showNumbers = false );
87 
88  /** Show a given color or grayscale image on the window and print a set of points on it.
89  * It adapts the size of the window to that of the image.
90  * The class of FEATURELIST can be: mrpt::vision::CFeatureList or any STL container of entities having "x","y" and "ID" fields.
91  */
92  template <class FEATURELIST>
93  void showImageAndPoints( const CImage &img, const FEATURELIST &list, const TColor &color = TColor::red, const bool &showIDs = false )
94  {
96  CImage imgColor(1,1,CH_RGB);
97  img.colorImage( imgColor ); // Create a colorimage
98  imgColor.drawFeatures(list,color,showIDs);
99  showImage(imgColor);
100  MRPT_END
101  }
102 
103  /** 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.
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>
108  void showTiledImageAndPoints( const CImage &img, const FEATURELIST &list, const TColor &color = TColor::red )
109  {
110  MRPT_START
111 
112  CImage imgColor(1,1,3);
113  img.colorImage( imgColor ); // Create a 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 window and print a set of matches on them.
129  * It adapts the size of the window to that of the image.
130  * 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)
131  */
132  template <class MATCHEDLIST>
133  void showImagesAndMatchedPoints( const CImage &img1, const CImage &img2, const MATCHEDLIST &mList, const TColor &color = TColor::red, bool showNumbers = false )
134  {
135  MRPT_START
136 
137  CImage imgColor;
138 
139  //img1.colorImage( imgColor ); // Create a colorimage
140  imgColor.joinImagesHorz( img1, img2 );
141 
142  unsigned int w = img1.getWidth();
143  unsigned int nf = 0;
144 
145  for( typename MATCHEDLIST::const_iterator i = mList.begin(); i != mList.end(); ++i, ++nf )
146  {
147  imgColor.drawCircle( round( i->first->x ), round( i->first->y ), 4, color );
148  imgColor.drawCircle( round( i->second->x + w ), round( i->second->y ), 4, color );
149  //imgColor.line( round( i->first->x ), round( i->first->y ), round( i->second->x + w ), round( i->second->y ), color );
150  if( showNumbers )
151  {
152  char buf[15];
153  mrpt::system::os::sprintf( buf, 15, "%d[%u]", nf, (unsigned int)i->first->ID );
154  imgColor.textOut( round( i->first->x ) - 10, round( i->first->y ), buf, color );
155  mrpt::system::os::sprintf( buf, 15, "%d[%u]", nf, (unsigned int)i->second->ID );
156  imgColor.textOut( round( i->second->x + w ) + 10, round( i->second->y ), buf, color );
157  }
158  }
159  showImage(imgColor);
160 
161  MRPT_END
162  }
163 
164  /** Show a pair of given color or grayscale images (put together) on the window and print a set of matches on them.
165  * It adapts the size of the window to that of the image.
166  * FEATURELIST can be of the class: mrpt::vision::CFeatureList
167  */
168  template <class FEATURELIST>
169  void showImagesAndMatchedPoints( const CImage &img1, const CImage &img2, const FEATURELIST &leftList, const FEATURELIST &rightList, const TColor &color = TColor::red )
170  {
171  MRPT_START
172 
173  CImage imgColor;
174 
175  //img1.colorImage( imgColor ); // Create a colorimage
176  ASSERT_( leftList.size() == rightList.size() );
177  imgColor.joinImagesHorz( img1, img2 );
178 
179  unsigned int w = img1.getWidth();
180 
181  for( typename FEATURELIST::const_iterator iL = leftList.begin(), iR = rightList.begin(); iL != leftList.end(); ++iL, ++iR )
182  {
183  imgColor.drawCircle( round( (*iL)->x ), round( (*iL)->y ), 4, color );
184  imgColor.drawCircle( round( (*iR)->x + w ), round( (*iR)->y ), 4, color );
185  imgColor.line( round( (*iL)->x ), round( (*iL)->y ), round( (*iR)->x + w ), round( (*iR)->y ), color );
186  }
187  showImage(imgColor);
188 
189  MRPT_END
190  }
191 
192  /** Show a given color or grayscale image on the window.
193  * It adapts the size of the window to that of the image.
194  */
195  void showImage( const CImage &img );
196 
197  /** Plots a graph in MATLAB-like style.
198  */
199  void plot( const vector_float &x, const vector_float &y );
200 
201  /** Plots a graph in MATLAB-like style.
202  */
203  void plot( const vector_float &y );
204 
205  /** Resizes the window, stretching the image to fit into the display area.
206  */
207  void resize( unsigned int width, unsigned int height );
208 
209  /** Changes the position of the window on the screen.
210  */
211  void setPos( int x, int y );
212 
213  /** Enables or disables the visualization of cursor coordinates on the window caption (default = enabled).
214  */
215  inline void enableCursorCoordinatesVisualization(bool enable)
216  {
217  m_enableCursorCoordinates = enable;
218  }
219 
220  /** Changes the window title text.
221  */
222  void setWindowTitle( const std::string &str );
223 
224  }; // End of class def.
225 
226  } // End of namespace
227 
228 } // End of namespace
229 
230 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013