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
float getCameraPointingX() const
Returns the x pointing of the camera See also setCameraPointing(float, float, float) ...
virtual void preRender()=0
virtual void preRender() override
virtual void setCameraProjective(bool is)
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...
CamaraParams cameraParams() const
Returns a copy of CamaraParams See also getRefCameraParams(), setCameraParams(const CamaraParams &) ...
virtual void postRender()=0
void setMaximumZoom(float zoom)
Sets the maximum of the zoom See also setMinimumZoom(float)
float getZoomDistance() const
Returns a zoom See also setZoomDistance(float)
mrpt::vision::TStereoCalibParams params
mrpt::opengl::COpenGLScene::Ptr m_openGLScene
virtual void setCameraParams(const CamaraParams &params)
Sets the CamaraParams See also cameraParams(), getRefCameraParams()
virtual void swapBuffers() override
virtual void postRender() override
virtual void swapBuffers()=0
void resizeViewport(int w, int h)
Calls the glViewport function.
const CamaraParams & getRefCameraParams() const
Returns a reference to CamaraParams See also cameraParams(), setCameraParams(const CamaraParams &) ...
void setMousePos(int x, int y)
Saves the click position of the mouse See also setMouseClicked(bool)
virtual void setElevationDegrees(float ang)
Saves the degrees of the elevation camera See also getElevationDegrees()
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...
virtual void renderError(const std::string &e) override
void setOpenGLSceneRef(mrpt::opengl::COpenGLScene::Ptr scene)
virtual void setAzimuthDegrees(float ang)
Saves the degrees of the azimuth camera See also getAzimuthDegrees()
virtual double renderCanvas(int width=-1, int height=-1)
virtual void setCameraPointing(float pointX, float pointY, float pointZ)
Saves the pointing of the camera See also getCameraPointingX(), getCameraPointingY(), getCameraPointingZ()
void clearColors()
Calls the glClearColor function See also setClearColors(float, float, float, float) ...
float getCameraPointingZ() const
Returns the z pointing of the camera See also setCameraPointing(float, float, float) ...
virtual void setCameraFOV(float FOV)
void setClearColors(float r, float g, float b, float a=1.0f)
Sets the RGBA colors for glClearColor See also clearColors(), getClearColorR(), getClearColorG(),getClearColorB(), getClearColorA()
void getLastMousePosition(int &x, int &y) const
virtual void setZoomDistance(float zoom)
Saves camera zooming See also getZoomDistance()
bool getUseCameraFromScene() const
See also void setUseCameraFromScene(bool)
float getAzimuthDegrees() const
Returns a azimuth degrees See also setAzimuthDegrees(float)
virtual ~CGlCanvasBaseHeadless() override=default
float getCameraPointingY() const
Returns the y pointing of the camera See also setCameraPointing(float, float, float) ...
mrpt::opengl::COpenGLScene::Ptr & getOpenGLSceneRef()
At constructor an empty scene is created.
void setMouseClicked(bool is)
Sets the property mouseClicked By default, this property is false.
void updateLastPos(int x, int y)
Sets the last mouse position.
float getElevationDegrees() const
Returns a elevation degrees See also setElevationDegrees(float)
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...
void setMinimumZoom(float zoom)
Sets the minimum of the zoom See also setMaximumZoom(float)
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
virtual void renderError(const std::string &err_msg)=0
void setUseCameraFromScene(bool is)
If set to true (default=false), the cameraPointingX,...
static Ptr Create(Args &&... args)
Definition: COpenGLScene.h:58
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
A headless dummy implementation of CGlCanvasBase: can be used to keep track of user UI mouse events a...
This base class implements a working with opengl::Camera and a OpenGL canvas, and it's used in gui::C...
Definition: CGlCanvasBase.h:24
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
Definition: CCamera.h:33
static float SENSIBILITY_DEG_PER_PIXEL
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 ...
mrpt::opengl::CCamera & updateCameraParams(mrpt::opengl::CCamera &cam) const
This function gets a reference to mrpt::opengl::CCamera and updates the camera parameters(pointing, zoom, azimuth, elevation, IsProjective, FOV)
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...



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020