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



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 15:15:43 UTC 2020