From 022923437b92ae69a8b7cc6360ab160107c2c853 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Thu, 25 Jul 2024 20:34:48 +0000 Subject: [PATCH] avoid extra copy in depth camera Signed-off-by: Ian Chen --- ogre2/src/Ogre2DepthCamera.cc | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/ogre2/src/Ogre2DepthCamera.cc b/ogre2/src/Ogre2DepthCamera.cc index db9ad5d99..de756e211 100644 --- a/ogre2/src/Ogre2DepthCamera.cc +++ b/ogre2/src/Ogre2DepthCamera.cc @@ -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; @@ -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; @@ -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) @@ -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 @@ -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(&color); // unsigned int r = *rgba >> 24 & 0xFF; @@ -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; // }