Visual Servoing Platform  version 3.6.1 under development (2024-12-13)
vpPanda3DBaseRenderer.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  */
30 
31 #ifndef VP_PANDA3D_BASE_RENDERER_H
32 #define VP_PANDA3D_BASE_RENDERER_H
33 
34 #include <visp3/core/vpConfig.h>
35 
36 #if defined(VISP_HAVE_PANDA3D)
37 #include <visp3/core/vpPoint.h>
38 #include <visp3/core/vpCameraParameters.h>
39 #include <visp3/ar/vpPanda3DRenderParameters.h>
40 
41 #include <pandaFramework.h>
42 #include <pandaSystem.h>
43 
44 BEGIN_VISP_NAMESPACE
57 class VISP_EXPORT vpPanda3DBaseRenderer
58 {
59 public:
60  vpPanda3DBaseRenderer(const std::string &rendererName)
61  : m_name(rendererName), m_renderOrder(-100), m_framework(nullptr), m_window(nullptr), m_camera(nullptr)
62  {
63  setVerticalSyncEnabled(false);
64  }
65 
66  virtual ~vpPanda3DBaseRenderer() = default;
67 
73  virtual void initFramework();
74  virtual void initFromParent(std::shared_ptr<PandaFramework> framework, PointerTo<WindowFramework> window);
75  virtual void initFromParent(const vpPanda3DBaseRenderer &renderer);
76 
77  virtual void beforeFrameRendered() { }
78  virtual void renderFrame();
79  virtual void afterFrameRendered()
80  {
81  GraphicsOutput *mainBuffer = getMainOutputBuffer();
82  if (mainBuffer != nullptr) {
83  m_framework->get_graphics_engine()->extract_texture_data(mainBuffer->get_texture(), mainBuffer->get_gsg());
84  }
85  }
86 
92  const std::string &getName() const { return m_name; }
93 
94  void setName(const std::string &name) { m_name = name; }
95 
100  NodePath &getRenderRoot() { return m_renderRoot; }
101 
107  virtual void setRenderParameters(const vpPanda3DRenderParameters &params);
108 
114  virtual bool isRendering3DScene() const { return true; }
115 
123  int getRenderOrder() const { return m_renderOrder; }
124 
125  void setRenderOrder(int order)
126  {
127  int previousOrder = m_renderOrder;
128  m_renderOrder = order;
129  for (GraphicsOutput *buffer: m_buffers) {
130  buffer->set_sort(buffer->get_sort() + (order - previousOrder));
131  }
132  }
133 
140  virtual void setCameraPose(const vpHomogeneousMatrix &wTc);
141 
146  virtual vpHomogeneousMatrix getCameraPose();
147 
157  virtual void setNodePose(const std::string &name, const vpHomogeneousMatrix &wTo);
158 
167  virtual void setNodePose(NodePath &object, const vpHomogeneousMatrix &wTo);
168 
176  virtual vpHomogeneousMatrix getNodePose(const std::string &name);
177 
181  virtual vpHomogeneousMatrix getNodePose(NodePath &object);
182 
200  void computeNearAndFarPlanesFromNode(const std::string &name, float &near, float &far, bool fast);
201 
211  NodePath loadObject(const std::string &nodeName, const std::string &modelPath);
212 
218  virtual void addNodeToScene(const NodePath &object);
219 
226  void setVerticalSyncEnabled(bool useVsync);
233  void setAbortOnPandaError(bool abort);
234  void enableDebugLog();
235 
236  static vpColVector vispPointToPanda(const vpColVector &point);
237  static vpColVector vispVectorToPanda(const vpColVector &vec);
238 
239  void printStructure();
240 
241  virtual GraphicsOutput *getMainOutputBuffer() { return nullptr; }
242 
243  virtual void enableSharedDepthBuffer(vpPanda3DBaseRenderer &sourceBuffer);
244 
245 protected:
246 
253  virtual void setupScene();
254 
259  virtual void setupCamera();
260 
265  virtual void setupRenderTarget() { }
266 
269 
270 protected:
271  std::string m_name;
273  std::shared_ptr<PandaFramework> m_framework;
274  PointerTo<WindowFramework> m_window;
276  NodePath m_renderRoot;
277  PointerTo<Camera> m_camera;
278  NodePath m_cameraPath;
279  std::vector<GraphicsOutput *> m_buffers;
280 };
281 
282 END_VISP_NAMESPACE
283 #endif //VISP_HAVE_PANDA3D
284 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Implementation of an homogeneous matrix and operations on such kind of matrices.
Base class for a panda3D renderer. This class handles basic functionalities, such as loading object,...
vpPanda3DBaseRenderer(const std::string &rendererName)
const std::string & getName() const
Get the name of the renderer.
std::shared_ptr< PandaFramework > m_framework
Rendering priority for this renderer and its buffers. A lower value will be rendered first....
virtual GraphicsOutput * getMainOutputBuffer()
NodePath m_renderRoot
Rendering parameters.
PointerTo< Camera > m_camera
Node containing all the objects and the camera for this renderer.
virtual bool isRendering3DScene() const
Returns true if this renderer process 3D data and its scene root can be interacted with.
virtual ~vpPanda3DBaseRenderer()=default
static const vpHomogeneousMatrix PANDA_T_VISP
Homogeneous transformation matrix to convert from the Panda coordinate system (right-handed Z-up) to ...
std::string m_name
Inverse of VISP_T_PANDA.
static const vpHomogeneousMatrix VISP_T_PANDA
virtual void afterFrameRendered()
void setName(const std::string &name)
PointerTo< WindowFramework > m_window
Pointer to the active panda framework.
int getRenderOrder() const
Get the rendering order of this renderer. If a renderer A has a lower order value than B,...
NodePath & getRenderRoot()
Get the scene root.
virtual void setupRenderTarget()
Initialize buffers and other objects that are required to save the render.
int m_renderOrder
name of the renderer
virtual void beforeFrameRendered()
std::vector< GraphicsOutput * > m_buffers
NodePath of the camera.
vpPanda3DRenderParameters m_renderParameters
Pointer to owning window, which can create buffers etc. It is not necessarily visible.
Rendering parameters for a panda3D simulation.