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



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019