Main MRPT website > C++ reference
MRPT logo

CDisplayWindow.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef  CDisplayWindow_H
00029 #define  CDisplayWindow_H
00030 
00031 #include <mrpt/gui/CBaseGUIWindow.h>
00032 #include <mrpt/utils/CImage.h>
00033 
00034 namespace mrpt
00035 {
00036         /** Classes for creating GUI windows for 2D and 3D visualization. */
00037         namespace gui
00038         {
00039                 using namespace mrpt::utils;
00040 
00041                 DEFINE_MRPT_OBJECT_PRE_CUSTOM_BASE_LINKAGE(CDisplayWindow, mrpt::gui::CBaseGUIWindow, GUI_IMPEXP)
00042 
00043                 /** This class creates a window as a graphical user interface (GUI) for displaying images to the user.
00044                  *
00045                  *  For a list of supported events with the observer/observable pattern, see the discussion in mrpt::gui::CBaseGUIWindow.
00046                  *
00047                  */
00048                 class GUI_IMPEXP CDisplayWindow : public mrpt::gui::CBaseGUIWindow
00049                 {
00050                         // This must be added to any CSerializable derived class:
00051                         DEFINE_MRPT_OBJECT( CDisplayWindow )
00052 
00053                 protected:
00054 
00055                         /** Enables or disables the visualization of cursor coordinates on the window caption.
00056                           */
00057                         bool                    m_enableCursorCoordinates;
00058 
00059                 public:
00060                         /** Constructor
00061                          */
00062                         CDisplayWindow( const std::string &windowCaption = std::string(), unsigned int initWidth = 400, unsigned int initHeight = 400 );
00063 
00064                         /** Class factory returning a smart pointer */
00065                         static CDisplayWindowPtr Create(
00066                                 const std::string       &windowCaption = std::string(),
00067                                 unsigned int initWidth = 400,
00068                                 unsigned int initHeight = 400  )
00069                         {
00070                                 return CDisplayWindowPtr(new CDisplayWindow(windowCaption,initWidth,initHeight));
00071                         }
00072 
00073                         /** Destructor
00074                          */
00075                         virtual ~CDisplayWindow();
00076 
00077                         /** Gets the last x,y pixel coordinates of the mouse. \return False if the window is closed. */
00078                         virtual bool getLastMousePosition(int &x, int &y) const;
00079 
00080                         /** Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) */
00081                         virtual void setCursorCross(bool cursorIsCross);
00082 
00083                         /** Show a given color or grayscale image on the window and print a set of points on it.
00084                          *  It adapts the size of the window to that of the image.
00085                          */
00086                         void  showImageAndPoints( const CImage &img, const vector_float &x, const vector_float &y, const TColor &color = TColor::red, const bool &showNumbers = false );
00087 
00088                         /** Show a given color or grayscale image on the window and print a set of points on it.
00089                          *  It adapts the size of the window to that of the image.
00090                          *  The class of FEATURELIST can be: mrpt::vision::CFeatureList or any STL container of entities having "x","y" and "ID" fields.
00091                          */
00092                         template <class FEATURELIST>
00093                         void  showImageAndPoints( const CImage &img, const FEATURELIST &list, const TColor &color = TColor::red, const bool &showIDs = false )
00094                         {
00095                                 MRPT_START
00096                                 CImage imgColor(1,1,CH_RGB);
00097                                 img.colorImage( imgColor );     // Create a colorimage
00098                                 imgColor.drawFeatures(list,color,showIDs);
00099                                 showImage(imgColor);
00100                                 MRPT_END
00101                         }
00102 
00103                         /** 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.
00104                          *  It adapts the size of the window to that of the image.
00105                          *  The class of FEATURELIST can be: mrpt::vision::CFeatureList
00106                          */
00107                         template <class FEATURELIST>
00108                         void  showTiledImageAndPoints( const CImage &img, const FEATURELIST &list, const TColor &color = TColor::red )
00109                         {
00110                                 MRPT_START
00111 
00112                                 CImage imgColor(1,1,3);
00113                                 img.colorImage( imgColor ); // Create a colorimage
00114 
00115                                 // Print the 4 tile lines
00116                                 unsigned int w = imgColor.getWidth();
00117                                 unsigned int h = imgColor.getHeight();
00118                                 imgColor.line( 0, h/2, w-1, h/2, TColor::green );
00119                                 imgColor.line( w/4, 0, w/4, h, TColor::green );
00120                                 imgColor.line( w/2, 0, w/2, h, TColor::green );
00121                                 imgColor.line( 3*w/4, 0, 3*w/4, h, TColor::green );
00122 
00123                                 showImageAndPoints( imgColor, list, color );
00124 
00125                                 MRPT_END
00126                         }
00127 
00128                         /** Show a pair of given color or grayscale images (put together) on the window and print a set of matches on them.
00129                          *  It adapts the size of the window to that of the image.
00130                          *  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)
00131                          */
00132                         template <class MATCHEDLIST>
00133                         void  showImagesAndMatchedPoints( const CImage &img1, const     CImage &img2, const MATCHEDLIST &mList, const TColor &color = TColor::red, bool showNumbers = false )
00134                         {
00135                                 MRPT_START
00136 
00137                                 CImage imgColor;
00138 
00139                                 //img1.colorImage( imgColor ); // Create a colorimage
00140                                 imgColor.joinImagesHorz( img1, img2 );
00141 
00142                                 unsigned int w = img1.getWidth();
00143                 unsigned int nf = 0;
00144 
00145                                 for( typename MATCHEDLIST::const_iterator i = mList.begin(); i != mList.end(); ++i, ++nf )
00146                                 {
00147                                         imgColor.drawCircle( round( i->first->x ), round( i->first->y ), 4, color );
00148                                         imgColor.drawCircle( round( i->second->x + w ), round( i->second->y ), 4, color );
00149                                         //imgColor.line( round( i->first->x ), round( i->first->y ), round( i->second->x + w ), round( i->second->y ), color );
00150                                         if( showNumbers )
00151                                         {
00152                                             char buf[15];
00153                                             mrpt::system::os::sprintf( buf, 15, "%d[%u]", nf, (unsigned int)i->first->ID );
00154                         imgColor.textOut( round( i->first->x ) - 10, round( i->first->y ), buf, color );
00155                         mrpt::system::os::sprintf( buf, 15, "%d[%u]", nf, (unsigned int)i->second->ID );
00156                         imgColor.textOut( round( i->second->x + w ) + 10, round( i->second->y ), buf, color );
00157                     }
00158                                 }
00159                                 showImage(imgColor);
00160 
00161                                 MRPT_END
00162                         }
00163 
00164                         /** Show a pair of given color or grayscale images (put together) on the window and print a set of matches on them.
00165                          *  It adapts the size of the window to that of the image.
00166                          *  FEATURELIST can be of the class: mrpt::vision::CFeatureList
00167                          */
00168                         template <class FEATURELIST>
00169                         void  showImagesAndMatchedPoints( const CImage &img1, const     CImage &img2, const FEATURELIST &leftList, const FEATURELIST &rightList, const TColor &color = TColor::red )
00170                         {
00171                                 MRPT_START
00172 
00173                                 CImage imgColor;
00174 
00175                                 //img1.colorImage( imgColor ); // Create a colorimage
00176                                 ASSERT_( leftList.size() == rightList.size() );
00177                                 imgColor.joinImagesHorz( img1, img2 );
00178 
00179                                 unsigned int w = img1.getWidth();
00180 
00181                                 for( typename FEATURELIST::const_iterator iL = leftList.begin(), iR = rightList.begin(); iL != leftList.end(); ++iL, ++iR )
00182                                 {
00183                                         imgColor.drawCircle( round( (*iL)->x ), round( (*iL)->y ), 4, color );
00184                                         imgColor.drawCircle( round( (*iR)->x + w ), round( (*iR)->y ), 4, color );
00185                                         imgColor.line( round( (*iL)->x ), round( (*iL)->y ), round( (*iR)->x + w ), round( (*iR)->y ), color );
00186                                 }
00187                                 showImage(imgColor);
00188 
00189                                 MRPT_END
00190                         }
00191 
00192                         /** Show a given color or grayscale image on the window.
00193                          *  It adapts the size of the window to that of the image.
00194                          */
00195                         void  showImage( const CImage   &img );
00196 
00197                         /** Plots a graph in MATLAB-like style.
00198                          */
00199                         void  plot( const vector_float &x, const vector_float &y );
00200 
00201                         /** Plots a graph in MATLAB-like style.
00202                          */
00203                         void  plot( const vector_float &y );
00204 
00205                         /** Resizes the window, stretching the image to fit into the display area.
00206                          */
00207                         void  resize( unsigned int width, unsigned int height );
00208 
00209                         /** Changes the position of the window on the screen.
00210                          */
00211                         void  setPos( int x, int y );
00212 
00213                         /** Enables or disables the visualization of cursor coordinates on the window caption (default = enabled).
00214                           */
00215                         inline void  enableCursorCoordinatesVisualization(bool enable)
00216                         {
00217                                 m_enableCursorCoordinates = enable;
00218                         }
00219 
00220                         /** Changes the window title text.
00221                           */
00222                         void  setWindowTitle( const std::string &str );
00223 
00224                 }; // End of class def.
00225 
00226         } // End of namespace
00227 
00228 } // End of namespace
00229 
00230 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011