Main MRPT website > C++ reference for MRPT 1.9.9
CGlCanvasBase.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-2018, 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 #pragma once
12 
13 namespace mrpt
14 {
15 namespace opengl
16 {
17 class CCamera;
18 }
19 }
20 
21 namespace mrpt
22 {
23 namespace gui
24 {
25 /** This base class implements a working with opengl::Camera and a OpenGL
26  * canvas, and it's used in gui::CWxGLCanvasBase and gui::CQtGlCanvasBase.
27 */
29 {
30  public:
31  struct CamaraParams
32  {
34  void setElevationDeg(float deg);
35 
36  float cameraPointingX = .0f, cameraPointingY = .0f,
38  float cameraZoomDistance = 40.f;
39  float cameraElevationDeg = 45.f, cameraAzimuthDeg = 45.f;
40  bool cameraIsProjective = true;
41  float cameraFOV = 30.f;
42  };
43 
45  virtual ~CGlCanvasBase() {}
46  /** Sets the minimum of the zoom
47  * See also setMaximumZoom(float) */
48  void setMinimumZoom(float zoom);
49 
50  /** Sets the maximum of the zoom
51  * See also setMinimumZoom(float) */
52  void setMaximumZoom(float zoom);
53 
54  /** Saves the click position of the mouse
55  * See also setMouseClicked(bool) */
56  void setMousePos(int x, int y);
57 
58  /** Sets the property mouseClicked
59  * By default, this property is false.
60  * See also setMousePos(int, int) */
61  void setMouseClicked(bool is);
62 
63  /** Sets the last mouse position */
64  void updateLastPos(int x, int y);
65  /** Calls the glViewport function*/
66  void resizeViewport(int w, int h);
67  /** Calls the glClearColor function
68  * See also setClearColors(float, float, float, float)*/
69  void clearColors();
70 
71  /** This function for the mouse event
72  * It gets a reference to CamaraParams, x, y
73  * and updates the zoom of the CameraParams.
74  * See also updateZoom(CamaraParams &, float)*/
75  void updateZoom(CamaraParams& params, int x, int y) const;
76  /** This function for the wheel event
77  * It gets a reference to CamaraParams, delta
78  * and updates the zoom of the CameraParams.
79  * See also updateZoom(CamaraParams &, int, int)*/
80  void updateZoom(CamaraParams& params, float delta) const;
81  /** This function for the mouse event
82  * It gets a reference to CamaraParams, x, y
83  * and updates the elevation and azimuth.
84  * See also getElevationDegrees(), getAzimuthDegrees()*/
85  void updateRotate(CamaraParams& params, int x, int y) const;
86  /** This function for the mouse event
87  * It gets a reference to CamaraParams, x, y
88  * and updates the elevation and azimuth.
89  * See also getElevationDegrees(), getAzimuthDegrees()*/
90  void updateOrbitCamera(CamaraParams& params, int x, int y) const;
91  /** This function for the mouse event
92  * It gets a reference to CamaraParams, x, y
93  * and updates the pointing of the camera.
94  * See also getCameraPointingX(), getCameraPointingY(),
95  * getCameraPointingZ()*/
96  void updatePan(CamaraParams& params, int x, int y) const;
97 
98  /** Returns a copy of CamaraParams
99  * See also getRefCameraParams(), setCameraParams(const CamaraParams &)*/
100  CamaraParams cameraParams() const;
101  /** Returns a reference to CamaraParams
102  * See also cameraParams(), setCameraParams(const CamaraParams &) */
103  const CamaraParams& getRefCameraParams() const;
104  /** Sets the CamaraParams
105  * See also cameraParams(), getRefCameraParams()*/
106  virtual void setCameraParams(const CamaraParams& params);
107 
108  /** This function gets a reference to mrpt::opengl::CCamera and
109  * updates the camera parameters(pointing, zoom, azimuth, elevation,
110  * IsProjective, FOV)
111  */
113 
114  /** If set to true (default=false), the cameraPointingX,... parameters are
115  * ignored and the camera stored in the 3D scene is used instead.
116  * See also void bool getUseCameraFromScene()
117  */
118  void setUseCameraFromScene(bool is);
119 
120  /** See also void setUseCameraFromScene(bool)
121  */
122  bool getUseCameraFromScene() const;
123 
124  // Visualization params:
125  /** Saves the pointing of the camera
126  * See also getCameraPointingX(), getCameraPointingY(), getCameraPointingZ()
127  */
128  virtual void setCameraPointing(float pointX, float pointY, float pointZ);
129 
130  /** Returns the x pointing of the camera
131  * See also setCameraPointing(float, float, float)
132  */
133  float getCameraPointingX() const;
134 
135  /** Returns the y pointing of the camera
136  * See also setCameraPointing(float, float, float)
137  */
138  float getCameraPointingY() const;
139 
140  /** Returns the z pointing of the camera
141  * See also setCameraPointing(float, float, float)
142  */
143  float getCameraPointingZ() const;
144 
145  /** Saves camera zooming
146  * See also getZoomDistance()
147  */
148  virtual void setZoomDistance(float zoom);
149 
150  /** Returns a zoom
151  * See also setZoomDistance(float)
152  */
153  float getZoomDistance() const;
154 
155  /** Saves the degrees of the azimuth camera
156  * See also getAzimuthDegrees()
157  */
158  virtual void setAzimuthDegrees(float ang);
159 
160  /** Returns a azimuth degrees
161  * See also setAzimuthDegrees(float)
162  */
163  float getAzimuthDegrees() const;
164 
165  /** Saves the degrees of the elevation camera
166  * See also getElevationDegrees()
167  */
168  virtual void setElevationDegrees(float ang);
169 
170  /** Returns a elevation degrees
171  * See also setElevationDegrees(float)
172  */
173  float getElevationDegrees() const;
174 
175  virtual void setCameraProjective(bool is);
176  bool isCameraProjective() const;
177 
178  virtual void setCameraFOV(float FOV);
179  float cameraFOV() const;
180 
181  /** Sets the RGBA colors for glClearColor
182  * See also clearColors(), getClearColorR(),
183  * getClearColorG(),getClearColorB(), getClearColorA()
184  */
185  void setClearColors(float r, float g, float b, float a = 1.0f);
186  float getClearColorR() const;
187  float getClearColorG() const;
188  float getClearColorB() const;
189  float getClearColorA() const;
190 
191  static float SENSIBILITY_DEG_PER_PIXEL; // Default = 0.1
192 
193  /** Overload this method to limit the capabilities of the user to move the
194  * camera using the mouse.
195  * For all these variables:
196  * - cameraPointingX
197  * - cameraPointingY
198  * - cameraPointingZ
199  * - cameraZoomDistance
200  * - cameraElevationDeg
201  * - cameraAzimuthDeg
202  *
203  * A "new_NAME" variable will be passed with the temptative new
204  * value after the user action.
205  * The default behavior should be to copy all the new variables
206  * to the variables listed above
207  * but in the middle any find of user-defined filter can be
208  * implemented.
209  */
211  float new_cameraPointingX, float new_cameraPointingY,
212  float new_cameraPointingZ, float new_cameraZoomDistance,
213  float new_cameraElevationDeg, float new_cameraAzimuthDeg)
214  {
215  m_cameraParams.cameraPointingX = new_cameraPointingX;
216  m_cameraParams.cameraPointingY = new_cameraPointingY;
217  m_cameraParams.cameraPointingZ = new_cameraPointingZ;
218  m_cameraParams.cameraZoomDistance = new_cameraZoomDistance;
219  m_cameraParams.cameraElevationDeg = new_cameraElevationDeg;
220  m_cameraParams.cameraAzimuthDeg = new_cameraAzimuthDeg;
221  }
222 
223  inline void getLastMousePosition(int& x, int& y) const
224  {
225  x = m_mouseLastX;
226  y = m_mouseLastY;
227  }
228 
229  /** At constructor an empty scene is created. The object is freed at GL
230  canvas destructor.
231  * This function returns a smart pointer to the opengl scene
232  getOpenGLSceneRef */
234  {
235  return m_openGLScene;
236  }
238 
239  protected:
240  virtual void swapBuffers() = 0;
241  virtual void preRender() = 0;
242  virtual void postRender() = 0;
243  virtual void renderError(const std::string& err_msg) = 0;
244 
245  virtual double renderCanvas(int width = -1, int height = -1);
246 
247  private:
248  float clearColorR = .4f, clearColorG = .4f, clearColorB = .4f,
249  clearColorA = 1.f;
250  bool useCameraFromScene = false;
252  mrpt::make_aligned_shared<mrpt::opengl::COpenGLScene>();
255  bool mouseClicked = false;
256  float m_minZoom = 1.f;
257  float m_maxZoom = 3200.f;
259 }; // end of class
260 } // end namespace
261 } // end namespace
mrpt::gui::CGlCanvasBase::m_mouseClickY
int m_mouseClickY
Definition: CGlCanvasBase.h:254
mrpt::gui::CGlCanvasBase::getRefCameraParams
const CamaraParams & getRefCameraParams() const
Returns a reference to CamaraParams See also cameraParams(), setCameraParams(const CamaraParams &)
Definition: CGlCanvasBase.cpp:146
mrpt::gui::CGlCanvasBase::postRender
virtual void postRender()=0
mrpt::gui::CGlCanvasBase::m_mouseLastX
int m_mouseLastX
Definition: CGlCanvasBase.h:253
mrpt::gui::CGlCanvasBase::updateOrbitCamera
void updateOrbitCamera(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the elevation...
Definition: CGlCanvasBase.cpp:101
mrpt::gui::CGlCanvasBase::updateZoom
void updateZoom(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the zoom of t...
Definition: CGlCanvasBase.cpp:51
mrpt::gui::CGlCanvasBase::updateCameraParams
mrpt::opengl::CCamera & updateCameraParams(mrpt::opengl::CCamera &cam) const
This function gets a reference to mrpt::opengl::CCamera and updates the camera parameters(pointing,...
Definition: CGlCanvasBase.cpp:166
mrpt::gui::CGlCanvasBase::getUseCameraFromScene
bool getUseCameraFromScene() const
See also void setUseCameraFromScene(bool)
Definition: CGlCanvasBase.cpp:181
mrpt::gui::CGlCanvasBase::useCameraFromScene
bool useCameraFromScene
Definition: CGlCanvasBase.h:250
mrpt::gui::CGlCanvasBase::getCameraPointingZ
float getCameraPointingZ() const
Returns the z pointing of the camera See also setCameraPointing(float, float, float)
Definition: CGlCanvasBase.cpp:248
mrpt::gui::CGlCanvasBase::getAzimuthDegrees
float getAzimuthDegrees() const
Returns a azimuth degrees See also setAzimuthDegrees(float)
Definition: CGlCanvasBase.cpp:192
mrpt::gui::CGlCanvasBase::setCameraProjective
virtual void setCameraProjective(bool is)
Definition: CGlCanvasBase.cpp:202
mrpt::gui::CGlCanvasBase::SENSIBILITY_DEG_PER_PIXEL
static float SENSIBILITY_DEG_PER_PIXEL
Definition: CGlCanvasBase.h:191
mrpt::gui::CGlCanvasBase::getClearColorG
float getClearColorG() const
Definition: CGlCanvasBase.cpp:223
mrpt::gui::CGlCanvasBase::m_maxZoom
float m_maxZoom
Definition: CGlCanvasBase.h:257
mrpt::gui::CGlCanvasBase::m_mouseClickX
int m_mouseClickX
Definition: CGlCanvasBase.h:254
mrpt::gui::CGlCanvasBase
This base class implements a working with opengl::Camera and a OpenGL canvas, and it's used in gui::C...
Definition: CGlCanvasBase.h:28
mrpt::gui::CGlCanvasBase::updateRotate
void updateRotate(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the elevation...
Definition: CGlCanvasBase.cpp:71
mrpt::gui::CGlCanvasBase::updatePan
void updatePan(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the pointing ...
Definition: CGlCanvasBase.cpp:130
mrpt::gui::CGlCanvasBase::setMaximumZoom
void setMaximumZoom(float zoom)
Sets the maximum of the zoom See also setMinimumZoom(float)
Definition: CGlCanvasBase.cpp:43
mrpt::gui::CGlCanvasBase::CamaraParams::cameraZoomDistance
float cameraZoomDistance
Definition: CGlCanvasBase.h:38
mrpt::gui::CGlCanvasBase::swapBuffers
virtual void swapBuffers()=0
mrpt::gui::CGlCanvasBase::CamaraParams::setElevationDeg
void setElevationDeg(float deg)
Definition: CGlCanvasBase.cpp:339
mrpt::gui::CGlCanvasBase::m_cameraParams
CamaraParams m_cameraParams
Definition: CGlCanvasBase.h:258
mrpt::gui::CGlCanvasBase::clearColorB
float clearColorB
Definition: CGlCanvasBase.h:248
mrpt::gui::CGlCanvasBase::setCameraParams
virtual void setCameraParams(const CamaraParams &params)
Sets the CamaraParams See also cameraParams(), getRefCameraParams()
Definition: CGlCanvasBase.cpp:151
mrpt::gui::CGlCanvasBase::OnUserManuallyMovesCamera
virtual void OnUserManuallyMovesCamera(float new_cameraPointingX, float new_cameraPointingY, float new_cameraPointingZ, float new_cameraZoomDistance, float new_cameraElevationDeg, float new_cameraAzimuthDeg)
Overload this method to limit the capabilities of the user to move the camera using the mouse.
Definition: CGlCanvasBase.h:210
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
g
GLubyte g
Definition: glext.h:6279
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
mrpt::gui::CGlCanvasBase::setClearColors
void setClearColors(float r, float g, float b, float a=1.0f)
Sets the RGBA colors for glClearColor See also clearColors(), getClearColorR(), getClearColorG(),...
Definition: CGlCanvasBase.cpp:214
mrpt::gui::CGlCanvasBase::CamaraParams::cameraPointingY
float cameraPointingY
Definition: CGlCanvasBase.h:36
mrpt::gui::CGlCanvasBase::CamaraParams::cameraPointingX
float cameraPointingX
Definition: CGlCanvasBase.h:36
mrpt::gui::CGlCanvasBase::isCameraProjective
bool isCameraProjective() const
Definition: CGlCanvasBase.cpp:207
mrpt::gui::CGlCanvasBase::setAzimuthDegrees
virtual void setAzimuthDegrees(float ang)
Saves the degrees of the azimuth camera See also getAzimuthDegrees()
Definition: CGlCanvasBase.cpp:182
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::gui::CGlCanvasBase::getCameraPointingY
float getCameraPointingY() const
Returns the y pointing of the camera See also setCameraPointing(float, float, float)
Definition: CGlCanvasBase.cpp:243
mrpt::gui::CGlCanvasBase::~CGlCanvasBase
virtual ~CGlCanvasBase()
Definition: CGlCanvasBase.h:45
COpenGLScene.h
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::gui::CGlCanvasBase::m_openGLScene
mrpt::opengl::COpenGLScene::Ptr m_openGLScene
Definition: CGlCanvasBase.h:251
mrpt::gui::CGlCanvasBase::updateLastPos
void updateLastPos(int x, int y)
Sets the last mouse position.
Definition: CGlCanvasBase.cpp:108
mrpt::opengl::CCamera
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
Definition: CCamera.h:30
mrpt::gui::CGlCanvasBase::CamaraParams::cameraFOV
float cameraFOV
Definition: CGlCanvasBase.h:41
mrpt::gui::CGlCanvasBase::getZoomDistance
float getZoomDistance() const
Returns a zoom See also setZoomDistance(float)
Definition: CGlCanvasBase.cpp:156
mrpt::gui::CGlCanvasBase::renderError
virtual void renderError(const std::string &err_msg)=0
mrpt::gui::CGlCanvasBase::CamaraParams::cameraPointingZ
float cameraPointingZ
Definition: CGlCanvasBase.h:37
mrpt::gui::CGlCanvasBase::clearColors
void clearColors()
Calls the glClearColor function See also setClearColors(float, float, float, float)
Definition: CGlCanvasBase.cpp:123
mrpt::gui::CGlCanvasBase::cameraFOV
float cameraFOV() const
Definition: CGlCanvasBase.cpp:213
mrpt::gui::CGlCanvasBase::getClearColorA
float getClearColorA() const
Definition: CGlCanvasBase.cpp:225
mrpt::gui::CGlCanvasBase::CamaraParams::cameraAzimuthDeg
float cameraAzimuthDeg
Definition: CGlCanvasBase.h:39
mrpt::gui::CGlCanvasBase::CGlCanvasBase
CGlCanvasBase()
Definition: CGlCanvasBase.h:44
height
GLenum GLsizei GLsizei height
Definition: glext.h:3554
mrpt::gui::CGlCanvasBase::CamaraParams::cameraElevationDeg
float cameraElevationDeg
Definition: CGlCanvasBase.h:39
mrpt::gui::CGlCanvasBase::getOpenGLSceneRef
mrpt::opengl::COpenGLScene::Ptr & getOpenGLSceneRef()
At constructor an empty scene is created.
Definition: CGlCanvasBase.h:233
mrpt::gui::CGlCanvasBase::CamaraParams::CamaraParams
CamaraParams()
Definition: CGlCanvasBase.h:33
mrpt::gui::CGlCanvasBase::CamaraParams::cameraIsProjective
bool cameraIsProjective
Definition: CGlCanvasBase.h:40
mrpt::gui::CGlCanvasBase::getElevationDegrees
float getElevationDegrees() const
Returns a elevation degrees See also setElevationDegrees(float)
Definition: CGlCanvasBase.cpp:197
mrpt::gui::CGlCanvasBase::clearColorA
float clearColorA
Definition: CGlCanvasBase.h:249
mrpt::gui::CGlCanvasBase::CamaraParams
Definition: CGlCanvasBase.h:31
mrpt::gui::CGlCanvasBase::setOpenGLSceneRef
void setOpenGLSceneRef(mrpt::opengl::COpenGLScene::Ptr scene)
Definition: CGlCanvasBase.cpp:226
mrpt::gui::CGlCanvasBase::setCameraFOV
virtual void setCameraFOV(float FOV)
Definition: CGlCanvasBase.cpp:212
mrpt::gui::CGlCanvasBase::getLastMousePosition
void getLastMousePosition(int &x, int &y) const
Definition: CGlCanvasBase.h:223
width
GLenum GLsizei width
Definition: glext.h:3531
mrpt::gui::CGlCanvasBase::getClearColorB
float getClearColorB() const
Definition: CGlCanvasBase.cpp:224
mrpt::gui::CGlCanvasBase::renderCanvas
virtual double renderCanvas(int width=-1, int height=-1)
Definition: CGlCanvasBase.cpp:253
mrpt::gui::CGlCanvasBase::getCameraPointingX
float getCameraPointingX() const
Returns the x pointing of the camera See also setCameraPointing(float, float, float)
Definition: CGlCanvasBase.cpp:238
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:61
mrpt::gui::CGlCanvasBase::setCameraPointing
virtual void setCameraPointing(float pointX, float pointY, float pointZ)
Saves the pointing of the camera See also getCameraPointingX(), getCameraPointingY(),...
Definition: CGlCanvasBase.cpp:231
mrpt::gui::CGlCanvasBase::resizeViewport
void resizeViewport(int w, int h)
Calls the glViewport function.
Definition: CGlCanvasBase.cpp:114
mrpt::gui::CGlCanvasBase::mouseClicked
bool mouseClicked
Definition: CGlCanvasBase.h:255
mrpt::gui::CGlCanvasBase::preRender
virtual void preRender()=0
mrpt::gui::CGlCanvasBase::setMousePos
void setMousePos(int x, int y)
Saves the click position of the mouse See also setMouseClicked(bool)
Definition: CGlCanvasBase.cpp:44
mrpt::gui::CGlCanvasBase::clearColorG
float clearColorG
Definition: CGlCanvasBase.h:248
mrpt::gui::CGlCanvasBase::setElevationDegrees
virtual void setElevationDegrees(float ang)
Saves the degrees of the elevation camera See also getElevationDegrees()
Definition: CGlCanvasBase.cpp:187
mrpt::gui::CGlCanvasBase::setMouseClicked
void setMouseClicked(bool is)
Sets the property mouseClicked By default, this property is false.
Definition: CGlCanvasBase.cpp:50
mrpt::gui::CGlCanvasBase::getClearColorR
float getClearColorR() const
Definition: CGlCanvasBase.cpp:222
y
GLenum GLint GLint y
Definition: glext.h:3538
mrpt::gui::CGlCanvasBase::m_mouseLastY
int m_mouseLastY
Definition: CGlCanvasBase.h:253
mrpt::gui::CGlCanvasBase::clearColorR
float clearColorR
Definition: CGlCanvasBase.h:248
mrpt::gui::CGlCanvasBase::setMinimumZoom
void setMinimumZoom(float zoom)
Sets the minimum of the zoom See also setMaximumZoom(float)
Definition: CGlCanvasBase.cpp:42
x
GLenum GLint x
Definition: glext.h:3538
mrpt::gui::CGlCanvasBase::setUseCameraFromScene
void setUseCameraFromScene(bool is)
If set to true (default=false), the cameraPointingX,...
Definition: CGlCanvasBase.cpp:180
mrpt::gui::CGlCanvasBase::m_minZoom
float m_minZoom
Definition: CGlCanvasBase.h:256
params
GLenum const GLfloat * params
Definition: glext.h:3534
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
mrpt::gui::CGlCanvasBase::cameraParams
CamaraParams cameraParams() const
Returns a copy of CamaraParams See also getRefCameraParams(), setCameraParams(const CamaraParams &)
Definition: CGlCanvasBase.cpp:141
mrpt::gui::CGlCanvasBase::setZoomDistance
virtual void setZoomDistance(float zoom)
Saves camera zooming See also getZoomDistance()
Definition: CGlCanvasBase.cpp:161



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST