Visual Servoing Platform  version 3.6.1 under development (2025-01-26)
vpObjectCentricRenderer.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 
35 #ifndef VP_OBJECT_CENTRIC_RENDERER_H
36 #define VP_OBJECT_CENTRIC_RENDERER_H
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #if defined(VISP_HAVE_PANDA3D)
41 
42 #include <visp3/core/vpMeterPixelConversion.h>
43 #include <visp3/ar/vpPanda3DRendererSet.h>
44 #include <visp3/core/vpRect.h>
45 
46 BEGIN_VISP_NAMESPACE
47 
53 {
54 public:
55  vpObjectCentricRenderer(const vpPanda3DRenderParameters &renderParameters);
56 
57  virtual void setRenderParameters(const vpPanda3DRenderParameters &params) VP_OVERRIDE
58  {
60  }
61 
62  vpRect getBoundingBox() const { return m_bb; }
63 
64  void setFocusedObject(const std::string &focused)
65  {
66  m_focusedObject = focused;
67  m_shouldComputeBBPoints = true;
68  }
69 
70  void beforeFrameRendered() VP_OVERRIDE;
71 
72  void computeBoundingBox3DPoints();
73  void computeClipping(float &nearV, float &farV);
74 
75  std::vector<vpColVector> getBoundingBox3D()
76  {
77  if (m_shouldComputeBBPoints) {
78  computeBoundingBox3DPoints();
79  m_shouldComputeBBPoints = false;
80  }
81  return m_bb3DPoints;
82  }
83 
84  vpRect computeBoundingBox();
85 
86  template <typename T>
87  void placeRenderInto(const vpImage<T> &render, vpImage<T> &target, const T &clearValue)
88  {
89  if (!m_enableCrop) {
90  target = render;
91  }
92  else {
93  const unsigned h = m_renderParameters.getImageHeight();
94  const unsigned w = m_renderParameters.getImageWidth();
95  const unsigned top = static_cast<unsigned int>(std::max(0.0, m_bb.getTop()));
96  const unsigned left = static_cast<unsigned int>(std::max(0.0, m_bb.getLeft()));
97  const unsigned bottom = static_cast<unsigned int>(std::min(static_cast<double>(h), m_bb.getBottom()));
98  const unsigned right = static_cast<unsigned int>(std::min(static_cast<double>(w), m_bb.getRight()));
99 
100  target.resize(h, w, clearValue);
101  for (unsigned int i = top; i < bottom; ++i) {
102  memcpy(target.bitmap + i * w + left, render[i - top], (right - left) * sizeof(T));
103  // for (unsigned int j = left; j < right; ++j) {
104  // target[i][j] = render[i - unsigned(m_bb.getTop())][j - unsigned(m_bb.getLeft())];
105  // }
106  }
107 
108  }
109  }
110 
111 private:
112  bool m_enableCrop;
113  std::string m_focusedObject;
114  vpRect m_bb;
115  std::vector<vpColVector> m_bb3DPoints;
116  bool m_shouldComputeBBPoints;
117  vpPanda3DRenderParameters m_subRenderParams;
118 };
119 
120 END_VISP_NAMESPACE
121 
122 #endif
123 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Definition of the vpImage class member functions.
Definition: vpImage.h:131
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:544
Type * bitmap
points toward the bitmap
Definition: vpImage.h:135
Single object focused renderer.
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 setFocusedObject(const std::string &focused)
void placeRenderInto(const vpImage< T > &render, vpImage< T > &target, const T &clearValue)
Rendering parameters for a panda3D simulation.
Class that renders multiple datatypes, in a single pass. A renderer set contains multiple subrenderer...
void beforeFrameRendered() VP_OVERRIDE
virtual void setRenderParameters(const vpPanda3DRenderParameters &params) VP_OVERRIDE
Set new rendering parameters. If the scene has already been initialized, the renderer camera is updat...
Defines a rectangle in the plane.
Definition: vpRect.h:79