Main MRPT website > C++ reference
MRPT logo

CMyGLCanvasBase.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 
00029 #ifndef CMyGLCanvas_H
00030 #define CMyGLCanvas_H
00031 
00032 #include <mrpt/opengl.h>
00033 #include <mrpt/opengl/opengl_fonts.h>
00034 
00035 #include <mrpt/gui/link_pragmas.h>
00036 
00037 #if MRPT_HAS_WXWIDGETS
00038 
00039 #include <wx/string.h>
00040 #include <wx/intl.h>
00041 #include <wx/bitmap.h>
00042 #include <wx/icon.h>
00043 #include <wx/image.h>
00044 #include <wx/artprov.h>
00045 
00046 #include <wx/msgdlg.h>
00047 #include <wx/filedlg.h>
00048 #include <wx/progdlg.h>
00049 #include <wx/imaglist.h>
00050 #include <wx/busyinfo.h>
00051 #include <wx/log.h>
00052 #include <wx/textdlg.h>
00053 #include <wx/dirdlg.h>
00054 #include <wx/colordlg.h>
00055 #include <wx/dcmemory.h>
00056 
00057 #if wxUSE_GLCANVAS && MRPT_HAS_OPENGL_GLUT
00058 
00059 #include <wx/glcanvas.h>
00060 #include <wx/dcclient.h>
00061 
00062 namespace mrpt
00063 {
00064         namespace gui
00065         {
00066                 /** This class implements a OpenGL canvas, and it's used in gui::CDisplayWindow3D and a number of standalone applications in the MRPT project.
00067                   *  There is a filter to control the user capability of moving the camera with the mouse. See OnUserManuallyMovesCamera
00068                   */
00069                 class GUI_IMPEXP CMyGLCanvasBase: public wxGLCanvas
00070                 {
00071                 public:
00072                         CMyGLCanvasBase( wxWindow *parent, wxWindowID id = wxID_ANY,
00073                                                  const wxPoint& pos = wxDefaultPosition,
00074                                                  const wxSize& size = wxDefaultSize,
00075                                                  long style = 0, const wxString& name = _T("CMyGLCanvasBase") );
00076 
00077                         virtual ~CMyGLCanvasBase();
00078 
00079                         void OnPaint(wxPaintEvent& event);
00080                         void OnSize(wxSizeEvent& event);
00081                         void OnEraseBackground(wxEraseEvent& event);
00082                         void OnEnterWindow(wxMouseEvent& event);
00083 
00084                         void OnChar(wxKeyEvent& event);
00085 
00086                         void OnLeftDown(wxMouseEvent& event);
00087                         void OnMouseMove(wxMouseEvent& event);
00088                         void OnRightDown(wxMouseEvent& event);
00089                         void OnRightUp(wxMouseEvent& event);
00090                         void OnLeftUp(wxMouseEvent& event);
00091                         void OnMouseWheel(wxMouseEvent& event);
00092 
00093                         void Render();
00094                         void InitGL();
00095 
00096                         // Visualization params:
00097                         float   cameraPointingX,cameraPointingY,cameraPointingZ;
00098                         float   cameraZoomDistance;
00099                         float   cameraElevationDeg,cameraAzimuthDeg;
00100                         bool    cameraIsProjective;
00101 
00102                         /** If set to true (default=false), the cameraPointingX,... parameters are ignored and the camera stored in the 3D scene is used instead.
00103                           */
00104                         bool    useCameraFromScene;
00105 
00106                         /** Set the camera from a CPose3D, which defines the +X,+Y axis as image place RIGHT and UP dirctions, and -Z as towards the pointing direction.
00107                           */
00108                         void setCameraPose(const mrpt::poses::CPose3D &camPose);
00109 
00110 
00111                         float   clearColorR,clearColorG,clearColorB;
00112 
00113                         static float  SENSIBILITY_DEG_PER_PIXEL;                // Default = 0.1
00114 
00115                         /**  Methods that can be implemented in custom derived classes  */
00116                         virtual void OnCharCustom( wxKeyEvent& event ) { }
00117 
00118                         virtual void OnPreRender() { }
00119                         virtual void OnPostRender()  { }
00120                         virtual void OnPostRenderSwapBuffers(double At, wxPaintDC &dc) { }
00121                         virtual void OnRenderError( const wxString &str ) { }
00122 
00123                         /** Overload this method to limit the capabilities of the user to move the camera using the mouse.
00124                           *  For all these variables:
00125                           *  - cameraPointingX
00126                           *  - cameraPointingY
00127                           *  - cameraPointingZ
00128                           *  - cameraZoomDistance
00129                           *  - cameraElevationDeg
00130                           *  - cameraAzimuthDeg
00131                           *
00132                           *  A "new_NAME" variable will be passed with the temptative new value after the user action.
00133                           *   The default behavior should be to copy all the new variables to the variables listed above
00134                           *   but in the middle any find of user-defined filter can be implemented.
00135                           */
00136                         virtual void OnUserManuallyMovesCamera(
00137                                 float   new_cameraPointingX,
00138                                 float   new_cameraPointingY,
00139                                 float   new_cameraPointingZ,
00140                                 float   new_cameraZoomDistance,
00141                                 float   new_cameraElevationDeg,
00142                                 float   new_cameraAzimuthDeg )
00143                         {
00144                                 cameraPointingX         = new_cameraPointingX;
00145                                 cameraPointingY         = new_cameraPointingY;
00146                                 cameraPointingZ         = new_cameraPointingZ;
00147                                 cameraZoomDistance      = new_cameraZoomDistance;
00148                                 cameraElevationDeg      = new_cameraElevationDeg ;
00149                                 cameraAzimuthDeg        = new_cameraAzimuthDeg;
00150                         }
00151 
00152                         inline void getLastMousePosition(int &x,int& y) const {
00153                                 x =m_mouseLastX;
00154                                 y =m_mouseLastY;
00155                         }
00156 
00157                         /**  At constructor an empty scene is created. The object is freed at GL canvas destructor.
00158                           */
00159                         opengl::COpenGLScenePtr         m_openGLScene;
00160 
00161                 protected:
00162                         wxGLContext *m_gl_context;
00163                         bool   m_init;
00164 
00165                         int     m_mouseLastX,m_mouseLastY;
00166 
00167                         int     mouseClickX,mouseClickY;
00168                         bool    mouseClicked;
00169 
00170                         long           m_Key;
00171                         unsigned long  m_StartTime;
00172                         unsigned long  m_LastTime;
00173                         unsigned long  m_LastRedraw;
00174 
00175                         /** Draws a text string on the screen.
00176                           *   - Coordinates (x,y) are 2D pixels, starting at bottom-left of the viewport. Negative numbers will wrap to the opposite side of the viewport (e.g. x=-10 means 10px fromt the right).
00177                           *   - The text color is defined by (color_r,color_g,color_b), each float numbers in the range [0,1].
00178                           *  \sa textBitmapWidth
00179                           */
00180                         void renderTextBitmap(
00181                                 int screen_x,
00182                                 int screen_y,
00183                                 const std::string &str,
00184                                 float  color_r=1,
00185                                 float  color_g=1,
00186                                 float  color_b=1,
00187                                 TOpenGLFont    font = MRPT_GLUT_BITMAP_TIMES_ROMAN_24
00188                                 );
00189 
00190                         /** Return the exact width in pixels for a given string, as will be rendered by renderTextBitmap().
00191                           * \sa renderTextBitmap
00192                           */
00193                         int textBitmapWidth(
00194                                 const std::string &str,
00195                                 TOpenGLFont    font = MRPT_GLUT_BITMAP_TIMES_ROMAN_24 );
00196 
00197                         // Used to create the gl context at startup.
00198                         void OnWindowCreation(wxWindowCreateEvent &ev);
00199 
00200                         DECLARE_EVENT_TABLE()
00201 
00202                 };  // end of class
00203 
00204         }       // end namespace
00205 }       // end namespace
00206 
00207 #endif          // wxUSE_GLCANVAS
00208 #endif          // MRPT_HAS_WXWIDGETS
00209 #endif          // CMyGLCanvas_H
00210 



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