31 #if MRPT_HAS_WXWIDGETS 53 Connect(wxEVT_PAINT, wxPaintEventHandler(CWindowDialog::wxMRPTImageControl::OnPaint));
54 Connect(wxEVT_MOTION, wxMouseEventHandler(CWindowDialog::wxMRPTImageControl::OnMouseMove));
55 Connect(wxID_ANY,wxEVT_LEFT_DOWN,wxMouseEventHandler(CWindowDialog::wxMRPTImageControl::OnMouseClick));
57 Connect(wxID_ANY,wxEVT_CHAR,(wxObjectEventFunction)&CWindowDialog::wxMRPTImageControl::OnChar);
58 Connect(wxEVT_CHAR,(wxObjectEventFunction)&CWindowDialog::wxMRPTImageControl::OnChar);
64 CWindowDialog::wxMRPTImageControl::~wxMRPTImageControl()
74 void CWindowDialog::wxMRPTImageControl::OnMouseMove(wxMouseEvent& ev)
77 m_last_mouse_point = ev.GetPosition();
80 void CWindowDialog::wxMRPTImageControl::OnMouseClick(wxMouseEvent& ev)
83 m_last_mouse_click= ev.GetPosition();
86 void CWindowDialog::wxMRPTImageControl::OnChar(wxKeyEvent & ev)
90 void CWindowDialog::wxMRPTImageControl::AssignImage(wxBitmap *
img)
102 void CWindowDialog::wxMRPTImageControl::OnPaint(wxPaintEvent &ev)
113 dc.DrawBitmap(*m_img,0,0);
116 void CWindowDialog::wxMRPTImageControl::GetBitmap(wxBitmap &bmp)
124 CWindowDialog::CWindowDialog(
129 wxSize initialSize ) :
139 wxDEFAULT_FRAME_STYLE,
141 SetClientSize(initialSize);
151 SetWindowStyle( GetWindowStyle() | wxCLIP_CHILDREN );
154 wxMenuBar *MenuBar1 =
new wxMenuBar();
156 wxMenu *Menu1 =
new wxMenu();
157 wxMenuItem *MenuItem3 =
new wxMenuItem(Menu1,
ID_MENUITEM3, _(
"Save to file..."), _(
""), wxITEM_NORMAL);
158 Menu1->Append(MenuItem3);
159 wxMenuItem *MenuItem1 =
new wxMenuItem(Menu1,
ID_MENUITEM1, _(
"Close"), _(
""), wxITEM_NORMAL);
160 Menu1->Append(MenuItem1);
161 MenuBar1->Append(Menu1, _(
"&File"));
163 wxMenu *Menu2 =
new wxMenu();
164 wxMenuItem *MenuItem2 =
new wxMenuItem(Menu2,
ID_MENUITEM2, _(
"About..."), _(
""), wxITEM_NORMAL);
165 Menu2->Append(MenuItem2);
166 MenuBar1->Append(Menu2, _(
"&Help"));
168 SetMenuBar(MenuBar1);
206 bool allow_close=
true;
212 if (!allow_close)
return;
235 const int code =
event.GetKeyCode();
296 ::wxMessageBox(_(
"Image viewer\n Class gui::CDisplayWindow\n MRPT C++ library"),_(
"About..."));
304 wxT(
"Save image as..."),
307 wxT(
"PNG image files (*.png)|*.png"),
308 #
if wxCHECK_VERSION(2, 8, 0)
309 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
311 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
314 if (wxID_OK == dialog.ShowModal())
320 bmp.SaveFile( dialog.GetPath(), wxBITMAP_TYPE_PNG );
333 unsigned int initWidth,
334 unsigned int initHeight )
336 return CDisplayWindowPtr(
new CDisplayWindow(windowCaption,initWidth,initHeight));
343 m_enableCursorCoordinates( true )
359 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 362 win->
m_image->SetCursor( *(cursorIsCross ? wxCROSS_CURSOR : wxSTANDARD_CURSOR) );
373 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 375 if (!win)
return false;
392 #if MRPT_HAS_WXWIDGETS 418 std::vector<float>
x(x_.size()),
y(y_.size());
419 for (
size_t i=0;i<
x.size();i++)
x[i]=x_[i];
420 for (
size_t i=0;i<
y.size();i++)
y[i]=y_[i];
427 #if MRPT_HAS_WXWIDGETS 432 img.colorImage( imgColor );
433 for(
size_t i = 0; i <
x.size(); i++)
467 imgColor.
resize( 640, 480, 3, 0 );
470 imgColor.
line( 40, 40, 560, 40, TColor::black, 3 );
471 imgColor.
line( 40, 40, 40, 440, TColor::black, 3 );
472 imgColor.
line( 560, 40, 555, 45, TColor::black, 3 );
473 imgColor.
line( 560, 40, 555, 35, TColor::black, 3 );
474 imgColor.
line( 40, 440, 35, 435, TColor::black, 3 );
475 imgColor.
line( 40, 440, 45, 435, TColor::black, 3 );
482 itymx = std::max_element(
y.begin(),
y.end() );
483 itymn = std::min_element(
y.begin(),
y.end() );
484 float px = (
x[
x.size()-1] -
x[0])/520;
485 float py = (*itymx - *itymn)/400;
487 float tpxA=0, tpyA=0;
489 for( itx =
x.begin(), ity =
y.begin(); itx !=
x.end(); ++itx, ++ity )
491 float tpx = (*itx-
x[0])/px + ox;
492 float tpy = (*ity-*itymn)/py + oy;
494 if( itx !=
x.begin() )
495 imgColor.
line( tpxA, tpyA, tpx, tpy,
TColor(0,0,255), 3 );
520 imgColor.
resize( 640, 480, 3, 0 );
523 imgColor.
line( 40, 40, 560, 40, TColor::black, 3 );
524 imgColor.
line( 40, 40, 40, 440, TColor::black, 3 );
525 imgColor.
line( 560, 40, 555, 45, TColor::black, 3 );
526 imgColor.
line( 560, 40, 555, 35, TColor::black, 3 );
527 imgColor.
line( 40, 440, 35, 435, TColor::black, 3 );
528 imgColor.
line( 40, 440, 45, 435, TColor::black, 3 );
530 imgColor.
textOut( 550, 25,
"x", TColor::black );
531 imgColor.
textOut( 25, 430,
"y", TColor::black );
535 itymx = std::max_element(
y.begin(),
y.end() );
536 itymn = std::min_element(
y.begin(),
y.end() );
537 float px =
y.size()/520.0f;
538 float py = (*itymx - *itymn)/400.0f;
539 float tpxA=0, tpyA=0;
543 for( k = 0, ity =
y.begin(); ity !=
y.end(); ++k, ++ity )
545 float tpx = k/px + ox;
546 float tpy = (*ity-*itymn)/py + oy;
566 #if MRPT_HAS_WXWIDGETS 569 cerr <<
"[CDisplayWindow::resize] Window closed!: " <<
m_caption << endl;
590 #if MRPT_HAS_WXWIDGETS 593 cerr <<
"[CDisplayWindow::setPos] Window closed!: " <<
m_caption << endl;
614 #if MRPT_HAS_WXWIDGETS 617 cerr <<
"[CDisplayWindow::setWindowTitle] Window closed!: " <<
m_caption << endl;
virtual void textOut(int x0, int y0, const std::string &str, const mrpt::utils::TColor color)
Renders 2D text using bitmap fonts.
An event sent by a window upon resize.
static void pushPendingWxRequest(TRequestToWxMainThread *data)
Thread-safe method to insert a new pending request (The memory must be dinamically allocated with "ne...
void * voidPtr
Parameters, depending on OPCODE.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates. ...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void resize(unsigned int width, unsigned int height) MRPT_OVERRIDE
Resizes the window, stretching the image to fit into the display area.
void OnMenuSave(wxCommandEvent &event)
void OnResize(wxSizeEvent &event)
The data structure for each inter-thread request:
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
#define IMPLEMENTS_MRPT_OBJECT(class_name, base, NameSpace)
This must be inserted in all CObject classes implementation files.
std::string m_caption
The caption of the window.
A class for storing images as grayscale or RGB bitmaps.
static int notifyWindowCreation()
Atomically increments the number of windows created with the main frame as parent.
void resize(unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
A pair (x,y) of pixel coordinates (integer resolution).
virtual ~CDisplayWindow()
Destructor.
void GetBitmap(wxBitmap &bmp)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
static wxBitmap getMRPTDefaultIcon()
const Scalar * const_iterator
bool hasSubscribers() const
Can be called by a derived class before preparing an event for publishing with publishEvent to determ...
wxPoint m_last_mouse_point
int OPCODE
Valid codes are: For CDisplayWindow:
An event sent by a window upon when it's about to be closed, either manually by the user or programat...
An event sent by a window when the mouse is moved over it.
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y)
Plots a graph in MATLAB-like style.
void notifyChildWindowDestruction()
Called by wx main thread to set m_hwnd to NULL.
wxMRPTImageControl * m_image
void OnKeyDown(wxKeyEvent &event)
void publishEvent(const mrptEvent &e) const
Called when you want this object to emit an event to all the observers currently subscribed to this o...
void OnMouseDown(wxMouseEvent &event)
void OnMenuClose(wxCommandEvent &event)
This base provides a set of functions for maths stuff.
A custom control to display the bitmap and avoid flicker.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
void cross(int x0, int y0, const mrpt::utils::TColor color, char type, unsigned int size=5, unsigned int width=1)
Draw a cross.
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
bool isOpen()
Returns false if the user has already closed the window.
The main frame of the wxWidgets application.
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.
The wx dialog for gui::CDisplayWindow.
void release(unsigned int increaseCount=1)
Increments the count of the semaphore by a given amount.
wxImage GUI_IMPEXP * MRPTImage2wxImage(const mrpt::utils::CImage &img)
Create a wxImage from a MRPT image.
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.
An event sent by a window upon a char pressed by the user.
void OnMouseMove(wxMouseEvent &event)
GLsizei const GLchar ** string
mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent &ev)
Extracts the key modifiers from a wxKeyEvent.
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::utils::TColor color)
Draws a filled rectangle.
virtual void setCursorCross(bool cursorIsCross) MRPT_OVERRIDE
Set cursor style to default (cursorIsCross=false) or to a cross (cursorIsCross=true) ...
void OnChar(wxKeyEvent &event)
volatile mrptKeyModifier m_keyPushedModifier
void showImage(const mrpt::utils::CImage &img)
Show a given color or grayscale image on the window.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static CDisplayWindowPtr Create()
void OnClose(wxCloseEvent &event)
void OnMenuAbout(wxCommandEvent &event)
volatile bool m_keyPushed
synch::CSemaphore m_semWindowDestroyed
This semaphore will be signaled when the wx window is destroyed.
static const long ID_IMAGE_BITMAP
void setWindowTitle(const std::string &str) MRPT_OVERRIDE
Changes the window title text.
void setPos(int x, int y) MRPT_OVERRIDE
Changes the position of the window on the screen.
int round(const T value)
Returns the closer integer (int) to x.
void destroyWxWindow()
Must be called by child classes in their destructors. The code cannot be put into this class' destruc...
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...
CDisplayWindow(const std::string &windowCaption=std::string(), unsigned int initWidth=400, unsigned int initHeight=400)
Constructor.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
Classes for creating GUI windows for 2D and 3D visualization.
void createWxWindow(unsigned int initialWidth, unsigned int initialHeight)
Must be called by child classes just within the constructor.
volatile int m_keyPushedCode
virtual bool getLastMousePosition(int &x, int &y) const MRPT_OVERRIDE
Gets the last x,y pixel coordinates of the mouse.
mrpt::gui::CDisplayWindow * source2D
Only one of source* can be non-NULL, indicating the class that generated the request.
GLenum GLsizei GLsizei height
std::string str
Parameters, depending on OPCODE.
mrpt::utils::void_ptr_noncopy m_hwnd
The window handle.
The base class for GUI window classes.
static int notifyWindowDestruction()
Atomically decrements the number of windows created with the main frame as parent.