diff --git a/modules/ar/include/visp3/ar/vpPanda3DLight.h b/modules/ar/include/visp3/ar/vpPanda3DLight.h index 729ae03fab..2362549acc 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DLight.h +++ b/modules/ar/include/visp3/ar/vpPanda3DLight.h @@ -157,10 +157,6 @@ class VISP_EXPORT vpPanda3DPointLight : public vpPanda3DLight NodePath np = scene.attach_new_node(light); vpColVector posPanda = vpPanda3DBaseRenderer::vispPointToPanda(m_position); np.set_pos(posPanda[0], posPanda[1], posPanda[2]); - std::cout << "posPanda = " << posPanda << std::endl; - std::cout << np.get_pos() << std::endl; - std::cout << scene.get_mat() << std::endl; - std::cout << np.get_mat(scene) << std::endl; scene.set_light(np); } diff --git a/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp b/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp index a65de360cf..9799c6590f 100644 --- a/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp +++ b/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp @@ -45,7 +45,6 @@ const vpHomogeneousMatrix vpPanda3DBaseRenderer::PANDA_T_VISP(vpPanda3DBaseRende void vpPanda3DBaseRenderer::initFramework(bool showWindow) { - load_prc_file_data("", "load-display p3tinydisplay"); if (m_framework.use_count() > 0) { throw vpException(vpException::notImplementedError, "Panda3D renderer: Reinitializing is not supported!"); @@ -209,7 +208,6 @@ void vpPanda3DBaseRenderer::setForcedInvertTextures(bool invert) vpColVector vpPanda3DBaseRenderer::vispPointToPanda(const vpColVector &point) { vpColVector pandaPos = PANDA_T_VISP * point; - std::cout <<"PANDA POS = " << pandaPos << std::endl; pandaPos /= pandaPos[3]; return pandaPos; } diff --git a/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp b/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp index ec367e4053..2c66339c87 100644 --- a/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp +++ b/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp @@ -142,16 +142,14 @@ void vpPanda3DGeometryRenderer::setupRenderTarget() WindowProperties win_prop; win_prop.set_size(m_renderParameters.getImageWidth(), m_renderParameters.getImageHeight()); - // Don't open a window - force it to be an offscreen buffer. int flags = GraphicsPipe::BF_refuse_window | GraphicsPipe::BF_resizeable; GraphicsOutput *windowOutput = m_window->get_graphics_output(); GraphicsEngine *engine = windowOutput->get_engine(); GraphicsPipe *pipe = windowOutput->get_pipe(); - m_normalDepthBuffer = engine->make_output(pipe, renderTypeToName(m_renderType), 0, fbp, win_prop, flags, - windowOutput->get_gsg(), - windowOutput); + m_normalDepthBuffer = engine->make_output(pipe, renderTypeToName(m_renderType), -100, fbp, win_prop, flags, + windowOutput->get_gsg(), windowOutput); if (m_normalDepthBuffer == nullptr) { throw vpException(vpException::fatalError, "Could not create geometry info buffer"); @@ -162,9 +160,8 @@ void vpPanda3DGeometryRenderer::setupRenderTarget() m_buffers.push_back(m_normalDepthBuffer); m_normalDepthTexture = new Texture(); m_normalDepthBuffer->set_inverted(windowOutput->get_gsg()->get_copy_texture_inverted()); - // fbp.setup_color_texture(m_normalDepthTexture); - // m_normalDepthTexture->set_format(Texture::F_rgba32); - + fbp.setup_color_texture(m_normalDepthTexture); + m_normalDepthTexture->set_format(Texture::F_rgba32); m_normalDepthBuffer->add_render_texture(m_normalDepthTexture, GraphicsOutput::RenderTextureMode::RTM_copy_ram); m_normalDepthBuffer->set_clear_color(LColor(0.f)); m_normalDepthBuffer->set_clear_color_active(true); @@ -180,32 +177,62 @@ void vpPanda3DGeometryRenderer::getRender(vpImage &normals, vpImageget_y_size(), m_normalDepthTexture->get_x_size()); depth.resize(m_normalDepthTexture->get_y_size(), m_normalDepthTexture->get_x_size()); - unsigned expectedSize = m_normalDepthTexture->get_y_size() * m_normalDepthTexture->get_x_size() * sizeof(float) * 4; - unsigned actualSize = m_normalDepthTexture->get_ram_image_size(); - if (expectedSize != actualSize) { - throw vpException(vpException::fatalError, "Expected %d bytes, but got %d bytes", expectedSize, actualSize); - } - float *data = (float *)(&(m_normalDepthTexture->get_ram_image().front())); + // unsigned expectedSize = m_normalDepthTexture->get_y_size() * m_normalDepthTexture->get_x_size() * sizeof(float) * 4; + // unsigned actualSize = m_normalDepthTexture->get_ram_image_size(); + // if (expectedSize != actualSize) { + // throw vpException(vpException::fatalError, "Expected %d bytes, but got %d bytes", expectedSize, actualSize); + // } + std::stringstream ss; + ss << "Texture info:" << std::endl; + ss << "Has ram image: " << m_normalDepthTexture->has_ram_image() << std::endl; + ss << "Size (H x W): " << m_normalDepthTexture->get_y_size() << " x " << m_normalDepthTexture->get_x_size() << std::endl; + ss << "Number of channels: " << m_normalDepthTexture->get_num_components() << std::endl; + ss << "Bytes per channel: " << m_normalDepthTexture->get_component_width() << std::endl; + ss << "Channel type: " << m_normalDepthTexture->get_component_type() << std::endl; + std::cout << ss.str() << std::endl; + + if (m_normalDepthTexture->get_component_type() == Texture::T_float) { + float *data = (float *)(&(m_normalDepthTexture->get_ram_image().front())); + for (unsigned int i = 0; i < normals.getSize(); ++i) { + normals.bitmap[i].B = (data[i * 4]); + normals.bitmap[i].G = (data[i * 4 + 1]); + normals.bitmap[i].R = (data[i * 4 + 2]); + depth.bitmap[i] = (data[i * 4 + 3]); + } -//#pragma omp parallel for simd - for (unsigned int i = 0; i < normals.getSize(); ++i) { - normals.bitmap[i].B = (data[i * 4]); - normals.bitmap[i].G = (data[i * 4 + 1]); - normals.bitmap[i].R = (data[i * 4 + 2]); - depth.bitmap[i] = (data[i * 4 + 3]); } + else if (m_normalDepthTexture->get_component_type() == Texture::T_unsigned_byte) { + unsigned char *data = (unsigned char *)(&(m_normalDepthTexture->get_ram_image().front())); + for (unsigned int i = 0; i < normals.getSize(); ++i) { + normals.bitmap[i].B = (static_cast(data[i * 4]) / 127.5f - 1.0); + normals.bitmap[i].G = (static_cast(data[i * 4 + 1]) / 127.5f - 1.0); + normals.bitmap[i].R = (static_cast(data[i * 4 + 2]) / 127.5f - 1.0); + depth.bitmap[i] = ((static_cast(data[i * 4 + 3]))); + } + } +//#pragma omp parallel for simd } void vpPanda3DGeometryRenderer::getRender(vpImage &normals) const { normals.resize(m_normalDepthTexture->get_y_size(), m_normalDepthTexture->get_x_size()); - float *data = (float *)(&(m_normalDepthTexture->get_ram_image().front())); //#pragma omp parallel for simd - for (unsigned int i = 0; i < normals.getSize(); ++i) { - normals.bitmap[i].B = (data[i * 4]); - normals.bitmap[i].G = (data[i * 4 + 1]); - normals.bitmap[i].R = (data[i * 4 + 2]); + if (m_normalDepthTexture->get_component_type() == Texture::T_float) { + float *data = (float *)(&(m_normalDepthTexture->get_ram_image().front())); + for (unsigned int i = 0; i < normals.getSize(); ++i) { + normals.bitmap[i].B = (data[i * 4]); + normals.bitmap[i].G = (data[i * 4 + 1]); + normals.bitmap[i].R = (data[i * 4 + 2]); + } + } + else if (m_normalDepthTexture->get_component_type() == Texture::T_unsigned_byte) { + unsigned char *data = (unsigned char *)(&(m_normalDepthTexture->get_ram_image().front())); + for (unsigned int i = 0; i < normals.getSize(); ++i) { + normals.bitmap[i].B = (static_cast(data[i * 4]) / 127.5f - 1.0); + normals.bitmap[i].G = (static_cast(data[i * 4 + 1]) / 127.5f - 1.0); + normals.bitmap[i].R = (static_cast(data[i * 4 + 2]) / 127.5f - 1.0); + } } } diff --git a/tutorial/ar/tutorial-panda3d-renderer.cpp b/tutorial/ar/tutorial-panda3d-renderer.cpp index 1da45b90db..54b11d9649 100644 --- a/tutorial/ar/tutorial-panda3d-renderer.cpp +++ b/tutorial/ar/tutorial-panda3d-renderer.cpp @@ -99,7 +99,7 @@ int main(int argc, const char **argv) } std::cout << "Initializing Panda3D rendering framework" << std::endl; - renderer.initFramework(true); + renderer.initFramework(false); std::cout << "Loading object " << modelPath << std::endl; NodePath object = renderer.loadObject(objectName, modelPath); @@ -152,7 +152,7 @@ int main(int argc, const char **argv) rgbRenderer->computeNearAndFarPlanesFromNode(objectName, near, far); // renderParams.setClippingDistance(near, far); renderer.setRenderParameters(renderParams); - std::cout << "Update clipping plane took " << vpTime::measureTimeMs() - beforeComputeBB << std::endl; + //std::cout << "Update clipping plane took " << vpTime::measureTimeMs() - beforeComputeBB << std::endl; const double beforeRender = vpTime::measureTimeMs(); renderer.renderFrame();