Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
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
47
60{
61public:
63
64 virtual void setRenderParameters(const vpPanda3DRenderParameters &params) VP_OVERRIDE
65 {
67 }
68
69 vpRect getBoundingBox() const { return m_bb; }
70
71 void setFocusedObject(const std::string &focused)
72 {
73 m_focusedObject = focused;
74 m_shouldComputeBBPoints = true;
75 }
76
77 void beforeFrameRendered() VP_OVERRIDE;
78
79 void computeBoundingBox3DPoints();
80 void computeClipping(float &nearV, float &farV);
81
83 {
84 if (m_shouldComputeBBPoints) {
86 m_shouldComputeBBPoints = false;
87 }
88 return m_bb3DPoints;
89 }
90
92 {
93 if (m_shouldComputeBBPoints) {
95 m_shouldComputeBBPoints = false;
96 }
97 for (unsigned int i = 0; i < 3; ++i) {
98 minValues[i] = std::numeric_limits<double>::max();
99 maxValues[i] = std::numeric_limits<double>::min();
100 }
101
102 for (const vpColVector &point: m_bb3DPoints) {
103 for (unsigned int i = 0; i < 3; ++i) {
104 if (point[i] < minValues[i]) {
105 minValues[i] = point[i];
106 }
107 if (point[i] > maxValues[i]) {
108 maxValues[i] = point[i];
109 }
110 }
111 }
112 }
113
114
115
116 vpRect computeBoundingBox();
117
118 template <typename T>
119 void placeRenderInto(const vpImage<T> &render, vpImage<T> &target, const T &clearValue)
120 {
121 if (!m_enableCrop) {
122 target = render;
123 }
124 else {
125 const unsigned h = m_renderParameters.getImageHeight();
126 const unsigned w = m_renderParameters.getImageWidth();
127 const unsigned top = static_cast<unsigned int>(std::max(0.0, m_bb.getTop()));
128 const unsigned left = static_cast<unsigned int>(std::max(0.0, m_bb.getLeft()));
129 const unsigned bottom = static_cast<unsigned int>(std::min(static_cast<double>(h), m_bb.getBottom()));
130 const unsigned right = static_cast<unsigned int>(std::min(static_cast<double>(w), m_bb.getRight()));
131
132 target.resize(h, w, clearValue);
133 for (unsigned int i = top; i < bottom; ++i) {
134 memcpy(target.bitmap + i * w + left, render[i - top], (right - left) * sizeof(T));
135 // for (unsigned int j = left; j < right; ++j) {
136 // target[i][j] = render[i - unsigned(m_bb.getTop())][j - unsigned(m_bb.getLeft())];
137 // }
138 }
139
140 }
141 }
142
143private:
144 bool m_enableCrop;
145 std::string m_focusedObject;
146 vpRect m_bb;
147 std::vector<vpColVector> m_bb3DPoints;
148 bool m_shouldComputeBBPoints;
149 vpPanda3DRenderParameters m_subRenderParams;
150};
151
152END_VISP_NAMESPACE
153
154#endif
155#endif
Implementation of column vector and the associated operations.
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
std::vector< vpColVector > getBoundingBox3D()
vpObjectCentricRenderer(const vpPanda3DRenderParameters &renderParameters)
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 get3DExtents(vpTranslationVector &minValues, vpTranslationVector &maxValues)
void setFocusedObject(const std::string &focused)
void placeRenderInto(const vpImage< T > &render, vpImage< T > &target, const T &clearValue)
vpPanda3DRenderParameters m_renderParameters
Pointer to owning window, which can create buffers etc. It is not necessarily visible.
Rendering parameters for a panda3D simulation.
virtual void setRenderParameters(const vpPanda3DRenderParameters &params) VP_OVERRIDE
Set new rendering parameters. If the scene has already been initialized, the renderer camera is updat...
virtual void beforeFrameRendered() VP_OVERRIDE
Defines a rectangle in the plane.
Definition vpRect.h:79
Class that consider the case of a translation vector.