Visual Servoing Platform  version 3.6.1 under development (2025-01-25)
test_utils.h
1 #ifndef VP_RB_TEST_UTILS_H
2 #define VP_RB_TEST_UTILS_H
3 
4 #include <visp3/ar/vpPanda3DRendererSet.h>
5 #include <visp3/ar/vpPanda3DGeometryRenderer.h>
6 #include <visp3/ar/vpPanda3DRGBRenderer.h>
7 
8 #include <vector>
9 
11 {
12  std::vector<vpImage<vpRGBa>> rgb;
13  std::vector<vpImage<float>> depth;
14  std::vector<vpHomogeneousMatrix> cTo;
15 };
16 
17 TrajectoryData generateTrajectory(const vpPanda3DRenderParameters &renderingParams,
18  const std::function<void(vpPanda3DRendererSet &)> &makeScene,
19  std::vector<vpHomogeneousMatrix> &cTw, std::vector<vpHomogeneousMatrix> &oTw)
20 {
21  vpPanda3DRendererSet renderer(renderingParams);
22  auto rgbRenderer = std::make_shared<vpPanda3DRGBRenderer>(true);
23  renderer.addSubRenderer(rgbRenderer);
24  renderer.addSubRenderer(std::make_shared<vpPanda3DGeometryRenderer>(vpPanda3DGeometryRenderer::OBJECT_NORMALS));
25  renderer.initFramework();
26  makeScene(renderer);
27 
28  if (cTw.size() != oTw.size()) {
29  throw vpException(vpException::dimensionError, "Number of poses don't match");
30  }
31  TrajectoryData res;
32  res.rgb.resize(cTw.size());
33  res.depth.resize(cTw.size());
34  res.cTo.resize(cTw.size());
35 
36  for (unsigned int i = 0; i < cTw.size(); ++i) {
37  res.rgb[i].resize(renderingParams.getImageHeight(), renderingParams.getImageWidth());
38  res.depth[i].resize(renderingParams.getImageHeight(), renderingParams.getImageWidth());
39  renderer.setNodePose("object", oTw[i].inverse());
40  renderer.setCameraPose(cTw[i].inverse());
41 
42  float nearV, farV;
43  rgbRenderer->computeNearAndFarPlanesFromNode("object", nearV, farV, true);
44  vpPanda3DRenderParameters renderingParamsFrame = renderingParams;
45  renderingParamsFrame.setClippingDistance(nearV, farV);
46  renderer.setRenderParameters(renderingParamsFrame);
47  // update clip
48  renderer.renderFrame();
49  renderer.getRenderer<vpPanda3DRGBRenderer>()->getRender(res.rgb[i]);
50  renderer.getRenderer<vpPanda3DGeometryRenderer>()->getRender(res.depth[i]);
51  res.cTo[i] = cTw[i] * oTw[i].inverse();
52  }
53  return res;
54 }
55 
56 #endif
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ dimensionError
Bad dimension.
Definition: vpException.h:71
Renderer that outputs object geometric information.
Implementation of a traditional RGB renderer in Panda3D.
Rendering parameters for a panda3D simulation.
void setClippingDistance(double nearV, double farV)
Set the clipping distance. When a panda camera uses these render parameters, objects that are closer ...
Class that renders multiple datatypes, in a single pass. A renderer set contains multiple subrenderer...
void initFramework() VP_OVERRIDE
Initialize the framework and propagate the created panda3D framework to the subrenderers.
virtual void setRenderParameters(const vpPanda3DRenderParameters &params) VP_OVERRIDE
Set new rendering parameters. If the scene has already been initialized, the renderer camera is updat...
void addSubRenderer(std::shared_ptr< vpPanda3DBaseRenderer > renderer)
Add a new subrenderer: This subrenderer should have a unique name, not present in the set.
void setNodePose(const std::string &name, const vpHomogeneousMatrix &wTo) VP_OVERRIDE
Set the pose of an object for all the subrenderers. The pose is specified using the ViSP convention T...
void setCameraPose(const vpHomogeneousMatrix &wTc) VP_OVERRIDE
Set the pose of the camera, using the ViSP convention. This change is propagated to all subrenderers.
std::shared_ptr< RendererType > getRenderer()
Retrieve the first subrenderer with the specified template type.
std::vector< vpHomogeneousMatrix > cTo
Definition: test_utils.h:14
std::vector< vpImage< float > > depth
Definition: test_utils.h:13
std::vector< vpImage< vpRGBa > > rgb
Definition: test_utils.h:12