Main MRPT website > C++ reference
MRPT logo
CMyGLCanvasBase.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 
29 #ifndef CMyGLCanvas_H
30 #define CMyGLCanvas_H
31 
32 #include <mrpt/opengl.h>
34 
35 #include <mrpt/gui/link_pragmas.h>
36 
37 #if MRPT_HAS_WXWIDGETS
38 
39 #include <wx/string.h>
40 #include <wx/intl.h>
41 #include <wx/bitmap.h>
42 #include <wx/icon.h>
43 #include <wx/image.h>
44 #include <wx/artprov.h>
45 
46 #include <wx/msgdlg.h>
47 #include <wx/filedlg.h>
48 #include <wx/progdlg.h>
49 #include <wx/imaglist.h>
50 #include <wx/busyinfo.h>
51 #include <wx/log.h>
52 #include <wx/textdlg.h>
53 #include <wx/dirdlg.h>
54 #include <wx/colordlg.h>
55 #include <wx/dcmemory.h>
56 
57 #if wxUSE_GLCANVAS && MRPT_HAS_OPENGL_GLUT
58 
59 #include <wx/glcanvas.h>
60 #include <wx/dcclient.h>
61 
62 namespace mrpt
63 {
64  namespace gui
65  {
66  /** This class implements a OpenGL canvas, and it's used in gui::CDisplayWindow3D and a number of standalone applications in the MRPT project.
67  * There is a filter to control the user capability of moving the camera with the mouse. See OnUserManuallyMovesCamera
68  * \ingroup mrpt_gui_grp
69  */
70  class GUI_IMPEXP CMyGLCanvasBase: public wxGLCanvas
71  {
72  public:
73  CMyGLCanvasBase( wxWindow *parent, wxWindowID id = wxID_ANY,
74  const wxPoint& pos = wxDefaultPosition,
75  const wxSize& size = wxDefaultSize,
76  long style = 0, const wxString& name = _T("CMyGLCanvasBase") );
77 
78  virtual ~CMyGLCanvasBase();
79 
80  void OnPaint(wxPaintEvent& event);
81  void OnSize(wxSizeEvent& event);
82  void OnEraseBackground(wxEraseEvent& event);
83  void OnEnterWindow(wxMouseEvent& event);
84 
85  void OnChar(wxKeyEvent& event);
86 
87  void OnLeftDown(wxMouseEvent& event);
88  void OnMouseMove(wxMouseEvent& event);
89  void OnRightDown(wxMouseEvent& event);
90  void OnRightUp(wxMouseEvent& event);
91  void OnLeftUp(wxMouseEvent& event);
92  void OnMouseWheel(wxMouseEvent& event);
93 
94  void Render();
95  void InitGL();
96 
97  // Visualization params:
98  float cameraPointingX,cameraPointingY,cameraPointingZ;
99  float cameraZoomDistance;
100  float cameraElevationDeg,cameraAzimuthDeg;
101  bool cameraIsProjective;
102 
103  /** If set to true (default=false), the cameraPointingX,... parameters are ignored and the camera stored in the 3D scene is used instead.
104  */
105  bool useCameraFromScene;
106 
107  /** 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.
108  */
109  void setCameraPose(const mrpt::poses::CPose3D &camPose);
110 
111 
112  float clearColorR,clearColorG,clearColorB;
113 
114  static float SENSIBILITY_DEG_PER_PIXEL; // Default = 0.1
115 
116  /** Methods that can be implemented in custom derived classes */
117  virtual void OnCharCustom( wxKeyEvent& event ) { }
118 
119  virtual void OnPreRender() { }
120  virtual void OnPostRender() { }
121  virtual void OnPostRenderSwapBuffers(double At, wxPaintDC &dc) { }
122  virtual void OnRenderError( const wxString &str ) { }
123 
124  /** Overload this method to limit the capabilities of the user to move the camera using the mouse.
125  * For all these variables:
126  * - cameraPointingX
127  * - cameraPointingY
128  * - cameraPointingZ
129  * - cameraZoomDistance
130  * - cameraElevationDeg
131  * - cameraAzimuthDeg
132  *
133  * A "new_NAME" variable will be passed with the temptative new value after the user action.
134  * The default behavior should be to copy all the new variables to the variables listed above
135  * but in the middle any find of user-defined filter can be implemented.
136  */
137  virtual void OnUserManuallyMovesCamera(
138  float new_cameraPointingX,
139  float new_cameraPointingY,
140  float new_cameraPointingZ,
141  float new_cameraZoomDistance,
142  float new_cameraElevationDeg,
143  float new_cameraAzimuthDeg )
144  {
145  cameraPointingX = new_cameraPointingX;
146  cameraPointingY = new_cameraPointingY;
147  cameraPointingZ = new_cameraPointingZ;
148  cameraZoomDistance = new_cameraZoomDistance;
149  cameraElevationDeg = new_cameraElevationDeg ;
150  cameraAzimuthDeg = new_cameraAzimuthDeg;
151  }
152 
153  inline void getLastMousePosition(int &x,int& y) const {
154  x =m_mouseLastX;
155  y =m_mouseLastY;
156  }
157 
158  /** At constructor an empty scene is created. The object is freed at GL canvas destructor.
159  */
160  opengl::COpenGLScenePtr m_openGLScene;
161 
162  protected:
163  wxGLContext *m_gl_context;
164  bool m_init;
165 
166  int m_mouseLastX,m_mouseLastY;
167 
168  int mouseClickX,mouseClickY;
169  bool mouseClicked;
170 
171  long m_Key;
172  unsigned long m_StartTime;
173  unsigned long m_LastTime;
174  unsigned long m_LastRedraw;
175 
176  /** DEPRECATED: Use CRenderizable static method instead */
177  static void renderTextBitmap(
178  int screen_x,
179  int screen_y,
180  const std::string &str,
181  float color_r=1,
182  float color_g=1,
183  float color_b=1,
185  )
186  {
187  mrpt::opengl::CRenderizable::renderTextBitmap(screen_x,screen_y,str,color_r,color_g,color_b, font);
188  }
189 
190  /** DEPRECATED: Use CRenderizable static method instead */
191  static int textBitmapWidth(
192  const std::string &str,
194  {
196  }
197 
198  // Used to create the gl context at startup.
199  void OnWindowCreation(wxWindowCreateEvent &ev);
200 
201  DECLARE_EVENT_TABLE()
202 
203  }; // end of class
204 
205  } // end namespace
206 } // end namespace
207 
208 #endif // wxUSE_GLCANVAS
209 #endif // MRPT_HAS_WXWIDGETS
210 #endif // CMyGLCanvas_H
211 



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