Skip to content

Commit

Permalink
Add texture information debug print, Try and reparse uint texture dat…
Browse files Browse the repository at this point in the history
…a when using tinydisplay (not working...)
  • Loading branch information
SamFlt committed Apr 24, 2024
1 parent 0089620 commit d61af18
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
4 changes: 0 additions & 4 deletions modules/ar/include/visp3/ar/vpPanda3DLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down Expand Up @@ -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;
}
Expand Down
75 changes: 51 additions & 24 deletions modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -180,32 +177,62 @@ void vpPanda3DGeometryRenderer::getRender(vpImage<vpRGBf> &normals, vpImage<floa
{
normals.resize(m_normalDepthTexture->get_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<float>(data[i * 4]) / 127.5f - 1.0);
normals.bitmap[i].G = (static_cast<float>(data[i * 4 + 1]) / 127.5f - 1.0);
normals.bitmap[i].R = (static_cast<float>(data[i * 4 + 2]) / 127.5f - 1.0);
depth.bitmap[i] = ((static_cast<float>(data[i * 4 + 3])));
}
}
//#pragma omp parallel for simd
}

void vpPanda3DGeometryRenderer::getRender(vpImage<vpRGBf> &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<float>(data[i * 4]) / 127.5f - 1.0);
normals.bitmap[i].G = (static_cast<float>(data[i * 4 + 1]) / 127.5f - 1.0);
normals.bitmap[i].R = (static_cast<float>(data[i * 4 + 2]) / 127.5f - 1.0);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions tutorial/ar/tutorial-panda3d-renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d61af18

Please sign in to comment.