Skip to content

Commit

Permalink
avoid extra copy in depth camera
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Jul 25, 2024
1 parent dab42ce commit 0229234
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions ogre2/src/Ogre2DepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ class Ogre2DepthGaussianNoisePass : public Ogre2GaussianNoisePass
/// \brief Private data for the Ogre2DepthCamera class
class gz::rendering::Ogre2DepthCameraPrivate
{
/// \brief The depth buffer
/// \brief The depth buffer - also the outgoing point cloud data used
/// by newRgbPointCloud event
public: float *depthBuffer = nullptr;

/// \brief Outgoing depth data, used by newDepthFrame event.
public: float *depthImage = nullptr;

/// \brief Outgoing point cloud data, used by newRgbPointCloud event.
public: float *pointCloudImage = nullptr;

/// \brief maximum value used for data outside sensor range
public: float dataMaxVal = gz::math::INF_D;

Expand Down Expand Up @@ -316,12 +314,6 @@ void Ogre2DepthCamera::Destroy()
this->dataPtr->depthImage = nullptr;
}

if (this->dataPtr->pointCloudImage)
{
delete [] this->dataPtr->pointCloudImage;
this->dataPtr->pointCloudImage = nullptr;
}

if (!this->ogreCamera)
return;

Expand Down Expand Up @@ -1195,10 +1187,6 @@ void Ogre2DepthCamera::PostRender()
{
this->dataPtr->depthImage = new float[len];
}
if (!this->dataPtr->pointCloudImage)
{
this->dataPtr->pointCloudImage = new float[len * channelCount];
}

// fill depth data
for (unsigned int i = 0; i < height; ++i)
Expand All @@ -1216,10 +1204,8 @@ void Ogre2DepthCamera::PostRender()
// point cloud data
if (this->dataPtr->newRgbPointCloud.ConnectionCount() > 0u)
{
memcpy(this->dataPtr->pointCloudImage,
this->dataPtr->depthBuffer, len * channelCount * sizeof(float));
this->dataPtr->newRgbPointCloud(
this->dataPtr->pointCloudImage, width, height, channelCount,
this->dataPtr->depthBuffer, width, height, channelCount,
"PF_FLOAT32_RGBA");

// Uncomment to debug color output
Expand All @@ -1229,7 +1215,7 @@ void Ogre2DepthCamera::PostRender()
// for (unsigned int j = 0; j < width; ++j)
// {
// float color =
// this->dataPtr->pointCloudImage[step + j*channelCount + 3];
// this->dataPtr->depthBuffer[step + j*channelCount + 3];
// // unpack rgb data
// uint32_t *rgba = reinterpret_cast<uint32_t *>(&color);
// unsigned int r = *rgba >> 24 & 0xFF;
Expand All @@ -1246,9 +1232,9 @@ void Ogre2DepthCamera::PostRender()
// {
// for (unsigned int j = 0; j < width; ++j)
// {
// gzdbg << "[" << this->dataPtr->pointCloudImage[i*width*4+j*4] << "]"
// << "[" << this->dataPtr->pointCloudImage[i*width*4+j*4+1] << "]"
// << "[" << this->dataPtr->pointCloudImage[i*width*4+j*4+2] << "],";
// gzdbg << "[" << this->dataPtr->depthBuffer[i*width*4+j*4] << "]"
// << "[" << this->dataPtr->depthBuffer[i*width*4+j*4+1] << "]"
// << "[" << this->dataPtr->depthBuffer[i*width*4+j*4+2] << "],";
// }
// gzdbg << std::endl;
// }
Expand Down

0 comments on commit 0229234

Please sign in to comment.