31 #include <visp3/core/vpConfig.h>
33 #if defined(VISP_HAVE_PANDA3D)
35 #include <visp3/ar/vpPanda3DGeometryRenderer.h>
39 const std::string SHADER_VERT_NORMAL_AND_DEPTH_CAMERA =
41 "in vec3 p3d_Normal;\n"
42 "in vec4 p3d_Vertex;\n"
43 "uniform mat3 p3d_NormalMatrix;\n"
44 "uniform mat4 p3d_ModelViewMatrix;\n"
45 "uniform mat4 p3d_ModelViewProjectionMatrix;\n"
47 "out float distToCamera;\n"
50 " gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;\n"
51 " oNormal = p3d_NormalMatrix * normalize(p3d_Normal);\n"
52 " vec4 cs_position = p3d_ModelViewMatrix * p3d_Vertex;\n"
53 " distToCamera = -cs_position.z;\n"
56 const std::string SHADER_VERT_NORMAL_AND_DEPTH_OBJECT =
58 "in vec3 p3d_Normal;\n"
59 "in vec4 p3d_Vertex;\n"
60 "uniform mat4 p3d_ModelViewMatrix;\n"
61 "uniform mat4 p3d_ModelViewProjectionMatrix;\n"
63 "out float distToCamera;\n"
66 " gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;\n"
67 " oNormal = vec3(p3d_Normal.x, -p3d_Normal.z, p3d_Normal.y);\n"
68 " vec4 cs_position = p3d_ModelViewMatrix * p3d_Vertex;\n"
69 " distToCamera = -cs_position.z;\n"
72 const std::string SHADER_FRAG_NORMAL_AND_DEPTH =
75 "in float distToCamera;\n"
76 "out vec4 p3d_FragData;\n"
79 " p3d_FragData.bgra = vec4(normalize(oNormal), distToCamera);\n"
85 case vpPanda3DGeometryRenderer::vpRenderType::OBJECT_NORMALS:
86 return "normals-world";
87 case vpPanda3DGeometryRenderer::vpRenderType::CAMERA_NORMALS:
88 return "normals-camera";
101 shader = Shader::make(Shader::ShaderLanguage::SL_GLSL,
102 SHADER_VERT_NORMAL_AND_DEPTH_OBJECT,
103 SHADER_FRAG_NORMAL_AND_DEPTH);
106 shader = Shader::make(Shader::ShaderLanguage::SL_GLSL,
107 SHADER_VERT_NORMAL_AND_DEPTH_CAMERA,
108 SHADER_FRAG_NORMAL_AND_DEPTH);
118 FrameBufferProperties fbp;
119 fbp.set_rgb_color(
true);
120 fbp.set_float_depth(
false);
121 fbp.set_float_color(
true);
122 fbp.set_depth_bits(16);
123 fbp.set_rgba_bits(32, 32, 32, 32);
125 WindowProperties win_prop;
128 int flags = GraphicsPipe::BF_refuse_window | GraphicsPipe::BF_resizeable | GraphicsPipe::BF_refuse_parasite;
129 GraphicsOutput *windowOutput =
m_window->get_graphics_output();
130 GraphicsEngine *engine = windowOutput->get_engine();
131 GraphicsPipe *pipe = windowOutput->get_pipe();
133 m_normalDepthBuffer = engine->make_output(pipe, renderTypeToName(m_renderType),
m_renderOrder, fbp, win_prop, flags,
134 windowOutput->get_gsg(), windowOutput);
136 if (m_normalDepthBuffer ==
nullptr) {
142 m_buffers.push_back(m_normalDepthBuffer);
143 m_normalDepthTexture =
new Texture();
144 m_normalDepthBuffer->set_inverted(windowOutput->get_gsg()->get_copy_texture_inverted());
145 fbp.setup_color_texture(m_normalDepthTexture);
146 m_normalDepthTexture->set_format(Texture::F_rgba32);
147 m_normalDepthBuffer->add_render_texture(m_normalDepthTexture, GraphicsOutput::RenderTextureMode::RTM_bind_or_copy, GraphicsOutput::RenderTexturePlane::RTP_color);
148 m_normalDepthBuffer->set_clear_color(LColor(0.f));
149 m_normalDepthBuffer->set_clear_color_active(
true);
150 DisplayRegion *region = m_normalDepthBuffer->make_display_region();
151 if (region ==
nullptr) {
155 region->set_clear_color(LColor(0.f));
160 normals.
resize(m_normalDepthTexture->get_y_size(), m_normalDepthTexture->get_x_size());
161 depth.
resize(m_normalDepthTexture->get_y_size(), m_normalDepthTexture->get_x_size());
162 if (m_normalDepthTexture->get_component_type() != Texture::T_float) {
166 int rowIncrement = normals.
getWidth() * 4;
167 float *data = (
float *)(&(m_normalDepthTexture->get_ram_image().front()));
168 data = data + rowIncrement * (normals.
getHeight() - 1);
169 rowIncrement = -rowIncrement;
171 for (
unsigned int i = 0; i < normals.
getHeight(); ++i) {
172 vpRGBf *normalRow = normals[i];
173 float *depthRow = depth[i];
174 for (
unsigned int j = 0; j < normals.
getWidth(); ++j) {
175 normalRow[j].
R = (data[j * 4]);
176 normalRow[j].
G = (data[j * 4 + 1]);
177 normalRow[j].
B = (data[j * 4 + 2]);
178 depthRow[j] = (data[j * 4 + 3]);
180 data += rowIncrement;
191 const unsigned top =
static_cast<unsigned int>(std::max(0.0, bb.
getTop()));
192 const unsigned left =
static_cast<unsigned int>(std::max(0.0, bb.
getLeft()));
193 const unsigned numComponents = m_normalDepthTexture->get_num_components();
195 const float *data = (
float *)(&(m_normalDepthTexture->get_ram_image().front()));
198 if (numComponents != 4) {
202 const float *
const rowData = data - i * rowIncrement;
203 vpRGBf *normalRow = normals[top + i];
204 float *depthRow = depth[top + i];
207 normalRow[left + j].
R = (rowData[j * 4]);
208 normalRow[left + j].
G = (rowData[j * 4 + 1]);
209 normalRow[left + j].
B = (rowData[j * 4 + 2]);
210 depthRow[left + j] = (rowData[j * 4 + 3]);
217 normals.
resize(m_normalDepthTexture->get_y_size(), m_normalDepthTexture->get_x_size());
218 if (m_normalDepthTexture->get_component_type() != Texture::T_float) {
222 int rowIncrement = normals.
getWidth() * 4;
223 float *data = (
float *)(&(m_normalDepthTexture->get_ram_image().front()));
224 data = data + rowIncrement * (normals.
getHeight() - 1);
225 rowIncrement = -rowIncrement;
226 for (
unsigned int i = 0; i < normals.
getHeight(); ++i) {
227 vpRGBf *normalRow = normals[i];
228 for (
unsigned int j = 0; j < normals.
getWidth(); ++j) {
229 normalRow[j].
R = (data[j * 4]);
230 normalRow[j].
G = (data[j * 4 + 1]);
231 normalRow[j].
B = (data[j * 4 + 2]);
233 data += rowIncrement;
239 depth.
resize(m_normalDepthTexture->get_y_size(), m_normalDepthTexture->get_x_size());
240 if (m_normalDepthTexture->get_component_type() != Texture::T_float) {
244 int rowIncrement = depth.
getWidth() * 4;
245 float *data = (
float *)(&(m_normalDepthTexture->get_ram_image().front()));
246 data = data + rowIncrement * (depth.
getHeight() - 1);
247 rowIncrement = -rowIncrement;
249 for (
unsigned int i = 0; i < depth.
getHeight(); ++i) {
250 float *depthRow = depth[i];
251 for (
unsigned int j = 0; j < depth.
getWidth(); ++j) {
252 depthRow[j] = (data[j * 4 + 3]);
254 data += rowIncrement;
260 #elif !defined(VISP_BUILD_SHARED_LIBS)
262 void dummy_vpPanda3DGeometryRenderer() { };
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
@ dimensionError
Bad dimension.
Definition of the vpImage class member functions.
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getHeight() const
Base class for a panda3D renderer. This class handles basic functionalities, such as loading object,...
NodePath m_renderRoot
Rendering parameters.
std::string m_name
Inverse of VISP_T_PANDA.
PointerTo< WindowFramework > m_window
Pointer to the active panda framework.
int m_renderOrder
name of the renderer
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.
void getRender(vpImage< vpRGBf > &colorData, vpImage< float > &depth) const
Get render results into ViSP readable structures.
void setupScene() VP_OVERRIDE
Initialize the scene for this specific renderer.
void setupRenderTarget() VP_OVERRIDE
Initialize buffers and other objects that are required to save the render.
vpPanda3DGeometryRenderer(vpRenderType renderType)
@ CAMERA_NORMALS
Surface normals in the object frame.
unsigned int getImageWidth() const
unsigned int getImageHeight() const
Defines a rectangle in the plane.