Main MRPT website > C++ reference for MRPT 1.4.0
CMyGLCanvasBase.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 
10 #ifndef CMyGLCanvas_H
11 #define CMyGLCanvas_H
12 
15 #include <mrpt/gui/link_pragmas.h>
16 
17 namespace mrpt { namespace gui { } } // At least declare the existence of the namespace mrpt::gui even if we don't have wxWidgets libs
18 
19 
20 #if MRPT_HAS_WXWIDGETS
21 
22 #include <wx/string.h>
23 #include <wx/intl.h>
24 #include <wx/bitmap.h>
25 #include <wx/icon.h>
26 #include <wx/image.h>
27 #include <wx/artprov.h>
28 
29 #include <wx/msgdlg.h>
30 #include <wx/filedlg.h>
31 #include <wx/progdlg.h>
32 #include <wx/imaglist.h>
33 #include <wx/busyinfo.h>
34 #include <wx/log.h>
35 #include <wx/textdlg.h>
36 #include <wx/dirdlg.h>
37 #include <wx/colordlg.h>
38 #include <wx/dcmemory.h>
39 
40 #if wxUSE_GLCANVAS && MRPT_HAS_OPENGL_GLUT
41 
42 #include <wx/glcanvas.h>
43 #include <wx/dcclient.h>
44 
45 // To avoid conflicts between Eigen & X11 headers
46 #ifdef Success
47 # undef Success
48 #endif
49 
50 
51 namespace mrpt
52 {
53  namespace gui
54  {
55  /** This class implements a OpenGL canvas, and it's used in gui::CDisplayWindow3D and a number of standalone applications in the MRPT project.
56  * There is a filter to control the user capability of moving the camera with the mouse. See OnUserManuallyMovesCamera
57  * \ingroup mrpt_gui_grp
58  */
59  class GUI_IMPEXP CMyGLCanvasBase: public wxGLCanvas
60  {
61  public:
62  CMyGLCanvasBase( wxWindow *parent, wxWindowID id = wxID_ANY,
63  const wxPoint& pos = wxDefaultPosition,
64  const wxSize& size = wxDefaultSize,
65  long style = 0, const wxString& name = _T("CMyGLCanvasBase") );
66 
67  virtual ~CMyGLCanvasBase();
68 
69  void OnPaint(wxPaintEvent& event);
70  void OnSize(wxSizeEvent& event);
71  void OnEraseBackground(wxEraseEvent& event);
72  void OnEnterWindow(wxMouseEvent& event);
73 
74  void OnChar(wxKeyEvent& event);
75 
76  void OnMouseDown(wxMouseEvent& event);
77  void OnMouseMove(wxMouseEvent& event);
78  void OnMouseUp(wxMouseEvent& event);
79  void OnMouseWheel(wxMouseEvent& event);
80 
81  void Render();
82  void InitGL();
83 
84  // Visualization params:
85  float cameraPointingX,cameraPointingY,cameraPointingZ;
86  float cameraZoomDistance;
87  float cameraElevationDeg,cameraAzimuthDeg;
88  bool cameraIsProjective;
89  float cameraFOV;
90 
91  /** If set to true (default=false), the cameraPointingX,... parameters are ignored and the camera stored in the 3D scene is used instead.
92  */
93  bool useCameraFromScene;
94 
95  /** 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.
96  */
97  void setCameraPose(const mrpt::poses::CPose3D &camPose);
98 
99 
100  float clearColorR,clearColorG,clearColorB;
101 
102  static float SENSIBILITY_DEG_PER_PIXEL; // Default = 0.1
103 
104  /** Methods that can be implemented in custom derived classes */
105  virtual void OnCharCustom( wxKeyEvent& event ) {
106  MRPT_UNUSED_PARAM(event);
107  }
108 
109  virtual void OnPreRender() { }
110  virtual void OnPostRender() { }
111  virtual void OnPostRenderSwapBuffers(double At, wxPaintDC &dc) {
113  }
114 
115  virtual void OnRenderError( const wxString &str ) {
116  MRPT_UNUSED_PARAM(str);
117  }
118 
119  /** Overload this method to limit the capabilities of the user to move the camera using the mouse.
120  * For all these variables:
121  * - cameraPointingX
122  * - cameraPointingY
123  * - cameraPointingZ
124  * - cameraZoomDistance
125  * - cameraElevationDeg
126  * - cameraAzimuthDeg
127  *
128  * A "new_NAME" variable will be passed with the temptative new value after the user action.
129  * The default behavior should be to copy all the new variables to the variables listed above
130  * but in the middle any find of user-defined filter can be implemented.
131  */
132  virtual void OnUserManuallyMovesCamera(
133  float new_cameraPointingX,
134  float new_cameraPointingY,
135  float new_cameraPointingZ,
136  float new_cameraZoomDistance,
137  float new_cameraElevationDeg,
138  float new_cameraAzimuthDeg )
139  {
140  cameraPointingX = new_cameraPointingX;
141  cameraPointingY = new_cameraPointingY;
142  cameraPointingZ = new_cameraPointingZ;
143  cameraZoomDistance = new_cameraZoomDistance;
144  cameraElevationDeg = new_cameraElevationDeg ;
145  cameraAzimuthDeg = new_cameraAzimuthDeg;
146  }
147 
148  inline void getLastMousePosition(int &x,int& y) const {
149  x =m_mouseLastX;
150  y =m_mouseLastY;
151  }
152 
153  /** At constructor an empty scene is created. The object is freed at GL canvas destructor.
154  */
155  mrpt::opengl::COpenGLScenePtr m_openGLScene;
156 
157  protected:
158  wxGLContext *m_gl_context;
159  bool m_init;
160 
161  int m_mouseLastX,m_mouseLastY;
162 
163  int mouseClickX,mouseClickY;
164  bool mouseClicked;
165 
166  long m_Key;
167  unsigned long m_StartTime;
168  unsigned long m_LastTime;
169  unsigned long m_LastRedraw;
170 
171  // Used to create the gl context at startup.
172  void OnWindowCreation(wxWindowCreateEvent &ev);
173 
174  DECLARE_EVENT_TABLE()
175 
176  }; // end of class
177 
178  } // end namespace
179 } // end namespace
180 
181 #endif // wxUSE_GLCANVAS
182 #endif // MRPT_HAS_WXWIDGETS
183 #endif // CMyGLCanvas_H
184 
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
size_t size(const MATRIXLIKE &m, int dim)
Definition: bits.h:38
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72



Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN:Unversioned directory at Tue Jun 28 11:46:25 UTC 2016