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



Page generated by Doxygen 1.9.8 for MRPT 1.4.0 SVN: at Thu Dec 14 16:54:58 UTC 2023